source: nagslang/widgets/text.py@ 195:b8701c0bb184

Last change on this file since 195:b8701c0bb184 was 33:d9b65cf72db4, checked in by Stefano Rivera <stefano@…>, 8 years ago

Prettier resource loading module

File size: 974 bytes
Line 
1from nagslang.constants import FONT, FONT_SIZE
2from nagslang.widgets.base import Widget
3from nagslang.utils import convert_colour
4from nagslang.resources import resources
5
6
7class TextWidget(Widget):
8 def __init__(self, pos, text, size=None, fontname=None, fontsize=None,
9 colour=None):
10 super(TextWidget, self).__init__(pos, size)
11
12 self.text = text
13 self.fontname = fontname or FONT
14 self.fontsize = fontsize or FONT_SIZE
15 self.colour = convert_colour(colour or (0, 0, 0))
16
17 self.prepare()
18
19 def prepare(self):
20 self.font = resources.get_font(self.fontname, self.fontsize)
21 self.surface = self.font.render(self.text, True, self.colour)
22 self.text_rect = self.surface.get_rect()
23 if not self.size:
24 self.rect.size = self.text_rect.size
25
26 def draw(self, surface):
27 if self.visible:
28 self.do_prepare()
29 surface.blit(self.surface, self.rect)
Note: See TracBrowser for help on using the repository browser.