# HG changeset patch # User Rizmari Versfeld # Date 1336597276 -7200 # Node ID 93ba0f1b4e06d0d715d84bfdf040d8928aac4304 # Parent 86a6434c4eb2ff9f51cf59a13224aef7422376c3 added textbox diff -r 86a6434c4eb2 -r 93ba0f1b4e06 gamelib/gui_base.py --- 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)