From 7385e030ddf1eca1317de45ffcde3a43190b4b64 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 3 Feb 2014 22:57:51 +0100 Subject: [PATCH] app, libgimp: add increment parameters to gimp_prop_widget_set_factor() Step and page increments can't be reasonable calculated or guessed based on the GUI widget's factor, so pass them each time we call set_factor(). This change reintroduces sane ranges for the levels tool for != u8 images again. --- app/tools/gimpbrightnesscontrasttool.c | 18 ++++++++------ app/tools/gimpcolorbalancetool.c | 2 +- app/tools/gimpcolorizetool.c | 8 +++--- app/tools/gimphuesaturationtool.c | 8 +++--- app/tools/gimplevelstool.c | 34 +++++++++++++++++--------- app/tools/gimppaintoptions-gui.c | 2 +- app/tools/gimptransformoptions.c | 2 +- app/widgets/gimppropwidgets.c | 12 +++++++-- app/widgets/gimppropwidgets.h | 2 ++ libgimpwidgets/gimppropwidgets.c | 14 ++++++++--- 10 files changed, 66 insertions(+), 36 deletions(-) diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c index 279b3d730d..b63845a222 100644 --- a/app/tools/gimpbrightnesscontrasttool.c +++ b/app/tools/gimpbrightnesscontrasttool.c @@ -144,13 +144,17 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool, if (gimp_drawable_get_component_type (drawable) == GIMP_COMPONENT_TYPE_U8) { - gimp_prop_widget_set_factor (bc_tool->brightness_scale, 127.0, 0); - gimp_prop_widget_set_factor (bc_tool->contrast_scale, 127.0, 0); + gimp_prop_widget_set_factor (bc_tool->brightness_scale, + 127.0, 1.0, 8.0, 0); + gimp_prop_widget_set_factor (bc_tool->contrast_scale, + 127.0, 1.0, 8.0, 0); } else { - gimp_prop_widget_set_factor (bc_tool->brightness_scale, 0.5, 3); - gimp_prop_widget_set_factor (bc_tool->contrast_scale, 0.5, 3); + gimp_prop_widget_set_factor (bc_tool->brightness_scale, + 0.5, 0.01, 0.1, 3); + gimp_prop_widget_set_factor (bc_tool->contrast_scale, + 0.5, 0.01, 0.1, 3); } return TRUE; @@ -249,8 +253,7 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool) /* Create the brightness scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "brightness", - _("_Brightness"), 1.0 / 127.0, 10.0 / 127.0, - 0); + _("_Brightness"), 0.01, 0.1, 3); gtk_box_pack_start (GTK_BOX (main_vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); @@ -258,8 +261,7 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool) /* Create the contrast scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "contrast", - _("_Contrast"), 1.0 / 127.0, 10.0 / 127.0, - 0); + _("_Contrast"), 0.01, 0.1, 3); gtk_box_pack_start (GTK_BOX (main_vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); diff --git a/app/tools/gimpcolorbalancetool.c b/app/tools/gimpcolorbalancetool.c index 017d450c4d..948905e6b9 100644 --- a/app/tools/gimpcolorbalancetool.c +++ b/app/tools/gimpcolorbalancetool.c @@ -168,7 +168,7 @@ create_levels_scale (GObject *config, scale = gimp_prop_spin_scale_new (config, property_name, NULL, 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_table_attach_defaults (GTK_TABLE (table), scale, 1, 2, col, col + 1); gtk_widget_show (scale); diff --git a/app/tools/gimpcolorizetool.c b/app/tools/gimpcolorizetool.c index 321cbbd9dd..3c8edc3cf4 100644 --- a/app/tools/gimpcolorizetool.c +++ b/app/tools/gimpcolorizetool.c @@ -171,22 +171,22 @@ gimp_colorize_tool_dialog (GimpImageMapTool *image_map_tool) /* Create the hue scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "hue", - _("_Hue"), 1.0 / 230.0, 15.0 / 360.0, 0); - gimp_prop_widget_set_factor (scale, 360.0, 1); + _("_Hue"), 1.0 / 360.0, 15.0 / 360.0, 0); + gimp_prop_widget_set_factor (scale, 360.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); /* Create the saturation scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "saturation", _("_Saturation"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); /* Create the lightness scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "lightness", _("_Lightness"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); diff --git a/app/tools/gimphuesaturationtool.c b/app/tools/gimphuesaturationtool.c index f3759c1e91..e3d462d63d 100644 --- a/app/tools/gimphuesaturationtool.c +++ b/app/tools/gimphuesaturationtool.c @@ -286,7 +286,7 @@ gimp_hue_saturation_tool_dialog (GimpImageMapTool *image_map_tool) /* Create the 'Overlap' option slider */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "overlap", _("_Overlap"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); @@ -301,21 +301,21 @@ gimp_hue_saturation_tool_dialog (GimpImageMapTool *image_map_tool) /* Create the hue scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "hue", _("_Hue"), 1.0 / 180.0, 15.0 / 180.0, 0); - gimp_prop_widget_set_factor (scale, 180.0, 1); + gimp_prop_widget_set_factor (scale, 180.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); /* Create the lightness scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "lightness", _("_Lightness"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); /* Create the saturation scale widget */ scale = gimp_prop_spin_scale_new (image_map_tool->config, "saturation", _("_Saturation"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c index b3f159aa68..a0fa064b86 100644 --- a/app/tools/gimplevelstool.c +++ b/app/tools/gimplevelstool.c @@ -194,6 +194,8 @@ gimp_levels_tool_initialize (GimpTool *tool, GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); gdouble scale_factor; + gdouble step_increment; + gdouble page_increment; gint digits; if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) @@ -210,23 +212,31 @@ gimp_levels_tool_initialize (GimpTool *tool, if (gimp_drawable_get_component_type (drawable) == GIMP_COMPONENT_TYPE_U8) { - scale_factor = 255.0; - digits = 0; + scale_factor = 255.0; + step_increment = 1.0; + page_increment = 8.0; + digits = 0; } else { - scale_factor = 10000; - digits = 0; + scale_factor = 100; + step_increment = 0.01; + page_increment = 1.0; + digits = 2; } gimp_prop_widget_set_factor (l_tool->low_input_spinbutton, - scale_factor, digits); + scale_factor, step_increment, page_increment, + digits); gimp_prop_widget_set_factor (l_tool->high_input_spinbutton, - scale_factor, digits); + scale_factor, step_increment, page_increment, + digits); gimp_prop_widget_set_factor (l_tool->low_output_spinbutton, - scale_factor, digits); + scale_factor, step_increment, page_increment, + digits); gimp_prop_widget_set_factor (l_tool->high_output_spinbutton, - scale_factor, digits); + scale_factor, step_increment, page_increment, + digits); gtk_adjustment_configure (l_tool->gamma_linear, scale_factor / 2.0, @@ -435,7 +445,7 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) tool->low_input_spinbutton = spinbutton = gimp_prop_spin_button_new (image_map_tool->config, "low-input", - 0.0001, 0.1, 1); + 0.01, 0.1, 1); gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0); gtk_widget_show (spinbutton); @@ -472,7 +482,7 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) gtk_widget_show (button); spinbutton = gimp_prop_spin_button_new (image_map_tool->config, "high-input", - 0.0001, 0.1, 1); + 0.01, 0.1, 1); gtk_box_pack_start (GTK_BOX (hbox2), spinbutton, FALSE, FALSE, 0); gtk_widget_show (spinbutton); tool->high_input_spinbutton = spinbutton; @@ -521,7 +531,7 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) /* low output spin */ tool->low_output_spinbutton = spinbutton = gimp_prop_spin_button_new (image_map_tool->config, "low-output", - 0.0001, 0.1, 1); + 0.01, 0.1, 1); gtk_box_pack_start (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0); gtk_widget_show (spinbutton); @@ -531,7 +541,7 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) /* high output spin */ tool->high_output_spinbutton = spinbutton = gimp_prop_spin_button_new (image_map_tool->config, "high-output", - 0.0001, 0.1, 1); + 0.01, 0.1, 1); gtk_box_pack_end (GTK_BOX (hbox), spinbutton, FALSE, FALSE, 0); gtk_widget_show (spinbutton); diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c index 114b4b41db..6c323ec21b 100644 --- a/app/tools/gimppaintoptions-gui.c +++ b/app/tools/gimppaintoptions-gui.c @@ -99,7 +99,7 @@ gimp_paint_options_gui (GimpToolOptions *tool_options) scale = gimp_prop_spin_scale_new (config, "opacity", _("Opacity"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); gtk_box_pack_start (GTK_BOX (vbox), scale, FALSE, FALSE, 0); gtk_widget_show (scale); diff --git a/app/tools/gimptransformoptions.c b/app/tools/gimptransformoptions.c index d6b6c090f4..a13ae7aa0e 100644 --- a/app/tools/gimptransformoptions.c +++ b/app/tools/gimptransformoptions.c @@ -415,7 +415,7 @@ gimp_transform_options_gui (GimpToolOptions *tool_options) scale = gimp_prop_spin_scale_new (config, "preview-opacity", _("Image opacity"), 0.01, 0.1, 0); - gimp_prop_widget_set_factor (scale, 100.0, 1); + gimp_prop_widget_set_factor (scale, 100.0, 0.0, 0.0, 1); frame = gimp_prop_expanding_frame_new (config, "show-preview", _("Show image preview"), scale, NULL); diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c index ad72d171c5..07040679f6 100644 --- a/app/widgets/gimppropwidgets.c +++ b/app/widgets/gimppropwidgets.c @@ -531,6 +531,8 @@ gimp_prop_spin_scale_new (GObject *config, void gimp_prop_widget_set_factor (GtkWidget *widget, gdouble factor, + gdouble step_increment, + gdouble page_increment, gint digits) { GtkAdjustment *adjustment; @@ -564,12 +566,18 @@ gimp_prop_widget_set_factor (GtkWidget *widget, f = factor / old_factor; + if (step_increment <= 0) + step_increment = f * gtk_adjustment_get_step_increment (adjustment); + + if (page_increment <= 0) + page_increment = f * gtk_adjustment_get_page_increment (adjustment); + gtk_adjustment_configure (adjustment, f * gtk_adjustment_get_value (adjustment), f * gtk_adjustment_get_lower (adjustment), f * gtk_adjustment_get_upper (adjustment), - f * gtk_adjustment_get_step_increment (adjustment), - f * gtk_adjustment_get_page_increment (adjustment), + step_increment, + page_increment, f * gtk_adjustment_get_page_size (adjustment)); gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), digits); diff --git a/app/widgets/gimppropwidgets.h b/app/widgets/gimppropwidgets.h index 212c8ad1e9..74b22d8930 100644 --- a/app/widgets/gimppropwidgets.h +++ b/app/widgets/gimppropwidgets.h @@ -62,6 +62,8 @@ GtkWidget * gimp_prop_spin_scale_new (GObject *config, void gimp_prop_widget_set_factor (GtkWidget *widget, gdouble factor, + gdouble step_increment, + gdouble page_increment, gint digits); diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c index 92751c97e5..1a19c699c1 100644 --- a/libgimpwidgets/gimppropwidgets.c +++ b/libgimpwidgets/gimppropwidgets.c @@ -1237,6 +1237,8 @@ static void gimp_prop_widget_set_factor (GtkWidget *widget, GtkAdjustment *adjustment, gdouble factor, + gdouble step_increment, + gdouble page_increment, gint digits) { gdouble *factor_store; @@ -1271,12 +1273,18 @@ gimp_prop_widget_set_factor (GtkWidget *widget, f = factor / old_factor; + if (step_increment <= 0) + step_increment = f * gtk_adjustment_get_step_increment (adjustment); + + if (page_increment <= 0) + page_increment = f * gtk_adjustment_get_page_increment (adjustment); + gtk_adjustment_configure (adjustment, f * gtk_adjustment_get_value (adjustment), f * gtk_adjustment_get_lower (adjustment), f * gtk_adjustment_get_upper (adjustment), - f * gtk_adjustment_get_step_increment (adjustment), - f * gtk_adjustment_get_page_increment (adjustment), + step_increment, + page_increment, f * gtk_adjustment_get_page_size (adjustment)); gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), digits); @@ -1323,7 +1331,7 @@ gimp_prop_opacity_entry_new (GObject *config, { gimp_prop_widget_set_factor (GIMP_SCALE_ENTRY_SPINBUTTON (adjustment), GTK_ADJUSTMENT (adjustment), - 100.0, 1); + 100.0, 0.0, 0.0, 1); } return adjustment;