Mercurial > sypikslang
comparison gamelib/gui_base.py @ 119:9a30162f2a9c
Add more logic around resizing surfaces
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 09 May 2012 23:27:10 +0200 |
parents | 0cdd13622355 |
children | 821ecb98e888 |
comparison
equal
deleted
inserted
replaced
118:bc9da66ec333 | 119:9a30162f2a9c |
---|---|
232 size = self.font.size(current_str + word) | 232 size = self.font.size(current_str + word) |
233 if size[0] < self.rect.width: | 233 if size[0] < self.rect.width: |
234 current_str += word + ' ' | 234 current_str += word + ' ' |
235 else: | 235 else: |
236 s = self.font.render(current_str[0:-1], True, self.color) | 236 s = self.font.render(current_str[0:-1], True, self.color) |
237 self._resize_text_surface(current_height + size[1]) | |
237 self.text_surface.blit(s, (0, current_height)) | 238 self.text_surface.blit(s, (0, current_height)) |
238 current_height += size[1] | 239 current_height += size[1] |
239 current_str = word + ' ' | 240 current_str = word + ' ' |
240 if current_str[-1] == ' ': | 241 if current_str[-1] == ' ': |
241 current_str = current_str[0:-1] | 242 current_str = current_str[0:-1] |
242 s = self.font.render(current_str, True, self.color) | 243 s = self.font.render(current_str, True, self.color) |
244 self._resize_text_surface(current_height + size[1]) | |
243 self.text_surface.blit(s, (0, current_height)) | 245 self.text_surface.blit(s, (0, current_height)) |
244 self.text_offset = (0, 0) | 246 self.text_offset = (0, 0) |
245 self.rect.height = current_height + size[1] | 247 self.rect.height = current_height + size[1] |
246 self.surface = Surface((self.rect.width, self.rect.height), | 248 self.surface = Surface((self.rect.width, self.rect.height), |
247 pygame.SRCALPHA) | 249 pygame.SRCALPHA) |
250 | |
251 def _resize_text_surface(self, new_height): | |
252 """Resize the text surface if needed""" | |
253 if new_height > self.text_surface.get_rect().height: | |
254 old_text = self.text_surface | |
255 self.text_surface = Surface((self.rect[2], new_height), | |
256 pygame.SRCALPHA) | |
257 self.text_surface.blit(old_text, (0, 0)) |