comparison gamelib/gui.py @ 143:821ecb98e888

some icons and toggle button
author Rizmari Versfeld <rizziepit@gmail.com>
date Fri, 11 May 2012 03:13:22 +0200
parents 3e02a8ccd72b
children 53277724645b
comparison
equal deleted inserted replaced
142:3e02a8ccd72b 143:821ecb98e888
1 from pygame import image 1 from pygame import image
2 2
3 from gamelib import data 3 from gamelib import data
4 from gamelib.gui_base import Drawable, TextButton, font_auto, Button 4 from gamelib.gui_base import Drawable, TextButton, font_auto, ToggleButton
5 5
6 6
7 class ImageDrawable(Drawable): 7 class ImageDrawable(Drawable):
8 8
9 def __init__(self, rect, image): 9 def __init__(self, rect, image):
26 d = ImageDrawable(rect1, self.BG_IMAGE_DOWN) 26 d = ImageDrawable(rect1, self.BG_IMAGE_DOWN)
27 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT) 27 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
28 super(BigButton, self).__init__(rect2, n, d, text, font, shadow) 28 super(BigButton, self).__init__(rect2, n, d, text, font, shadow)
29 29
30 30
31 class IconButton(Button): 31 class IconButton(ToggleButton):
32 WIDTH = 64 32 WIDTH = 64
33 HEIGHT = 64 33 HEIGHT = 64
34 BG_IMAGE_NORMAL = image.load(data.filepath('images/research_normal.png')) 34 BG_IMAGE_NORMAL = image.load(data.filepath('images/research_normal.png'))
35 BG_IMAGE_DOWN = image.load(data.filepath('images/research_down.png')) 35 BG_IMAGE_DOWN = image.load(data.filepath('images/research_down.png'))
36 36
42 n.image.blit(n_icon, (0, 0)) 42 n.image.blit(n_icon, (0, 0))
43 d = ImageDrawable(rect, self.BG_IMAGE_DOWN.copy()) 43 d = ImageDrawable(rect, self.BG_IMAGE_DOWN.copy())
44 d.image.blit(d_icon, (0, 0)) 44 d.image.blit(d_icon, (0, 0))
45 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT) 45 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
46 super(IconButton, self).__init__(rect2, n, d) 46 super(IconButton, self).__init__(rect2, n, d)
47
48
49 class RadioButton(IconButton):
50 SELECTED_BUTTON = None
51
52 def on_click(self):
53 print(RadioButton.CHECK)
54 super(RadioButton, self).on_click()
55 if self.toggled:
56 if RadioButton.SELECTED_BUTTON:
57 RadioButton.SELECTED_BUTTON.on_click()
58 RadioButton.SELECTED_BUTTON = self
59 print("I am selected")
60 else:
61 RadioButton.SELECTED_BUTTON = None
62 print("I am deselected")