Commit 56781537 authored by Ell's avatar Ell

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.
parent 92fd5675
Pipeline #162732 passed with stages
in 35 minutes and 17 seconds
......@@ -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)
......@@ -752,13 +755,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) text_area.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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment