Mercurial > pyntnclick
comparison gamelib/cursor.py @ 70:213e47dea4d0
Funkier cursor handling
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Mon, 23 Aug 2010 20:54:04 +0200 |
parents | 05346a412b55 |
children | c76f2fad2af5 |
comparison
equal
deleted
inserted
replaced
69:d4bbb26099cc | 70:213e47dea4d0 |
---|---|
1 # cursor.py | 1 # cursor.py |
2 # Copyright Boomslang team, 2010 (see COPYING File) | 2 # Copyright Boomslang team, 2010 (see COPYING File) |
3 # Sprite Cursor | 3 # Sprite Cursor |
4 | 4 |
5 from albow.screen import Screen | 5 from albow.screen import Screen |
6 from albow.widget import Widget | |
6 from albow.resource import get_image | 7 from albow.resource import get_image |
7 import pygame.mouse as mouse | 8 import pygame.mouse as mouse |
8 from pygame.sprite import Sprite, RenderUpdates | 9 from pygame.sprite import Sprite, RenderUpdates |
10 import pygame.cursors | |
11 import pygame.mouse | |
12 | |
13 # FIXME: make this a all transparent cursor | |
14 BLANK_CURSOR=pygame.cursors.broken_x | |
9 | 15 |
10 class CursorSprite(Sprite): | 16 class CursorSprite(Sprite): |
11 "A Sprite that follows the Cursor" | 17 "A Sprite that follows the Cursor" |
12 | 18 |
13 def __init__(self, filename): | 19 def __init__(self, filename): |
16 self.rect = self.image.get_rect() | 22 self.rect = self.image.get_rect() |
17 | 23 |
18 def update(self): | 24 def update(self): |
19 self.rect.midtop = mouse.get_pos() | 25 self.rect.midtop = mouse.get_pos() |
20 | 26 |
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 | |
21 | 36 |
22 class CursorSpriteScreen(Screen): | 37 class CursorSpriteScreen(Screen): |
23 "A Screen with a CursorSprite" | 38 "A Screen with a CursorSprite" |
24 | 39 |
25 def __init__(self, shell): | 40 def __init__(self, shell): |
27 | 42 |
28 sprite = CursorSprite('hand') | 43 sprite = CursorSprite('hand') |
29 self.cursor_group = RenderUpdates(sprite) | 44 self.cursor_group = RenderUpdates(sprite) |
30 | 45 |
31 def draw(self, surface): | 46 def draw(self, surface): |
32 self.cursor_group.update() | 47 if self.get_cursor(None) == pygame.mouse.get_cursor(): |
33 self.cursor_group.draw(surface) | 48 self.cursor_group.update() |
49 self.cursor_group.draw(surface) | |
34 | 50 |
35 def mouse_move(self, event): | 51 def mouse_move(self, event): |
36 self.invalidate() | 52 self.invalidate() |
53 | |
54 def get_cursor(self, event): | |
55 return BLANK_CURSOR |