diff 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
line wrap: on
line diff
--- a/gamelib/widgets.py	Thu Aug 26 14:59:29 2010 +0200
+++ b/gamelib/widgets.py	Thu Aug 26 16:29:54 2010 +0200
@@ -6,6 +6,8 @@
 import textwrap
 
 import albow.controls
+from pygame.color import Color
+from pygame.locals import BLEND_ADD
 
 from cursor import CursorWidget
 
@@ -20,19 +22,46 @@
         self.margin = margin
         self.size = (w + 2 * d, h + 2 * d)
 
+    def draw_all(self, surface):
+        bg_color = self.bg_color
+        self.bg_color = None
+        if bg_color is not None:
+            new_surface = surface.convert_alpha()
+            new_surface.fill(bg_color)
+            surface.blit(new_surface, surface.get_rect())
+        albow.controls.Label.draw_all(self, surface)
+        self._draw_all_no_bg(surface)
+        self.bg_color = bg_color
+
+    def _draw_all_no_bg(self, surface):
+        pass
+
 
 class MessageDialog(BoomLabel, CursorWidget):
 
-    def __init__(self, screen, text, wrap_width, **kwds):
+    def __init__(self, screen, text, wrap_width, style=None, **kwds):
         CursorWidget.__init__(self, screen)
         paras = text.split("\n\n")
         text = "\n".join([textwrap.fill(para, wrap_width) for para in paras])
         albow.controls.Label.__init__(self, text, **kwds)
+        self.set_style(style)
+
+    def set_style(self, style):
         self.set_margin(5)
         self.border_width = 1
         self.border_color = (0, 0, 0)
         self.bg_color = (127, 127, 127)
         self.fg_color = (0, 0, 0)
+        if style == "JIM":
+            self.bg_color = Color(127, 0, 0, 191)
+            self.fg_color = (0, 0, 0)
+            self.border_color = (255, 0, 0)
+
+    def draw_all(self, surface):
+        BoomLabel.draw_all(self, surface)
+
+    def _draw_all_no_bg(self, surface):
+        CursorWidget.draw_all(self, surface)
 
     def mouse_down(self, event):
         self.dismiss()