[gimp] Bug 768066 - Color picker tool should indicate pick position



commit 157d70e3964202d11ced1b00be9693121e20de7d
Author: Michael Natterer <mitch gimp org>
Date:   Sat Mar 11 00:01:01 2017 +0100

    Bug 768066 - Color picker tool should indicate pick position
    
    Add optional coordinate display to GimpColorFrame, and enable it for
    the color picker tool and the sample point dockable.

 app/display/gimpcursorview.c        |   14 +++++--
 app/tools/gimpcolorpickertool.c     |   21 +++++++--
 app/widgets/gimpcolorframe.c        |   76 ++++++++++++++++++++++++++++++++--
 app/widgets/gimpcolorframe.h        |   13 +++++-
 app/widgets/gimpsamplepointeditor.c |    4 +-
 5 files changed, 111 insertions(+), 17 deletions(-)
---
diff --git a/app/display/gimpcursorview.c b/app/display/gimpcursorview.c
index 0e35aab..dea8bda 100644
--- a/app/display/gimpcursorview.c
+++ b/app/display/gimpcursorview.c
@@ -754,6 +754,8 @@ gimp_cursor_view_update_cursor (GimpCursorView   *view,
   GimpRGB       color;
   gdouble       xres;
   gdouble       yres;
+  gint          int_x;
+  gint          int_y;
 
   g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
   g_return_if_fail (GIMP_IS_IMAGE (image));
@@ -782,17 +784,21 @@ gimp_cursor_view_update_cursor (GimpCursorView   *view,
   gtk_label_set_text (GTK_LABEL (view->priv->unit_y_label), buf);
   gimp_cursor_view_set_label_italic (view->priv->unit_y_label, ! in_image);
 
+  int_x = (gint) floor (x);
+  int_y = (gint) floor (y);
+
   if (gimp_image_pick_color (image, NULL,
-                             (gint) floor (x),
-                             (gint) floor (y),
+                             int_x, int_y,
                              view->priv->sample_merged,
                              FALSE, 0.0,
                              &sample_format, pixel, &color))
     {
       gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_1),
-                                  FALSE, sample_format, pixel, &color);
+                                  FALSE, sample_format, pixel, &color,
+                                  int_x, int_y);
       gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->priv->color_frame_2),
-                                  FALSE, sample_format, pixel, &color);
+                                  FALSE, sample_format, pixel, &color,
+                                  int_x, int_y);
     }
   else
     {
diff --git a/app/tools/gimpcolorpickertool.c b/app/tools/gimpcolorpickertool.c
index 447c4a0..56cb718 100644
--- a/app/tools/gimpcolorpickertool.c
+++ b/app/tools/gimpcolorpickertool.c
@@ -20,6 +20,7 @@
 #include <gegl.h>
 #include <gtk/gtk.h>
 
+#include "libgimpmath/gimpmath.h"
 #include "libgimpcolor/gimpcolor.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -80,7 +81,9 @@ static void   gimp_color_picker_tool_info_update   (GimpColorPickerTool *picker_
                                                     gboolean             sample_average,
                                                     const Babl          *sample_format,
                                                     gpointer             pixel,
-                                                    const GimpRGB       *color);
+                                                    const GimpRGB       *color,
+                                                    gint                 x,
+                                                    gint                 y);
 
 
 G_DEFINE_TYPE (GimpColorPickerTool, gimp_color_picker_tool,
@@ -313,7 +316,9 @@ gimp_color_picker_tool_picked (GimpColorTool      *color_tool,
     {
       gimp_color_picker_tool_info_update (picker_tool,
                                           GIMP_COLOR_OPTIONS (options)->sample_average,
-                                          sample_format, pixel, color);
+                                          sample_format, pixel, color,
+                                          (gint) floor (x),
+                                          (gint) floor (y));
     }
 
   GIMP_COLOR_TOOL_CLASS (parent_class)->picked (color_tool, pick_state,
@@ -368,6 +373,8 @@ gimp_color_picker_tool_info_create (GimpColorPickerTool *picker_tool)
                                      context->gimp->config->color_management);
   gimp_color_frame_set_mode (GIMP_COLOR_FRAME (picker_tool->color_frame1),
                              GIMP_COLOR_FRAME_MODE_PIXEL);
+  gimp_color_frame_set_has_coords (GIMP_COLOR_FRAME (picker_tool->color_frame1),
+                                   TRUE);
   gtk_box_pack_start (GTK_BOX (hbox), picker_tool->color_frame1,
                       FALSE, FALSE, 0);
   gtk_widget_show (picker_tool->color_frame1);
@@ -417,7 +424,9 @@ gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
                                     gboolean             sample_average,
                                     const Babl          *sample_format,
                                     gpointer             pixel,
-                                    const GimpRGB       *color)
+                                    const GimpRGB       *color,
+                                    gint                 x,
+                                    gint                 y)
 {
   GimpTool *tool = GIMP_TOOL (picker_tool);
 
@@ -430,9 +439,11 @@ gimp_color_picker_tool_info_update (GimpColorPickerTool *picker_tool,
                              color);
 
   gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame1),
