def __init__(self, pos, text, fontname=None, fontsize=None,
colour=None, unselectable_colour=None, view_port=None,
- centre=False):
+ centre=False, border=0, border_colour=PALETTE.GREY,
+ padding=2):
super(TextWidget, self).__init__(pos)
self.text = text
pygame.Rect((0, 0), view_port) if view_port is not None else None)
self.centre = centre
self.centre_pos = pos
+ self.border = border
+ self.border_colour = border_colour
+ self.padding = padding
def render_line(self, text):
colour = self.colour
text_surf, (text_rect.width * EIGHT_BIT_SCALE,
text_rect.height * EIGHT_BIT_SCALE))
+ def render_border(self, surface):
+ if not self.border or not self.border_colour:
+ return
+ rect = surface.get_rect()
+ rect = rect.inflate(- self.border / 2, - self.border / 2)
+ pygame.draw.rect(surface, self.border_colour, rect, self.border)
+
def update_size(self):
if self.view_port is not None:
self.size = self.view_port.size
def prepare(self):
self.font = resources.get_font(self.fontname, self.fontsize)
self.surface = self.render_line(self.text)
+ self.render_border(self.surface)
self.update_size()
def handle_event(self, ev):
class TextBoxWidget(TextWidget):
def __init__(self, *args, **kwargs):
- self.padding = kwargs.pop('padding', 4)
- self.border = kwargs.pop('border', 2)
self.bg_colour = convert_colour(kwargs.pop('bg_colour',
PALETTE.LIGHT_VIOLET))
- self.border_colour = convert_colour(kwargs.pop('border_colour',
- PALETTE.BLACK))
self.box_width = kwargs.pop('box_width', 0)
-
self.full_width = kwargs.pop('full_width', True)
+ kwargs.setdefault('padding', 4)
super(TextBoxWidget, self).__init__(*args, **kwargs)
y += line_surface.get_rect().height
for pos, img in image_map.items():
self.surface.blit(img, pos)
+
+ self.render_border(self.surface)