Blocky text (4 pixels per pixel)
[naja.git] / naja / widgets / text.py
1 import pygame
2
3 from naja.constants import FONT, FONT_SIZE
4 from naja.widgets.base import Widget
5 from naja.resources import resources
6
7
8 class TextWidget(Widget):
9     def __init__(self, pos, text, size=None, fontname=None, fontsize=None,
10                  colour=None):
11         super(TextWidget, self).__init__(pos, size)
12
13         self.text = text
14         self.fontname = fontname or FONT
15         self.fontsize = (fontsize or FONT_SIZE) / 2
16         self.colour = colour or (0, 0, 0)
17
18     def prepare(self):
19         self.font = resources.get_font(self.fontname, self.fontsize)
20         text = self.font.render(self.text, True, self.colour)
21         text_rect = text.get_rect()
22         self.surface = pygame.transform.scale(text, (text_rect.width * 2,
23                                                      text_rect.height * 2))
24         self.size = self.surface.get_rect().size
25
26     def draw(self, surface):
27         surface.blit(self.surface, self.rect)