Mercurial > mamba
changeset 93:8d073e402294
Add start of image button
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 19:15:58 +0200 |
parents | 1e9da4893d51 |
children | aba653f8383e |
files | mamba/widgets/imagebutton.py |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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))