Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-11-04 16:49:41 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-11-04 16:49:41 (GMT)
commit3e84b1221e1a062289f5c476d6e8ecb8bba9fa37 (patch)
tree42796f541a5e8550a0833f1e8bb9176181fa87f0 /TurtleArt
parent0514aa054eecd9ece92d00c82a7521e77a5c65f0 (diff)
fixed get_pixel by mapping the cairo surface to a pixmap
Diffstat (limited to 'TurtleArt')
-rw-r--r--TurtleArt/tacanvas.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py
index 1a8a238..96f323d 100644
--- a/TurtleArt/tacanvas.py
+++ b/TurtleArt/tacanvas.py
@@ -708,11 +708,25 @@ class TurtleGraphics:
def get_pixel(self):
""" Read the pixel at x, y """
- # FIX ME: broken for Cairo
+ # Fix me: Is there a more efficient way of doing this?
if self.tw.interactive_mode:
x, y = self.turtle_to_screen_coordinates(self.xcor, self.ycor)
- return self.canvas.get_pixel((int(x), int(y)), 0,
- self.tw.color_mode)
+ x = int(x)
+ y = int(y)
+ w = self.tw.turtle_canvas.get_width()
+ h = self.tw.turtle_canvas.get_height()
+ if x < 0 or x > (w - 1) or y < 0 or y > (h - 1):
+ return(-1, -1, -1, -1)
+ # Map the cairo surface onto a pixmap
+ pixmap = gtk.gdk.Pixmap(None, w, h, 24)
+ cr = pixmap.cairo_create()
+ cr.set_source_surface(self.tw.turtle_canvas, 0, 0)
+ cr.paint()
+ # Read the pixel
+ pixel = pixmap.get_image(x, y, 1, 1).get_pixel(0, 0)
+ return(int((pixel & 0xFF0000) >> 16),
+ int((pixel & 0x00FF00) >> 8),
+ int((pixel & 0x0000FF) >> 0), 0)
else:
return(-1, -1, -1, -1)