Mercurial > mamba
view 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 |
line wrap: on
line source
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))