[gimp/gimp-2-10] app: snap spin scale to page increments when holding Ctrl



commit e27aa6c000fbfa16b577b0acce409b08e665a190
Author: Ell <ell_se yahoo com>
Date:   Thu Jan 9 01:41:48 2020 +0200

    app: snap spin scale to page increments when holding Ctrl
    
    When click-dragging a GimpSpinScale while holding Ctrl, in either
    absolute or relative mode, snap the value (or the delta) to the
    page increment.

 app/widgets/gimpspinscale.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/app/widgets/gimpspinscale.c b/app/widgets/gimpspinscale.c
index cff875a803..0f9b694adb 100644
--- a/app/widgets/gimpspinscale.c
+++ b/app/widgets/gimpspinscale.c
@@ -31,11 +31,13 @@
 #include "widgets-types.h"
 
 #include "gimpspinscale.h"
-#include "gimpwidgets-utils.h"
 
 #include "gimp-intl.h"
 
 
+#define RELATIVE_CHANGE_SPEED 0.1
+
+
 enum
 {
   PROP_0,
@@ -604,7 +606,7 @@ gimp_spin_scale_get_target (GtkWidget      *widget,
       switch (event->button)
         {
         case 1:
-          if (event->state & gimp_get_extend_selection_mask ())
+          if (event->state & GDK_SHIFT_MASK)
             return TARGET_LOWER;
           else
             return TARGET_UPPER;
@@ -711,7 +713,8 @@ gimp_spin_scale_get_limits (GimpSpinScale *scale,
 
 static void
 gimp_spin_scale_change_value (GtkWidget *widget,
-                              gdouble    x)
+                              gdouble    x,
+                              guint      state)
 {
   GimpSpinScalePrivate *private     = GET_PRIVATE (widget);
   GtkSpinButton        *spin_button = GTK_SPIN_BUTTON (widget);
@@ -733,17 +736,23 @@ gimp_spin_scale_change_value (GtkWidget *widget,
 
   if (private->relative_change)
     {
-      gdouble diff;
       gdouble step;
 
-      step = (upper - lower) / width / 10.0;
+      step = (upper - lower) / width * RELATIVE_CHANGE_SPEED;
 
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-        diff = x - (width - private->start_x);
+        step *= x - (width - private->start_x);
       else
-        diff = x - private->start_x;
+        step *= x - private->start_x;
+
+      if (state & GDK_CONTROL_MASK)
+        {
+          gdouble page_inc = gtk_adjustment_get_page_increment (adjustment);
+
+          step = RINT (step / page_inc) * page_inc;
+        }
 
-      value = (private->start_value + diff * step);
+      value = private->start_value + step;
     }
   else
     {
@@ -754,6 +763,13 @@ gimp_spin_scale_change_value (GtkWidget *widget,
         fraction = pow (fraction, private->gamma);
 
       value = fraction * (upper - lower) + lower;
+
+      if (state & GDK_CONTROL_MASK)
+        {
+          gdouble page_inc = gtk_adjustment_get_page_increment (adjustment);
+
+          value = RINT (value / page_inc) * page_inc;
+        }
     }
 
   digits = gtk_spin_button_get_digits (spin_button);
@@ -798,7 +814,7 @@ gimp_spin_scale_button_press (GtkWidget      *widget,
 
           gtk_widget_grab_focus (widget);
 
-          gimp_spin_scale_change_value (widget, event->x);
+          gimp_spin_scale_change_value (widget, event->x, event->state);
 
           return TRUE;
 
@@ -840,7 +856,7 @@ gimp_spin_scale_button_release (GtkWidget      *widget,
        * gimp_spin_scale_motion_notify().
        */
       if (! private->pointer_warp)
-        gimp_spin_scale_change_value (widget, event->x);
+        gimp_spin_scale_change_value (widget, event->x, event->state);
 
       if (private->relative_change)
         {
@@ -930,7 +946,7 @@ gimp_spin_scale_motion_notify (GtkWidget      *widget,
             private->start_x = private->pointer_warp_start_x;
         }
 
-      gimp_spin_scale_change_value (widget, event->x);
+      gimp_spin_scale_change_value (widget, event->x, event->state);
 
       if (private->relative_change)
         {


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