-                              sample_average, sample_format, pixel, color);
+                              sample_average, sample_format, pixel, color,
+                              x, y);
   gimp_color_frame_set_color (GIMP_COLOR_FRAME (picker_tool->color_frame2),
-                              sample_average, sample_format, pixel, color);
+                              sample_average, sample_format, pixel, color,
+                              x, y);
 
   gimp_tool_gui_show (picker_tool->gui);
 }
diff --git a/app/widgets/gimpcolorframe.c b/app/widgets/gimpcolorframe.c
index 2d52477..d8ef0f2 100644
--- a/app/widgets/gimpcolorframe.c
+++ b/app/widgets/gimpcolorframe.c
@@ -42,7 +42,8 @@ enum
   PROP_MODE,
   PROP_HAS_NUMBER,
   PROP_NUMBER,
-  PROP_HAS_COLOR_AREA
+  PROP_HAS_COLOR_AREA,
+  PROP_HAS_COORDS
 };
 
 
@@ -115,6 +116,12 @@ gimp_color_frame_class_init (GimpColorFrameClass *klass)
                                                          NULL, NULL,
                                                          FALSE,
                                                          GIMP_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class, PROP_HAS_COORDS,
+                                   g_param_spec_boolean ("has-coords",
+                                                         NULL, NULL,
+                                                         FALSE,
+                                                         GIMP_PARAM_READWRITE));
 }
 
 static void
@@ -122,6 +129,7 @@ gimp_color_frame_init (GimpColorFrame *frame)
 {
   GtkWidget *vbox;
   GtkWidget *vbox2;
+  GtkWidget *label;
   gint       i;
 
   frame->sample_valid  = FALSE;
@@ -177,6 +185,19 @@ gimp_color_frame_init (GimpColorFrame *frame)
                         FALSE, FALSE, 0);
       gtk_widget_show (frame->value_labels[i]);
     }
+
+  frame->coords_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+  gtk_box_pack_start (GTK_BOX (vbox), frame->coords_box, FALSE, FALSE, 0);
+
+  label = gtk_label_new (_("X,Y:"));
+  gtk_box_pack_start (GTK_BOX (frame->coords_box), label, FALSE, FALSE, 0);
+  gtk_widget_show (label);
+
+  frame->coords_label = gtk_label_new (" ");
+  gtk_label_set_selectable (GTK_LABEL (frame->coords_label), TRUE);
+  gtk_box_pack_end (GTK_BOX (frame->coords_box), frame->coords_label,
+                    FALSE, FALSE, 0);
+  gtk_widget_show (frame->coords_label);
 }
 
 static void
