[gimp/wip/gradient-edit: 33/42] app: implement blend tool gui for gradient endpoints



commit d0fd7d791af0c2ad83e0d804653e280b4533d560
Author: Ell <ell_se yahoo com>
Date:   Thu Aug 3 01:05:44 2017 -0400

    app: implement blend tool gui for gradient endpoints
    
    Allows setting the endpoint's position, its color, and its color
    type.

 app/core/core-enums.c            |   10 +-
 app/core/core-enums.h            |   10 +-
 app/tools/gimpblendtool-editor.c |  592 +++++++++++++++++++++++++++++++++++---
 app/tools/gimpblendtool.h        |    4 +
 4 files changed, 561 insertions(+), 55 deletions(-)
---
diff --git a/app/core/core-enums.c b/app/core/core-enums.c
index 174436e..1e1570e 100644
--- a/app/core/core-enums.c
+++ b/app/core/core-enums.c
@@ -983,11 +983,11 @@ gimp_gradient_color_get_type (void)
 
   static const GimpEnumDesc descs[] =
   {
-    { GIMP_GRADIENT_COLOR_FIXED, "GIMP_GRADIENT_COLOR_FIXED", NULL },
-    { GIMP_GRADIENT_COLOR_FOREGROUND, "GIMP_GRADIENT_COLOR_FOREGROUND", NULL },
-    { GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT, "GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT", NULL },
-    { GIMP_GRADIENT_COLOR_BACKGROUND, "GIMP_GRADIENT_COLOR_BACKGROUND", NULL },
-    { GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT, "GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT", NULL },
+    { GIMP_GRADIENT_COLOR_FIXED, NC_("gradient-color", "Fixed"), NULL },
+    { GIMP_GRADIENT_COLOR_FOREGROUND, NC_("gradient-color", "FG"), NULL },
+    { GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT, NC_("gradient-color", "FG (t)"), NULL },
+    { GIMP_GRADIENT_COLOR_BACKGROUND, NC_("gradient-color", "BG"), NULL },
+    { GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT, NC_("gradient-color", "BG (t)"), NULL },
     { 0, NULL, NULL }
   };
 
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index da34406..429de3a 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -464,11 +464,11 @@ GType gimp_gradient_color_get_type (void) G_GNUC_CONST;
 
 typedef enum  /*< pdb-skip >*/
 {
-  GIMP_GRADIENT_COLOR_FIXED,
-  GIMP_GRADIENT_COLOR_FOREGROUND,
-  GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT,
-  GIMP_GRADIENT_COLOR_BACKGROUND,
-  GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT
+  GIMP_GRADIENT_COLOR_FIXED,                  /*< desc="Fixed"  >*/
+  GIMP_GRADIENT_COLOR_FOREGROUND,             /*< desc="FG"     >*/
+  GIMP_GRADIENT_COLOR_FOREGROUND_TRANSPARENT, /*< desc="FG (t)" >*/
+  GIMP_GRADIENT_COLOR_BACKGROUND,             /*< desc="BG"     >*/
+  GIMP_GRADIENT_COLOR_BACKGROUND_TRANSPARENT  /*< desc="BG (t)" >*/
 } GimpGradientColor;
 
 
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index 2487477..67a085c 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -21,6 +21,7 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "libgimpbase/gimpbase.h"
 #include "libgimpmath/gimpmath.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -31,10 +32,14 @@
 #include "core/gimpdata.h"
 #include "core/gimpgradient.h"
 #include "core/gimp-gradients.h"
+#include "core/gimpimage.h"
 
+#include "widgets/gimpcolorpanel.h"
+#include "widgets/gimpeditor.h"
 #include "widgets/gimpwidgets-utils.h"
 
 #include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
 #include "display/gimptoolgui.h"
 #include "display/gimptoolline.h"
 
@@ -48,53 +53,79 @@
 #define EPSILON 1e-10
 
 
+typedef enum
+{
+  DIRECTION_NONE,
+  DIRECTION_LEFT,
+  DIRECTION_RIGHT
+} Direction;
+
+
 /*  local function prototypes  */
 
-static gboolean              gimp_blend_tool_editor_line_can_add_slider    (GimpToolLine        *line,
-                                                                            gdouble              value,
-                                                                            GimpBlendTool       *blend_tool);
-static gint                  gimp_blend_tool_editor_line_add_slider        (GimpToolLine        *line,
-                                                                            gdouble              value,
-                                                                            GimpBlendTool       *blend_tool);
-static void                  gimp_blend_tool_editor_line_remove_slider     (GimpToolLine        *line,
-                                                                            gint                 slider,
-                                                                            GimpBlendTool       *blend_tool);
-static void                  gimp_blend_tool_editor_line_selection_changed (GimpToolLine        *line,
-                                                                            GimpBlendTool       *blend_tool);
-static gboolean              gimp_blend_tool_editor_line_handle_clicked    (GimpToolLine        *line,
-                                                                            gint                 handle,
-                                                                            GdkModifierType      state,
-                                                                            GimpButtonPressType  press_type,
-                                                                            GimpBlendTool       *blend_tool);
-
-static void                  gimp_blend_tool_editor_gui_response           (GimpToolGui         *gui,
-                                                                            gint                 response_id,
-                                                                            GimpBlendTool       *blend_tool);
-
-static gboolean              gimp_blend_tool_editor_is_gradient_editable   (GimpBlendTool       *blend_tool);
-
-static gboolean              gimp_blend_tool_editor_handle_is_endpoint     (GimpBlendTool       *blend_tool,
-                                                                            gint                 handle);
-static gboolean              gimp_blend_tool_editor_handle_is_stop         (GimpBlendTool       *blend_tool,
-                                                                            gint                 handle);
-static gboolean              gimp_blend_tool_editor_handle_is_midpoint     (GimpBlendTool       *blend_tool,
-                                                                            gint                 handle);
-static GimpGradientSegment * gimp_blend_tool_editor_handle_get_segment     (GimpBlendTool       *blend_tool,
-                                                                            gint                 handle);
-
-static void                  gimp_blend_tool_editor_block_handlers         (GimpBlendTool       *blend_tool);
-static void                  gimp_blend_tool_editor_unblock_handlers       (GimpBlendTool       *blend_tool);
-static gboolean              gimp_blend_tool_editor_are_handlers_blocked   (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 gint                  gimp_blend_tool_editor_add_stop               (GimpBlendTool       *blend_tool,
-                                                                            gdouble              value);
-
-static void                  gimp_blend_tool_editor_update_sliders         (GimpBlendTool       *blend_tool);
-
-static void                  gimp_blend_tool_editor_update_gui             (GimpBlendTool       *blend_tool);
+static gboolean              gimp_blend_tool_editor_line_can_add_slider        (GimpToolLine         *line,
+                                                                                gdouble               value,
+                                                                                GimpBlendTool        
*blend_tool);
+static gint                  gimp_blend_tool_editor_line_add_slider            (GimpToolLine         *line,
+                                                                                gdouble               value,
+                                                                                GimpBlendTool        
*blend_tool);
+static void                  gimp_blend_tool_editor_line_remove_slider         (GimpToolLine         *line,
+                                                                                gint                  slider,
+                                                                                GimpBlendTool        
*blend_tool);
+static void                  gimp_blend_tool_editor_line_selection_changed     (GimpToolLine         *line,
+                                                                                GimpBlendTool        
*blend_tool);
+static gboolean              gimp_blend_tool_editor_line_handle_clicked        (GimpToolLine         *line,
+                                                                                gint                  handle,
+                                                                                GdkModifierType       state,
+                                                                                GimpButtonPressType   
press_type,
+                                                                                GimpBlendTool        
*blend_tool);
+
+static void                  gimp_blend_tool_editor_gui_response               (GimpToolGui          *gui,
+                                                                                gint                  
response_id,
+                                                                                GimpBlendTool        
*blend_tool);
+
+static void                  gimp_blend_tool_editor_color_entry_color_changed  (GimpColorButton       
*button,
+                                                                                GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_color_entry_type_changed   (GtkComboBox           *combo,
+                                                                                GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_endpoint_se_value_changed  (GimpSizeEntry         *se,
+                                                                                GimpBlendTool         
*blend_tool);
+
+static gboolean              gimp_blend_tool_editor_is_gradient_editable       (GimpBlendTool        
*blend_tool);
+
+static gboolean              gimp_blend_tool_editor_handle_is_endpoint         (GimpBlendTool        
*blend_tool,
+                                                                                gint                  
handle);
+static gboolean              gimp_blend_tool_editor_handle_is_stop             (GimpBlendTool        
*blend_tool,
+                                                                                gint                  
handle);
+static gboolean              gimp_blend_tool_editor_handle_is_midpoint         (GimpBlendTool        
*blend_tool,
+                                                                                gint                  
handle);
+static GimpGradientSegment * gimp_blend_tool_editor_handle_get_segment         (GimpBlendTool        
*blend_tool,
+                                                                                gint                  
handle);
+
+static void                  gimp_blend_tool_editor_block_handlers             (GimpBlendTool        
*blend_tool);
+static void                  gimp_blend_tool_editor_unblock_handlers           (GimpBlendTool        
*blend_tool);
+static gboolean              gimp_blend_tool_editor_are_handlers_blocked       (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 gint                  gimp_blend_tool_editor_add_stop                   (GimpBlendTool        
*blend_tool,
+                                                                                gdouble               value);
+
+static void                  gimp_blend_tool_editor_update_sliders             (GimpBlendTool        
*blend_tool);
+
+static GtkWidget           * gimp_blend_tool_editor_color_entry_new            (GimpBlendTool        
*blend_tool,
+                                                                                const gchar          *title,
+                                                                                Direction             
direction,
+                                                                                GtkWidget            
*chain_button,
+                                                                                GtkWidget           
**color_panel,
+                                                                                GtkWidget           
**type_combo);
+static void                  gimp_blend_tool_editor_init_endpoint_gui          (GimpBlendTool        
*blend_tool);
+static void                  gimp_blend_tool_editor_update_endpoint_gui        (GimpBlendTool        
*blend_tool,
+                                                                                gint                  
selection);
+static void                  gimp_blend_tool_editor_update_gui                 (GimpBlendTool        
*blend_tool);
 
 
 /*  private functions  */
@@ -152,6 +183,14 @@ static void
 gimp_blend_tool_editor_line_selection_changed (GimpToolLine  *line,
                                                GimpBlendTool *blend_tool)
 {
+  if (blend_tool->gui)
+    {
+      /* hide all color dialogs */
+      gimp_color_panel_dialog_response (
+        GIMP_COLOR_PANEL (blend_tool->endpoint_color_panel),
+        GIMP_COLOR_DIALOG_OK);
+    }
+
   gimp_blend_tool_editor_update_gui (blend_tool);
 }
 
@@ -204,6 +243,201 @@ gimp_blend_tool_editor_gui_response (GimpToolGui   *gui,
     }
 }
 
+static void
+gimp_blend_tool_editor_color_entry_color_changed (GimpColorButton *button,
+                                                  GimpBlendTool   *blend_tool)
+{
+  GimpBlendOptions    *options       = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpPaintOptions    *paint_options = GIMP_PAINT_OPTIONS (options);
+  gint                 selection;
+  GimpRGB              color;
+  Direction            direction;
+  GtkWidget           *chain_button;
+  GimpGradientSegment *seg;
+
+  if (gimp_blend_tool_editor_are_handlers_blocked (blend_tool))
+    return;
+
+  selection =
+    gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
+
+  gimp_color_button_get_color (button, &color);
+
+  direction =
+    GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+                                        "gimp-blend-tool-editor-direction"));
+  chain_button = g_object_get_data (G_OBJECT (button),
+                                    "gimp-blend-tool-editor-chain-button");
+
+  gimp_blend_tool_editor_freeze_gradient (blend_tool);
+
+  /* swap the endpoint handles, if necessary */
+  if (paint_options->gradient_options->gradient_reverse)
+    {
+      switch (selection)
+        {
+        case GIMP_TOOL_LINE_HANDLE_START:
+          selection = GIMP_TOOL_LINE_HANDLE_END;
+          break;
+
+        case GIMP_TOOL_LINE_HANDLE_END:
+          selection = GIMP_TOOL_LINE_HANDLE_START;
+          break;
+        }
+    }
+
+  seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
+
+  switch (selection)
+    {
+    case GIMP_TOOL_LINE_HANDLE_START:
+      seg->left_color      = color;
+      seg->left_color_type = GIMP_GRADIENT_COLOR_FIXED;
+      break;
+
+    case GIMP_TOOL_LINE_HANDLE_END:
+      seg->right_color      = color;
+      seg->right_color_type = GIMP_GRADIENT_COLOR_FIXED;
+      break;
+
+    default:
+      if (direction == DIRECTION_LEFT ||
+          (chain_button               &&
+           gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chain_button))))
+        {
+          seg->right_color      = color;
+          seg->right_color_type = GIMP_GRADIENT_COLOR_FIXED;
+        }
+
+      if (direction == DIRECTION_RIGHT ||
+          (chain_button                &&
+           gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chain_button))))
+        {
+          seg->next->left_color      = color;
+          seg->next->left_color_type = GIMP_GRADIENT_COLOR_FIXED;
+        }
+    }
+
+  gimp_blend_tool_editor_thaw_gradient (blend_tool);
+}
+
+static void
+gimp_blend_tool_editor_color_entry_type_changed (GtkComboBox   *combo,
+                                                 GimpBlendTool *blend_tool)
+{
+  GimpBlendOptions    *options       = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpPaintOptions    *paint_options = GIMP_PAINT_OPTIONS (options);
+  gint                 selection;
+  gint                 color_type;
+  Direction            direction;
+  GtkWidget           *chain_button;
+  GimpGradientSegment *seg;
+
+  if (gimp_blend_tool_editor_are_handlers_blocked (blend_tool))
+    return;
+
+  selection =
+    gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
+
+  if (! gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (combo), &color_type))
+    return;
+
+  direction =
+    GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo),
+                                        "gimp-blend-tool-editor-direction"));
+  chain_button = g_object_get_data (G_OBJECT (combo),
+                                    "gimp-blend-tool-editor-chain-button");
+
+  gimp_blend_tool_editor_freeze_gradient (blend_tool);
+
+  /* swap the endpoint handles, if necessary */
+  if (paint_options->gradient_options->gradient_reverse)
+    {
+      switch (selection)
+        {
+        case GIMP_TOOL_LINE_HANDLE_START:
+          selection = GIMP_TOOL_LINE_HANDLE_END;
+          break;
+
+        case GIMP_TOOL_LINE_HANDLE_END:
+          selection = GIMP_TOOL_LINE_HANDLE_START;
+          break;
+        }
+    }
+
+  seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
+
+  switch (selection)
+    {
+    case GIMP_TOOL_LINE_HANDLE_START:
+      seg->left_color_type = color_type;
+      break;
+
+    case GIMP_TOOL_LINE_HANDLE_END:
+      seg->right_color_type = color_type;
+      break;
+
+    default:
+      if (direction == DIRECTION_LEFT ||
+          (chain_button               &&
+           gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chain_button))))
+        {
+          seg->right_color_type = color_type;
+        }
+
+      if (direction == DIRECTION_RIGHT ||
+          (chain_button                &&
+           gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (chain_button))))
+        {
+          seg->next->left_color_type = color_type;
+        }
+    }
+
+  gimp_blend_tool_editor_thaw_gradient (blend_tool);
+}
+
+static void
+gimp_blend_tool_editor_endpoint_se_value_changed (GimpSizeEntry *se,
+                                                  GimpBlendTool *blend_tool)
+{
+  gint    selection;
+  gdouble x;
+  gdouble y;
+
+  if (gimp_blend_tool_editor_are_handlers_blocked (blend_tool))
+    return;
+
+  selection =
+    gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
+
+  x = gimp_size_entry_get_refval (se, 0);
+  y = gimp_size_entry_get_refval (se, 1);
+
+  gimp_blend_tool_editor_block_handlers (blend_tool);
+
+  switch (selection)
+    {
+    case GIMP_TOOL_LINE_HANDLE_START:
+      g_object_set (blend_tool->widget,
+                    "x1", x,
+                    "y1", y,
+                    NULL);
+      break;
+
+    case GIMP_TOOL_LINE_HANDLE_END:
+      g_object_set (blend_tool->widget,
+                    "x2", x,
+                    "y2", y,
+                    NULL);
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+
+  gimp_blend_tool_editor_unblock_handlers (blend_tool);
+}
+
 static gboolean
 gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool)
 {
@@ -468,6 +702,263 @@ gimp_blend_tool_editor_update_sliders (GimpBlendTool *blend_tool)
   g_free (sliders);
 }
 
