[gimp/soc-2012-unified-transformation: 18/52] transformtool: Make shear op behave as spec, no frompivot



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

    transformtool: Make shear op behave as spec, no frompivot

 app/tools/gimpunifiedtransformtool.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index fccd9e2..455525d 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -861,12 +861,43 @@ gimp_unified_transform_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]