comparison gamelib/cursor.py @ 139:a5972444ad1e

Improve cursor state handling, disable highlights on modal dialogs
author Stefano Rivera <stefano@rivera.za.net>
date Tue, 24 Aug 2010 22:02:22 +0200
parents b43599b7f8a2
children a1162ea4ad67
comparison
equal deleted inserted replaced
138:0fe0a91c4296 139:a5972444ad1e
25 self.image = self.plain_image 25 self.image = self.plain_image
26 self.rect = self.image.get_rect() 26 self.rect = self.image.get_rect()
27 self.highlight = pygame.Surface(self.rect.size) 27 self.highlight = pygame.Surface(self.rect.size)
28 color = pygame.color.Color(255, 100, 100, 0) 28 color = pygame.color.Color(255, 100, 100, 0)
29 self.highlight.fill(color) 29 self.highlight.fill(color)
30 self.highlighted = False
30 31
31 def update(self): 32 def update(self):
32 pos = pygame.mouse.get_pos() 33 pos = pygame.mouse.get_pos()
33 self.rect.left = pos[0] - self.pointer_x 34 self.rect.left = pos[0] - self.pointer_x
34 self.rect.top = pos[1] - self.pointer_y 35 self.rect.top = pos[1] - self.pointer_y
35 36
36 def set_highlight(self, enable): 37 def set_highlight(self, enable):
37 self.image = self.plain_image.copy() 38 if enable != self.highlighted:
38 if enable: 39 self.highlighted = enable
39 self.image.blit(self.highlight, self.highlight.get_rect(), None, pygame.BLEND_MULT) 40 self.image = self.plain_image.copy()
41 if enable:
42 self.image.blit(self.highlight, self.highlight.get_rect(),
43 None, pygame.BLEND_MULT)
40 44
41 45
42 HAND = CursorSprite('hand.png', 12, 0) 46 HAND = CursorSprite('hand.png', 12, 0)
43 47
44 48
49 53
50 def __init__(self, *args, **kwargs): 54 def __init__(self, *args, **kwargs):
51 Widget.__init__(self, *args, **kwargs) 55 Widget.__init__(self, *args, **kwargs)
52 self._cursor_group = RenderUpdates() 56 self._cursor_group = RenderUpdates()
53 self._loaded_cursor = None 57 self._loaded_cursor = None
58
59 def enter_screen(self):
60 pygame.mouse.set_visible(0)
61
62 def leave_screen(self):
63 pygame.mouse.set_visible(1)
54 64
55 def draw_all(self, _surface): 65 def draw_all(self, _surface):
56 Widget.draw_all(self, _surface) 66 Widget.draw_all(self, _surface)
57 surface = self.get_root().surface 67 surface = self.get_root().surface
58 if self.cursor != self._loaded_cursor: 68 if self.cursor != self._loaded_cursor: