changeset 217:146cec58ddd8

Highlight detailed view close button
author Neil Muller <neil@dip.sun.ac.za>
date Thu, 26 Aug 2010 20:26:41 +0200
parents f7dc767dd971
children 6ad6575b501c
files gamelib/gamescreen.py gamelib/widgets.py
diffstat 2 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gamescreen.py	Thu Aug 26 20:02:02 2010 +0200
+++ b/gamelib/gamescreen.py	Thu Aug 26 20:26:41 2010 +0200
@@ -6,7 +6,6 @@
 from albow.layout import Row
 from albow.palette_view import PaletteView
 from albow.screen import Screen
-from albow.resource import get_font
 from pygame import Rect, mouse
 from pygame.color import Color
 from pygame.locals import BLEND_ADD
@@ -16,7 +15,7 @@
 from hand import HandButton
 from popupmenu import PopupMenu, PopupMenuButton
 from state import initial_state, Item, handle_result
-from widgets import MessageDialog, BoomLabel
+from widgets import MessageDialog, BoomButton
 
 
 class InventoryView(PaletteView):
@@ -122,12 +121,11 @@
         self.state = screen.state
         self.border_width = 5
         self.border_color = (0, 0, 0)
-        self.close = BoomLabel('Close', font=get_font(20, 'Vera.ttf'))
-        self.close.bg_color = (0, 0, 0)
+        # parent only gets set when we get added to the scene
+        self.close = BoomButton('Close', self.close_but, screen)
         self.add(self.close)
-        self.close.mouse_down = self.close_but
 
-    def close_but(self, e):
+    def close_but(self):
         self.parent.clear_detail()
 
     def set_image_rect(self, rect):
--- a/gamelib/widgets.py	Thu Aug 26 20:02:02 2010 +0200
+++ b/gamelib/widgets.py	Thu Aug 26 20:26:41 2010 +0200
@@ -6,6 +6,7 @@
 import textwrap
 
 import albow.controls
+from albow.resource import get_font
 from pygame.color import Color
 from pygame.locals import BLEND_ADD
 
@@ -36,6 +37,23 @@
     def _draw_all_no_bg(self, surface):
         pass
 
+class BoomButton(BoomLabel):
+
+    def __init__(self, text, action, screen):
+        super(BoomLabel, self).__init__(text, font=get_font(20, 'Vera.ttf'))
+        self.bg_color = (0, 0, 0)
+        self.action = action
+        self.screen = screen
+
+    def mouse_down(self, event):
+        self.action()
+        self.screen.state_widget.mouse_move(event)
+
+    def mouse_move(self, event):
+        pos = self.parent.global_to_local(event.pos)
+        if self.rect.collidepoint(pos):
+            self.screen.cursor_highlight(True)
+
 
 class MessageDialog(BoomLabel, CursorWidget):