[gimp] app: add a pivot selector to the Rotate tool



commit c0552de62b4193cac69cdbcc4c687a105fa0e733
Author: Ell <ell_se yahoo com>
Date:   Mon Jan 6 12:50:48 2020 +0200

    app: add a pivot selector to the Rotate tool
    
    Add a GimpPivotSelector widget to the Rotate tool dialog, to allow
    for quickly picking a pivot.

 app/tools/gimprotatetool.c | 48 ++++++++++++++++++++++++++++++++++++++++++++--
 app/tools/gimprotatetool.h |  1 +
 app/widgets/meson.build    |  1 +
 3 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/app/tools/gimprotatetool.c b/app/tools/gimprotatetool.c
index 27114e5459..51715afdfe 100644
--- a/app/tools/gimprotatetool.c
+++ b/app/tools/gimprotatetool.c
@@ -30,6 +30,7 @@
 #include "core/gimpimage.h"
 
 #include "widgets/gimphelp-ids.h"
+#include "widgets/gimppivotselector.h"
 
 #include "display/gimpdisplay.h"
 #include "display/gimpdisplayshell.h"
@@ -53,7 +54,7 @@ enum
 };
 
 
-#define SB_WIDTH 10
+#define SB_WIDTH 8
 #define EPSILON  1e-6
 
 
@@ -80,6 +81,8 @@ static void             rotate_angle_changed            (GtkAdjustment         *
                                                          GimpTransformGridTool *tg_tool);
 static void             rotate_center_changed           (GtkWidget             *entry,
                                                          GimpTransformGridTool *tg_tool);
+static void             rotate_pivot_changed            (GimpPivotSelector     *selector,
+                                                         GimpTransformGridTool *tg_tool);
 
 
 G_DEFINE_TYPE (GimpRotateTool, gimp_rotate_tool, GIMP_TYPE_TRANSFORM_GRID_TOOL)
@@ -288,7 +291,7 @@ gimp_rotate_tool_dialog (GimpTransformGridTool *tg_tool)
   scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, rotate->angle_adj);
   gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
   gtk_widget_set_hexpand (scale, TRUE);
-  gtk_grid_attach (GTK_GRID (grid), scale, 1, 1, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), scale, 1, 1, 2, 1);
   gtk_widget_show (scale);
 
   adj = gtk_adjustment_new (0, -1, 1, 1, 10, 0);
@@ -312,6 +315,14 @@ gimp_rotate_tool_dialog (GimpTransformGridTool *tg_tool)
   g_signal_connect (rotate->sizeentry, "value-changed",
                     G_CALLBACK (rotate_center_changed),
                     tg_tool);
+
+  rotate->pivot_selector = gimp_pivot_selector_new (0.0, 0.0, 0.0, 0.0);
+  gtk_grid_attach (GTK_GRID (grid), rotate->pivot_selector, 2, 2, 1, 2);
+  gtk_widget_show (rotate->pivot_selector);
+
+  g_signal_connect (rotate->pivot_selector, "changed",
+                    G_CALLBACK (rotate_pivot_changed),
+                    tg_tool);
 }
 
 static void
@@ -334,6 +345,19 @@ gimp_rotate_tool_dialog_update (GimpTransformGridTool *tg_tool)
   g_signal_handlers_unblock_by_func (rotate->sizeentry,
                                      rotate_center_changed,
                                      tg_tool);
+
+  g_signal_handlers_block_by_func (rotate->pivot_selector,
+                                   rotate_pivot_changed,
+                                   tg_tool);
+
+  gimp_pivot_selector_set_position (
+    GIMP_PIVOT_SELECTOR (rotate->pivot_selector),
+    tg_tool->trans_info[PIVOT_X],
+    tg_tool->trans_info[PIVOT_Y]);
+
+  g_signal_handlers_unblock_by_func (rotate->pivot_selector,
+                                     rotate_pivot_changed,
+                                     tg_tool);
 }
 
 static void
@@ -381,6 +405,10 @@ gimp_rotate_tool_prepare (GimpTransformGridTool *tg_tool)
   g_signal_handlers_unblock_by_func (rotate->sizeentry,
                                      rotate_center_changed,
                                      tg_tool);
+
+  gimp_pivot_selector_set_bounds (GIMP_PIVOT_SELECTOR (rotate->pivot_selector),
+                                  tr_tool->x1, tr_tool->y1,
+                                  tr_tool->x2, tr_tool->y2);
 }
 
 static void
@@ -491,3 +519,19 @@ rotate_center_changed (GtkWidget             *widget,
       gimp_transform_tool_recalc_matrix (tr_tool, tool->display);
     }
 }
+
+static void
+rotate_pivot_changed (GimpPivotSelector     *selector,
+                      GimpTransformGridTool *tg_tool)
+{
+  GimpTool          *tool    = GIMP_TOOL (tg_tool);
+  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tg_tool);
+
+  gimp_pivot_selector_get_position (selector,
+                                    &tg_tool->trans_info[PIVOT_X],
+                                    &tg_tool->trans_info[PIVOT_Y]);
+
+  gimp_transform_grid_tool_push_internal_undo (tg_tool, TRUE);
+
+  gimp_transform_tool_recalc_matrix (tr_tool, tool->display);
+}
diff --git a/app/tools/gimprotatetool.h b/app/tools/gimprotatetool.h
index f8a68eda71..5a09ca2eab 100644
--- a/app/tools/gimprotatetool.h
+++ b/app/tools/gimprotatetool.h
@@ -40,6 +40,7 @@ struct _GimpRotateTool
   GtkAdjustment         *angle_adj;
   GtkWidget             *angle_spin_button;
   GtkWidget             *sizeentry;
+  GtkWidget             *pivot_selector;
 };
 
 struct _GimpRotateToolClass
diff --git a/app/widgets/meson.build b/app/widgets/meson.build
index f7b30b8847..a323f34ff0 100644
--- a/app/widgets/meson.build
+++ b/app/widgets/meson.build
@@ -155,6 +155,7 @@ libappwidgets_sources = [
   'gimppdbdialog.c',
   'gimppickablebutton.c',
   'gimppickablepopup.c',
+  'gimppivotselector.c',
   'gimppixbuf.c',
   'gimppluginview.c',
   'gimppolar.c',


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