[gimp/gimp-2-10] app: implement readjust() in various transform tools



commit ab060c110f979319f5c6c0eca4aeb8da23d489cc
Author: Ell <ell_se yahoo com>
Date:   Thu Mar 7 16:18:03 2019 -0500

    app: implement readjust() in various transform tools
    
    Implement GimpTransformGridTool::radjust(), added in the previous
    commit, in various transform tools:
    
    The unified-transform, scale, and perspective tools readjust the
    transformation such that the grid is centered relative to the view,
    and its handles are fully within view under arbitrary rotation.
    
    The rotate tool readjusts the transformation such that the pivot is
    centered, and the grid is unrotated, relative to the view.
    
    (cherry picked from commit 5e5118c1db86b01ae7bdfba1e0f81d587538385d)

 app/tools/gimpperspectivetool.c      | 35 +++++++++++++++++++++++++++++++
 app/tools/gimprotatetool.c           | 21 +++++++++++++++++++
 app/tools/gimpscaletool.c            | 26 +++++++++++++++++++++++
 app/tools/gimpunifiedtransformtool.c | 40 ++++++++++++++++++++++++++++++++++++
 4 files changed, 122 insertions(+)
---
diff --git a/app/tools/gimpperspectivetool.c b/app/tools/gimpperspectivetool.c
index 185227cb73..58d0e8983e 100644
--- a/app/tools/gimpperspectivetool.c
+++ b/app/tools/gimpperspectivetool.c
@@ -28,6 +28,8 @@
 #include "widgets/gimphelp-ids.h"
 
 #include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-transform.h"
 #include "display/gimptoolgui.h"
 #include "display/gimptooltransformgrid.h"
 
@@ -57,6 +59,7 @@ enum
 static void             gimp_perspective_tool_matrix_to_info (GimpTransformGridTool    *tg_tool,
                                                               const GimpMatrix3        *transform);
 static void             gimp_perspective_tool_prepare        (GimpTransformGridTool    *tg_tool);
+static void             gimp_perspective_tool_readjust       (GimpTransformGridTool    *tg_tool);
 static GimpToolWidget * gimp_perspective_tool_get_widget     (GimpTransformGridTool    *tg_tool);
 static void             gimp_perspective_tool_update_widget  (GimpTransformGridTool    *tg_tool);
 static void             gimp_perspective_tool_widget_changed (GimpTransformGridTool    *tg_tool);
@@ -97,6 +100,7 @@ gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass)
 
   tg_class->matrix_to_info      = gimp_perspective_tool_matrix_to_info;
   tg_class->prepare             = gimp_perspective_tool_prepare;
+  tg_class->readjust            = gimp_perspective_tool_readjust;
   tg_class->get_widget          = gimp_perspective_tool_get_widget;
   tg_class->update_widget       = gimp_perspective_tool_update_widget;
   tg_class->widget_changed      = gimp_perspective_tool_widget_changed;
@@ -161,6 +165,37 @@ gimp_perspective_tool_prepare (GimpTransformGridTool *tg_tool)
   tg_tool->trans_info[Y3] = (gdouble) tr_tool->y2;
 }
 
