comparison gamelib/widgets.py @ 358:760f6a318d2e

Moved some widgets around.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 28 Aug 2010 16:50:37 +0200
parents 92cc50d7ce7a
children 277a7a0c2cea
comparison
equal deleted inserted replaced
357:e5f28bd6d4ce 358:760f6a318d2e
4 """Custom Albow widgets""" 4 """Custom Albow widgets"""
5 5
6 import textwrap 6 import textwrap
7 7
8 import albow.controls 8 import albow.controls
9 from albow.resource import get_font 9 import albow.menu
10 from albow.resource import get_font, get_image
10 from pygame.color import Color 11 from pygame.color import Color
12 from pygame.rect import Rect
11 13
14 from constants import BUTTON_SIZE
12 from cursor import CursorWidget 15 from cursor import CursorWidget
13 16
14 17
15 class BoomLabel(albow.controls.Label): 18 class BoomLabel(albow.controls.Label):
16 19
33 self._draw_all_no_bg(surface) 36 self._draw_all_no_bg(surface)
34 self.bg_color = bg_color 37 self.bg_color = bg_color
35 38
36 def _draw_all_no_bg(self, surface): 39 def _draw_all_no_bg(self, surface):
37 pass 40 pass
41
38 42
39 class BoomButton(BoomLabel): 43 class BoomButton(BoomLabel):
40 44
41 def __init__(self, text, action, screen): 45 def __init__(self, text, action, screen):
42 super(BoomLabel, self).__init__(text, font=get_font(20, 'Vera.ttf')) 46 super(BoomLabel, self).__init__(text, font=get_font(20, 'Vera.ttf'))
82 def mouse_down(self, event): 86 def mouse_down(self, event):
83 self.dismiss() 87 self.dismiss()
84 88
85 def cursor_highlight(self): 89 def cursor_highlight(self):
86 return False 90 return False
91
92
93 class HandButton(albow.controls.Image):
94 """The fancy hand button for the widget"""
95
96 def __init__(self, action):
97 # FIXME: Yes, please.
98 this_image = get_image('items', 'hand.png')
99 albow.controls.Image.__init__(self, image=this_image)
100 self.action = action
101 self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE))
102
103 def mouse_down(self, event):
104 self.action()
105
106
107 class PopupMenuButton(albow.controls.Button):
108
109 def __init__(self, text, action):
110 albow.controls.Button.__init__(self, text, action)
111
112 self.font = get_font(16, 'Vera.ttf')
113 self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE))
114 self.margin = (BUTTON_SIZE - self.font.get_linesize()) / 2
115
116
117 class PopupMenu(albow.menu.Menu, CursorWidget):
118
119 def __init__(self, screen):
120 CursorWidget.__init__(self, screen)
121 self.screen = screen
122 self.shell = screen.shell
123 items = [
124 ('Resume Game', 'hide'),
125 ('Quit Game', 'quit'),
126 ('Exit to Main Menu', 'main_menu'),
127 ]
128 # albow.menu.Menu ignores title string
129 albow.menu.Menu.__init__(self, None, items)
130 self.font = get_font(16, 'Vera.ttf')
131
132 def show_menu(self):
133 """Call present, with the correct position"""
134 item_height = self.font.get_linesize()
135 menu_top = 600 - (len(self.items) * item_height + BUTTON_SIZE)
136 item = self.present(self.shell, (0, menu_top))
137 if item > -1:
138 # A menu item needs to be invoked
139 self.invoke_item(item)
140