Mercurial > boomslang
comparison pyntnclick/widgets/text.py @ 688:6892d36dad75 pyntnclick
Remove an unecessary extra surface from WrappedTextLabel, making it look a lot prettier
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Mon, 13 Feb 2012 15:53:54 +0200 |
parents | fa168b5e2624 |
children | c8b683dd56d3 |
comparison
equal
deleted
inserted
replaced
687:6d75895477ac | 688:6892d36dad75 |
---|---|
129 self._render() | 129 self._render() |
130 width, height = self.surface.get_rect().size | 130 width, height = self.surface.get_rect().size |
131 self.rect.width = max(self.rect.width, width) | 131 self.rect.width = max(self.rect.width, width) |
132 self.rect.height = max(self.rect.height, height) | 132 self.rect.height = max(self.rect.height, height) |
133 | 133 |
134 self.rect.width += 2 * self.padding | |
135 self.rect.height += 2 * self.padding | |
136 new_surface = pygame.Surface(self.rect.size) | |
137 new_surface = new_surface.convert_alpha() | |
138 new_surface.fill(self.bg_color) | |
139 new_surface.blit(self.surface, self.surface.get_rect().move( | |
140 (self.padding, self.padding))) | |
141 if self.border: | 134 if self.border: |
142 pygame.draw.rect(new_surface, self.border_color, | 135 pygame.draw.rect(self.surface, self.border_color, |
143 new_surface.get_rect(), | 136 self.surface.get_rect(), |
144 self.border) | 137 self.border) |
145 self.surface = new_surface | |
146 | 138 |
147 def _render(self): | 139 def _render(self): |
148 surfaces = [] | 140 surfaces = [] |
149 width = 0 | 141 width = 0 |
150 height = 0 | 142 height = 0 |
151 for line in self._text_lines: | 143 for line in self._text_lines: |
152 line_surf = self.font.render(line, True, self.color, | 144 line_surf = self.font.render(line, True, self.color) |
153 self.bg_color) | |
154 surfaces.append(line_surf) | 145 surfaces.append(line_surf) |
155 width = max(line_surf.get_rect().width, width) | 146 width = max(line_surf.get_rect().width, width) |
156 height += line_surf.get_rect().height | 147 height += line_surf.get_rect().height |
148 | |
149 width += 2 * self.padding | |
150 height += 2 * self.padding | |
151 | |
157 self.surface = pygame.Surface((width, height)) | 152 self.surface = pygame.Surface((width, height)) |
153 self.surface = self.surface.convert_alpha() | |
158 self.surface.fill(self.bg_color) | 154 self.surface.fill(self.bg_color) |
159 height = 0 | 155 height = self.padding |
160 for line_surf in surfaces: | 156 for line_surf in surfaces: |
161 rect = pygame.Rect((0, height), (line_surf.get_rect().size)) | 157 rect = pygame.Rect((self.padding, height), |
158 (line_surf.get_rect().size)) | |
162 self.surface.blit(line_surf, rect) | 159 self.surface.blit(line_surf, rect) |
163 height += line_surf.get_rect().height | 160 height += line_surf.get_rect().height |
164 | 161 |
165 | 162 |
166 class ModalWrappedTextLabel(WrappedTextLabel): | 163 class ModalWrappedTextLabel(WrappedTextLabel): |