+static void
+gimp_perspective_tool_readjust (GimpTransformGridTool *tg_tool)
+{
+  GimpTool         *tool  = GIMP_TOOL (tg_tool);
+  GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+  gdouble           x;
+  gdouble           y;
+  gdouble           r;
+
+  x = shell->disp_width  / 2.0;
+  y = shell->disp_height / 2.0;
+  r = MIN (x, y) / G_SQRT2;
+
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x - r, y - r,
+                                       &tg_tool->trans_info[X0],
+                                       &tg_tool->trans_info[Y0]);
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x + r, y - r,
+                                       &tg_tool->trans_info[X1],
+                                       &tg_tool->trans_info[Y1]);
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x - r, y + r,
+                                       &tg_tool->trans_info[X2],
+                                       &tg_tool->trans_info[Y2]);
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x + r, y + r,
+                                       &tg_tool->trans_info[X3],
+                                       &tg_tool->trans_info[Y3]);
+}
+
 static GimpToolWidget *
 gimp_perspective_tool_get_widget (GimpTransformGridTool *tg_tool)
 {
diff --git a/app/tools/gimprotatetool.c b/app/tools/gimprotatetool.c
index 2c8146d528..b7785b8d7d 100644
--- a/app/tools/gimprotatetool.c
+++ b/app/tools/gimprotatetool.c
@@ -33,6 +33,7 @@
 
 #include "display/gimpdisplay.h"
 #include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-transform.h"
 #include "display/gimptoolgui.h"
 #include "display/gimptoolrotategrid.h"
 
@@ -70,6 +71,7 @@ static gchar          * gimp_rotate_tool_get_undo_desc  (GimpTransformGridTool *
 static void             gimp_rotate_tool_dialog         (GimpTransformGridTool *tg_tool);
 static void             gimp_rotate_tool_dialog_update  (GimpTransformGridTool *tg_tool);
 static void             gimp_rotate_tool_prepare        (GimpTransformGridTool *tg_tool);
+static void             gimp_rotate_tool_readjust       (GimpTransformGridTool *tg_tool);
 static GimpToolWidget * gimp_rotate_tool_get_widget     (GimpTransformGridTool *tg_tool);
 static void             gimp_rotate_tool_update_widget  (GimpTransformGridTool *tg_tool);
 static void             gimp_rotate_tool_widget_changed (GimpTransformGridTool *tg_tool);
@@ -117,6 +119,7 @@ gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
   tg_class->dialog          = gimp_rotate_tool_dialog;
   tg_class->dialog_update   = gimp_rotate_tool_dialog_update;
   tg_class->prepare         = gimp_rotate_tool_prepare;
+  tg_class->readjust        = gimp_rotate_tool_readjust;
   tg_class->get_widget      = gimp_rotate_tool_get_widget;
   tg_class->update_widget   = gimp_rotate_tool_update_widget;
   tg_class->widget_changed  = gimp_rotate_tool_widget_changed;
@@ -379,6 +382,24 @@ gimp_rotate_tool_prepare (GimpTransformGridTool *tg_tool)
                                      tg_tool);
 }
 
+static void
+gimp_rotate_tool_readjust (GimpTransformGridTool *tg_tool)
+{
+  GimpTool         *tool  = GIMP_TOOL (tg_tool);
+  GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+
+  tg_tool->trans_info[ANGLE] = -gimp_deg_to_rad (shell->rotate_angle);
+
+  if (tg_tool->trans_info[ANGLE] <= -G_PI)
+    tg_tool->trans_info[ANGLE] += 2.0 * G_PI;
+
+  gimp_display_shell_untransform_xy_f (shell,
+                                       shell->disp_width  / 2.0,
+                                       shell->disp_height / 2.0,
+                                       &tg_tool->trans_info[PIVOT_X],
+                                       &tg_tool->trans_info[PIVOT_Y]);
+}
+
 static GimpToolWidget *
 gimp_rotate_tool_get_widget (GimpTransformGridTool *tg_tool)
 {
diff --git a/app/tools/gimpscaletool.c b/app/tools/gimpscaletool.c
index 1924541a3e..c0486c4ee5 100644
--- a/app/tools/gimpscaletool.c
+++ b/app/tools/gimpscaletool.c
@@ -35,6 +35,7 @@
 
 #include "display/gimpdisplay.h"
 #include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-transform.h"
 #include "display/gimptoolgui.h"
 #include "display/gimptooltransformgrid.h"
 
@@ -68,6 +69,7 @@ static gchar          * gimp_scale_tool_get_undo_desc  (GimpTransformGridTool *t
 static void             gimp_scale_tool_dialog         (GimpTransformGridTool *tg_tool);
 static void             gimp_scale_tool_dialog_update  (GimpTransformGridTool *tg_tool);
 static void             gimp_scale_tool_prepare        (GimpTransformGridTool *tg_tool);
+static void             gimp_scale_tool_readjust       (GimpTransformGridTool *tg_tool);
 static GimpToolWidget * gimp_scale_tool_get_widget     (GimpTransformGridTool *tg_tool);
 static void             gimp_scale_tool_update_widget  (GimpTransformGridTool *tg_tool);
 static void             gimp_scale_tool_widget_changed (GimpTransformGridTool *tg_tool);
@@ -111,6 +113,7 @@ gimp_scale_tool_class_init (GimpScaleToolClass *klass)
   tg_class->dialog          = gimp_scale_tool_dialog;
   tg_class->dialog_update   = gimp_scale_tool_dialog_update;
   tg_class->prepare         = gimp_scale_tool_prepare;
+  tg_class->readjust        = gimp_scale_tool_readjust;
   tg_class->get_widget      = gimp_scale_tool_get_widget;
   tg_class->update_widget   = gimp_scale_tool_update_widget;
   tg_class->widget_changed  = gimp_scale_tool_widget_changed;
@@ -254,6 +257,29 @@ gimp_scale_tool_prepare (GimpTransformGridTool *tg_tool)
                     tg_tool);
 }
 
