Mercurial > sypikslang
changeset 114:0cdd13622355
merge
author | Rizmari Versfeld <rizziepit@gmail.com> |
---|---|
date | Wed, 09 May 2012 23:03:45 +0200 |
parents | 93ba0f1b4e06 (diff) f741bedf6670 (current diff) |
children | ef63532cac13 94258a86f773 |
files | gamelib/gui_base.py |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/gui_base.py Wed May 09 22:40:40 2012 +0200 +++ b/gamelib/gui_base.py Wed May 09 23:03:45 2012 +0200 @@ -218,3 +218,30 @@ super(TextLabel, self).draw(self.surface) self.surface.blit(self.text_surface, self.text_offset) surface.blit(self.surface, self.rect) + + +class TextBox(TextLabel): + + def _draw_text(self): + self.text_surface = Surface((self.rect[2], self.rect[3]), + pygame.SRCALPHA) + current_height = 0 + current_str = '' + size = None + for word in self.text.split(' '): + size = self.font.size(current_str + word) + if size[0] < self.rect.width: + current_str += word + ' ' + else: + s = self.font.render(current_str[0:-1], True, self.color) + self.text_surface.blit(s, (0, current_height)) + current_height += size[1] + current_str = word + ' ' + if current_str[-1] == ' ': + current_str = current_str[0:-1] + s = self.font.render(current_str, True, self.color) + self.text_surface.blit(s, (0, current_height)) + self.text_offset = (0, 0) + self.rect.height = current_height + size[1] + self.surface = Surface((self.rect.width, self.rect.height), + pygame.SRCALPHA)