changeset 755:64fe88a322d3 pyntnclick

Re-implement cursor highlighting using a Colour transformation
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 26 Jan 2013 12:10:41 +0200
parents f703bdce8c9e
children bd8227068d86
files pyntnclick/cursor.py
diffstat 1 files changed, 6 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/pyntnclick/cursor.py	Sat Jan 26 11:27:02 2013 +0200
+++ b/pyntnclick/cursor.py	Sat Jan 26 12:10:41 2013 +0200
@@ -9,6 +9,7 @@
 import pygame.mouse
 
 from pyntnclick.engine import Screen
+from pyntnclick.image_transforms import Colour
 
 
 class CursorSprite(Sprite):
@@ -23,33 +24,23 @@
 
     def load(self, resources):
         if not hasattr(self, 'plain_image'):
+            self.highlight_transform = Colour((255, 100, 100, 255))
             self.plain_image = resources.get_image('items', self.filename)
-            self.image = self.plain_image
-            self.rect = self.image.get_rect()
-
+            self.highlighted_image = resources.get_image('items', self.filename,
+                    transforms=(self.highlight_transform,))
+            self.rect = self.plain_image.get_rect()
             if self.pointer_x is None:
                 self.pointer_x = self.rect.size[0] // 2
             if self.pointer_y is None:
                 self.pointer_y = self.rect.size[1] // 2
 
-            self.highlight = pygame.Surface(self.rect.size)
-            color = pygame.color.Color(255, 100, 100, 0)
-            self.highlight.fill(color)
-
     def update(self):
         pos = pygame.mouse.get_pos()
         self.rect.left = pos[0] - self.pointer_x
         self.rect.top = pos[1] - self.pointer_y
 
     def set_highlight(self, enable):
-        # XXX: Use image transforms and such here.
-        if enable != self.highlighted:
-            #XXX: Do we need this? self.load()
-            self.highlighted = enable
-            self.image = self.plain_image.copy()
-            if enable:
-                self.image.blit(self.highlight, self.highlight.get_rect(),
-                                None, pygame.BLEND_MULT)
+        self.image = self.highlighted_image if enable else self.plain_image
 
 
 HAND = CursorSprite('hand.png', 12, 0)