[gimp/gimp-2-10] Issue #1805 - Sample Points keep resetting themselves to "Pixel"



commit 88db1f82826138e5250088f294ec2b8d00fbb14e
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jul 16 00:35:33 2018 +0200

    Issue #1805 - Sample Points keep resetting themselves to "Pixel"
    
    Remember the sample point's GimpColorPickMode in the sample point
    itself, so it is remembered across switching between images.
    
    Not persistent in the XCF yet tho...
    
    (cherry picked from commit a0129504c811fa10cbd5483d40c2c3ada27a71f6)

 app/core/gimpimage-sample-points.c  | 21 ++++++++++++
 app/core/gimpimage-sample-points.h  |  5 +++
 app/core/gimpsamplepoint.c          | 60 ++++++++++++++++++++++++++++------
 app/core/gimpsamplepoint.h          | 20 +++++++-----
 app/core/gimpsamplepointundo.c      | 10 ++++--
 app/core/gimpsamplepointundo.h      |  7 ++--
 app/widgets/gimpsamplepointeditor.c | 64 ++++++++++++++++++++++++++++++++-----
 7 files changed, 157 insertions(+), 30 deletions(-)
---
diff --git a/app/core/gimpimage-sample-points.c b/app/core/gimpimage-sample-points.c
index 0f3fd65908..24fc66f2b2 100644
--- a/app/core/gimpimage-sample-points.c
+++ b/app/core/gimpimage-sample-points.c
@@ -131,6 +131,27 @@ gimp_image_move_sample_point (GimpImage       *image,
   gimp_image_sample_point_moved (image, sample_point);
 }
 
+void
+gimp_image_set_sample_point_pick_mode (GimpImage         *image,
+                                       GimpSamplePoint   *sample_point,
+                                       GimpColorPickMode  pick_mode,
+                                       gboolean           push_undo)
+{
+  g_return_if_fail (GIMP_IS_IMAGE (image));
+  g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
+
+  if (push_undo)
+    gimp_image_undo_push_sample_point (image,
+                                       C_("undo-type",
+                                          "Set Sample Point Pick Mode"),
+                                       sample_point);
+
+  gimp_sample_point_set_pick_mode (sample_point, pick_mode);
+
+  /* well... */
+  gimp_image_sample_point_moved (image, sample_point);
+}
+
 GList *
 gimp_image_get_sample_points (GimpImage *image)
 {
diff --git a/app/core/gimpimage-sample-points.h b/app/core/gimpimage-sample-points.h
index 7cc85de2a2..c84a02b30d 100644
--- a/app/core/gimpimage-sample-points.h
+++ b/app/core/gimpimage-sample-points.h
@@ -43,6 +43,11 @@ void              gimp_image_move_sample_point       (GimpImage       *image,
                                                       gint             x,
                                                       gint             y,
                                                       gboolean         push_undo);
+void              gimp_image_set_sample_point_pick_mode
+                                                     (GimpImage       *image,
+                                                      GimpSamplePoint *sample_point,
+                                                      GimpColorPickMode pick_mode,
+                                                      gboolean         push_undo);
 
 GList           * gimp_image_get_sample_points       (GimpImage       *image);
 GimpSamplePoint * gimp_image_get_sample_point        (GimpImage       *image,
diff --git a/app/core/gimpsamplepoint.c b/app/core/gimpsamplepoint.c
index 4b6970adc1..60870594b6 100644
--- a/app/core/gimpsamplepoint.c
+++ b/app/core/gimpsamplepoint.c
@@ -31,14 +31,16 @@ enum
 {
   PROP_0,
   PROP_POSITION_X,
-  PROP_POSITION_Y
+  PROP_POSITION_Y,
+  PROP_PICK_MODE
 };
 
 
 struct _GimpSamplePointPrivate
 {
-  gint  position_x;
-  gint  position_y;
+  gint              position_x;
+  gint              position_y;
+  GimpColorPickMode pick_mode;
 };
 
 
@@ -79,6 +81,13 @@ gimp_sample_point_class_init (GimpSamplePointClass *klass)
                         GIMP_SAMPLE_POINT_POSITION_UNDEFINED,
                         0);
 
+  GIMP_CONFIG_PROP_ENUM (object_class, PROP_PICK_MODE,
+                         "pick-mode",
+                         NULL, NULL,
+                         GIMP_TYPE_COLOR_PICK_MODE,
+                         GIMP_COLOR_PICK_MODE_PIXEL,
+                         0);
+
   g_type_class_add_private (klass, sizeof (GimpSamplePointPrivate));
 }
 
