[gimp/soc-2012-unified-transformation: 18/21] transformtool: Make shear op behave as spec - fromcenter constraint



commit 10e12930a50c1da0f4c02c5e85e23cab433b2201
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Fri Jun 15 10:54:02 2012 +0200

    transformtool: Make shear op behave as spec - fromcenter constraint

 app/tools/gimpunifiedtransformationtool.c |   33 ++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/app/tools/gimpunifiedtransformationtool.c b/app/tools/gimpunifiedtransformationtool.c
index 12f195f..a3845a9 100644
--- a/app/tools/gimpunifiedtransformationtool.c
+++ b/app/tools/gimpunifiedtransformationtool.c
@@ -886,12 +886,43 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
       //TODO: scale through side
     }
 
+  /* shear */
   if (function == TRANSFORM_HANDLE_N_S ||
       function == TRANSFORM_HANDLE_E_S ||
       function == TRANSFORM_HANDLE_S_S ||
       function == TRANSFORM_HANDLE_W_S)
     {
-      //TODO: shear
+      gint left, right;
+
+      if (function == TRANSFORM_HANDLE_N_S) {
+        left = 1; right = 0;
+      } else if (function == TRANSFORM_HANDLE_W_S) {
+        left = 0; right = 2;
+      } else if (function == TRANSFORM_HANDLE_S_S) {
+        left = 2; right = 3;
+      } else if (function == TRANSFORM_HANDLE_E_S) {
+        left = 3; right = 1;
+      } else g_assert_not_reached();
+
+      if (constrain)
+        {
+          /* restrict to movement along the side */
+          GimpVector2 lp = { .x = px[left],  .y = py[left] },
+                      rp = { .x = px[right], .y = py[right] },
+                      p =  { .x = dx,        .y = dy },
+                      side = vectorsubtract(rp, lp);
+
+          p = vectorproject(p, side);
+
+          dx = p.x;
+          dy = p.y;
+        }
+
+      *x[left] = px[left] + dx;
+      *y[left] = py[left] + dy;
+
+      *x[right] = px[right] + dx;
+      *y[right] = py[right] + dy;
     }
 
   /* perspective transform */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]