[gimp/soc-2012-unified-transformation: 11/25] transformtool: Make move op behave as spec
- From: Mikael Magnusson <mikachu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2012-unified-transformation: 11/25] transformtool: Make move op behave as spec
- Date: Tue, 10 Jul 2012 20:34:44 +0000 (UTC)
commit b753a4b58c64c9c2d6b8e2c3b8a1de58deb48e56
Author: Mikael Magnusson <mikachu src gnome org>
Date: Thu Jun 14 09:04:01 2012 +0200
transformtool: Make move op behave as spec
app/tools/gimpunifiedtransformationtool.c | 48 ++++++++++++++++++++++++++---
1 files changed, 43 insertions(+), 5 deletions(-)
---
diff --git a/app/tools/gimpunifiedtransformationtool.c b/app/tools/gimpunifiedtransformationtool.c
index f649015..cda3cf8 100644
--- a/app/tools/gimpunifiedtransformationtool.c
+++ b/app/tools/gimpunifiedtransformationtool.c
@@ -703,7 +703,7 @@ static inline gdouble calcangle(GimpVector2 a, GimpVector2 b) {
b.y = -b.x;
b.x = angle2;
angle2 = acos(dotprod(a, b)/length);
- return -((angle2 > G_PI/2.) ? 2*G_PI-angle : angle);
+ return ((angle2 > G_PI/2.) ? angle : 2*G_PI-angle);
}
static inline GimpVector2 rotate2d(GimpVector2 p, gdouble angle) {
@@ -729,6 +729,9 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
gint i;
gboolean horizontal = FALSE;
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (transform_tool);
+ gboolean constrain = options->constrain;
+ gboolean fromcenter = options->alternate;
+ TransformAction function = transform_tool->function;
x[0] = &transform_tool->trans_info[X0];
x[1] = &transform_tool->trans_info[X1];
@@ -751,12 +754,46 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
pivot_x = &transform_tool->trans_info[PIVOT_X];
pivot_y = &transform_tool->trans_info[PIVOT_Y];
+ if (function == TRANSFORM_HANDLE_CENTER)
+ {
+ gdouble dx = transform_tool->curx - transform_tool->mousex;
+ gdouble dy = transform_tool->cury - transform_tool->mousey;
+ if (constrain)
+ {
+ /* snap to 45 degree vectors from starting point */
+ gdouble angle = calcangle((GimpVector2){1., 0.}, (GimpVector2){dx, dy}) / (2.*G_PI);
+ if (angle < 1./16 || angle > 15./16)
+ dy = 0;
+ else if (angle < 3./16)
+ dy = -(dx = sqrt(dx*dx+dy*dy)/sqrt(2));
+ else if (angle < 5./16)
+ dx = 0;
+ else if (angle < 7./16)
+ dx = dy = -sqrt(dx*dx+dy*dy)/sqrt(2);
+ else if (angle < 9./16)
+ dy = 0;
+ else if (angle < 11./16)
+ dx = -(dy = sqrt(dx*dx+dy*dy)/sqrt(2));
+ else if (angle < 13./16)
+ dx = 0;
+ else if (angle < 15./16)
+ dx = dy = sqrt(dx*dx+dy*dy)/sqrt(2);
+ }
+ for (i = 0; i < 4; i++)
+ {
+ *x[i] = px[i] + dx;
+ *y[i] = py[i] + dy;
+ }
+ }
+
+ /* old code below */
+#if 0
if (options->alternate)
{
gdouble *x0, *x1, *y0, *y1;
gboolean moveedge = FALSE;
- switch (transform_tool->function)
+ switch (function)
{
case TRANSFORM_HANDLE_W:
x0 = x[0]; y0 = y[0];
@@ -815,7 +852,7 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
}
}
- switch (transform_tool->function)
+ switch (function)
{
case TRANSFORM_HANDLE_NW:
case TRANSFORM_HANDLE_NE:
@@ -835,7 +872,7 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
return;
}
case TRANSFORM_HANDLE_CENTER:
- if (options->constrain) {
+ if (constrain) {
diff_y = diff_x;
}
*x[0] += diff_x;
@@ -858,7 +895,7 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
horizontal = TRUE;
case TRANSFORM_HANDLE_N:
case TRANSFORM_HANDLE_S:
- if (! options->constrain)
+ if (!constrain)
{
for (i = 0; i < 4; i++)
{
@@ -885,6 +922,7 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
default:
break;
}
+#endif
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]