# HG changeset patch # User Neil Muller # Date 1336598830 -7200 # Node ID 9a30162f2a9c89c2323eed62bb18a691db2491a3 # Parent bc9da66ec333c1da3b7942cef3f2c6c9ffff67ce Add more logic around resizing surfaces diff -r bc9da66ec333 -r 9a30162f2a9c gamelib/gui_base.py --- a/gamelib/gui_base.py Wed May 09 23:23:00 2012 +0200 +++ b/gamelib/gui_base.py Wed May 09 23:27:10 2012 +0200 @@ -234,14 +234,24 @@ current_str += word + ' ' else: s = self.font.render(current_str[0:-1], True, self.color) + self._resize_text_surface(current_height + size[1]) 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._resize_text_surface(current_height + size[1]) 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) + + def _resize_text_surface(self, new_height): + """Resize the text surface if needed""" + if new_height > self.text_surface.get_rect().height: + old_text = self.text_surface + self.text_surface = Surface((self.rect[2], new_height), + pygame.SRCALPHA) + self.text_surface.blit(old_text, (0, 0))