From f88201e7622c14bcaaea0426ddc3cb730509acf2 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 18 Dec 2012 12:03:15 +0000 Subject: Fix pick color math - SL #4333 The value obtained by read the pick color tool was wrong, because the range is 0 to 255, and we use it between 0 and 65535 A similar problem is described here [1] Aditionally, this patch set the right mouse cursor for the case where the bucket do not fill anything, because the selected color is the same to the color in the point to fill. Previously the clock cursor was not removed, and confused the user. Signed-off-by: Gonzalo Odiard [1] http://old.nabble.com/-cairo--Getting-wrong-cairo-pixel-color.-td31256086.html --- (limited to 'Area.py') diff --git a/Area.py b/Area.py index 48f9757..9318266 100644 --- a/Area.py +++ b/Area.py @@ -827,6 +827,10 @@ class Area(Gtk.DrawingArea): old_color = pixels[x + y * width] if old_color == fill_color: logging.debug('Already filled') + # reset the cursor + display = Gdk.Display.get_default() + cursor = Gdk.Cursor.new_from_name(display, 'paint-bucket') + self.get_window().set_cursor(cursor) return if FALLBACK_FILL: @@ -884,11 +888,14 @@ class Area(Gtk.DrawingArea): cairo_context.set_operator(cairo.OPERATOR_SOURCE) cairo_context.fill() cairo_surface.flush() + # Read the pixel pixels = cairo_surface.get_data() - red = ord(pixels[2]) * 256 - green = ord(pixels[1]) * 256 - blue = ord(pixels[0]) * 256 + + # the values are between 0 and 255 + red = ord(pixels[2]) / 255.0 * 65535.0 + green = ord(pixels[1]) / 255.0 * 65535.0 + blue = ord(pixels[0]) / 255.0 * 65535.0 stroke_color = Gdk.Color(red, green, blue) -- cgit v0.9.1