comparison gamelib/gui.py @ 140:abbceec3cc8b

added examples of nodes in main menu
author Rizmari Versfeld <rizziepit@gmail.com>
date Fri, 11 May 2012 00:23:01 +0200
parents ff7c953502d5
children 3e02a8ccd72b
comparison
equal deleted inserted replaced
137:fb8037bc22f1 140:abbceec3cc8b
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 4 from gamelib.gui_base import Drawable, TextButton, font_auto, Button
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):
24 rect1 = (0, 0, self.WIDTH, self.HEIGHT) 24 rect1 = (0, 0, self.WIDTH, self.HEIGHT)
25 n = ImageDrawable(rect1, self.BG_IMAGE_NORMAL) 25 n = ImageDrawable(rect1, self.BG_IMAGE_NORMAL)
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
30
31 class IconButton(Button):
32 WIDTH = 64
33 HEIGHT = 64
34 BG_IMAGE_NORMAL = image.load(data.filepath('images/research_normal.png'))
35 BG_IMAGE_DOWN = image.load(data.filepath('images/research_down.png'))
36
37 def __init__(self, pos, name):
38 rect = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
39 n_icon = image.load(data.filepath('images/icons/%s_normal.png' % name))
40 d_icon = image.load(data.filepath('images/icons/%s_down.png' % name))
41 n = ImageDrawable(rect, self.BG_IMAGE_NORMAL.copy())
42 n.image.blit(n_icon, (0,0))
43 d = ImageDrawable(rect, self.BG_IMAGE_DOWN.copy())
44 d.image.blit(d_icon, (0,0))
45 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
46 super(IconButton, self).__init__(rect2, n, d)