[gimp/gimp-2-10] app: apply spin-scale gamma to input, not output



commit 0e8b995ba03adef3a72b6e3ec3954e6adc2d98a4
Author: Ell <ell_se yahoo com>
Date:   Sun Mar 22 13:22:54 2020 +0200

    app: apply spin-scale gamma to input, not output
    
    In GimpSpinScale, apply the slider gamma to the input [min,max]
    range, rather than the output [0,1] range, using an odd gamma
    curve, in particular, so that we handle negative values correctly.
    
    (cherry picked from commit 56781537976100c23154d6aa351f92a011747001)

 app/widgets/gimpspinscale.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/app/widgets/gimpspinscale.c b/app/widgets/gimpspinscale.c
index a443b411e9..afd742df3e 100644
--- a/app/widgets/gimpspinscale.c
+++ b/app/widgets/gimpspinscale.c
@@ -133,6 +133,9 @@ static void       gimp_spin_scale_mnemonics_notify  (GtkWindow        *window,
 static void       gimp_spin_scale_setup_mnemonic    (GimpSpinScale    *scale,
                                                      guint             previous_keyval);
 
+static gdouble    odd_pow                           (gdouble           x,
+                                                     gdouble           y);
+
 
 G_DEFINE_TYPE_WITH_PRIVATE (GimpSpinScale, gimp_spin_scale,
                             GIMP_TYPE_SPIN_BUTTON)
@@ -757,13 +760,16 @@ gimp_spin_scale_change_value (GtkWidget *widget,
     }
   else
     {
+      gdouble x0, x1;
       gdouble fraction;
 
+      x0 = odd_pow (lower, 1.0 / private->gamma);
+      x1 = odd_pow (upper, 1.0 / private->gamma);
+
       fraction = x / (gdouble) width;
-      if (fraction > 0.0)
-        fraction = pow (fraction, private->gamma);
 
-      value = fraction * (upper - lower) + lower;
+      value = fraction * (x1 - x0) + x0;
+      value = odd_pow (value, private->gamma);
 
       if (state & GDK_CONTROL_MASK)
         {
@@ -1085,14 +1091,19 @@ gimp_spin_scale_value_changed (GtkSpinButton *spin_button)
   gdouble               lower;
   gdouble               upper;
   gdouble               value;
+  gdouble               x0, x1;
+  gdouble               x;
 
   gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (spin_button), &lower, &upper);
 
   value = CLAMP (gtk_adjustment_get_value (adjustment), lower, upper);
 
+  x0 = odd_pow (lower, 1.0 / private->gamma);
+  x1 = odd_pow (upper, 1.0 / private->gamma);
+  x  = odd_pow (value, 1.0 / private->gamma);
+
   gtk_entry_set_progress_fraction (GTK_ENTRY (spin_button),
-                                   pow ((value - lower) / (upper - lower),
-                                        1.0 / private->gamma));
+                                   (x - x0) / (x1 - x0));
 }
 
 static void
@@ -1176,6 +1187,16 @@ gimp_spin_scale_setup_mnemonic (GimpSpinScale *scale,
      }
 }
 
+static gdouble
+odd_pow (gdouble x,
+         gdouble y)
+{
+  if (x >= 0.0)
+    return pow (x, y);
+  else
+    return -pow (-x, y);
+}
+
 
 /*  public functions  */
 


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