[gimp] app: "distance-metric" is now a property of GimpContext.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: "distance-metric" is now a property of GimpContext.
- Date: Sat, 17 Mar 2018 18:47:10 +0000 (UTC)
commit 2c799d4af967b8ee94045798098452e820a92733
Author: Jehan <jehan girinstud io>
Date: Sat Mar 17 18:18:56 2018 +0100
app: "distance-metric" is now a property of GimpContext.
Remove the property from Blend tool and make it use the context one.
app/core/core-enums.h | 47 +++++++++---------
app/core/gimpcontext.c | 108 ++++++++++++++++++++++++++++++++++++------
app/core/gimpcontext.h | 89 +++++++++++++++++++---------------
app/tools/gimpblendoptions.c | 17 +------
app/tools/gimpblendoptions.h | 1 -
app/tools/gimpblendtool.c | 3 +-
6 files changed, 170 insertions(+), 95 deletions(-)
---
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index f73d867..8a58a17 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -565,29 +565,30 @@ typedef enum /*< pdb-skip >*/
typedef enum /*< pdb-skip, skip >*/
{
- GIMP_CONTEXT_PROP_FIRST = 2,
-
- GIMP_CONTEXT_PROP_IMAGE = GIMP_CONTEXT_PROP_FIRST,
- GIMP_CONTEXT_PROP_DISPLAY = 3,
- GIMP_CONTEXT_PROP_TOOL = 4,
- GIMP_CONTEXT_PROP_PAINT_INFO = 5,
- GIMP_CONTEXT_PROP_FOREGROUND = 6,
- GIMP_CONTEXT_PROP_BACKGROUND = 7,
- GIMP_CONTEXT_PROP_OPACITY = 8,
- GIMP_CONTEXT_PROP_PAINT_MODE = 9,
- GIMP_CONTEXT_PROP_BRUSH = 10,
- GIMP_CONTEXT_PROP_DYNAMICS = 11,
- GIMP_CONTEXT_PROP_MYBRUSH = 12,
- GIMP_CONTEXT_PROP_PATTERN = 13,
- GIMP_CONTEXT_PROP_GRADIENT = 14,
- GIMP_CONTEXT_PROP_PALETTE = 15,
- GIMP_CONTEXT_PROP_TOOL_PRESET = 16,
- GIMP_CONTEXT_PROP_FONT = 17,
- GIMP_CONTEXT_PROP_BUFFER = 18,
- GIMP_CONTEXT_PROP_IMAGEFILE = 19,
- GIMP_CONTEXT_PROP_TEMPLATE = 20,
-
- GIMP_CONTEXT_PROP_LAST = GIMP_CONTEXT_PROP_TEMPLATE
+ GIMP_CONTEXT_PROP_FIRST = 2,
+
+ GIMP_CONTEXT_PROP_IMAGE = GIMP_CONTEXT_PROP_FIRST,
+ GIMP_CONTEXT_PROP_DISPLAY = 3,
+ GIMP_CONTEXT_PROP_TOOL = 4,
+ GIMP_CONTEXT_PROP_PAINT_INFO = 5,
+ GIMP_CONTEXT_PROP_FOREGROUND = 6,
+ GIMP_CONTEXT_PROP_BACKGROUND = 7,
+ GIMP_CONTEXT_PROP_OPACITY = 8,
+ GIMP_CONTEXT_PROP_PAINT_MODE = 9,
+ GIMP_CONTEXT_PROP_BRUSH = 10,
+ GIMP_CONTEXT_PROP_DYNAMICS = 11,
+ GIMP_CONTEXT_PROP_MYBRUSH = 12,
+ GIMP_CONTEXT_PROP_PATTERN = 13,
+ GIMP_CONTEXT_PROP_GRADIENT = 14,
+ GIMP_CONTEXT_PROP_PALETTE = 15,
+ GIMP_CONTEXT_PROP_TOOL_PRESET = 16,
+ GIMP_CONTEXT_PROP_FONT = 17,
+ GIMP_CONTEXT_PROP_BUFFER = 18,
+ GIMP_CONTEXT_PROP_IMAGEFILE = 19,
+ GIMP_CONTEXT_PROP_TEMPLATE = 20,
+ GIMP_CONTEXT_PROP_DISTANCE_METRIC = 21,
+
+ GIMP_CONTEXT_PROP_LAST = GIMP_CONTEXT_PROP_DISTANCE_METRIC
} GimpContextPropType;
diff --git a/app/core/gimpcontext.c b/app/core/gimpcontext.c
index dfda990..2e1a7df 100644
--- a/app/core/gimpcontext.c
+++ b/app/core/gimpcontext.c
@@ -277,6 +277,10 @@ static void gimp_context_template_list_thaw (GimpContainer *container,
static void gimp_context_real_set_template (GimpContext *context,
GimpTemplate *template);
+/* distance metric */
+static void gimp_context_distance_metric_changed (GimpContext *context);
+static void gimp_context_real_set_distance_metric (GimpContext *context,
+ GeglDistanceMetric metric);
/* utilities */
static gpointer gimp_context_find_object (GimpContext *context,
@@ -318,6 +322,7 @@ enum
BUFFER_CHANGED,
IMAGEFILE_CHANGED,
TEMPLATE_CHANGED,
+ DISTANCE_METRIC_CHANGED,
PROP_NAME_CHANGED,
LAST_SIGNAL
};
@@ -344,7 +349,8 @@ static const gchar * const gimp_context_prop_names[] =
"font",
"buffer",
"imagefile",
- "template"
+ "template",
+ "distance-metric"
};
static GType gimp_context_prop_types[] =
@@ -369,6 +375,7 @@ static GType gimp_context_prop_types[] =
0,
0,
0,
+ 0,
0
};
@@ -583,6 +590,16 @@ gimp_context_class_init (GimpContextClass *klass)
G_TYPE_NONE, 1,
GIMP_TYPE_TEMPLATE);
+ gimp_context_signals[DISTANCE_METRIC_CHANGED] =
+ g_signal_new ("distance-metric-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GimpContextClass, distance_metric_changed),
+ NULL, NULL,
+ gimp_marshal_VOID__DOUBLE,
+ G_TYPE_NONE, 1,
+ GEGL_TYPE_DISTANCE_METRIC);
+
gimp_context_signals[PROP_NAME_CHANGED] =
g_signal_new ("prop-name-changed",
G_TYPE_FROM_CLASS (klass),
@@ -622,20 +639,21 @@ gimp_context_class_init (GimpContextClass *klass)
klass->template_changed = NULL;
klass->prop_name_changed = NULL;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_IMAGE] = GIMP_TYPE_IMAGE;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL] = GIMP_TYPE_TOOL_INFO;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_PAINT_INFO] = GIMP_TYPE_PAINT_INFO;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_BRUSH] = GIMP_TYPE_BRUSH;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_DYNAMICS] = GIMP_TYPE_DYNAMICS;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_MYBRUSH] = GIMP_TYPE_MYBRUSH;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_PATTERN] = GIMP_TYPE_PATTERN;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_GRADIENT] = GIMP_TYPE_GRADIENT;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_PALETTE] = GIMP_TYPE_PALETTE;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL_PRESET] = GIMP_TYPE_TOOL_PRESET;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_FONT] = GIMP_TYPE_FONT;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_BUFFER] = GIMP_TYPE_BUFFER;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_IMAGEFILE] = GIMP_TYPE_IMAGEFILE;
- gimp_context_prop_types[GIMP_CONTEXT_PROP_TEMPLATE] = GIMP_TYPE_TEMPLATE;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_IMAGE] = GIMP_TYPE_IMAGE;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL] = GIMP_TYPE_TOOL_INFO;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_PAINT_INFO] = GIMP_TYPE_PAINT_INFO;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_BRUSH] = GIMP_TYPE_BRUSH;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_DYNAMICS] = GIMP_TYPE_DYNAMICS;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_MYBRUSH] = GIMP_TYPE_MYBRUSH;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_PATTERN] = GIMP_TYPE_PATTERN;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_GRADIENT] = GIMP_TYPE_GRADIENT;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_PALETTE] = GIMP_TYPE_PALETTE;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_TOOL_PRESET] = GIMP_TYPE_TOOL_PRESET;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_FONT] = GIMP_TYPE_FONT;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_BUFFER] = GIMP_TYPE_BUFFER;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_IMAGEFILE] = GIMP_TYPE_IMAGEFILE;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_TEMPLATE] = GIMP_TYPE_TEMPLATE;
+ gimp_context_prop_types[GIMP_CONTEXT_PROP_DISTANCE_METRIC] = GEGL_TYPE_DISTANCE_METRIC;
g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_GIMP,
g_param_spec_object ("gimp",
@@ -772,6 +790,13 @@ gimp_context_class_init (GimpContextClass *klass)
NULL, NULL,
GIMP_TYPE_TEMPLATE,
GIMP_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class, GIMP_CONTEXT_PROP_DISTANCE_METRIC,
+ g_param_spec_enum
(gimp_context_prop_names[GIMP_CONTEXT_PROP_DISTANCE_METRIC],
+ NULL, NULL,
+ GEGL_TYPE_DISTANCE_METRIC,
+ GEGL_DISTANCE_METRIC_EUCLIDEAN,
+ GIMP_PARAM_READWRITE));
}
static void
@@ -1081,6 +1106,9 @@ gimp_context_set_property (GObject *object,
case GIMP_CONTEXT_PROP_TEMPLATE:
gimp_context_set_template (context, g_value_get_object (value));
break;
+ case GIMP_CONTEXT_PROP_DISTANCE_METRIC:
+ gimp_context_set_distance_metric (context, g_value_get_enum (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -1167,6 +1195,9 @@ gimp_context_get_property (GObject *object,
case GIMP_CONTEXT_PROP_TEMPLATE:
g_value_set_object (value, gimp_context_get_template (context));
break;
+ case GIMP_CONTEXT_PROP_DISTANCE_METRIC:
+ g_value_set_enum (value, gimp_context_get_distance_metric (context));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -1707,6 +1738,10 @@ gimp_context_copy_property (GimpContext *src,
gimp_context_real_set_template (dest, src->template);
break;
+ case GIMP_CONTEXT_PROP_DISTANCE_METRIC:
+ gimp_context_real_set_distance_metric (dest, src->distance_metric);
+ break;
+
default:
break;
}
@@ -3887,6 +3922,49 @@ gimp_context_real_set_template (GimpContext *context,
gimp_context_template_changed (context);
}
+/*****************************************************************************/
+/* distance metric **********************************************************/
+
+GeglDistanceMetric
+gimp_context_get_distance_metric (GimpContext *context)
+{
+ g_return_val_if_fail (GIMP_IS_CONTEXT (context), GEGL_DISTANCE_METRIC_EUCLIDEAN);
+
+ return context->distance_metric;
+}
+
+void
+gimp_context_set_distance_metric (GimpContext *context,
+ GeglDistanceMetric metric)
+{
+ g_return_if_fail (GIMP_IS_CONTEXT (context));
+ context_find_defined (context, GIMP_CONTEXT_PROP_DISTANCE_METRIC);
+
+ gimp_context_real_set_distance_metric (context, metric);
+}
+
+static void
+gimp_context_distance_metric_changed (GimpContext *context)
+{
+ g_return_if_fail (GIMP_IS_CONTEXT (context));
+
+ g_signal_emit (context,
+ gimp_context_signals[DISTANCE_METRIC_CHANGED], 0,
+ context->distance_metric);
+}
+
+static void
+gimp_context_real_set_distance_metric (GimpContext *context,
+ GeglDistanceMetric metric)
+{
+ if (context->distance_metric == metric)
+ return;
+
+ context->distance_metric = metric;
+
+ g_object_notify (G_OBJECT (context), "distance-metric");
+ gimp_context_distance_metric_changed (context);
+}
/*****************************************************************************/
/* utility functions *******************************************************/
diff --git a/app/core/gimpcontext.h b/app/core/gimpcontext.h
index c90493e..a25ca4e 100644
--- a/app/core/gimpcontext.h
+++ b/app/core/gimpcontext.h
@@ -102,52 +102,56 @@ struct _GimpContext
GimpTemplate *template;
gchar *template_name;
+
+ GeglDistanceMetric distance_metric;
};
struct _GimpContextClass
{
GimpViewableClass parent_class;
- void (* image_changed) (GimpContext *context,
- GimpImage *image);
- void (* display_changed) (GimpContext *context,
- gpointer display);
-
- void (* tool_changed) (GimpContext *context,
- GimpToolInfo *tool_info);
- void (* paint_info_changed) (GimpContext *context,
- GimpPaintInfo *paint_info);
-
- void (* foreground_changed) (GimpContext *context,
- GimpRGB *color);
- void (* background_changed) (GimpContext *context,
- GimpRGB *color);
- void (* opacity_changed) (GimpContext *context,
- gdouble opacity);
- void (* paint_mode_changed) (GimpContext *context,
- GimpLayerMode paint_mode);
- void (* brush_changed) (GimpContext *context,
- GimpBrush *brush);
- void (* dynamics_changed) (GimpContext *context,
- GimpDynamics *dynamics);
- void (* mybrush_changed) (GimpContext *context,
- GimpMybrush *brush);
- void (* pattern_changed) (GimpContext *context,
- GimpPattern *pattern);
- void (* gradient_changed) (GimpContext *context,
- GimpGradient *gradient);
- void (* palette_changed) (GimpContext *context,
- GimpPalette *palette);
- void (* tool_preset_changed)(GimpContext *context,
- GimpToolPreset *tool_preset);
- void (* font_changed) (GimpContext *context,
- GimpFont *font);
- void (* buffer_changed) (GimpContext *context,
- GimpBuffer *buffer);
- void (* imagefile_changed) (GimpContext *context,
- GimpImagefile *imagefile);
- void (* template_changed) (GimpContext *context,
- GimpTemplate *template);
+ void (* image_changed) (GimpContext *context,
+ GimpImage *image);
+ void (* display_changed) (GimpContext *context,
+ gpointer display);
+
+ void (* tool_changed) (GimpContext *context,
+ GimpToolInfo *tool_info);
+ void (* paint_info_changed) (GimpContext *context,
+ GimpPaintInfo *paint_info);
+
+ void (* foreground_changed) (GimpContext *context,
+ GimpRGB *color);
+ void (* background_changed) (GimpContext *context,
+ GimpRGB *color);
+ void (* opacity_changed) (GimpContext *context,
+ gdouble opacity);
+ void (* paint_mode_changed) (GimpContext *context,
+ GimpLayerMode paint_mode);
+ void (* brush_changed) (GimpContext *context,
+ GimpBrush *brush);
+ void (* dynamics_changed) (GimpContext *context,
+ GimpDynamics *dynamics);
+ void (* mybrush_changed) (GimpContext *context,
+ GimpMybrush *brush);
+ void (* pattern_changed) (GimpContext *context,
+ GimpPattern *pattern);
+ void (* gradient_changed) (GimpContext *context,
+ GimpGradient *gradient);
+ void (* palette_changed) (GimpContext *context,
+ GimpPalette *palette);
+ void (* tool_preset_changed) (GimpContext *context,
+ GimpToolPreset *tool_preset);
+ void (* font_changed) (GimpContext *context,
+ GimpFont *font);
+ void (* buffer_changed) (GimpContext *context,
+ GimpBuffer *buffer);
+ void (* imagefile_changed) (GimpContext *context,
+ GimpImagefile *imagefile);
+ void (* template_changed) (GimpContext *context,
+ GimpTemplate *template);
+ void (* distance_metric_changed) (GimpContext *context,
+ GeglDistanceMetric metric);
void (* prop_name_changed) (GimpContext *context,
GimpContextPropType prop);
@@ -356,5 +360,10 @@ void gimp_context_set_template (GimpContext *context,
GimpTemplate *template);
void gimp_context_template_changed (GimpContext *context);
+/* distance metric */
+GeglDistanceMetric
+ gimp_context_get_distance_metric (GimpContext *context);
+void gimp_context_set_distance_metric (GimpContext *context,
+ GeglDistanceMetric metric);
#endif /* __GIMP_CONTEXT_H__ */
diff --git a/app/tools/gimpblendoptions.c b/app/tools/gimpblendoptions.c
index 40ecd29..447fee6 100644
--- a/app/tools/gimpblendoptions.c
+++ b/app/tools/gimpblendoptions.c
@@ -44,7 +44,6 @@ enum
PROP_0,
PROP_OFFSET,
PROP_GRADIENT_TYPE,
- PROP_DISTANCE_METRIC,
PROP_GRADIENT_REPEAT, /* overrides a GimpPaintOptions property */
PROP_SUPERSAMPLE,
PROP_SUPERSAMPLE_DEPTH,
@@ -96,13 +95,6 @@ gimp_blend_options_class_init (GimpBlendOptionsClass *klass)
GIMP_TYPE_GRADIENT_TYPE,
GIMP_GRADIENT_LINEAR,
GIMP_PARAM_STATIC_STRINGS);
- GIMP_CONFIG_PROP_ENUM (object_class, PROP_DISTANCE_METRIC,
- "distance-metric",
- _("Metric"),
- _("Metric to use for the distance calculation"),
- GEGL_TYPE_DISTANCE_METRIC,
- GEGL_DISTANCE_METRIC_EUCLIDEAN,
- GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_ENUM (object_class, PROP_GRADIENT_REPEAT,
"gradient-repeat",
_("Repeat"),
@@ -173,9 +165,6 @@ gimp_blend_options_set_property (GObject *object,
case PROP_GRADIENT_TYPE:
options->gradient_type = g_value_get_enum (value);
break;
- case PROP_DISTANCE_METRIC:
- options->distance_metric = g_value_get_enum (value);
- break;
case PROP_GRADIENT_REPEAT:
GIMP_PAINT_OPTIONS (options)->gradient_options->gradient_repeat =
g_value_get_enum (value);
@@ -224,9 +213,6 @@ gimp_blend_options_get_property (GObject *object,
case PROP_GRADIENT_TYPE:
g_value_set_enum (value, options->gradient_type);
break;
- case PROP_DISTANCE_METRIC:
- g_value_set_enum (value, options->distance_metric);
- break;
case PROP_GRADIENT_REPEAT:
g_value_set_enum (value,
GIMP_PAINT_OPTIONS (options)->gradient_options->gradient_repeat);
@@ -299,7 +285,8 @@ gimp_blend_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (combo);
/* the distance metric menu */
- combo = gimp_prop_enum_combo_box_new (config, "distance-metric", 0, 0);
+ combo = gimp_prop_enum_combo_box_new (G_OBJECT (context),
+ "distance-metric", 0, 0);
gimp_int_combo_box_set_label (GIMP_INT_COMBO_BOX (combo), _("Metric"));
g_object_set (combo, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
diff --git a/app/tools/gimpblendoptions.h b/app/tools/gimpblendoptions.h
index 7974a78..5248f18 100644
--- a/app/tools/gimpblendoptions.h
+++ b/app/tools/gimpblendoptions.h
@@ -39,7 +39,6 @@ struct _GimpBlendOptions
gdouble offset;
GimpGradientType gradient_type;
- GeglDistanceMetric distance_metric;
gboolean supersample;
gint supersample_depth;
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 27e73b4..3fb60e4 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -792,6 +792,7 @@ static void
gimp_blend_tool_precalc_shapeburst (GimpBlendTool *blend_tool)
{
GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+ GimpContext *context = GIMP_CONTEXT (options);
GimpTool *tool = GIMP_TOOL (blend_tool);
gint x, y, width, height;
@@ -803,7 +804,7 @@ gimp_blend_tool_precalc_shapeburst (GimpBlendTool *blend_tool)
return;
blend_tool->dist_buffer =
- gimp_drawable_blend_shapeburst_distmap (tool->drawable, options->distance_metric,
+ gimp_drawable_blend_shapeburst_distmap (tool->drawable, context->distance_metric,
GEGL_RECTANGLE (x, y, width, height),
GIMP_PROGRESS (blend_tool));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]