cursors.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env python
  2. import pygame
  3. arrow = ( "xX ",
  4. "X.X ",
  5. "X..X ",
  6. "X...X ",
  7. "X....X ",
  8. "X.....X ",
  9. "X......X ",
  10. "X.......X ",
  11. "X........X ",
  12. "X.........X ",
  13. "X......XXXXX ",
  14. "X...X..X ",
  15. "X..XX..X ",
  16. "X.X XX..X ",
  17. "XX X..X ",
  18. "X X..X ",
  19. " X..X ",
  20. " X..X ",
  21. " X..X ",
  22. " XX ",
  23. " ",
  24. " ",
  25. " ",
  26. " ")
  27. no = (" ",
  28. " ",
  29. " XXXXXX ",
  30. " XX......XX ",
  31. " X..........X ",
  32. " X....XXXX....X ",
  33. " X...XX XX...X ",
  34. " X.....X X...X ",
  35. " X..X...X X..X ",
  36. " X...XX...X X...X ",
  37. " X..X X...X X..X ",
  38. " X..X X...X X..X ",
  39. " X..X X.,.X X..X ",
  40. " X..X X...X X..X ",
  41. " X...X X...XX...X ",
  42. " X..X X...X..X ",
  43. " X...X X.....X ",
  44. " X...XX X...X ",
  45. " X....XXXXX...X ",
  46. " X..........X ",
  47. " XX......XX ",
  48. " XXXXXX ",
  49. " ",
  50. " ",
  51. )
  52. def TestCursor(arrow):
  53. hotspot = None
  54. for y in range(len(arrow)):
  55. for x in range(len(arrow[y])):
  56. if arrow[y][x] in ['x', ',', 'O']:
  57. hotspot = x,y
  58. break
  59. if hotspot != None:
  60. break
  61. if hotspot == None:
  62. raise Exception("No hotspot specified for cursor '%s'!" %
  63. cursorname)
  64. s2 = []
  65. for line in arrow:
  66. s2.append(line.replace('x', 'X').replace(',', '.').replace('O',
  67. 'o'))
  68. cursor, mask = pygame.cursors.compile(s2, 'X', '.', 'o')
  69. size = len(arrow[0]), len(arrow)
  70. pygame.mouse.set_cursor(size, hotspot, cursor, mask)
  71. def main():
  72. pygame.init()
  73. pygame.font.init()
  74. font = pygame.font.Font(None, 24)
  75. bg = pygame.display.set_mode((800, 600), 0, 24)
  76. bg.fill((255,255,255))
  77. bg.blit(font.render("Click to advance", 1, (0, 0, 0)), (0, 0))
  78. pygame.display.update()
  79. for cursor in [no, arrow]:
  80. TestCursor(cursor)
  81. going = True
  82. while going:
  83. pygame.event.pump()
  84. for e in pygame.event.get():
  85. if e.type == pygame.MOUSEBUTTONDOWN:
  86. going = False
  87. pygame.quit()
  88. if __name__ == '__main__':
  89. main()