[gimp] app: Add option to re-enable previous drag-to-zoom behavior



commit 505a78e7159431f2ab9cbf22c73dfc80746a49d7
Author: woob <thetoastcaper gmail com>
Date:   Mon Apr 4 17:08:14 2022 -0400

    app: Add option to re-enable previous drag-to-zoom behavior
    
    Adds a new configuration option "drag-zoom-mode" to choose whether to
    zoom by distance of movement (newly added) or by duration of movement
    (previous behavior) when zooming via dragging the mouse, defaulting to
    distance.
    This option can be found in the preferences dialog as:
      Image Windows -> Zoom & Resize Behavior -> Drag-to-zoom behavior

 app/config/config-enums.h            |  9 +++++++++
 app/config/gimpdisplayconfig.c       | 15 +++++++++++++++
 app/config/gimpdisplayconfig.h       |  1 +
 app/config/gimprc-blurbs.h           |  4 ++++
 app/dialogs/preferences-dialog.c     |  6 ++++++
 app/display/gimpdisplayshell-scale.c | 28 ++++++++++++++++++++++++----
 6 files changed, 59 insertions(+), 4 deletions(-)
---
diff --git a/app/config/config-enums.h b/app/config/config-enums.h
index 7894903ee4..84a36c52ef 100644
--- a/app/config/config-enums.h
+++ b/app/config/config-enums.h
@@ -107,6 +107,15 @@ typedef enum
   GIMP_POSITION_RIGHT   /*< desc="Right" >*/
 } GimpPosition;
 
+#define GIMP_TYPE_DRAG_ZOOM_MODE (gimp_drag_zoom_mode_get_type ())
+
+GType gimp_drag_zoom_mode_get_type (void) G_GNUC_CONST;
+
+typedef enum
+{
+  PROP_DRAG_ZOOM_MODE_DISTANCE,  /*< desc="By distance" >*/
+  PROP_DRAG_ZOOM_MODE_DURATION,  /*< desc="By duration" >*/
+} GimpDragZoomMode;
 
 #define GIMP_TYPE_SPACE_BAR_ACTION (gimp_space_bar_action_get_type ())
 
diff --git a/app/config/gimpdisplayconfig.c b/app/config/gimpdisplayconfig.c
index d38a6a18aa..e2c51d0ecc 100644
--- a/app/config/gimpdisplayconfig.c
+++ b/app/config/gimpdisplayconfig.c
@@ -54,6 +54,7 @@ enum
   PROP_DEFAULT_SHOW_ALL,
   PROP_DEFAULT_DOT_FOR_DOT,
   PROP_INITIAL_ZOOM_TO_FIT,
+  PROP_DRAG_ZOOM_MODE,
   PROP_CURSOR_MODE,
   PROP_CURSOR_UPDATING,
   PROP_SHOW_BRUSH_OUTLINE,
