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



commit 7b8d8a29a552aae058e212af8d82df0a29f4d833
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jul 7 19:17:58 2018 +0200

    Issue #1805 - Sample Points keep resetting themselves to "Pixel"
    
    Don't destroy the color frames when the number of points changes.
    Instead, simply hide them so they keep their color model, but add an
    upper limit of an arbitrary number of 16 frames to keep around.
    
    (cherry picked from commit 370680f9bc81227b45c3abbdb9a632cb444bb71d)

 app/widgets/gimpsamplepointeditor.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/app/widgets/gimpsamplepointeditor.c b/app/widgets/gimpsamplepointeditor.c
index 464534451c..d45db54c1c 100644
--- a/app/widgets/gimpsamplepointeditor.c
+++ b/app/widgets/gimpsamplepointeditor.c
@@ -420,15 +420,25 @@ gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor)
   gtk_widget_set_visible (editor->empty_label,
                           image_editor->image && n_points == 0);
 
-  if (n_points < editor->n_color_frames)
+  /*  Keep that many color frames around so they remember their color
+   *  model. Let's hope nobody uses more and notices they get reset to
+   *  "pixel". See https://gitlab.gnome.org/GNOME/gimp/issues/1805
+   */
+#define RANDOM_MAGIC 16
+
+  if (n_points < editor->n_color_frames &&
+      n_points < RANDOM_MAGIC           &&
+      editor->n_color_frames > RANDOM_MAGIC)
     {
-      for (i = n_points; i < editor->n_color_frames; i++)
+      for (i = RANDOM_MAGIC; i < editor->n_color_frames; i++)
         {
           gtk_widget_destroy (editor->color_frames[i]);
         }
 
       editor->color_frames = g_renew (GtkWidget *, editor->color_frames,
-                                      n_points);
+                                      RANDOM_MAGIC);
+
+      editor->n_color_frames = RANDOM_MAGIC;
     }
   else if (n_points > editor->n_color_frames)
     {
@@ -459,14 +469,18 @@ gimp_sample_point_editor_points_changed (GimpSamplePointEditor *editor)
           gtk_table_attach (GTK_TABLE (editor->table), editor->color_frames[i],
                             column, column + 1, row, row + 1,
                             GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
-          gtk_widget_show (editor->color_frames[i]);
 
           g_object_set_data (G_OBJECT (editor->color_frames[i]),
                              "dirty", GINT_TO_POINTER (TRUE));
         }
+
+      editor->n_color_frames = n_points;
     }
 
-  editor->n_color_frames = n_points;
+  for (i = 0; i < editor->n_color_frames; i++)
+    {
+      gtk_widget_set_visible (editor->color_frames[i], i < n_points);
+    }
 
   if (n_points > 0)
     gimp_sample_point_editor_dirty (editor, -1);


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