import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
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(
(24, 24), (0, 0), *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((40, 40)) # 이미지를 로드할 수 도 있다.
surf.fill((120, 50, 50)) # 이미지를 로드하는 경우 불필요한 코드
surfaceCursor = pygame.cursors.Cursor((20, 20), 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((0, 75, 30))
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()