+static void
+gimp_scale_tool_readjust (GimpTransformGridTool *tg_tool)
+{
+  GimpTool         *tool  = GIMP_TOOL (tg_tool);
+  GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+  gdouble           x;
+  gdouble           y;
+  gdouble           r;
+
+  x = shell->disp_width  / 2.0;
+  y = shell->disp_height / 2.0;
+  r = MIN (x, y) / G_SQRT2;
+
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x, y,
+                                       &x, &y);
+
+  tg_tool->trans_info[X0] = RINT (x - FUNSCALEX (shell, r));
+  tg_tool->trans_info[Y0] = RINT (y - FUNSCALEY (shell, r));
+  tg_tool->trans_info[X1] = RINT (x + FUNSCALEX (shell, r));
+  tg_tool->trans_info[Y1] = RINT (y + FUNSCALEY (shell, r));
+}
+
 static GimpToolWidget *
 gimp_scale_tool_get_widget (GimpTransformGridTool *tg_tool)
 {
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index 00a1934efa..ba474b50b3 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -28,6 +28,8 @@
 #include "widgets/gimphelp-ids.h"
 
 #include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-transform.h"
 #include "display/gimptoolgui.h"
 #include "display/gimptooltransformgrid.h"
 
@@ -59,6 +61,7 @@ enum
 static void             gimp_unified_transform_tool_matrix_to_info (GimpTransformGridTool    *tg_tool,
                                                                     const GimpMatrix3        *transform);
 static void             gimp_unified_transform_tool_prepare        (GimpTransformGridTool    *tg_tool);
+static void             gimp_unified_transform_tool_readjust       (GimpTransformGridTool    *tg_tool);
 static GimpToolWidget * gimp_unified_transform_tool_get_widget     (GimpTransformGridTool    *tg_tool);
 static void             gimp_unified_transform_tool_update_widget  (GimpTransformGridTool    *tg_tool);
 static void             gimp_unified_transform_tool_widget_changed (GimpTransformGridTool    *tg_tool);
@@ -99,6 +102,7 @@ gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
 
   tg_class->matrix_to_info      = gimp_unified_transform_tool_matrix_to_info;
   tg_class->prepare             = gimp_unified_transform_tool_prepare;
+  tg_class->readjust            = gimp_unified_transform_tool_readjust;
   tg_class->get_widget          = gimp_unified_transform_tool_get_widget;
   tg_class->update_widget       = gimp_unified_transform_tool_update_widget;
   tg_class->widget_changed      = gimp_unified_transform_tool_widget_changed;
@@ -173,6 +177,42 @@ gimp_unified_transform_tool_prepare (GimpTransformGridTool *tg_tool)
   tg_tool->trans_info[Y3] = (gdouble) tr_tool->y2;
 }
 
+static void
+gimp_unified_transform_tool_readjust (GimpTransformGridTool *tg_tool)
+{
+  GimpTool         *tool  = GIMP_TOOL (tg_tool);
+  GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
+  gdouble           x;
+  gdouble           y;
+  gdouble           r;
+
+  x = shell->disp_width  / 2.0;
+  y = shell->disp_height / 2.0;
+  r = MIN (x, y) / G_SQRT2;
+
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x, y,
+                                       &tg_tool->trans_info[PIVOT_X],
+                                       &tg_tool->trans_info[PIVOT_Y]);
+
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x - r, y - r,
+                                       &tg_tool->trans_info[X0],
+                                       &tg_tool->trans_info[Y0]);
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x + r, y - r,
+                                       &tg_tool->trans_info[X1],
+                                       &tg_tool->trans_info[Y1]);
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x - r, y + r,
+                                       &tg_tool->trans_info[X2],
+                                       &tg_tool->trans_info[Y2]);
+  gimp_display_shell_untransform_xy_f (shell,
+                                       x + r, y + r,
+                                       &tg_tool->trans_info[X3],
+                                       &tg_tool->trans_info[Y3]);
+}
+
 static GimpToolWidget *
 gimp_unified_transform_tool_get_widget (GimpTransformGridTool *tg_tool)
 {


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