[gimp] app: configure GimpBrightnessContrastTool's scales according to image precision



commit efbe095b66e63de5000471895604be87accb8a7f
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jun 14 08:17:39 2013 +0200

    app: configure GimpBrightnessContrastTool's scales according to image precision

 app/tools/gimpbrightnesscontrasttool.c |   54 ++++++++++++++++++++++++++++++--
 app/tools/gimpbrightnesscontrasttool.h |    4 ++
 2 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/app/tools/gimpbrightnesscontrasttool.c b/app/tools/gimpbrightnesscontrasttool.c
index 826fe91..3ab9e06 100644
--- a/app/tools/gimpbrightnesscontrasttool.c
+++ b/app/tools/gimpbrightnesscontrasttool.c
@@ -50,6 +50,9 @@
 #define SLIDER_WIDTH 200
 
 
+static gboolean   gimp_brightness_contrast_tool_initialize (GimpTool              *tool,
+                                                            GimpDisplay           *display,
+                                                            GError               **error);
 static void   gimp_brightness_contrast_tool_button_press   (GimpTool              *tool,
                                                             const GimpCoords      *coords,
                                                             guint32                time,
@@ -106,6 +109,7 @@ gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *klass
   GimpToolClass         *tool_class    = GIMP_TOOL_CLASS (klass);
   GimpImageMapToolClass *im_tool_class = GIMP_IMAGE_MAP_TOOL_CLASS (klass);
 
+  tool_class->initialize             = gimp_brightness_contrast_tool_initialize;
   tool_class->button_press           = gimp_brightness_contrast_tool_button_press;
   tool_class->button_release         = gimp_brightness_contrast_tool_button_release;
   tool_class->motion                 = gimp_brightness_contrast_tool_motion;
@@ -124,6 +128,45 @@ gimp_brightness_contrast_tool_init (GimpBrightnessContrastTool *bc_tool)
 {
 }
 
+static gboolean
+gimp_brightness_contrast_tool_initialize (GimpTool     *tool,
+                                          GimpDisplay  *display,
+                                          GError      **error)
+{
+  GimpBrightnessContrastTool *bc_tool  = GIMP_BRIGHTNESS_CONTRAST_TOOL (tool);
+  GimpImage                  *image    = gimp_display_get_image (display);
+  GimpDrawable               *drawable = gimp_image_get_active_drawable (image);
+  GtkWidget                  *scale;
+
+  if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
+    {
+      return FALSE;
+    }
+
+  if (gimp_drawable_get_precision (drawable) == GIMP_PRECISION_U8)
+    {
+      scale = bc_tool->brightness_scale;
+      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (scale), 0);
+      gimp_spin_scale_set_factor (GIMP_SPIN_SCALE (scale), 127.0);
+
+      scale = bc_tool->contrast_scale;
+      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (scale), 0);
+      gimp_spin_scale_set_factor (GIMP_SPIN_SCALE (scale), 127.0);
+    }
+  else
+    {
+      scale = bc_tool->brightness_scale;
+      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (scale), 3);
+      gimp_spin_scale_set_factor (GIMP_SPIN_SCALE (scale), 0.5);
+
+      scale = bc_tool->contrast_scale;
+      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (scale), 3);
+      gimp_spin_scale_set_factor (GIMP_SPIN_SCALE (scale), 0.5);
+    }
+
+  return TRUE;
+}
+
 static GeglNode *
 gimp_brightness_contrast_tool_get_operation (GimpImageMapTool  *im_tool,
                                              GObject          **config,
@@ -208,9 +251,10 @@ gimp_brightness_contrast_tool_motion (GimpTool         *tool,
 static void
 gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool)
 {
-  GtkWidget *main_vbox;
-  GtkWidget *scale;
-  GtkWidget *button;
+  GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (image_map_tool);
+  GtkWidget                  *main_vbox;
+  GtkWidget                  *scale;
+  GtkWidget                  *button;
 
   main_vbox = gimp_image_map_tool_dialog_get_vbox (image_map_tool);
 
@@ -222,6 +266,8 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool)
   gtk_box_pack_start (GTK_BOX (main_vbox), scale, FALSE, FALSE, 0);
   gtk_widget_show (scale);
 
+  bc_tool->brightness_scale = scale;
+
   /*  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,
@@ -230,6 +276,8 @@ gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool)
   gtk_box_pack_start (GTK_BOX (main_vbox), scale, FALSE, FALSE, 0);
   gtk_widget_show (scale);
 
+  bc_tool->contrast_scale = scale;
+
   button = gimp_stock_button_new (GIMP_STOCK_TOOL_LEVELS,
                                   _("Edit these Settings as Levels"));
   gtk_box_pack_start (GTK_BOX (main_vbox), button, FALSE, FALSE, 0);
diff --git a/app/tools/gimpbrightnesscontrasttool.h b/app/tools/gimpbrightnesscontrasttool.h
index 0685161..9a02737 100644
--- a/app/tools/gimpbrightnesscontrasttool.h
+++ b/app/tools/gimpbrightnesscontrasttool.h
@@ -41,6 +41,10 @@ struct _GimpBrightnessContrastTool
 
   gdouble                       x, y;
   gdouble                       dx, dy;
+
+  /* dialog */
+  GtkWidget                    *brightness_scale;
+  GtkWidget                    *contrast_scale;
 };
 
 struct _GimpBrightnessContrastToolClass


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