Mercurial > boomslang
diff gamelib/widgets.py @ 450:ece69836f00a
Image buttons for game over screen
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Sun, 29 Aug 2010 00:50:25 +0200 |
parents | 05d15be39377 |
children | 03dcb25d8370 |
line wrap: on
line diff
--- a/gamelib/widgets.py Sun Aug 29 00:31:03 2010 +0200 +++ b/gamelib/widgets.py Sun Aug 29 00:50:25 2010 +0200 @@ -176,3 +176,28 @@ # A menu item needs to be invoked self.invoke_item(item) +class BoomImageButton(albow.controls.Image): + """The fancy image button for the screens""" + + FOLDER = None + + def __init__(self, filename, x, y, action, enable=None): + this_image = get_image(self.FOLDER, filename) + albow.controls.Image.__init__(self, image=this_image) + self.action = action + self.set_rect(Rect((x, y), this_image.get_size())) + self.enable = enable + + def draw(self, surface): + if self.is_enabled(): + surface.blit(self.get_image(), self.get_rect()) + + def mouse_down(self, event): + if self.is_enabled(): + self.action() + + def is_enabled(self): + if self.enable: + return self.enable() + return True +