Ignore:
Timestamp:
09/03/13 20:24:38 (8 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Children:
197:34c11bb5c96e, 240:f89576cec59a
Phase:
public
Message:

Overlays that don't suck as much

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/widgets/text.py

    r33 r196  
     1import pygame
     2
    13from nagslang.constants import FONT, FONT_SIZE
    24from nagslang.widgets.base import Widget
     
    2830            self.do_prepare()
    2931            surface.blit(self.surface, self.rect)
     32
     33
     34class LabelWidget(TextWidget):
     35    def __init__(self, *args, **kwargs):
     36        self.padding = kwargs.pop('padding', 5)
     37        self.border = kwargs.pop('border', 2)
     38        self.bg_colour = convert_colour(kwargs.pop('bg_colour',
     39                                                   (255, 255, 255, 150)))
     40        self.border_colour = convert_colour(kwargs.pop('border_colour',
     41                                                       (0, 0, 0)))
     42        super(LabelWidget, self).__init__(*args, **kwargs)
     43
     44    def prepare(self):
     45        super(LabelWidget, self).prepare()
     46        if not self.size:
     47            self.rect.width += 2 * self.padding
     48            self.rect.height += 2 * self.padding
     49        surface = pygame.Surface(self.rect.size)
     50        surface = surface.convert_alpha()
     51        surface.fill(self.bg_colour)
     52        surface.blit(self.surface, self.surface.get_rect().move(
     53            (self.padding, self.padding)))
     54        pygame.draw.rect(surface, self.border_colour, surface.get_rect(),
     55                         self.border)
     56        self.surface = surface
Note: See TracChangeset for help on using the changeset viewer.