[gimp/soc-2012-unified-transformation: 32/51] transformtool: Add option for locking pivot to canvas, add code to transform the pivot along with al
- From: Mikael Magnusson <mikachu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2012-unified-transformation: 32/51] transformtool: Add option for locking pivot to canvas, add code to transform the pivot along with al
- Date: Mon, 20 Aug 2012 13:53:27 +0000 (UTC)
commit 9be0d2b029571660d17431de7b16279835939b34
Author: Mikael Magnusson <mikachu src gnome org>
Date: Wed Aug 1 06:58:05 2012 +0200
transformtool: Add option for locking pivot to canvas, add code to transform the pivot along with all transformations
app/tools/gimptransformoptions.c | 34 +++++++++++++++++--------
app/tools/gimptransformoptions.h | 1 +
app/tools/gimpunifiedtransformtool.c | 45 ++++++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 13 deletions(-)
---
diff --git a/app/tools/gimptransformoptions.c b/app/tools/gimptransformoptions.c
index 111749a..966715c 100644
--- a/app/tools/gimptransformoptions.c
+++ b/app/tools/gimptransformoptions.c
@@ -58,6 +58,7 @@ enum
PROP_FROMPIVOT,
PROP_FREESHEAR,
PROP_CORNERSNAP,
+ PROP_FIXEDPIVOT,
};
@@ -164,6 +165,11 @@ gimp_transform_options_class_init (GimpTransformOptionsClass *klass)
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
+ GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FIXEDPIVOT,
+ "fixedpivot",
+ NULL,
+ FALSE,
+ GIMP_PARAM_STATIC_STRINGS);
}
static void
@@ -221,6 +227,9 @@ gimp_transform_options_set_property (GObject *object,
case PROP_CORNERSNAP:
options->cornersnap = g_value_get_boolean (value);
break;
+ case PROP_FIXEDPIVOT:
+ options->fixedpivot = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -276,6 +285,9 @@ gimp_transform_options_get_property (GObject *object,
case PROP_CORNERSNAP:
g_value_set_boolean (value, options->cornersnap);
break;
+ case PROP_FIXEDPIVOT:
+ g_value_set_boolean (value, options->fixedpivot);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -416,29 +428,29 @@ gimp_transform_options_gui (GimpToolOptions *tool_options)
//TODO: check that the selection tools use the gimp_get_*_mask() functions for constrain/etc or change to what they use
else if (tool_options->tool_info->tool_type == GIMP_TYPE_UNIFIED_TRANSFORM_TOOL)
{
+ GdkModifierType shift = gimp_get_extend_selection_mask ();
+ GdkModifierType ctrl = gimp_get_constrain_behavior_mask ();
struct {
- gboolean shift;
+ GdkModifierType mod;
gchar *name;
gchar *desc;
} opt_list[] = {
- { TRUE, "keepaspect", "Keep aspect (%s)" },
- { TRUE, "freeshear", "Move edge freely in shearing (%s)" },
- { FALSE, "frompivot", "Scale from pivot / Symmetric shearing (%s)" },
- { FALSE, "cornersnap", "Snap pivot point to corners/center (%s)" },
- { FALSE, "constrain", "Constrain movement (%s)" },
+ { shift, "keepaspect", "Keep aspect (%s)" },
+ { shift, "freeshear", "Move edge freely in shearing (%s)" },
+ { ctrl, "frompivot", "Scale from pivot / Symmetric shearing (%s)" },
+ { ctrl, "cornersnap", "Snap pivot point to corners/center (%s)" },
+ { ctrl, "constrain", "Constrain movement (%s)" },
+ { 0, "fixedpivot", "Lock pivot to canvas" },
};
GtkWidget *button;
gchar *label;
gint i;
- for (i = 0; i < 5; i++)
+ for (i = 0; i < 6; i++)
{
label = g_strdup_printf (opt_list[i].desc,
- gimp_get_mod_string (
- opt_list[i].shift
- ? gimp_get_extend_selection_mask ()
- : gimp_get_constrain_behavior_mask ()));
+ gimp_get_mod_string (opt_list[i].mod));
button = gimp_prop_check_button_new (config, opt_list[i].name, label);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
diff --git a/app/tools/gimptransformoptions.h b/app/tools/gimptransformoptions.h
index f483ed8..df3060e 100644
--- a/app/tools/gimptransformoptions.h
+++ b/app/tools/gimptransformoptions.h
@@ -51,6 +51,7 @@ struct _GimpTransformOptions
gboolean frompivot;
gboolean freeshear;
gboolean cornersnap;
+ gboolean fixedpivot;
};
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index 4c75864..155599f 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -763,6 +763,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
gboolean frompivot = options->frompivot;
gboolean freeshear = options->freeshear;
gboolean cornersnap = options->cornersnap;
+ gboolean fixedpivot = options->fixedpivot;
TransformAction function = transform_tool->function;
@@ -825,8 +826,11 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
*x[i] = px[i] + dx;
*y[i] = py[i] + dy;
}
- *pivot_x = ppivot_x + dx;
- *pivot_y = ppivot_y + dy;
+ if (!fixedpivot) {
+ *pivot_x = ppivot_x + dx;
+ *pivot_y = ppivot_y + dy;
+ fixedpivot = TRUE;
+ }
}
/* rotate */
@@ -849,6 +853,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
*x[i] = m.x;
*y[i] = m.y;
}
+ fixedpivot = TRUE;
}
/* move rotation axis */
@@ -880,6 +885,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
}
*pivot_x = ppivot_x + dx;
*pivot_y = ppivot_y + dy;
+ fixedpivot = TRUE;
}
/* scaling via corner */
@@ -1019,6 +1025,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
*x[i] -= comp_x - pivot.x;
*y[i] -= comp_y - pivot.y;
}
+ fixedpivot = TRUE;
}
}
@@ -1130,6 +1137,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
*x[i] -= comp_x - pivot.x;
*y[i] -= comp_y - pivot.y;
}
+ fixedpivot = TRUE;
}
}
@@ -1271,6 +1279,39 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
*x[this] = px[this] + dx;
*y[this] = py[this] + dy;
}
+
+ if (!fixedpivot)
+ {
+ //TODO don't duplicate this code from above
+ GimpMatrix3 transform_before, transform_after;
+ gdouble comp_x, comp_y;
+ gimp_matrix3_identity (&transform_before);
+ gimp_matrix3_identity (&transform_after);
+ gimp_transform_matrix_perspective (&transform_before,
+ transform_tool->x1,
+ transform_tool->y1,
+ transform_tool->x2 - transform_tool->x1,
+ transform_tool->y2 - transform_tool->y1,
+ px[0], py[0],
+ px[1], py[1],
+ px[2], py[2],
+ px[3], py[3]);
+ gimp_transform_matrix_perspective (&transform_after,
+ transform_tool->x1,
+ transform_tool->y1,
+ transform_tool->x2 - transform_tool->x1,
+ transform_tool->y2 - transform_tool->y1,
+ *x[0], *y[0],
+ *x[1], *y[1],
+ *x[2], *y[2],
+ *x[3], *y[3]);
+ gimp_matrix3_invert(&transform_before);
+ GimpMatrix3 transform = transform_before;
+ gimp_matrix3_mult(&transform_after, &transform);
+ gimp_matrix3_transform_point(&transform, ppivot_x, ppivot_y, &comp_x, &comp_y);
+ *pivot_x = comp_x;
+ *pivot_y = comp_y;
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]