Changeset 196:40f618978c00


Ignore:
Timestamp:
Sep 3, 2013, 8:24:38 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Children:
197:34c11bb5c96e, 240:f89576cec59a
Message:

Overlays that don't suck as much

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r192 r196  
    1111from nagslang.resources import resources
    1212from nagslang.events import DoorEvent
    13 from nagslang.widgets.text import TextWidget
     13from nagslang.widgets.text import LabelWidget
    1414
    1515
     
    336336    def __init__(self, text):
    337337        self.text = text
    338         self.widget = TextWidget((20, 20), self.text)
     338        self.widget = LabelWidget((20, 20), self.text)
    339339
    340340    def render(self, surface):
  • 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.