+static GtkWidget *
+gimp_blend_tool_editor_color_entry_new (GimpBlendTool  *blend_tool,
+                                        const gchar    *title,
+                                        Direction       direction,
+                                        GtkWidget      *chain_button,
+                                        GtkWidget     **color_panel,
+                                        GtkWidget     **type_combo)
+{
+  GimpContext *context = GIMP_CONTEXT (GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool));
+  GtkWidget   *hbox;
+  GtkWidget   *button;
+  GtkWidget   *combo;
+  GimpRGB      color   = {};
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+
+  /* the color panel */
+  *color_panel = button = gimp_color_panel_new (title, &color,
+                                                GIMP_COLOR_AREA_SMALL_CHECKS,
+                                                24, 24);
+  gimp_color_button_set_update (GIMP_COLOR_BUTTON (button), TRUE);
+  gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
+  gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+  gtk_widget_show (button);
+
+  g_object_set_data (G_OBJECT (button),
+                     "gimp-blend-tool-editor-direction",
+                     GINT_TO_POINTER (direction));
+  g_object_set_data (G_OBJECT (button),
+                     "gimp-blend-tool-editor-chain-button",
+                     chain_button);
+
+  g_signal_connect (button, "color-changed",
+                    G_CALLBACK (gimp_blend_tool_editor_color_entry_color_changed),
+                    blend_tool);
+
+  /* the color type combo */
+  *type_combo = combo = gimp_enum_combo_box_new (GIMP_TYPE_GRADIENT_COLOR);
+  gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, TRUE, 0);
+  gtk_widget_show (combo);
+
+  g_object_set_data (G_OBJECT (combo),
+                     "gimp-blend-tool-editor-direction",
+                     GINT_TO_POINTER (direction));
+  g_object_set_data (G_OBJECT (combo),
+                     "gimp-blend-tool-editor-chain-button",
+                     chain_button);
+
+  g_signal_connect (combo, "changed",
+                    G_CALLBACK (gimp_blend_tool_editor_color_entry_type_changed),
+                    blend_tool);
+
+  return hbox;
+}
+
+static void
+gimp_blend_tool_editor_init_endpoint_gui (GimpBlendTool *blend_tool)
+{
+  GimpDisplay      *display = GIMP_TOOL (blend_tool)->display;
+  GimpDisplayShell *shell   = gimp_display_get_shell (display);
+  GimpImage        *image   = gimp_display_get_image (display);
+  gdouble           xres;
+  gdouble           yres;
+  GtkWidget        *editor;
+  GtkWidget        *table;
+  GtkWidget        *label;
+  GtkWidget        *spinbutton;
+  GtkWidget        *se;
+  GtkWidget        *hbox;
+  gint              row     = 0;
+
+  gimp_image_get_resolution (image, &xres, &yres);
+
+  /* the endpoint editor */
+  blend_tool->endpoint_editor =
+  editor                      = gimp_editor_new ();
+  gtk_box_pack_start (GTK_BOX (gimp_tool_gui_get_vbox (blend_tool->gui)),
+                      editor, FALSE, TRUE, 0);
+
+  /* the main table */
+  table = gtk_table_new (1, 2, FALSE);
+  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
+  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
+  gtk_box_pack_start (GTK_BOX (editor), table, FALSE, TRUE, 0);
+  gtk_widget_show (table);
+
+  /* the position labels */
+  label = gtk_label_new (_("X:"));
+  gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
+                    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+  gtk_widget_show (label);
+
+  label = gtk_label_new (_("Y:"));
+  gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row + 1, row + 2,
+                    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+  gtk_widget_show (label);
+
+  /* the position size entry */
+  spinbutton = gtk_spin_button_new_with_range (0.0, 0.0, 1.0);
+  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
+  gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 6);
+
+  blend_tool->endpoint_se =
+  se                      = gimp_size_entry_new (1, GIMP_UNIT_PIXEL, "%a",
+                                                 TRUE, TRUE, FALSE, 6,
+                                                 GIMP_SIZE_ENTRY_UPDATE_SIZE);
+  gtk_table_set_row_spacings (GTK_TABLE (se), 4);
+  gtk_table_set_col_spacings (GTK_TABLE (se), 2);
+
+  gimp_size_entry_add_field (GIMP_SIZE_ENTRY (se),
+                             GTK_SPIN_BUTTON (spinbutton), NULL);
+  gtk_table_attach_defaults (GTK_TABLE (se), spinbutton, 1, 2, 0, 1);
+  gtk_widget_show (spinbutton);
+
+  gtk_table_attach (GTK_TABLE (table), se, 1, 2, row, row + 2,
+                    GTK_SHRINK | GTK_FILL | GTK_EXPAND,
+                    GTK_SHRINK | GTK_FILL,
+                    0, 0);
+  gtk_widget_show (se);
+
+  gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (se), shell->unit);
+
+  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (se), 0, xres, FALSE);
+  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (se), 1, yres, FALSE);
+
+  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (se), 0,
+                                         -GIMP_MAX_IMAGE_SIZE,
+                                         GIMP_MAX_IMAGE_SIZE);
+  gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (se), 1,
+                                         -GIMP_MAX_IMAGE_SIZE,
+                                         GIMP_MAX_IMAGE_SIZE);
+
+  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (se), 0,
+                            0, gimp_image_get_width (image));
+  gimp_size_entry_set_size (GIMP_SIZE_ENTRY (se), 1,
+                            0, gimp_image_get_height (image));
+
+  g_signal_connect (se, "value-changed",
+                    G_CALLBACK (gimp_blend_tool_editor_endpoint_se_value_changed),
+                    blend_tool);
+
+  row += 2;
+
+  /* the color label */
+  label = gtk_label_new (_("Color:"));
+  gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
+                    GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
+  gtk_widget_show (label);
+
+  /* the color entry */
+  hbox = gimp_blend_tool_editor_color_entry_new (
+    blend_tool, _("Change Endpoint Color"), DIRECTION_NONE, NULL,
+    &blend_tool->endpoint_color_panel, &blend_tool->endpoint_type_combo);
+  gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, row, row + 1,
+                    GTK_SHRINK | GTK_FILL | GTK_EXPAND,
+                    GTK_SHRINK | GTK_FILL,
+                    0, 0);
+  gtk_widget_show (hbox);
+
+  row++;
+}
+
+static void
+gimp_blend_tool_editor_update_endpoint_gui (GimpBlendTool *blend_tool,
+                                            gint           selection)
+{
+  GimpBlendOptions    *options       = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpPaintOptions    *paint_options = GIMP_PAINT_OPTIONS (options);
+  GimpContext         *context       = GIMP_CONTEXT (options);
+  gboolean             editable;
+  GimpGradientSegment *seg;
+  const gchar         *title;
+  gdouble              x;
+  gdouble              y;
+  GimpRGB              color;
+  GimpGradientColor    color_type;
+
+  editable = gimp_blend_tool_editor_is_gradient_editable (blend_tool);
+
+  switch (selection)
+    {
+    case GIMP_TOOL_LINE_HANDLE_START:
+      g_object_get (blend_tool->widget,
+                    "x1", &x,
+                    "y1", &y,
+                    NULL);
+      break;
+
+    case GIMP_TOOL_LINE_HANDLE_END:
+      g_object_get (blend_tool->widget,
+                    "x2", &x,
+                    "y2", &y,
+                    NULL);
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+
+  /* swap the endpoint handles, if necessary */
+  if (paint_options->gradient_options->gradient_reverse)
+    {
+      switch (selection)
+        {
+        case GIMP_TOOL_LINE_HANDLE_START:
+          selection = GIMP_TOOL_LINE_HANDLE_END;
+          break;
+
+        case GIMP_TOOL_LINE_HANDLE_END:
+          selection = GIMP_TOOL_LINE_HANDLE_START;
+          break;
+        }
+    }
+
+  seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
+
+  switch (selection)
+    {
+    case GIMP_TOOL_LINE_HANDLE_START:
+      title = _("Start Endpoint");
+
+      gimp_gradient_segment_get_left_flat_color (blend_tool->gradient, context,
+                                                 seg, &color);
+      color_type = seg->left_color_type;
+      break;
+
+    case GIMP_TOOL_LINE_HANDLE_END:
+      title = _("End Endpoint");
+
+      gimp_gradient_segment_get_right_flat_color (blend_tool->gradient, context,
+                                                  seg, &color);
+      color_type = seg->right_color_type;
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+
+  gimp_tool_gui_set_title (blend_tool->gui, title);
+
+  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (blend_tool->endpoint_se), 0, x);
+  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (blend_tool->endpoint_se), 1, y);
+
+  gimp_color_button_set_color (
+    GIMP_COLOR_BUTTON (blend_tool->endpoint_color_panel), &color);
+  gimp_int_combo_box_set_active (
+    GIMP_INT_COMBO_BOX (blend_tool->endpoint_type_combo), color_type);
+
+  gtk_widget_set_sensitive (blend_tool->endpoint_color_panel, editable);
+  gtk_widget_set_sensitive (blend_tool->endpoint_type_combo,  editable);
+
+  gtk_widget_show (blend_tool->endpoint_editor);
+}
+
 static void
 gimp_blend_tool_editor_update_gui (GimpBlendTool *blend_tool)
 {
@@ -507,8 +998,19 @@ gimp_blend_tool_editor_update_gui (GimpBlendTool *blend_tool)
               g_signal_connect (blend_tool->gui, "response",
                                 G_CALLBACK (gimp_blend_tool_editor_gui_response),
                                 blend_tool);
+
+              gimp_blend_tool_editor_init_endpoint_gui (blend_tool);
             }
 
+          gimp_blend_tool_editor_block_handlers (blend_tool);
+
+          if (gimp_blend_tool_editor_handle_is_endpoint (blend_tool, selection))
+            gimp_blend_tool_editor_update_endpoint_gui (blend_tool, selection);
+          else
+            gtk_widget_hide (blend_tool->endpoint_editor);
+
+          gimp_blend_tool_editor_unblock_handlers (blend_tool);
+
           gimp_tool_gui_show (blend_tool->gui);
 
           return;
diff --git a/app/tools/gimpblendtool.h b/app/tools/gimpblendtool.h
index a855bef..0eedb7d 100644
--- a/app/tools/gimpblendtool.h
+++ b/app/tools/gimpblendtool.h
@@ -67,6 +67,10 @@ struct _GimpBlendTool
   gint                block_handlers_count;
 
   GimpToolGui        *gui;
+  GtkWidget          *endpoint_editor;
+  GtkWidget          *endpoint_se;
+  GtkWidget          *endpoint_color_panel;
+  GtkWidget          *endpoint_type_combo;
 };
 
 struct _GimpBlendToolClass


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