[gimp/soc-2012-unified-transformation: 17/25] transformtool: implement fromcenter constraint for shearing



commit 36b468f77f35876156a5df5f66761165effe0828
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Fri Jun 15 11:16:15 2012 +0200

    transformtool: implement fromcenter constraint for shearing

 app/tools/gimpunifiedtransformationtool.c |   40 ++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/app/tools/gimpunifiedtransformationtool.c b/app/tools/gimpunifiedtransformationtool.c
index 092cbea..8a96daa 100644
--- a/app/tools/gimpunifiedtransformationtool.c
+++ b/app/tools/gimpunifiedtransformationtool.c
@@ -873,8 +873,11 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
       function == TRANSFORM_HANDLE_S_S ||
       function == TRANSFORM_HANDLE_W_S)
     {
-      gint left, right;
+      /* o for the opposite edge, for fromcenter */
+      gint left, right, lefto, righto;
+      gdouble dxo, dyo;
 
+      /* set up indices for this edge and the opposite edge */
       if (function == TRANSFORM_HANDLE_N_S) {
         left = 1; right = 0;
       } else if (function == TRANSFORM_HANDLE_W_S) {
@@ -885,6 +888,19 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
         left = 3; right = 1;
       } else g_assert_not_reached();
 
+      lefto  = 3 - left;
+      righto = 3 - right;
+
+      if (fromcenter)
+        {
+          dxo = -dx;
+          dyo = -dy;
+        }
+      else
+        {
+          dxo = dyo = 0;
+        }
+
       if (constrain)
         {
           /* restrict to movement along the side */
@@ -899,11 +915,33 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
           dy = p.y;
         }
 
+      if (constrain && fromcenter)
+        {
+          /* restrict to movement along the opposite side */
+          GimpVector2 lp = { .x = px[lefto],  .y = py[lefto] },
+                      rp = { .x = px[righto], .y = py[righto] },
+                      p =  { .x = dxo,        .y = dyo },
+                      side = vectorsubtract(rp, lp);
+
+          p = vectorproject(p, side);
+
+          dxo = p.x;
+          dyo = p.y;
+        }
+
       *x[left] = px[left] + dx;
       *y[left] = py[left] + dy;
 
       *x[right] = px[right] + dx;
       *y[right] = py[right] + dy;
+
+      /* We have to set these unconditionally, or the opposite edge will stay
+       * in place when you toggle the fromcenter constraint during an action */
+      *x[lefto] = px[lefto] + dxo;
+      *y[lefto] = py[lefto] + dyo;
+
+      *x[righto] = px[righto] + dxo;
+      *y[righto] = py[righto] + dyo;
     }
 
   /* perspective transform */



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