Commit 9469ac26 authored by Ell's avatar Ell

app, libgimpbase: implement blend tool gui for gradient midpoints

Allows setting the midpoint's position, blending function, and
coloring type.

The midpoint can be converted to a stop, and centered, through
editor buttons.
parent 1aa48774
......@@ -103,6 +103,20 @@ static void gimp_blend_tool_editor_stop_se_value_changed
static void gimp_blend_tool_editor_stop_delete_clicked (GtkWidget *button,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_midpoint_se_value_changed (GimpSizeEntry *se,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_midpoint_type_changed (GtkComboBox *combo,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_midpoint_color_changed (GtkComboBox *combo,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_midpoint_new_stop_clicked (GtkWidget *button,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_midpoint_center_clicked (GtkWidget *button,
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,
......@@ -125,6 +139,8 @@ static gint gimp_blend_tool_editor_add_stop
gdouble value);
static void gimp_blend_tool_editor_delete_stop (GimpBlendTool *blend_tool,
gint slider);
static gint gimp_blend_tool_editor_midpoint_to_stop (GimpBlendTool *blend_tool,
gint slider);
static void gimp_blend_tool_editor_update_sliders (GimpBlendTool *blend_tool);
......@@ -136,10 +152,13 @@ static GtkWidget * gimp_blend_tool_editor_color_entry_new
GtkWidget **type_combo);
static void gimp_blend_tool_editor_init_endpoint_gui (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_init_stop_gui (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_init_midpoint_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_stop_gui (GimpBlendTool *blend_tool,
gint selection);
static void gimp_blend_tool_editor_update_midpoint_gui (GimpBlendTool *blend_tool,
gint selection);
static void gimp_blend_tool_editor_update_gui (GimpBlendTool *blend_tool);
......@@ -277,19 +296,11 @@ gimp_blend_tool_editor_line_handle_clicked (GimpToolLine *line,
if (press_type == GIMP_BUTTON_PRESS_DOUBLE &&
gimp_blend_tool_editor_is_gradient_editable (blend_tool))
{
const GimpControllerSlider *sliders;
gint stop;
sliders = gimp_tool_line_get_sliders (line, NULL);
gint stop;
if (sliders[handle].value > sliders[handle].min + EPSILON &&
sliders[handle].value < sliders[handle].max - EPSILON)
{
stop = gimp_blend_tool_editor_add_stop (blend_tool,
sliders[handle].value);
stop = gimp_blend_tool_editor_midpoint_to_stop (blend_tool, handle);
gimp_tool_line_set_selection (line, stop);
}
gimp_tool_line_set_selection (line, stop);
/* return FALSE, so that the new slider can be dragged immediately */
return FALSE;
......@@ -554,6 +565,120 @@ gimp_blend_tool_editor_stop_delete_clicked (GtkWidget *button,
gimp_blend_tool_editor_delete_stop (blend_tool, selection);
}
static void
gimp_blend_tool_editor_midpoint_se_value_changed (GimpSizeEntry *se,
GimpBlendTool *blend_tool)
{
gint selection;
gdouble value;
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 (selection == GIMP_TOOL_LINE_HANDLE_NONE)
return;
value = gimp_size_entry_get_refval (se, 0) / 100.0;
gimp_blend_tool_editor_freeze_gradient (blend_tool);
seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
seg->middle = value;
gimp_blend_tool_editor_thaw_gradient (blend_tool);
}
static void
gimp_blend_tool_editor_midpoint_type_changed (GtkComboBox *combo,
GimpBlendTool *blend_tool)
{
gint selection;
gint type;
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), &type))
return;
gimp_blend_tool_editor_freeze_gradient (blend_tool);
seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
seg->type = type;
gimp_blend_tool_editor_thaw_gradient (blend_tool);
}
static void
gimp_blend_tool_editor_midpoint_color_changed (GtkComboBox *combo,
GimpBlendTool *blend_tool)
{
gint selection;
gint color;
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))
return;
gimp_blend_tool_editor_freeze_gradient (blend_tool);
seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
seg->color = color;
gimp_blend_tool_editor_thaw_gradient (blend_tool);
}
static void
gimp_blend_tool_editor_midpoint_new_stop_clicked (GtkWidget *button,
GimpBlendTool *blend_tool)
{
gint selection;
gint stop;
selection =
gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
stop = gimp_blend_tool_editor_midpoint_to_stop (blend_tool, selection);
gimp_tool_line_set_selection (GIMP_TOOL_LINE (blend_tool->widget), stop);
}
static void
gimp_blend_tool_editor_midpoint_center_clicked (GtkWidget *button,
GimpBlendTool *blend_tool)
{
gint selection;
GimpGradientSegment *seg;
selection =
gimp_tool_line_get_selection (GIMP_TOOL_LINE (blend_tool->widget));
gimp_blend_tool_editor_freeze_gradient (blend_tool);
seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
gimp_gradient_segment_range_recenter_handles (blend_tool->gradient, seg, seg);
gimp_blend_tool_editor_thaw_gradient (blend_tool);
}
static gboolean
gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool)
{
......@@ -726,6 +851,25 @@ gimp_blend_tool_editor_delete_stop (GimpBlendTool *blend_tool,
gimp_blend_tool_editor_thaw_gradient (blend_tool);
}
static gint
gimp_blend_tool_editor_midpoint_to_stop (GimpBlendTool *blend_tool,
gint slider)
{
const GimpControllerSlider *sliders;
sliders = gimp_tool_line_get_sliders (GIMP_TOOL_LINE (blend_tool->widget),
NULL);
if (sliders[slider].value > sliders[slider].min + EPSILON &&
sliders[slider].value < sliders[slider].max - EPSILON)
{
slider = gimp_blend_tool_editor_add_stop (blend_tool,
sliders[slider].value);
}
return slider;
}
static void
gimp_blend_tool_editor_update_sliders (GimpBlendTool *blend_tool)
{
......@@ -1121,6 +1265,126 @@ gimp_blend_tool_editor_init_stop_gui (GimpBlendTool *blend_tool)
NULL, blend_tool);
}
static void
gimp_blend_tool_editor_init_midpoint_gui (GimpBlendTool *blend_tool)
{
GtkWidget *editor;
GtkWidget *table;
GtkWidget *label;
GtkWidget *se;
GtkWidget *combo;
GtkWidget *separator;
gint row = 0;
/* the stop editor */
blend_tool->midpoint_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 label */
label = gtk_label_new (_("Position:"));
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 position size entry */
blend_tool->midpoint_se =
se = gimp_size_entry_new (1, GIMP_UNIT_PERCENT, "%a",
FALSE, TRUE, FALSE, 6,
GIMP_SIZE_ENTRY_UPDATE_SIZE);
gimp_size_entry_show_unit_menu (GIMP_SIZE_ENTRY (se), FALSE);
gtk_table_attach (GTK_TABLE (table), se, 1, 2, row, row + 1,
GTK_SHRINK | GTK_FILL | GTK_EXPAND,
GTK_SHRINK | GTK_FILL,
0, 0);
gtk_widget_show (se);
g_signal_connect (se, "value-changed",
G_CALLBACK (gimp_blend_tool_editor_midpoint_se_value_changed),
blend_tool);
row++;
/* the type label */
label = gtk_label_new (_("Blending:"));
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 type combo */
blend_tool->midpoint_type_combo =
combo = gimp_enum_combo_box_new (GIMP_TYPE_GRADIENT_SEGMENT_TYPE);
gtk_table_attach (GTK_TABLE (table), combo, 1, 2, row, row + 1,
GTK_SHRINK | GTK_FILL | GTK_EXPAND,
GTK_SHRINK | GTK_FILL,
0, 0);
gtk_widget_show (combo);
g_signal_connect (combo, "changed",
G_CALLBACK (gimp_blend_tool_editor_midpoint_type_changed),
blend_tool);
row++;
/* the color label */
label = gtk_label_new (_("Coloring:"));
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 combo */
blend_tool->midpoint_color_combo =
combo = gimp_enum_combo_box_new (GIMP_TYPE_GRADIENT_SEGMENT_COLOR);
gtk_table_attach (GTK_TABLE (table), combo, 1, 2, row, row + 1,
GTK_SHRINK | GTK_FILL | GTK_EXPAND,
GTK_SHRINK | GTK_FILL,
0, 0);
gtk_widget_show (combo);
g_signal_connect (combo, "changed",
G_CALLBACK (gimp_blend_tool_editor_midpoint_color_changed),
blend_tool);
row++;
/* the action buttons separator */
separator = gtk_hseparator_new ();
gtk_table_attach (GTK_TABLE (table), separator, 0, 2, row, row + 1,
GTK_SHRINK | GTK_FILL | GTK_EXPAND,
GTK_SHRINK | GTK_FILL,
0, 0);
gtk_widget_show (separator);
row++;
/* the new stop button */
blend_tool->midpoint_new_stop_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GIMP_ICON_DOCUMENT_NEW, _("New stop at midpoint"),
NULL,
G_CALLBACK (gimp_blend_tool_editor_midpoint_new_stop_clicked),
NULL, blend_tool);
/* the center button */
blend_tool->midpoint_center_button =
gimp_editor_add_button (GIMP_EDITOR (editor),
GIMP_ICON_CENTER_HORIZONTAL, _("Center midpoint"),
NULL,
G_CALLBACK (gimp_blend_tool_editor_midpoint_center_clicked),
NULL, blend_tool);
}
static void
gimp_blend_tool_editor_update_endpoint_gui (GimpBlendTool *blend_tool,
gint selection)
......@@ -1285,6 +1549,66 @@ gimp_blend_tool_editor_update_stop_gui (GimpBlendTool *blend_tool,
gtk_widget_show (blend_tool->stop_editor);
}
static void
gimp_blend_tool_editor_update_midpoint_gui (GimpBlendTool *blend_tool,
gint selection)
{
gboolean editable;
const GimpGradientSegment *seg;
gint index;
gchar *title;
gdouble min;
gdouble max;
gdouble value;
GimpGradientSegmentType type;
GimpGradientSegmentColor color;
editable = gimp_blend_tool_editor_is_gradient_editable (blend_tool);
seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, selection);
index = GPOINTER_TO_INT (
gimp_tool_line_get_sliders (GIMP_TOOL_LINE (blend_tool->widget),
NULL)[selection].data);
title = g_strdup_printf (_("Midpoint %d"), index + 1);
min = seg->left;
max = seg->right;
value = seg->middle;
type = seg->type;
color = seg->color;
gimp_tool_gui_set_title (blend_tool->gui, title);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (blend_tool->midpoint_se),
0, 100.0 * min, 100.0 * max);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (blend_tool->midpoint_se),
0, 100.0 * value);
gimp_int_combo_box_set_active (
GIMP_INT_COMBO_BOX (blend_tool->midpoint_type_combo), type);
gimp_int_combo_box_set_active (
GIMP_INT_COMBO_BOX (blend_tool->midpoint_color_combo), color);
gtk_widget_set_sensitive (blend_tool->midpoint_new_stop_button,
value > min + EPSILON && value < max - EPSILON);
gtk_widget_set_sensitive (blend_tool->midpoint_center_button,
fabs (value - (min + max) / 2.0) > EPSILON);
gtk_widget_set_sensitive (blend_tool->midpoint_se, editable);
gtk_widget_set_sensitive (blend_tool->midpoint_type_combo, editable);
gtk_widget_set_sensitive (blend_tool->midpoint_color_combo, editable);
gtk_widget_set_sensitive (
GTK_WIDGET (gimp_editor_get_button_box (GIMP_EDITOR (blend_tool->midpoint_editor))),
editable);
g_free (title);
gtk_widget_show (blend_tool->midpoint_editor);
}
static void
gimp_blend_tool_editor_update_gui (GimpBlendTool *blend_tool)
{
......@@ -1327,6 +1651,7 @@ gimp_blend_tool_editor_update_gui (GimpBlendTool *blend_tool)
gimp_blend_tool_editor_init_endpoint_gui (blend_tool);
gimp_blend_tool_editor_init_stop_gui (blend_tool);
gimp_blend_tool_editor_init_midpoint_gui (blend_tool);
}
gimp_blend_tool_editor_block_handlers (blend_tool);
......@@ -1341,6 +1666,11 @@ gimp_blend_tool_editor_update_gui (GimpBlendTool *blend_tool)
else
gtk_widget_hide (blend_tool->stop_editor);
if (gimp_blend_tool_editor_handle_is_midpoint (blend_tool, selection))
gimp_blend_tool_editor_update_midpoint_gui (blend_tool, selection);
else
gtk_widget_hide (blend_tool->midpoint_editor);
gimp_blend_tool_editor_unblock_handlers (blend_tool);
gimp_tool_gui_show (blend_tool->gui);
......
......@@ -79,6 +79,12 @@ struct _GimpBlendTool
GtkWidget *stop_right_color_panel;
GtkWidget *stop_right_type_combo;
GtkWidget *stop_chain_button;
GtkWidget *midpoint_editor;
GtkWidget *midpoint_se;
GtkWidget *midpoint_type_combo;
GtkWidget *midpoint_color_combo;
GtkWidget *midpoint_new_stop_button;
GtkWidget *midpoint_center_button;
};
struct _GimpBlendToolClass
......
......@@ -641,9 +641,9 @@ gimp_gradient_segment_color_get_type (void)
static const GimpEnumDesc descs[] =
{
{ GIMP_GRADIENT_SEGMENT_RGB, "GIMP_GRADIENT_SEGMENT_RGB", NULL },
{ GIMP_GRADIENT_SEGMENT_HSV_CCW, "GIMP_GRADIENT_SEGMENT_HSV_CCW", NULL },
{ GIMP_GRADIENT_SEGMENT_HSV_CW, "GIMP_GRADIENT_SEGMENT_HSV_CW", NULL },
{ GIMP_GRADIENT_SEGMENT_RGB, NC_("gradient-segment-color", "RGB"), NULL },
{ GIMP_GRADIENT_SEGMENT_HSV_CCW, NC_("gradient-segment-color", "HSV (ccw)"), NULL },
{ GIMP_GRADIENT_SEGMENT_HSV_CW, NC_("gradient-segment-color", "HSV (cw)"), NULL },
{ 0, NULL, NULL }
};
......@@ -675,11 +675,11 @@ gimp_gradient_segment_type_get_type (void)
static const GimpEnumDesc descs[] =
{
{ GIMP_GRADIENT_SEGMENT_LINEAR, "GIMP_GRADIENT_SEGMENT_LINEAR", NULL },
{ GIMP_GRADIENT_SEGMENT_CURVED, "GIMP_GRADIENT_SEGMENT_CURVED", NULL },
{ GIMP_GRADIENT_SEGMENT_SINE, "GIMP_GRADIENT_SEGMENT_SINE", NULL },
{ GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING, "GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING", NULL },
{ GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING, "GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING", NULL },
{ GIMP_GRADIENT_SEGMENT_LINEAR, NC_("gradient-segment-type", "Linear"), NULL },
{ GIMP_GRADIENT_SEGMENT_CURVED, NC_("gradient-segment-type", "Curved"), NULL },
{ GIMP_GRADIENT_SEGMENT_SINE, NC_("gradient-segment-type", "Sinusoidal"), NULL },
{ GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING, NC_("gradient-segment-type", "Spherical (inc)"), NULL },
{ GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING, NC_("gradient-segment-type", "Spherical (dec)"), NULL },
{ 0, NULL, NULL }
};
......
......@@ -346,9 +346,9 @@ GType gimp_gradient_segment_color_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_GRADIENT_SEGMENT_RGB, /* normal RGB */
GIMP_GRADIENT_SEGMENT_HSV_CCW, /* counterclockwise hue */
GIMP_GRADIENT_SEGMENT_HSV_CW /* clockwise hue */
GIMP_GRADIENT_SEGMENT_RGB, /*< desc="RGB" >*/
GIMP_GRADIENT_SEGMENT_HSV_CCW, /*< desc="HSV (ccw)" >*/
GIMP_GRADIENT_SEGMENT_HSV_CW /*< desc="HSV (cw)" >*/
} GimpGradientSegmentColor;
......@@ -358,11 +358,11 @@ GType gimp_gradient_segment_type_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_GRADIENT_SEGMENT_LINEAR,
GIMP_GRADIENT_SEGMENT_CURVED,
GIMP_GRADIENT_SEGMENT_SINE,
GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING,
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING
GIMP_GRADIENT_SEGMENT_LINEAR, /*< desc="Linear" >*/
GIMP_GRADIENT_SEGMENT_CURVED, /*< desc="Curved" >*/
GIMP_GRADIENT_SEGMENT_SINE, /*< desc="Sinusoidal" >*/
GIMP_GRADIENT_SEGMENT_SPHERE_INCREASING, /*< desc="Spherical (inc)" >*/
GIMP_GRADIENT_SEGMENT_SPHERE_DECREASING /*< desc="Spherical (dec)" >*/
} GimpGradientSegmentType;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment