Add transform support to cursor and image buttons
authorNeil <neil@dip.sun.ac.za>
Fri, 9 Sep 2016 20:07:47 +0000 (22:07 +0200)
committerNeil <neil@dip.sun.ac.za>
Fri, 9 Sep 2016 20:25:07 +0000 (22:25 +0200)
tabakrolletjie/cursor.py
tabakrolletjie/scenes/base.py
tabakrolletjie/widgets.py

index 69b57a384d3b4c51473ba3aef1fc673198be991c..e460763f287eaa156f0056ba2ddbc96df4db37ef 100644 (file)
@@ -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()
index 320ff8006b312abe49f96fe7af021472f9e82605..566c325555190dd5c78ff3c9a813306f0ba76f9a 100644 (file)
@@ -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)
index f34fa35fccc0427477107fae9677b4be91d1cea0..8ca16e31510c061a261a5cc39200dd01798f30bf 100644 (file)
@@ -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)