[gimp/goat-invasion: 334/418] app: add configurable nonlinear mapping (gamma) to spinscale widget
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/goat-invasion: 334/418] app: add configurable nonlinear mapping (gamma) to spinscale widget
- Date: Wed, 4 Apr 2012 10:53:52 +0000 (UTC)
commit 504ff79b12123caa956a2c73685eee4a28ddd788
Author: Ãyvind KolÃs <pippin gimp org>
Date: Fri Mar 30 21:34:59 2012 +0100
app: add configurable nonlinear mapping (gamma) to spinscale widget
The default value is 1.0 which is linear and the old behavior, values above
1.0 gives finer control in the lower portions of the range, the lower half of
the widget behaves like before doing small relative adjustments.
app/widgets/gimpspinscale.c | 34 ++++++++++++++++++++++++++++++++--
app/widgets/gimpspinscale.h | 4 ++++
2 files changed, 36 insertions(+), 2 deletions(-)
---
diff --git a/app/widgets/gimpspinscale.c b/app/widgets/gimpspinscale.c
index 5c2aded..807b3d1 100644
--- a/app/widgets/gimpspinscale.c
+++ b/app/widgets/gimpspinscale.c
@@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
+#include "libgimpmath/gimpmath.h"
#include "widgets-types.h"
@@ -54,6 +55,7 @@ struct _GimpSpinScalePrivate
gboolean scale_limits_set;
gdouble scale_lower;
gdouble scale_upper;
+ gdouble gamma;
PangoLayout *layout;
gboolean changing_value;
@@ -459,6 +461,7 @@ gimp_spin_scale_change_value (GtkWidget *widget,
gdouble fraction;
fraction = x / (gdouble) width;
+ fraction = pow (fraction, private->gamma);
value = fraction * (upper - lower) + lower;
}
@@ -582,6 +585,7 @@ static void
gimp_spin_scale_value_changed (GtkSpinButton *spin_button)
{
GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
+ GimpSpinScalePrivate *private = GET_PRIVATE (spin_button);
gdouble lower;
gdouble upper;
gdouble value;
@@ -590,8 +594,9 @@ gimp_spin_scale_value_changed (GtkSpinButton *spin_button)
value = CLAMP (gtk_adjustment_get_value (adjustment), lower, upper);
+
gtk_entry_set_progress_fraction (GTK_ENTRY (spin_button),
- (value - lower) / (upper - lower));
+ pow((value - lower) / (upper - lower), 1.0/private->gamma));
}
@@ -632,11 +637,37 @@ gimp_spin_scale_set_scale_limits (GimpSpinScale *scale,
private->scale_limits_set = TRUE;
private->scale_lower = lower;
private->scale_upper = upper;
+ private->gamma = 1.0;
gimp_spin_scale_value_changed (spin_button);
}
void
+gimp_spin_scale_set_gamma (GimpSpinScale *scale,
+ gdouble gamma)
+{
+ GimpSpinScalePrivate *private;
+
+ g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
+
+ private = GET_PRIVATE (scale);
+
+ private->gamma = gamma;
+}
+
+gdouble
+gimp_spin_scale_get_gamma (GimpSpinScale *scale)
+{
+ GimpSpinScalePrivate *private;
+
+ g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
+
+ private = GET_PRIVATE (scale);
+
+ return private->gamma;
+}
+
+void
gimp_spin_scale_unset_scale_limits (GimpSpinScale *scale)
{
GimpSpinScalePrivate *private;
@@ -671,4 +702,3 @@ gimp_spin_scale_get_scale_limits (GimpSpinScale *scale,
return private->scale_limits_set;
}
-
diff --git a/app/widgets/gimpspinscale.h b/app/widgets/gimpspinscale.h
index d896845..2ab3090 100644
--- a/app/widgets/gimpspinscale.h
+++ b/app/widgets/gimpspinscale.h
@@ -58,5 +58,9 @@ gboolean gimp_spin_scale_get_scale_limits (GimpSpinScale *scale,
gdouble *lower,
gdouble *upper);
+void gimp_spin_scale_set_gamma (GimpSpinScale *scale,
+ gdouble gamma);
+
+gdouble gimp_spin_scale_get_gamma (GimpSpinScale *scale);
#endif /* __GIMP_SPIN_SCALE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]