# HG changeset patch # User Stefano Rivera # Date 1282600691 -7200 # Node ID c76f2fad2af5fade0e240be06c1164569c09c241 # Parent 4fd56ee2af61a4bd1ee68c3fb2797a38527eb714 Draw CursorWidget on top of StateWidget diff -r 4fd56ee2af61 -r c76f2fad2af5 gamelib/cursor.py --- a/gamelib/cursor.py Mon Aug 23 23:47:29 2010 +0200 +++ b/gamelib/cursor.py Mon Aug 23 23:58:11 2010 +0200 @@ -2,7 +2,6 @@ # Copyright Boomslang team, 2010 (see COPYING File) # Sprite Cursor -from albow.screen import Screen from albow.widget import Widget from albow.resource import get_image import pygame.mouse as mouse @@ -10,9 +9,6 @@ import pygame.cursors import pygame.mouse -# FIXME: make this a all transparent cursor -BLANK_CURSOR=pygame.cursors.broken_x - class CursorSprite(Sprite): "A Sprite that follows the Cursor" @@ -27,29 +23,28 @@ class CursorWidget(Widget): """Mix-in widget to ensure that mouse_move is propogated to parents""" - def mouse_move(self, event): - self.call_parent_handler('mouse_move', event) - - def get_cursor(self, event): - return BLANK_CURSOR - - -class CursorSpriteScreen(Screen): - "A Screen with a CursorSprite" - - def __init__(self, shell): - Screen.__init__(self, shell) - - sprite = CursorSprite('hand') - self.cursor_group = RenderUpdates(sprite) + def __init__(self, *args, **kwargs): + Widget.__init__(self, *args, **kwargs) + self._cursor_group = RenderUpdates() + self._cursor_name = '' def draw(self, surface): - if self.get_cursor(None) == pygame.mouse.get_cursor(): - self.cursor_group.update() - self.cursor_group.draw(surface) + if self.rect.collidepoint(mouse.get_pos()): + cursor = self.get_sprite_cursor() + if cursor != self._cursor_name: + if self.get_sprite_cursor() is None: + pygame.mouse.set_visible(1) + self._cursor_group.empty() + else: + pygame.mouse.set_visible(0) + self._cursor_group.empty() + self._cursor_group.add(CursorSprite(cursor)) + if cursor is not None: + self._cursor_group.update() + self._cursor_group.draw(surface) def mouse_move(self, event): self.invalidate() - def get_cursor(self, event): - return BLANK_CURSOR + def get_sprite_cursor(self): + return 'hand' diff -r 4fd56ee2af61 -r c76f2fad2af5 gamelib/gamescreen.py --- a/gamelib/gamescreen.py Mon Aug 23 23:47:29 2010 +0200 +++ b/gamelib/gamescreen.py Mon Aug 23 23:58:11 2010 +0200 @@ -7,19 +7,20 @@ from albow.controls import Button, Label, Widget from albow.layout import Column from albow.palette_view import PaletteView -from pygame import Rect +from albow.screen import Screen +from pygame import Rect, mouse from pygame.color import Color from pygame.locals import BLEND_ADD from constants import BUTTON_SIZE -from cursor import CursorSpriteScreen, CursorWidget +from cursor import CursorWidget from hand import HandButton from popupmenu import PopupMenu, PopupMenuButton from state import initial_state, Item from widgets import BoomLabel -class InventoryView(PaletteView, CursorWidget): +class InventoryView(PaletteView): sel_color = Color("yellow") sel_width = 2 @@ -66,11 +67,12 @@ class StateWidget(CursorWidget): def __init__(self, state): - Widget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) + CursorWidget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) self.state = state def draw(self, surface): self.state.draw(surface) + CursorWidget.draw(self, surface) def mouse_down(self, event): result = self.state.interact(event.pos) @@ -85,7 +87,7 @@ CursorWidget.mouse_move(self, event) -class DetailWindow(CursorWidget): +class DetailWindow(Widget): def mouse_down(self, e): if e not in self: self.dismiss() @@ -94,9 +96,9 @@ surface.fill(Color('green')) -class GameScreen(CursorSpriteScreen): +class GameScreen(Screen): def __init__(self, shell): - CursorSpriteScreen.__init__(self, shell) + Screen.__init__(self, shell) # TODO: Randomly plonk the state here for now self.state = initial_state() @@ -150,4 +152,7 @@ self.handbutton.toggle_selected() self.inventory.unselect() - + def mouse_delta(self, event): + w = self.shell.find_widget(event.pos) + if not isinstance(w, CursorWidget): + mouse.set_visible(1) diff -r 4fd56ee2af61 -r c76f2fad2af5 gamelib/hand.py --- a/gamelib/hand.py Mon Aug 23 23:47:29 2010 +0200 +++ b/gamelib/hand.py Mon Aug 23 23:58:11 2010 +0200 @@ -1,7 +1,6 @@ # Button for the hand image from constants import BUTTON_SIZE -from cursor import CursorWidget from albow.controls import ImageButton from albow.resource import get_image @@ -9,7 +8,7 @@ from pygame.color import Color from pygame.rect import Rect -class HandButton(ImageButton, CursorWidget): +class HandButton(ImageButton): """The fancy hand button for the widget""" sel_colour = Color('red') diff -r 4fd56ee2af61 -r c76f2fad2af5 gamelib/menu.py --- a/gamelib/menu.py Mon Aug 23 23:47:29 2010 +0200 +++ b/gamelib/menu.py Mon Aug 23 23:58:11 2010 +0200 @@ -6,11 +6,9 @@ from albow.controls import Button, Label from albow.layout import Column -from cursor import CursorSpriteScreen - -class MenuScreen(CursorSpriteScreen): +class MenuScreen(Screen): def __init__(self, shell): - CursorSpriteScreen.__init__(self, shell) + Screen.__init__(self, shell) StartButton = Button('Start New Game', action = self.start) QuitButton = Button('Quit', action = shell.quit) Title = Label('Suspended Sentence') diff -r 4fd56ee2af61 -r c76f2fad2af5 gamelib/popupmenu.py --- a/gamelib/popupmenu.py Mon Aug 23 23:47:29 2010 +0200 +++ b/gamelib/popupmenu.py Mon Aug 23 23:58:11 2010 +0200 @@ -3,14 +3,13 @@ # Popup menu for the game screen from constants import BUTTON_SIZE -from cursor import CursorWidget from albow.menu import Menu from albow.controls import Button from albow.resource import get_font from pygame.rect import Rect -class PopupMenuButton(Button, CursorWidget): +class PopupMenuButton(Button): def __init__(self, text, action): Button.__init__(self, text, action) @@ -19,10 +18,6 @@ self.set_rect(Rect(0, 0, BUTTON_SIZE, BUTTON_SIZE)) self.margin = (BUTTON_SIZE - self.font.get_linesize()) / 2 - def get_cursor(self, event): - # Draw standard arrow, not the sprite cursor - return None - class PopupMenu(Menu): def __init__(self, shell):