comparison mamba/widgets/imagebutton.py @ 93:8d073e402294

Add start of image button
author Neil Muller <drnlmuller@gmail.com>
date Sun, 11 Sep 2011 19:15:58 +0200
parents
children 45397addd80d
comparison
equal deleted inserted replaced
92:1e9da4893d51 93:8d073e402294
1 import pygame
2
3 from mamba.widgets.text import TextWidget
4
5
6 class ImageButtonWidget(TextWidget):
7 """Text label with image on the left"""
8
9 def __init__(self, rect, image, text, fontsize=16, color='black'):
10 self.image = image
11 super(ImageButtonWidget, self).__init__(rect, text, fontsize, color)
12
13 def prepare(self):
14 super(ImageButtonWidget, self).prepare()
15 text_surface = self.font.render(self.text, True, self.color)
16 # Image is already a surface
17 self.rect.width = text_surface.get_width() + self.image.get_width() + 5
18 self.rect.height = text_surface.get_height() + self.image.get_height()
19 self.surface = pygame.Surface((self.rect.width, self.rect.height))
20 self.surface.blit(self.image, (0, 0))
21 self.surface.blit(text_surface, (self.image.get_width() + 5, 0))