@@ -106,6 +115,9 @@ gimp_sample_point_get_property (GObject    *object,
     case PROP_POSITION_Y:
       g_value_set_int (value, sample_point->priv->position_y);
       break;
+    case PROP_PICK_MODE:
+      g_value_set_enum (value, sample_point->priv->pick_mode);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -129,6 +141,9 @@ gimp_sample_point_set_property (GObject      *object,
     case PROP_POSITION_Y:
       sample_point->priv->position_y = g_value_get_int (value);
       break;
+    case PROP_PICK_MODE:
+      sample_point->priv->pick_mode = g_value_get_enum (value);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -164,13 +179,40 @@ gimp_sample_point_set_position (GimpSamplePoint *sample_point,
 {
   g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
 
-  sample_point->priv->position_x = position_x;
-  sample_point->priv->position_y = position_y;
+  if (sample_point->priv->position_x != position_x ||
+      sample_point->priv->position_y != position_y)
+    {
+      sample_point->priv->position_x = position_x;
+      sample_point->priv->position_y = position_y;
+
+      g_object_freeze_notify (G_OBJECT (sample_point));
+
+      g_object_notify (G_OBJECT (sample_point), "position-x");
+      g_object_notify (G_OBJECT (sample_point), "position-y");
+
+      g_object_thaw_notify (G_OBJECT (sample_point));
+    }
+}
+
+GimpColorPickMode
+gimp_sample_point_get_pick_mode (GimpSamplePoint *sample_point)
+{
+  g_return_val_if_fail (GIMP_IS_SAMPLE_POINT (sample_point),
+                        GIMP_COLOR_PICK_MODE_PIXEL);
 
-  g_object_freeze_notify (G_OBJECT (sample_point));
+  return sample_point->priv->pick_mode;
+}
 
-  g_object_notify (G_OBJECT (sample_point), "position-x");
-  g_object_notify (G_OBJECT (sample_point), "position-y");
+void
+gimp_sample_point_set_pick_mode (GimpSamplePoint   *sample_point,
+                                 GimpColorPickMode  pick_mode)
+{
+  g_return_if_fail (GIMP_IS_SAMPLE_POINT (sample_point));
+
+  if (sample_point->priv->pick_mode != pick_mode)
+    {
+      sample_point->priv->pick_mode = pick_mode;
 
-  g_object_thaw_notify (G_OBJECT (sample_point));
+      g_object_notify (G_OBJECT (sample_point), "pick-mode");
+    }
 }
diff --git a/app/core/gimpsamplepoint.h b/app/core/gimpsamplepoint.h
index 563723e429..dddd328f7f 100644
--- a/app/core/gimpsamplepoint.h
+++ b/app/core/gimpsamplepoint.h
@@ -49,16 +49,20 @@ struct _GimpSamplePointClass
 };
 
 
-GType             gimp_sample_point_get_type (void) G_GNUC_CONST;
+GType             gimp_sample_point_get_type      (void) G_GNUC_CONST;
 
-GimpSamplePoint * gimp_sample_point_new          (guint32          sample_point_ID);
+GimpSamplePoint * gimp_sample_point_new           (guint32            sample_point_ID);
 
-void              gimp_sample_point_get_position (GimpSamplePoint *sample_point,
-                                                  gint            *position_x,
-                                                  gint            *position_y);
-void              gimp_sample_point_set_position (GimpSamplePoint *sample_point,
-                                                  gint             position_x,
-                                                  gint             position_y);
+void              gimp_sample_point_get_position  (GimpSamplePoint   *sample_point,
+                                                   gint              *position_x,
+                                                   gint              *position_y);
+void              gimp_sample_point_set_position  (GimpSamplePoint   *sample_point,
+                                                   gint               position_x,
+                                                   gint               position_y);
+
+GimpColorPickMode gimp_sample_point_get_pick_mode (GimpSamplePoint   *sample_point);
+void              gimp_sample_point_set_pick_mode (GimpSamplePoint   *sample_point,
+                                                   GimpColorPickMode  pick_mode);
 
 
 #endif /* __GIMP_SAMPLE_POINT_H__ */
diff --git a/app/core/gimpsamplepointundo.c b/app/core/gimpsamplepointundo.c
index 157437c63d..89cd8ae44d 100644
--- a/app/core/gimpsamplepointundo.c
+++ b/app/core/gimpsamplepointundo.c
@@ -72,6 +72,7 @@ gimp_sample_point_undo_constructed (GObject *object)
   gimp_sample_point_get_position (sample_point,
                                   &sample_point_undo->x,
                                   &sample_point_undo->y);
+  sample_point_undo->pick_mode = gimp_sample_point_get_pick_mode (sample_point);
 }
 
 static void
@@ -83,12 +84,14 @@ gimp_sample_point_undo_pop (GimpUndo              *undo,
   GimpSamplePoint     *sample_point;
   gint                 x;
   gint                 y;
+  GimpColorPickMode    pick_mode;
 
   GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);
 
   sample_point = GIMP_SAMPLE_POINT (GIMP_AUX_ITEM_UNDO (undo)->aux_item);
 
   gimp_sample_point_get_position (sample_point, &x, &y);
+  pick_mode = gimp_sample_point_get_pick_mode (sample_point);
 
   if (x == GIMP_SAMPLE_POINT_POSITION_UNDEFINED)
     {
@@ -106,10 +109,13 @@ gimp_sample_point_undo_pop (GimpUndo              *undo,
       gimp_sample_point_set_position (sample_point,
                                       sample_point_undo->x,
                                       sample_point_undo->y);
+      gimp_sample_point_set_pick_mode (sample_point,
+                                       sample_point_undo->pick_mode);
 
       gimp_image_sample_point_moved (undo->image, sample_point);
     }
 
-  sample_point_undo->x = x;
-  sample_point_undo->y = y;
+  sample_point_undo->x         = x;
+  sample_point_undo->y         = y;
+  sample_point_undo->pick_mode = pick_mode;
 }
diff --git a/app/core/gimpsamplepointundo.h b/app/core/gimpsamplepointundo.h
index 63899a7933..10a3e90daa 100644
--- a/app/core/gimpsamplepointundo.h
+++ b/app/core/gimpsamplepointundo.h
@@ -35,10 +35,11 @@ typedef struct _GimpSamplePointUndoClass GimpSamplePointUndoClass;
 
 struct _GimpSamplePointUndo
 {
-  GimpAuxItemUndo  parent_instance;
+  GimpAuxItemUndo    parent_instance;
 
-  gint             x;
-  gint             y;
+  gint               x;
+  gint               y;
+  GimpColorPickMode  pick_mode;
 };
 
 struct _GimpSamplePointUndoClass
diff --git a/app/widgets/gimpsamplepointeditor.c b/app/widgets/gimpsamplepointeditor.c
index f8349ea4a8..b9de0f21df 100644
--- a/app/widgets/gimpsamplepointeditor.c
+++ b/app/widgets/gimpsamplepointeditor.c
@@ -86,6 +86,9 @@ static void   gimp_sample_point_editor_points_changed (GimpSamplePointEditor *ed
 static void   gimp_sample_point_editor_dirty          (GimpSamplePointEditor *editor,
                                                        gint                   index);
 static gboolean gimp_sample_point_editor_update       (GimpSamplePointEditor *editor);
+static void     gimp_sample_point_editor_mode_notify  (GimpColorFrame        *frame,
+                                                       const GParamSpec      *pspec,
+                                                       GimpSamplePointEditor *editor);
 
 
 G_DEFINE_TYPE (GimpSamplePointEditor, gimp_sample_point_editor,
@@ -470,6 +473,10 @@ gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor)
                             column, column + 1, row, row + 1,
                             GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
+          g_signal_connect_object (editor->color_frames[i], "notify::mode",
+                                   G_CALLBACK (gimp_sample_point_editor_mode_notify),
+                                   editor, 0);
+
           g_object_set_data (G_OBJECT (editor->color_frames[i]),
                              "dirty", GINT_TO_POINTER (TRUE));
         }
@@ -517,7 +524,7 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
 {
   GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
   GList           *sample_points;
-  gint             n_points     = 0;
+  gint             n_points;
   GList           *list;
   gint             i;
 
@@ -534,17 +541,18 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
        i < n_points;
        i++, list = g_list_next (list))
     {
-      GimpColorFrame  *color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);
+      GimpColorFrame *color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);
 
       if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (color_frame),
                                               "dirty")))
         {
-          GimpSamplePoint *sample_point = list->data;
-          const Babl      *format;
-          guchar           pixel[32];
-          GimpRGB          color;
-          gint             x;
-          gint             y;
+          GimpSamplePoint   *sample_point = list->data;
+          const Babl        *format;
+          guchar             pixel[32];
+          GimpRGB            color;
+          GimpColorPickMode  pick_mode;
+          gint               x;
+          gint               y;
 
           g_object_set_data (G_OBJECT (color_frame),
                              "dirty", GINT_TO_POINTER (FALSE));
@@ -567,8 +575,48 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
             {
               gimp_color_frame_set_invalid (color_frame);
             }
+
+          pick_mode = gimp_sample_point_get_pick_mode (sample_point);
+
+          gimp_color_frame_set_mode (color_frame, pick_mode);
         }
     }
 
   return FALSE;
 }
+
+static void
+gimp_sample_point_editor_mode_notify (GimpColorFrame        *frame,
+                                      const GParamSpec      *pspec,
+                                      GimpSamplePointEditor *editor)
+{
+  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
+  GList           *sample_points;
+  gint             n_points;
+  GList           *list;
+  gint             i;
+
+  sample_points = gimp_image_get_sample_points (image_editor->image);
+
+  n_points = MIN (editor->n_color_frames, g_list_length (sample_points));
+
+  for (i = 0, list = sample_points;
+       i < n_points;
+       i++, list = g_list_next (list))
+    {
+      if (GIMP_COLOR_FRAME (editor->color_frames[i]) == frame)
+        {
+          GimpSamplePoint   *sample_point = list->data;
+          GimpColorPickMode  pick_mode;
+
+          g_object_get (frame, "mode", &pick_mode, NULL);
+
+          if (pick_mode != gimp_sample_point_get_pick_mode (sample_point))
+            gimp_image_set_sample_point_pick_mode (image_editor->image,
+                                                   sample_point,
+                                                   pick_mode,
+                                                   TRUE);
+          break;
+        }
+    }
+}


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