From ffe2fb478ca2bfb7adf0d5c3d556221db18cd8f9 Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 25 Jan 2019 18:21:05 +0100 Subject: [PATCH] app: new gimp_spin_scale_set_constrain_drag() and use it on paint... ... tools' brush options. After discussions, it turned out that many people disliked that the spin scale for brush size (and some other options) get you fractional values. How often do you actually need to get a 4.32 pixel-size brush? And even how meaningful is it? On the other hand, you usually want a 4 or a 5 pixel size brush and it's nearly impossible to get (exactly) by dragging the scale widget. It is so annoying that some even resort to edit the value with keyboard! So I am adding an optional "constrain" feature to GimpSpinScale. It will still be possible to get fractional values when constraining is on, for instance with keyboard edit (the arrow incrementation also will keep any fractional part). So the interaction for such scales is simply reversed so that you get integers easily, and fractional parts with a bit more effort. It is not turned on by default (some feature actually need precision and we don't want to break the sliders for these) and for the time being, I only applied it to all the brush settings in paint tools. Now that it exist, we may want to apply this to more scales in various parts of GIMP. (cherry picked from commit bff3903f377ea26471c00bff132c5dbb99b04c29) --- app/tools/gimppaintoptions-gui.c | 2 ++ app/widgets/gimpspinscale.c | 37 ++++++++++++++++++++++++++++++++ app/widgets/gimpspinscale.h | 3 +++ 3 files changed, 42 insertions(+) diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c index 7955438ef7..23aef019e6 100644 --- a/app/tools/gimppaintoptions-gui.c +++ b/app/tools/gimppaintoptions-gui.c @@ -524,6 +524,8 @@ gimp_paint_options_gui_scale_with_buttons (GObject *config, scale = gimp_prop_spin_scale_new (config, prop_name, NULL, step_increment, page_increment, digits); + gimp_spin_scale_set_constrain_drag (GIMP_SPIN_SCALE (scale), TRUE); + gimp_prop_widget_set_factor (scale, factor, step_increment, page_increment, digits); gimp_spin_scale_set_scale_limits (GIMP_SPIN_SCALE (scale), diff --git a/app/widgets/gimpspinscale.c b/app/widgets/gimpspinscale.c index 2b11e1b9b4..31769a6693 100644 --- a/app/widgets/gimpspinscale.c +++ b/app/widgets/gimpspinscale.c @@ -62,6 +62,8 @@ struct _GimpSpinScalePrivate guint mnemonic_keyval; gboolean mnemonics_visible; + gboolean constrain_drag; + gboolean scale_limits_set; gdouble scale_lower; gdouble scale_upper; @@ -721,6 +723,9 @@ gimp_spin_scale_change_value (GtkWidget *widget, value = RINT (value); value /= power; + if (private->constrain_drag) + value = rint (value); + gtk_adjustment_set_value (adjustment, value); } @@ -1338,3 +1343,35 @@ gimp_spin_scale_get_gamma (GimpSpinScale *scale) return GET_PRIVATE (scale)->gamma; } + +/** + * gimp_spin_scale_set_constrain_drag: + * @scale: the #GimpSpinScale. + * @constrain: whether constraining to integer values when dragging with + * pointer. + * + * If @constrain_drag is TRUE, dragging the scale with the pointer will + * only result into integer values. It will still possible to set the + * scale to fractional values (if the spin scale "digits" is above 0) + * for instance with keyboard edit. + */ +void +gimp_spin_scale_set_constrain_drag (GimpSpinScale *scale, + gboolean constrain) +{ + GimpSpinScalePrivate *private; + + g_return_if_fail (GIMP_IS_SPIN_SCALE (scale)); + + private = GET_PRIVATE (scale); + + private->constrain_drag = constrain; +} + +gboolean +gimp_spin_scale_get_constrain_drag (GimpSpinScale *scale) +{ + g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), 1.0); + + return GET_PRIVATE (scale)->constrain_drag; +} diff --git a/app/widgets/gimpspinscale.h b/app/widgets/gimpspinscale.h index 4435cf50b0..0693ac2745 100644 --- a/app/widgets/gimpspinscale.h +++ b/app/widgets/gimpspinscale.h @@ -66,5 +66,8 @@ void gimp_spin_scale_set_gamma (GimpSpinScale *scale, gdouble gamma); gdouble gimp_spin_scale_get_gamma (GimpSpinScale *scale); +void gimp_spin_scale_set_constrain_drag (GimpSpinScale *scale, + gboolean constrain); +gboolean gimp_spin_scale_get_constrain_drag (GimpSpinScale *scale); #endif /* __GIMP_SPIN_SCALE_H__ */