@@ -181,6 +182,14 @@ gimp_display_config_class_init (GimpDisplayConfigClass *klass)
                             TRUE,
                             GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_ENUM (object_class, PROP_DRAG_ZOOM_MODE,
+                         "drag-zoom-mode",
+                         "Drag-to-zoom behavior",
+                         DRAG_ZOOM_MODE_BLURB,
+                         GIMP_TYPE_DRAG_ZOOM_MODE,
+                         PROP_DRAG_ZOOM_MODE_DISTANCE,
+                         GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_ENUM (object_class, PROP_CURSOR_MODE,
                          "cursor-mode",
                          "Cursor mode",
@@ -426,6 +435,9 @@ gimp_display_config_set_property (GObject      *object,
     case PROP_INITIAL_ZOOM_TO_FIT:
       display_config->initial_zoom_to_fit = g_value_get_boolean (value);
       break;
+    case PROP_DRAG_ZOOM_MODE:
+      display_config->drag_zoom_mode = g_value_get_enum (value);
+      break;
     case PROP_CURSOR_MODE:
       display_config->cursor_mode = g_value_get_enum (value);
       break;
@@ -538,6 +550,9 @@ gimp_display_config_get_property (GObject    *object,
     case PROP_INITIAL_ZOOM_TO_FIT:
       g_value_set_boolean (value, display_config->initial_zoom_to_fit);
       break;
+    case PROP_DRAG_ZOOM_MODE:
+      g_value_set_enum (value, display_config->drag_zoom_mode);
+      break;
     case PROP_CURSOR_MODE:
       g_value_set_enum (value, display_config->cursor_mode);
       break;
diff --git a/app/config/gimpdisplayconfig.h b/app/config/gimpdisplayconfig.h
index e4c2a72962..1de8bffe89 100644
--- a/app/config/gimpdisplayconfig.h
+++ b/app/config/gimpdisplayconfig.h
@@ -50,6 +50,7 @@ struct _GimpDisplayConfig
   gboolean            default_show_all;
   gboolean            default_dot_for_dot;
   gboolean            initial_zoom_to_fit;
+  GimpDragZoomMode    drag_zoom_mode;
   GimpCursorMode      cursor_mode;
   gboolean            cursor_updating;
   gboolean            show_brush_outline;
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 8a7c4cfb3a..00726264df 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -257,6 +257,10 @@ _("Sets the preferred pen and touch input API.")
 _("When enabled, this will ensure that the full image is visible after a " \
   "file is opened, otherwise it will be displayed with a scale of 1:1.")
 
+#define DRAG_ZOOM_MODE_BLURB \
+_("Whether to zoom based on distance moved or time spent moving, when " \
+  "zooming via dragging the mouse.")
+
 #define INTERPOLATION_TYPE_BLURB \
 _("Sets the level of interpolation used for scaling and other " \
   "transformations.")
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index f83be9ab06..6d50f1aba3 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -2933,6 +2933,12 @@ prefs_dialog_new (Gimp       *gimp,
                                _("Initial zoom _ratio:"),
                                GTK_GRID (grid), 0, size_group);
 
+  grid = prefs_grid_new (GTK_CONTAINER (vbox2));
+
+  prefs_enum_combo_box_add (object, "drag-zoom-mode", 0, 0,
+                            _("Dra_g-to-zoom behavior:"),
+                            GTK_GRID (grid), 0, size_group);
+
   /*  Space Bar  */
   vbox2 = prefs_frame_new (_("Space Bar"),
                            GTK_CONTAINER (vbox), FALSE);
diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c
index 4c2450fcbf..3f443c650c 100644
--- a/app/display/gimpdisplayshell-scale.c
+++ b/app/display/gimpdisplayshell-scale.c
@@ -811,12 +811,32 @@ gimp_display_shell_scale_drag (GimpDisplayShell *shell,
 
   if (delta_y != 0.0)
     {
+      GimpDisplayConfig *config = shell->display->config;
+
       gimp_display_shell_push_zoom_focus_pointer_pos (shell, start_x, start_y);
 
-      gimp_display_shell_scale (shell,
-                                GIMP_ZOOM_TO,
-                                scale * exp (0.01 * delta_y),
-                                GIMP_ZOOM_FOCUS_POINTER);
+      if (config->drag_zoom_mode == PROP_DRAG_ZOOM_MODE_DISTANCE)
+        {
+          gimp_display_shell_scale (shell,
+                                    GIMP_ZOOM_TO,
+                                    scale * exp (0.01 * delta_y),
+                                    GIMP_ZOOM_FOCUS_POINTER);
+        }
+      else if (delta_y > 0.0) /* drag_zoom_mode == PROP_DRAG_ZOOM_MODE_DURATION */
+        {
+          gimp_display_shell_scale (shell,
+                                    GIMP_ZOOM_TO,
+                                    scale * 1.1,
+                                    GIMP_ZOOM_FOCUS_POINTER);
+        }
+      else /* delta_y < 0.0 */
+        {
+          gimp_display_shell_scale (shell,
+                                    GIMP_ZOOM_TO,
+                                    scale * 0.9,
+                                    GIMP_ZOOM_FOCUS_POINTER);
+        }
+
 
       if (shell->zoom_focus_point)
         {


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