From e39d0d676be451f3776413051947f6530144c0b7 Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 9 Sep 2016 22:07:47 +0200 Subject: [PATCH] Add transform support to cursor and image buttons --- tabakrolletjie/cursor.py | 8 ++++++-- tabakrolletjie/scenes/base.py | 4 ++-- tabakrolletjie/widgets.py | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tabakrolletjie/cursor.py b/tabakrolletjie/cursor.py index 69b57a3..e460763 100644 --- a/tabakrolletjie/cursor.py +++ b/tabakrolletjie/cursor.py @@ -11,8 +11,12 @@ class Cursor(pygame.sprite.Sprite): super(Cursor, self).__init__() self._active = False - def activate(self, name, group): - self.image = loader.load_image('cursors', name + '.png') + def activate(self, name, group, transform=None): + if transform: + self.image = loader.load_image('cursors', name + '.png', + transform=transform) + else: + self.image = loader.load_image('cursors', name + '.png') self.rect = self.image.get_rect() self._active = True group.empty() diff --git a/tabakrolletjie/scenes/base.py b/tabakrolletjie/scenes/base.py index 320ff80..566c325 100644 --- a/tabakrolletjie/scenes/base.py +++ b/tabakrolletjie/scenes/base.py @@ -9,8 +9,8 @@ class BaseScene(object): self._cursor = Cursor() self._cursor_group = RenderUpdates() - def _set_cursor(self, name): - self._cursor.activate(name, self._cursor_group) + def _set_cursor(self, name, transform=None): + self._cursor.activate(name, self._cursor_group, transform=transform) def _unset_cursor(self): self._cursor.deactivate(self._cursor_group) diff --git a/tabakrolletjie/widgets.py b/tabakrolletjie/widgets.py index f34fa35..8ca16e3 100644 --- a/tabakrolletjie/widgets.py +++ b/tabakrolletjie/widgets.py @@ -6,6 +6,7 @@ import pygame.locals as pgl from .loader import loader from .constants import FONTS +from .transforms import NullTransform class Button(object): @@ -64,7 +65,8 @@ class TextButton(Button): class ImageButton(Button): def __init__(self, *imgparts, **kwargs): - self._img = loader.load_image(*imgparts) + transform = kwargs.pop("transform", NullTransform()) + self._img = loader.load_image(*imgparts, transform=transform) name = kwargs.get('name') pos = kwargs.get('pos') padding = kwargs.get('padding', 0) -- 2.34.1