66
|
1 # cursor.py
|
|
2 # Copyright Boomslang team, 2010 (see COPYING File)
|
|
3 # Sprite Cursor
|
|
4
|
|
5 from albow.screen import Screen
|
70
|
6 from albow.widget import Widget
|
66
|
7 from albow.resource import get_image
|
|
8 import pygame.mouse as mouse
|
|
9 from pygame.sprite import Sprite, RenderUpdates
|
70
|
10 import pygame.cursors
|
|
11 import pygame.mouse
|
|
12
|
|
13 # FIXME: make this a all transparent cursor
|
|
14 BLANK_CURSOR=pygame.cursors.broken_x
|
66
|
15
|
|
16 class CursorSprite(Sprite):
|
|
17 "A Sprite that follows the Cursor"
|
|
18
|
|
19 def __init__(self, filename):
|
|
20 Sprite.__init__(self)
|
|
21 self.image = get_image('items', filename + '.png')
|
|
22 self.rect = self.image.get_rect()
|
|
23
|
|
24 def update(self):
|
|
25 self.rect.midtop = mouse.get_pos()
|
|
26
|
70
|
27 class CursorWidget(Widget):
|
|
28 """Mix-in widget to ensure that mouse_move is propogated to parents"""
|
|
29
|
|
30 def mouse_move(self, event):
|
|
31 self.call_parent_handler('mouse_move', event)
|
|
32
|
|
33 def get_cursor(self, event):
|
|
34 return BLANK_CURSOR
|
|
35
|
66
|
36
|
|
37 class CursorSpriteScreen(Screen):
|
|
38 "A Screen with a CursorSprite"
|
|
39
|
|
40 def __init__(self, shell):
|
|
41 Screen.__init__(self, shell)
|
|
42
|
|
43 sprite = CursorSprite('hand')
|
|
44 self.cursor_group = RenderUpdates(sprite)
|
|
45
|
|
46 def draw(self, surface):
|
70
|
47 if self.get_cursor(None) == pygame.mouse.get_cursor():
|
|
48 self.cursor_group.update()
|
|
49 self.cursor_group.draw(surface)
|
66
|
50
|
|
51 def mouse_move(self, event):
|
|
52 self.invalidate()
|
70
|
53
|
|
54 def get_cursor(self, event):
|
|
55 return BLANK_CURSOR
|