Mercurial > sypikslang
comparison gamelib/gui_base.py @ 212:16ce5ed563c9
Change science buttons
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 12 May 2012 20:17:28 +0200 |
parents | 53277724645b |
children | ce1e23ea46e5 |
comparison
equal
deleted
inserted
replaced
211:ba7c0953853b | 212:16ce5ed563c9 |
---|---|
154 | 154 |
155 | 155 |
156 class TextButton(Button): | 156 class TextButton(Button): |
157 | 157 |
158 def __init__(self, rect, normal_drawable, down_drawable, text, font, | 158 def __init__(self, rect, normal_drawable, down_drawable, text, font, |
159 shadow, text_rect=None): | 159 shadow, text_rect=None, color=(0, 0, 0), |
160 shadow_color=(128, 128, 128)): | |
160 super(TextButton, self).__init__(rect, normal_drawable, down_drawable) | 161 super(TextButton, self).__init__(rect, normal_drawable, down_drawable) |
161 self.text_rect = Rect((0, 0), self.rect.size) | 162 self.text_rect = Rect((0, 0), self.rect.size) |
162 if text_rect is not None: | 163 if text_rect is not None: |
163 self.text_rect = Rect(*text_rect) | 164 self.text_rect = Rect(*text_rect) |
164 self.text = text | 165 self.text = text |
165 if font is font_auto: | 166 if font is font_auto: |
166 font = self._auto_font() | 167 font = self._auto_font() |
167 self.font = font | 168 self.font = font |
168 self.shadow = shadow | 169 self.shadow = shadow |
170 self.shadow_color = shadow_color | |
171 self.color = color | |
169 self._draw_text() | 172 self._draw_text() |
170 | 173 |
171 def _auto_font(self): | 174 def _auto_font(self): |
172 for font in (font_large, font_medium): | 175 for font in (font_large, font_medium): |
173 h, w = font.size(self.text) | 176 h, w = font.size(self.text) |
175 return font | 178 return font |
176 return font_small | 179 return font_small |
177 | 180 |
178 def _draw_text(self): | 181 def _draw_text(self): |
179 self.font.set_bold(True) | 182 self.font.set_bold(True) |
180 self.text_surface = self.font.render(self.text, True, (0, 0, 0)) | 183 self.text_surface = self.font.render(self.text, True, self.color) |
181 size = self.font.size(self.text) | 184 size = self.font.size(self.text) |
182 if self.shadow: | 185 if self.shadow: |
183 s = self.font.render(self.text, True, (128, 128, 128)) | 186 s = self.font.render(self.text, True, self.shadow_color) |
184 temp = Surface((s.get_width() + 1, s.get_width() + 1), SRCALPHA) | 187 temp = Surface((s.get_width() + 1, s.get_width() + 1), SRCALPHA) |
185 temp.fill((255, 255, 255, 0)) | 188 temp.fill((255, 255, 255, 0)) |
186 temp.blit(s, (1, 1)) | 189 temp.blit(s, (1, 1)) |
187 temp.blit(self.text_surface, (0, 0)) | 190 temp.blit(self.text_surface, (0, 0)) |
188 self.text_surface = temp | 191 self.text_surface = temp |