@@ -229,6 +250,10 @@ gimp_color_frame_get_property (GObject    *object,
       g_value_set_boolean (value, frame->has_color_area);
       break;
 
+    case PROP_HAS_COORDS:
+      g_value_set_boolean (value, frame->has_coords);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -261,6 +286,10 @@ gimp_color_frame_set_property (GObject      *object,
       gimp_color_frame_set_has_color_area (frame, g_value_get_boolean (value));
       break;
 
+    case PROP_HAS_COORDS:
+      gimp_color_frame_set_has_coords (frame, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -294,6 +323,7 @@ gimp_color_frame_expose (GtkWidget      *widget,
       GtkAllocation  allocation;
       GtkAllocation  menu_allocation;
       GtkAllocation  color_area_allocation;
+      GtkAllocation  coords_box_allocation;
       cairo_t       *cr;
       gchar          buf[8];
       gint           w, h;
@@ -302,6 +332,7 @@ gimp_color_frame_expose (GtkWidget      *widget,
       gtk_widget_get_allocation (widget, &allocation);
       gtk_widget_get_allocation (frame->menu, &menu_allocation);
       gtk_widget_get_allocation (frame->color_area, &color_area_allocation);
+      gtk_widget_get_allocation (frame->coords_box, &coords_box_allocation);
 
       cr = gdk_cairo_create (gtk_widget_get_window (widget));
       gdk_cairo_region (cr, eevent->region);
@@ -321,7 +352,8 @@ gimp_color_frame_expose (GtkWidget      *widget,
 
       scale = ((gdouble) (allocation.height -
                           menu_allocation.height -
-                          color_area_allocation.height) /
+                          color_area_allocation.height -
+                          coords_box_allocation.height) /
                (gdouble) h);
 
       cairo_scale (cr, scale, scale);
@@ -330,7 +362,8 @@ gimp_color_frame_expose (GtkWidget      *widget,
                      (allocation.width / 2.0) / scale - w / 2.0,
                      (allocation.height / 2.0 +
                       menu_allocation.height / 2.0 +
-                      color_area_allocation.height / 2.0) / scale - h / 2.0);
+                      color_area_allocation.height / 2.0 +
+                      coords_box_allocation.height / 2.0) / scale - h / 2.0);
       pango_cairo_show_layout (cr, frame->number_layout);
 
       cairo_destroy (cr);
@@ -423,6 +456,22 @@ gimp_color_frame_set_has_color_area (GimpColorFrame *frame,
     }
 }
 
+void
+gimp_color_frame_set_has_coords (GimpColorFrame *frame,
+                                 gboolean        has_coords)
+{
+  g_return_if_fail (GIMP_IS_COLOR_FRAME (frame));
+
+  if (has_coords != frame->has_coords)
+    {
+      frame->has_coords = has_coords ? TRUE : FALSE;
+
+      g_object_set (frame->coords_box, "visible", frame->has_coords, NULL);
+
+      g_object_notify (G_OBJECT (frame), "has-coords");
+    }
+}
+
 /**
  * gimp_color_frame_set_color:
  * @frame:          The #GimpColorFrame.
@@ -431,6 +480,8 @@ gimp_color_frame_set_has_color_area (GimpColorFrame *frame,
  *                  was picked from.
  * @pixel:          The raw pixel in @sample_format.
  * @color:          The @color to set.
+ * @x:              X position where the color was picked.
+ * @y:              Y position where the color was picked.
  *
  * Sets the color sample to display in the #GimpColorFrame. if
  * @sample_average is %TRUE, @pixel represents the sample at the
@@ -441,14 +492,18 @@ gimp_color_frame_set_color (GimpColorFrame *frame,
                             gboolean        sample_average,
                             const Babl     *sample_format,
                             gpointer        pixel,
-                            const GimpRGB  *color)
+                            const GimpRGB  *color,
+                            gint            x,
+                            gint            y)
 {
   g_return_if_fail (GIMP_IS_COLOR_FRAME (frame));
   g_return_if_fail (color != NULL);
 
   if (frame->sample_valid                     &&
       frame->sample_average == sample_average &&
-      frame->sample_format == sample_format   &&
+      frame->sample_format  == sample_format  &&
+      frame->x              == x              &&
+      frame->y              == y              &&
       gimp_rgba_distance (&frame->color, color) < 0.0001)
     {
       frame->color = *color;
@@ -459,6 +514,8 @@ gimp_color_frame_set_color (GimpColorFrame *frame,
   frame->sample_average = sample_average;
   frame->sample_format  = sample_format;
   frame->color          = *color;
+  frame->x              = x;
+  frame->y              = y;
 
   memcpy (frame->pixel, pixel, babl_format_get_bytes_per_pixel (sample_format));
 
@@ -551,8 +608,17 @@ gimp_color_frame_update (GimpColorFrame *frame)
 
   if (frame->sample_valid)
     {
+      gchar str[16];
+
       gimp_color_area_set_color (GIMP_COLOR_AREA (frame->color_area),
                                  &frame->color);
+
+      g_snprintf (str, sizeof (str), "%d, %d", frame->x, frame->y);
+      gtk_label_set_text (GTK_LABEL (frame->coords_label), str);
+    }
+  else
+    {
+      gtk_label_set_text (GTK_LABEL (frame->coords_label), _("n/a"));
     }
 
   switch (frame->frame_mode)
diff --git a/app/widgets/gimpcolorframe.h b/app/widgets/gimpcolorframe.h
index 86f0dd5..15ef8cf 100644
--- a/app/widgets/gimpcolorframe.h
+++ b/app/widgets/gimpcolorframe.h
@@ -41,6 +41,8 @@ struct _GimpColorFrame
   const Babl         *sample_format;
   guchar              pixel[32];
   GimpRGB             color;
+  gint                x;
+  gint                y;
 
   GimpColorFrameMode  frame_mode;
 
@@ -48,9 +50,12 @@ struct _GimpColorFrame
   gint                number;
 
   gboolean            has_color_area;
+  gboolean            has_coords;
 
   GtkWidget          *menu;
   GtkWidget          *color_area;
+  GtkWidget          *coords_box;
+  GtkWidget          *coords_label;
   GtkWidget          *name_labels[GIMP_COLOR_FRAME_ROWS];
   GtkWidget          *value_labels[GIMP_COLOR_FRAME_ROWS];
 
@@ -72,20 +77,24 @@ GtkWidget * gimp_color_frame_new                (void);
 
 void        gimp_color_frame_set_mode           (GimpColorFrame     *frame,
                                                  GimpColorFrameMode  mode);
+
 void        gimp_color_frame_set_has_number     (GimpColorFrame     *frame,
                                                  gboolean            has_number);
 void        gimp_color_frame_set_number         (GimpColorFrame     *frame,
                                                  gint                number);
 
-
 void        gimp_color_frame_set_has_color_area (GimpColorFrame     *frame,
                                                  gboolean            has_color_area);
+void        gimp_color_frame_set_has_coords     (GimpColorFrame     *frame,
+                                                 gboolean            has_coords);
 
 void        gimp_color_frame_set_color          (GimpColorFrame     *frame,
                                                  gboolean            sample_average,
                                                  const Babl         *format,
                                                  gpointer            pixel,
-                                                 const GimpRGB      *color);
+                                                 const GimpRGB      *color,
+                                                 gint                x,
+                                                 gint                y);
 void        gimp_color_frame_set_invalid        (GimpColorFrame     *frame);
 
 void        gimp_color_frame_set_color_config   (GimpColorFrame     *frame,
diff --git a/app/widgets/gimpsamplepointeditor.c b/app/widgets/gimpsamplepointeditor.c
index 8e55be1..f52975e 100644
--- a/app/widgets/gimpsamplepointeditor.c
+++ b/app/widgets/gimpsamplepointeditor.c
@@ -150,6 +150,7 @@ gimp_sample_point_editor_init (GimpSamplePointEditor *editor)
                             "has-number",     TRUE,
                             "number",         i + 1,
                             "has-color-area", TRUE,
+                            "has-coords",     TRUE,
                             "sensitive",      FALSE,
                             NULL);
 
@@ -506,7 +507,8 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
                                      &color))
             {
               gimp_color_frame_set_color (color_frame, FALSE,
-                                          format, pixel, &color);
+                                          format, pixel, &color,
+                                          x, y);
             }
           else
             {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]