annotate gamelib/hand.py @ 70:213e47dea4d0

Funkier cursor handling
author Neil Muller <neil@dip.sun.ac.za>
date Mon, 23 Aug 2010 20:54:04 +0200
parents 4f9d412d83db
children c76f2fad2af5
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
57
4f9d412d83db Use hand icon from openclipart
Neil Muller <neil@dip.sun.ac.za>
parents: 49
diff changeset
3 from constants import BUTTON_SIZE
70
213e47dea4d0 Funkier cursor handling
Neil Muller <neil@dip.sun.ac.za>
parents: 57
diff changeset
4 from cursor import CursorWidget
57
4f9d412d83db Use hand icon from openclipart
Neil Muller <neil@dip.sun.ac.za>
parents: 49
diff changeset
5
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
6 from albow.controls import ImageButton
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
7 from albow.resource import get_image
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
8 from albow.utils import frame_rect
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
9 from pygame.color import Color
57
4f9d412d83db Use hand icon from openclipart
Neil Muller <neil@dip.sun.ac.za>
parents: 49
diff changeset
10 from pygame.rect import Rect
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
11
70
213e47dea4d0 Funkier cursor handling
Neil Muller <neil@dip.sun.ac.za>
parents: 57
diff changeset
12 class HandButton(ImageButton, CursorWidget):
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
13 """The fancy hand button for the widget"""
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
14
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
15 sel_colour = Color('red')
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
16 sel_width = 2
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
17
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
18 def __init__(self, action):
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
19 # FIXME: Yes, please.
57
4f9d412d83db Use hand icon from openclipart
Neil Muller <neil@dip.sun.ac.za>
parents: 49
diff changeset
20 this_image = get_image('items', 'hand.png')
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
21 ImageButton.__init__(self, image=this_image, action=action)
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
22 self.selected = False # Flag if we're selected
57
4f9d412d83db Use hand icon from openclipart
Neil Muller <neil@dip.sun.ac.za>
parents: 49
diff changeset
23 self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE))
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
24
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
25 def draw(self, surface):
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
26 """Draw the widget"""
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
27 ImageButton.draw(self, surface)
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
28 if self.selected:
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
29 rect = surface.get_rect().inflate(-self.sel_width, -self.sel_width)
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
30 frame_rect(surface, self.sel_colour, rect, self.sel_width)
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
31
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
32 def toggle_selected(self):
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
33 self.selected = not self.selected
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
34
44
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
35 def unselect(self):
79062a225703 Correct out-by-one indentation error. :)
Simon Cross <simon@simonx>
parents: 36
diff changeset
36 self.selected = False
36
31a431f795e1 Add a hand button placeholder
Neil Muller <neil@dip.sun.ac.za>
parents:
diff changeset
37