annotate gamelib/hand.py @ 41:ad6f56bfa8b7

Cryo door, titanium leg and some interaction prototypes.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 23 Aug 2010 00:49:22 +0200
parents 31a431f795e1
children 79062a225703
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
1 # Button for the hand image
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
2
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
3 from albow.controls import ImageButton
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
4 from albow.resource import get_image
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
5 from albow.utils import frame_rect
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
6 from pygame.color import Color
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
7
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
8 class HandButton(ImageButton):
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
9 """The fancy hand button for the widget"""
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
10
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
11 sel_colour = Color('red')
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
12 sel_width = 2
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
13
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
14 def __init__(self, action):
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
15 # FIXME: Yes, please.
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
16 this_image = get_image('items', 'square.png')
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
17 ImageButton.__init__(self, image=this_image, action=action)
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
18 self.selected = False # Flag if we're selected
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
19
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
20 def draw(self, surface):
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
21 """Draw the widget"""
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
22 print 'drawing widget', self.selected
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
23 ImageButton.draw(self, surface)
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
24 if self.selected:
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
25 rect = surface.get_rect().inflate(-self.sel_width, -self.sel_width)
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
26 frame_rect(surface, self.sel_colour, rect, self.sel_width)
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
27
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
28 def toggle_selected(self):
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
29 self.selected = not self.selected
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
30
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
31 def unselect(self):
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
32 self.selected = False
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
33