comparison gamelib/widgets.py @ 210:eb101b6fb3dd

Transparent message dialogs.
author Jeremy Thurgood <firxen@gmail.com>
date Thu, 26 Aug 2010 16:29:54 +0200
parents fbfd8e748ac0
children 20998c650ce1
comparison
equal deleted inserted replaced
209:aeb96ca5f76c 210:eb101b6fb3dd
4 """Custom Albow widgets""" 4 """Custom Albow widgets"""
5 5
6 import textwrap 6 import textwrap
7 7
8 import albow.controls 8 import albow.controls
9 from pygame.color import Color
10 from pygame.locals import BLEND_ADD
9 11
10 from cursor import CursorWidget 12 from cursor import CursorWidget
11 13
12 14
13 class BoomLabel(albow.controls.Label): 15 class BoomLabel(albow.controls.Label):
18 w, h = self.size 20 w, h = self.size
19 d = margin - old_margin 21 d = margin - old_margin
20 self.margin = margin 22 self.margin = margin
21 self.size = (w + 2 * d, h + 2 * d) 23 self.size = (w + 2 * d, h + 2 * d)
22 24
25 def draw_all(self, surface):
26 bg_color = self.bg_color
27 self.bg_color = None
28 if bg_color is not None:
29 new_surface = surface.convert_alpha()
30 new_surface.fill(bg_color)
31 surface.blit(new_surface, surface.get_rect())
32 albow.controls.Label.draw_all(self, surface)
33 self._draw_all_no_bg(surface)
34 self.bg_color = bg_color
35
36 def _draw_all_no_bg(self, surface):
37 pass
38
23 39
24 class MessageDialog(BoomLabel, CursorWidget): 40 class MessageDialog(BoomLabel, CursorWidget):
25 41
26 def __init__(self, screen, text, wrap_width, **kwds): 42 def __init__(self, screen, text, wrap_width, style=None, **kwds):
27 CursorWidget.__init__(self, screen) 43 CursorWidget.__init__(self, screen)
28 paras = text.split("\n\n") 44 paras = text.split("\n\n")
29 text = "\n".join([textwrap.fill(para, wrap_width) for para in paras]) 45 text = "\n".join([textwrap.fill(para, wrap_width) for para in paras])
30 albow.controls.Label.__init__(self, text, **kwds) 46 albow.controls.Label.__init__(self, text, **kwds)
47 self.set_style(style)
48
49 def set_style(self, style):
31 self.set_margin(5) 50 self.set_margin(5)
32 self.border_width = 1 51 self.border_width = 1
33 self.border_color = (0, 0, 0) 52 self.border_color = (0, 0, 0)
34 self.bg_color = (127, 127, 127) 53 self.bg_color = (127, 127, 127)
35 self.fg_color = (0, 0, 0) 54 self.fg_color = (0, 0, 0)
55 if style == "JIM":
56 self.bg_color = Color(127, 0, 0, 191)
57 self.fg_color = (0, 0, 0)
58 self.border_color = (255, 0, 0)
59
60 def draw_all(self, surface):
61 BoomLabel.draw_all(self, surface)
62
63 def _draw_all_no_bg(self, surface):
64 CursorWidget.draw_all(self, surface)
36 65
37 def mouse_down(self, event): 66 def mouse_down(self, event):
38 self.dismiss() 67 self.dismiss()