Mercurial > sypikslang
changeset 113:93ba0f1b4e06
added textbox
author | Rizmari Versfeld <rizziepit@gmail.com> |
---|---|
date | Wed, 09 May 2012 23:01:16 +0200 |
parents | 86a6434c4eb2 |
children | 0cdd13622355 |
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:18:09 2012 +0200 +++ b/gamelib/gui_base.py Wed May 09 23:01:16 2012 +0200 @@ -208,3 +208,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)