File: cursors.py

package info (click to toggle)
pygame 1.9.4.post1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,412 kB
  • sloc: ansic: 54,632; python: 28,791; objc: 334; php: 92; sh: 76; makefile: 36; cpp: 25
file content (99 lines) | stat: -rw-r--r-- 3,062 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python

import pygame


arrow = ( "xX                      ",
          "X.X                     ",
          "X..X                    ",
          "X...X                   ",
          "X....X                  ",
          "X.....X                 ",
          "X......X                ",
          "X.......X               ",
          "X........X              ",
          "X.........X             ",
          "X......XXXXX            ",
          "X...X..X                ",
          "X..XX..X                ",
          "X.X XX..X               ",
          "XX   X..X               ",
          "X     X..X              ",
          "      X..X              ",
          "       X..X             ",
          "       X..X             ",
          "        XX              ",
          "                        ",
          "                        ",
          "                        ",
          "                        ")


no = ("                        ",
         "                        ",
         "         XXXXXX         ",
         "       XX......XX       ",
         "      X..........X      ",
         "     X....XXXX....X     ",
         "    X...XX    XX...X    ",
         "   X.....X      X...X   ",
         "   X..X...X      X..X   ",
         "  X...XX...X     X...X  ",
         "  X..X  X...X     X..X  ",
         "  X..X   X...X    X..X  ",
         "  X..X    X.,.X   X..X  ",
         "  X..X     X...X  X..X  ",
         "  X...X     X...XX...X  ",
         "   X..X      X...X..X   ",
         "   X...X      X.....X   ",
         "    X...XX     X...X    ",
         "     X....XXXXX...X     ",
         "      X..........X      ",
         "       XX......XX       ",
         "         XXXXXX         ",
         "                        ",
         "                        ",
        )

def TestCursor(arrow):
    hotspot = None
    for y in range(len(arrow)):
        for x in range(len(arrow[y])):
            if arrow[y][x] in ['x', ',', 'O']:
                hotspot = x,y
                break
        if hotspot != None:
            break
    if hotspot == None:
        raise Exception("No hotspot specified for cursor '%s'!" %
cursorname)
    s2 = []
    for line in arrow:
        s2.append(line.replace('x', 'X').replace(',', '.').replace('O',
'o'))
    cursor, mask = pygame.cursors.compile(s2, 'X', '.', 'o')
    size = len(arrow[0]), len(arrow)
    pygame.mouse.set_cursor(size, hotspot, cursor, mask)

def main():
    pygame.init()
    pygame.font.init()
    font = pygame.font.Font(None, 24)
    bg = pygame.display.set_mode((800, 600), 0, 24)
    bg.fill((255,255,255))
    bg.blit(font.render("Click to advance", 1, (0, 0, 0)), (0, 0))
    pygame.display.update()
    for cursor in [no, arrow]:
        TestCursor(cursor)
        going = True
        while going:
            pygame.event.pump()
            for e in pygame.event.get():
                if e.type == pygame.MOUSEBUTTONDOWN:
                    going = False
    pygame.quit()


if __name__ == '__main__':
    main()