# HG changeset patch # User Neil Muller # Date 1315761358 -7200 # Node ID 8d073e4022945c6157b999048be0bfb4bbe9aaf4 # Parent 1e9da4893d51c464ac3417f7ebeb86e65ff9fe15 Add start of image button diff -r 1e9da4893d51 -r 8d073e402294 mamba/widgets/imagebutton.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mamba/widgets/imagebutton.py Sun Sep 11 19:15:58 2011 +0200 @@ -0,0 +1,21 @@ +import pygame + +from mamba.widgets.text import TextWidget + + +class ImageButtonWidget(TextWidget): + """Text label with image on the left""" + + def __init__(self, rect, image, text, fontsize=16, color='black'): + self.image = image + super(ImageButtonWidget, self).__init__(rect, text, fontsize, color) + + def prepare(self): + super(ImageButtonWidget, self).prepare() + text_surface = self.font.render(self.text, True, self.color) + # Image is already a surface + self.rect.width = text_surface.get_width() + self.image.get_width() + 5 + self.rect.height = text_surface.get_height() + self.image.get_height() + self.surface = pygame.Surface((self.rect.width, self.rect.height)) + self.surface.blit(self.image, (0, 0)) + self.surface.blit(text_surface, (self.image.get_width() + 5, 0))