[gimp] app: GimpOperationTool: add support for picking coordinates from the image
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: GimpOperationTool: add support for picking coordinates from the image
- Date: Thu, 30 May 2013 21:36:12 +0000 (UTC)
commit 40a1efef095d3c67d7ff62e277157278e5987e53
Author: Michael Natterer <mitch gimp org>
Date: Thu May 30 23:32:54 2013 +0200
app: GimpOperationTool: add support for picking coordinates from the image
gimp_operation_tool_color_picked(): if the picker's identifier is of
the form "param_spec_name:param_spec_name" and the param specs both
exist and are of the same numeric type, set the pick coordinates on
these properties of the operation's config object.
app/tools/gimpoperationtool.c | 91 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 87 insertions(+), 4 deletions(-)
---
diff --git a/app/tools/gimpoperationtool.c b/app/tools/gimpoperationtool.c
index e1ce72d..dacaa34 100644
--- a/app/tools/gimpoperationtool.c
+++ b/app/tools/gimpoperationtool.c
@@ -271,11 +271,94 @@ gimp_operation_tool_color_picked (GimpImageMapTool *im_tool,
const Babl *sample_format,
const GimpRGB *color)
{
- GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool);
+ GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool);
+ gchar **pspecs;
+
+ pspecs = g_strsplit (identifier, ":", 2);
+
+ if (pspecs[1])
+ {
+ GimpDrawable *drawable = GIMP_TOOL (im_tool)->drawable;
+ GObjectClass *object_class = G_OBJECT_GET_CLASS (tool->config);
+ GParamSpec *pspec_x;
+ GParamSpec *pspec_y;
+
+ /* the operation's coordinate system is the selection bounds of
+ * the drawable
+ */
+ if (drawable)
+ {
+ gint off_x, off_y;
+
+ gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+ x -= off_x;
+ y -= off_y;
+
+ if (gimp_item_mask_intersect (GIMP_ITEM (drawable),
+ &off_x, &off_y, NULL, NULL))
+ {
+ x -= off_x;
+ y -= off_y;
+ }
+ }
+
+ pspec_x = g_object_class_find_property (object_class, pspecs[0]);
+ pspec_y = g_object_class_find_property (object_class, pspecs[1]);
+
+ if (pspec_x && pspec_y &&
+ G_PARAM_SPEC_TYPE (pspec_x) == G_PARAM_SPEC_TYPE (pspec_y))
+ {
+ GValue value_x = G_VALUE_INIT;
+ GValue value_y = G_VALUE_INIT;
+
+ g_value_init (&value_x, G_PARAM_SPEC_VALUE_TYPE (pspec_x));
+ g_value_init (&value_y, G_PARAM_SPEC_VALUE_TYPE (pspec_y));
+
+ if (G_IS_PARAM_SPEC_INT (pspec_x))
+ {
+ g_value_set_int (&value_x, x);
+ g_value_set_int (&value_y, y);
+
+ g_param_value_validate (pspec_x, &value_x);
+ g_param_value_validate (pspec_y, &value_y);
+
+ g_object_set (tool->config,
+ pspecs[0], g_value_get_int (&value_x),
+ pspecs[1], g_value_get_int (&value_y),
+ NULL);
+ }
+ else if (G_IS_PARAM_SPEC_DOUBLE (pspec_x))
+ {
+ g_value_set_double (&value_x, x);
+ g_value_set_double (&value_y, y);
+
+ g_param_value_validate (pspec_x, &value_x);
+ g_param_value_validate (pspec_y, &value_y);
+
+ g_object_set (tool->config,
+ pspecs[0], g_value_get_double (&value_x),
+ pspecs[1], g_value_get_double (&value_y),
+ NULL);
+ }
+ else
+ {
+ g_warning ("%s: unhandled param spec of type %s",
+ G_STRFUNC, G_PARAM_SPEC_TYPE_NAME (pspec_x));
+ }
+
+ g_value_unset (&value_x);
+ g_value_unset (&value_y);
+ }
+ }
+ else
+ {
+ g_object_set (tool->config,
+ pspecs[0], color,
+ NULL);
+ }
- g_object_set (tool->config,
- identifier, color,
- NULL);
+ g_strfreev (pspecs);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]