comparison gamelib/gui.py @ 110:ff7c953502d5

Auto-downsize fonts on BigButtons that are too large.
author Simon Cross <hodgestar@gmail.com>
date Wed, 09 May 2012 22:37:07 +0200
parents 22b65c943712
children abbceec3cc8b
comparison
equal deleted inserted replaced
98:e386ec5d179b 110:ff7c953502d5
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_large 4 from gamelib.gui_base import Drawable, TextButton, font_auto
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):
18 WIDTH = 128 18 WIDTH = 128
19 HEIGHT = 64 19 HEIGHT = 64
20 BG_IMAGE_NORMAL = image.load(data.filepath('images/button_normal.png')) 20 BG_IMAGE_NORMAL = image.load(data.filepath('images/button_normal.png'))
21 BG_IMAGE_DOWN = image.load(data.filepath('images/button_down.png')) 21 BG_IMAGE_DOWN = image.load(data.filepath('images/button_down.png'))
22 22
23 def __init__(self, pos, text, font=font_large, shadow=True): 23 def __init__(self, pos, text, font=font_auto, shadow=True):
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)