[gimp/soc-2012-unified-transformation: 15/21] transformtool: Make rotation axis behave mostly as spec



commit 72740b9394e60f7ab5807f4e0cc0acbd162c7e24
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Thu Jun 14 09:51:54 2012 +0200

    transformtool: Make rotation axis behave mostly as spec
    
    The snapping seems to depend on zoom which it shouldn't, should always
    be monitor pixels.

 app/tools/gimpunifiedtransformationtool.c |   47 +++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/app/tools/gimpunifiedtransformationtool.c b/app/tools/gimpunifiedtransformationtool.c
index 28bceaf..e134f3d 100644
--- a/app/tools/gimpunifiedtransformationtool.c
+++ b/app/tools/gimpunifiedtransformationtool.c
@@ -740,7 +740,7 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
 {
   gdouble diff_x = transform_tool->curx - transform_tool->lastx,
           diff_y = transform_tool->cury - transform_tool->lasty;
-  gdouble *x[4], *y[4], px[4], py[4], *pivot_x, *pivot_y;
+  gdouble *x[4], *y[4], px[5], py[5], *pivot_x, *pivot_y, ppivot_x, ppivot_y;
   gint i;
   gboolean horizontal = FALSE;
   GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (transform_tool);
@@ -756,7 +756,7 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
   y[1] = &transform_tool->trans_info[Y1];
   y[2] = &transform_tool->trans_info[Y2];
   y[3] = &transform_tool->trans_info[Y3];
-  
+
   px[0] = (*transform_tool->prev_trans_info)[X0];
   px[1] = (*transform_tool->prev_trans_info)[X1];
   px[2] = (*transform_tool->prev_trans_info)[X2];
@@ -766,9 +766,15 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
   py[2] = (*transform_tool->prev_trans_info)[Y2];
   py[3] = (*transform_tool->prev_trans_info)[Y3];
 
+  px[4] = (px[0] + px[1] + px[2] + px[3]) / 4.;
+  py[4] = (py[0] + py[1] + py[2] + py[3]) / 4.;
+  
   pivot_x = &transform_tool->trans_info[PIVOT_X];
   pivot_y = &transform_tool->trans_info[PIVOT_Y];
 
+  ppivot_x = (*transform_tool->prev_trans_info)[PIVOT_X];
+  ppivot_y = (*transform_tool->prev_trans_info)[PIVOT_Y];
+
   if (function == TRANSFORM_HANDLE_CENTER)
     {
       gdouble dx = transform_tool->curx - transform_tool->mousex;
@@ -824,6 +830,43 @@ gimp_unified_transformation_tool_motion (GimpTransformTool *transform_tool)
       return;
     }
 
+  if (function == TRANSFORM_HANDLE_PIVOT)
+    {
+      gdouble dx = transform_tool->curx - transform_tool->mousex;
+      gdouble dy = transform_tool->cury - transform_tool->mousey;
+
+      gint screenx, screeny;
+
+      if (constrain)
+        {
+          /* snap to corner points and center */
+          gint closest;
+          gdouble closest_dist = G_MAXDOUBLE, dist;
+          for (i = 0; i < 5; i++)
+            {
+              dist = norm(vectorsubtract((GimpVector2){transform_tool->curx, transform_tool->cury}, (GimpVector2){px[i], py[i]}));
+              if (dist < closest_dist)
+                {
+                  closest_dist = dist;
+                  closest = i;
+                }
+            }
+          /* this seems to almost work right */
+          gimp_display_shell_untransform_xy (gimp_display_get_shell (GIMP_TOOL (transform_tool)->display),
+                                             closest_dist, 0, &screenx, &screeny, TRUE);
+          if (screenx < 25) {
+            *pivot_x = px[closest];
+            *pivot_y = py[closest];
+
+            return;
+          }
+        }
+      *pivot_x = ppivot_x + dx;
+      *pivot_y = ppivot_y + dy;
+
+      return;
+    }
+
   if (options->alternate)
     {
       gdouble *x0, *x1, *y0, *y1;



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