반응형

커서를 바꿔보자.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pygame
 
pygame.init()
screen = pygame.display.set_mode((640480))
pygame.display.set_caption("Example code for the cursors module")
 
# 시스템 커서 생성
systemCursor = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_NO)
#pygame.SYSTEM_CURSOR_ARROW       arrow
#pygame.SYSTEM_CURSOR_IBEAM       i-beam
#pygame.SYSTEM_CURSOR_WAIT        wait
#pygame.SYSTEM_CURSOR_CROSSHAIR   crosshair
#pygame.SYSTEM_CURSOR_WAITARROW   small wait cursor
#                                 (or wait if not available)
#pygame.SYSTEM_CURSOR_SIZENWSE    double arrow pointing
#                                 northwest and southeast
#pygame.SYSTEM_CURSOR_SIZENESW    double arrow pointing
#                                 northeast and southwest
#pygame.SYSTEM_CURSOR_SIZEWE      double arrow pointing
#                                 west and east
#pygame.SYSTEM_CURSOR_SIZENS      double arrow pointing
#                                 north and south
#pygame.SYSTEM_CURSOR_SIZEALL     four pointed arrow pointing
#                                 north, south, east, and west
#pygame.SYSTEM_CURSOR_NO          slashed circle or crossbones
#pygame.SYSTEM_CURSOR_HAND        hand
 
# 비트맵 커서 생성.
bitmapCursor1 = pygame.cursors.Cursor(*pygame.cursors.arrow)
#pygame.cursors.arrow
#pygame.cursors.diamond
#pygame.cursors.broken_x
#pygame.cursors.tri_left
#pygame.cursors.tri_right
 
custom_strings = (           # size: 24x24
  "XX                      ",
  "XXX                     ",
  "XXXX                    ",
  "XX.XX                   ",
  "XX..XX                  ",
  "XX...XX                 ",
  "XX    XX                ",
  "XX     XX               ",
  "XX      XX              ",
  "XX       XX             ",
  "XX        XX            ",
  "XX        XXX           ",
  "XX      XXXXX           ",
  "XX XXX..XX              ",
  "XXXX XX..XX             ",
  "XX   XX..XX             ",
  "     XX..XX             ",
  "      XX..XX            ",
  "      XX..XX            ",
  "       XXXX             ",
  "       XX               ",
  "                        ",
  "                        ",
  "                        ")
 
bitmapCursor2 = pygame.cursors.Cursor(
    (2424), (00), *pygame.cursors.compile(custom_strings))
# Cursor클래스 인수: Cursor(size, hotspot, xormasks, andmasks)
# size는 8의 배수. hotspot은 클릭 지점. xormasks와 andmasks는
# pygame.cursors.compile()로 만들 수 있다. compile()에는 직접
# 만든 스트링이나 아래 상수 대입 가능.
#pygame.cursors.thickarrow_strings
#pygame.cursors.sizer_x_strings
#pygame.cursors.sizer_y_strings
#pygame.cursors.sizer_xy_strings
#pygame.cursor.textmarker_strings
 
# Surface 커서 생성.
surf = pygame.Surface((4040)) # 이미지를 로드할 수 도 있다.
surf.fill((1205050))        # 이미지를 로드하는 경우 불필요한 코드
surfaceCursor = pygame.cursors.Cursor((2020), surf)
 
cursors = [systemCursor, bitmapCursor1, bitmapCursor2, surfaceCursor]
cursor_index = 0
 
pygame.mouse.set_cursor(cursors[cursor_index])
 
clock = pygame.time.Clock()
going = True
while going:
    clock.tick(60)
    screen.fill((07530))
    pygame.display.flip()
 
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and
                                        event.key == pygame.K_ESCAPE):
            going = False
 
        # 마우스 버튼이 눌리면 커서를 바꾼다.
        if event.type == pygame.MOUSEBUTTONDOWN:
            cursor_index += 1
            cursor_index %= len(cursors)
            pygame.mouse.set_cursor(cursors[cursor_index])
 
pygame.quit()
 

 

 

마우스를 클릭할 때 마다 커서가 바뀐다.

 

반응형
Posted by J-sean
: