[gimp/wip/gradient-edit: 25/33] app: add sliders for gradient stops and midpoints in the blend tool



commit eccdb4d0af2816a37d7971ae99f89fb6f15b1efa
Author: Ell <ell_se yahoo com>
Date:   Tue Aug 1 11:33:36 2017 -0400

    app: add sliders for gradient stops and midpoints in the blend tool
    
    They can't be used to modify the gradient yet, but soon...  Very
    soon!

 app/tools/gimpblendtool-editor.c |  176 ++++++++++++++++++++++++++++++++++++-
 app/tools/gimpblendtool-editor.h |    8 ++-
 app/tools/gimpblendtool.c        |    4 +
 3 files changed, 182 insertions(+), 6 deletions(-)
---
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index edeab92..b3d3b92 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -45,10 +45,12 @@
 
 /*  local function prototypes  */
 
-static gboolean   gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool);
+static gboolean   gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool  *blend_tool);
 
-static void       gimp_blend_tool_editor_freeze_gradient      (GimpBlendTool *blend_tool);
-static void       gimp_blend_tool_editor_thaw_gradient        (GimpBlendTool *blend_tool);
+static void       gimp_blend_tool_editor_freeze_gradient      (GimpBlendTool  *blend_tool);
+static void       gimp_blend_tool_editor_thaw_gradient        (GimpBlendTool  *blend_tool);
+
+static void       gimp_blend_tool_editor_update_sliders       (GimpBlendTool  *blend_tool);
 
 
 /*  private functions  */
@@ -59,8 +61,9 @@ gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool)
 {
   GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
 
-  return ! options->modify_active ||
-         gimp_data_is_writable (GIMP_DATA (blend_tool->gradient));
+  return ! options->instant        &&
+         (! options->modify_active ||
+          gimp_data_is_writable (GIMP_DATA (blend_tool->gradient)));
 }
 
 static void
@@ -100,11 +103,166 @@ gimp_blend_tool_editor_thaw_gradient(GimpBlendTool *blend_tool)
   gimp_data_thaw (GIMP_DATA (blend_tool->gradient));
 }
 
+static void
+gimp_blend_tool_editor_update_sliders (GimpBlendTool *blend_tool)
+{
+  GimpBlendOptions     *options       = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpPaintOptions     *paint_options = GIMP_PAINT_OPTIONS (options);
+  GimpControllerSlider *sliders       = NULL;
+  gint                  n_sliders     = 0;
+
+  if (! blend_tool->widget)
+    return;
+
+  if (gimp_blend_tool_editor_is_gradient_editable (blend_tool))
+    {
+      GimpGradientSegment  *seg;
+      gint                  n_segments;
+      gdouble               offset = options->offset / 100.0;
+      GimpControllerSlider *slider;
+      gint                  i;
+
+      n_segments = gimp_gradient_segment_range_get_n_segments (
+        blend_tool->gradient, blend_tool->gradient->segments, NULL);
+
+      n_sliders = (n_segments - 1) + /* gradient stops, between each adjacent
+                                      * pair of segments */
+                  (n_segments);      /* midpoints, inside each segment */
+
+      sliders = g_new (GimpControllerSlider, n_sliders);
+
+      slider = sliders;
+
+      /* initialize the gradient-stop sliders */
+      for (seg = blend_tool->gradient->segments, i = 0;
+           seg->next;
+           seg = seg->next, i++)
+        {
+          *slider = GIMP_CONTROLLER_SLIDER_DEFAULT;
+
+          slider->value = seg->right;
+          slider->min   = seg->left;
+          slider->max   = seg->next->right;
+
+          slider->data  = GINT_TO_POINTER (i);
+
+          slider++;
+        }
+
+      /* initialize the midpoint sliders */
+      for (seg = blend_tool->gradient->segments, i = 0;
+           seg;
+           seg = seg->next, i++)
+        {
+          *slider = GIMP_CONTROLLER_SLIDER_DEFAULT;
+
+          slider->value    = seg->middle;
+          slider->min      = seg->left;
+          slider->max      = seg->right;
+
+          /* hide midpoints of zero-length segments, since they'd otherwise
+           * prevent the segment's endpoints from being selected
+           */
+          if (slider->min == slider->max)
+            slider->visible = FALSE;
+
+          slider->autohide = TRUE;
+          slider->type     = GIMP_HANDLE_FILLED_CIRCLE;
+          slider->size     = 0.6;
+
+          slider->data     = GINT_TO_POINTER (i);
+
+          slider++;
+        }
+
+      /* flip the slider limits and values, if necessary */
+      if (paint_options->gradient_options->gradient_reverse)
+        {
+          for (i = 0; i < n_sliders; i++)
+            {
+              gdouble temp;
+
+              sliders[i].value = 1.0 - sliders[i].value;
+              temp             = sliders[i].min;
+              sliders[i].min   = 1.0 - sliders[i].max;
+              sliders[i].max   = 1.0 - temp;
+            }
+        }
+
+      /* adjust the sliders according to the offset */
+      for (i = 0; i < n_sliders; i++)
+        {
+          sliders[i].value = (1.0 - offset) * sliders[i].value + offset;
+          sliders[i].min   = (1.0 - offset) * sliders[i].min   + offset;
+          sliders[i].max   = (1.0 - offset) * sliders[i].max   + offset;
+        }
+    }
+
+  gimp_tool_line_set_sliders (GIMP_TOOL_LINE (blend_tool->widget),
+                              sliders, n_sliders);
+
+  g_free (sliders);
+}
+
 
 /*  public functions  */
 
 
 void
+gimp_blend_tool_editor_options_notify (GimpBlendTool    *blend_tool,
+                                       GimpToolOptions  *options,
+                                       const GParamSpec *pspec)
+{
+  if (! strcmp (pspec->name, "modify-active"))
+    {
+      gimp_blend_tool_editor_update_sliders (blend_tool);
+    }
+  else if (! strcmp (pspec->name, "gradient-reverse"))
+    {
+      gimp_blend_tool_editor_update_sliders (blend_tool);
+
+      /* if an endpoint is selected, swap the selected endpoint */
+      if (blend_tool->widget)
+        {
+          gint selection;
+
+          selection =
+            gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
+
+          switch (selection)
+            {
+            case GIMP_TOOL_LINE_HANDLE_START:
+              gimp_tool_line_set_selection (GIMP_TOOL_LINE (blend_tool->widget),
+                                            GIMP_TOOL_LINE_HANDLE_END);
+              break;
+
+            case GIMP_TOOL_LINE_HANDLE_END:
+              gimp_tool_line_set_selection (GIMP_TOOL_LINE (blend_tool->widget),
+                                            GIMP_TOOL_LINE_HANDLE_START);
+              break;
+            }
+        }
+    }
+  else if (blend_tool->render_node &&
+      gegl_node_find_property (blend_tool->render_node, pspec->name))
+    {
+      gimp_blend_tool_editor_update_sliders (blend_tool);
+    }
+}
+
+void
+gimp_blend_tool_editor_gradient_dirty (GimpBlendTool *blend_tool)
+{
+  if (blend_tool->widget)
+    {
+      gimp_blend_tool_editor_update_sliders (blend_tool);
+
+      gimp_tool_line_set_selection (GIMP_TOOL_LINE (blend_tool->widget),
+                                    GIMP_TOOL_LINE_HANDLE_NONE);
+    }
+}
+
+void
 gimp_blend_tool_editor_gradient_changed (GimpBlendTool *blend_tool)
 {
   GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
@@ -123,4 +281,12 @@ gimp_blend_tool_editor_gradient_changed (GimpBlendTool *blend_tool)
                               blend_tool->gradient &&
                               ! gimp_data_is_writable (GIMP_DATA (blend_tool->gradient)));
     }
+
+  if (blend_tool->widget)
+    {
+      gimp_blend_tool_editor_update_sliders (blend_tool);
+
+      gimp_tool_line_set_selection (GIMP_TOOL_LINE (blend_tool->widget),
+                                    GIMP_TOOL_LINE_HANDLE_NONE);
+    }
 }
diff --git a/app/tools/gimpblendtool-editor.h b/app/tools/gimpblendtool-editor.h
index 5e49e60..d34324b 100644
--- a/app/tools/gimpblendtool-editor.h
+++ b/app/tools/gimpblendtool-editor.h
@@ -19,7 +19,13 @@
 #define  __GIMP_BLEND_TOOL_EDITOR_H__
 
 
-void   gimp_blend_tool_editor_gradient_changed (GimpBlendTool *blend_tool);
+void   gimp_blend_tool_editor_options_notify   (GimpBlendTool    *blend_tool,
+                                                GimpToolOptions  *options,
+                                                const GParamSpec *pspec);
+
+void   gimp_blend_tool_editor_gradient_dirty   (GimpBlendTool    *blend_tool);
+
+void   gimp_blend_tool_editor_gradient_changed (GimpBlendTool    *blend_tool);
 
 
 #endif  /*  __GIMP_BLEND_TOOL_EDITOR_H__  */
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index d921a37..425007b 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -593,6 +593,8 @@ gimp_blend_tool_options_notify (GimpTool         *tool,
                                      GIMP_LAYER_COLOR_SPACE_AUTO,
                                      GIMP_LAYER_COMPOSITE_AUTO);
     }
+
+  gimp_blend_tool_editor_options_notify (blend_tool, options, pspec);
 }
 
 static void
@@ -906,6 +908,8 @@ gimp_blend_tool_gradient_dirty (GimpBlendTool *blend_tool)
 
   /* Update the filter */
   gimp_drawable_filter_apply (blend_tool->filter, NULL);
+
+  gimp_blend_tool_editor_gradient_dirty (blend_tool);
 }
 
 static void


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