[gimp] app: Expose brush size in pixels, not as ratio



commit 5d42803d7fff78cf4ef07dd2ea86f03d46dfa451
Author: Alexia Death <alexiadeath gmail com>
Date:   Fri Oct 29 22:57:26 2010 +0300

    app: Expose brush size in pixels, not as ratio

 app/actions/tools-actions.c      |   48 +++++++++++++++++-----------------
 app/actions/tools-commands.c     |   10 +++---
 app/actions/tools-commands.h     |    2 +-
 app/paint/gimpbrushcore.c        |   14 ++++++++--
 app/paint/gimppaintoptions.c     |   18 ++++++------
 app/paint/gimppaintoptions.h     |    2 +-
 app/tools/gimppaintoptions-gui.c |   52 +++++++++++++++++++++++++++++++------
 7 files changed, 94 insertions(+), 52 deletions(-)
---
diff --git a/app/actions/tools-actions.c b/app/actions/tools-actions.c
index 544353f..ed5c3e0 100644
--- a/app/actions/tools-actions.c
+++ b/app/actions/tools-actions.c
@@ -102,38 +102,38 @@ static const GimpEnumActionEntry tools_color_average_radius_actions[] =
     NULL },
 };
 
-static const GimpEnumActionEntry tools_paint_brush_scale_actions[] =
+static const GimpEnumActionEntry tools_paint_brush_size_actions[] =
 {
-  { "tools-paint-brush-scale-set", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Set Brush Scale", NULL, NULL,
+  { "tools-paint-brush-size-set", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Set Brush Size", NULL, NULL,
     GIMP_ACTION_SELECT_SET, TRUE,
     NULL },
-  { "tools-paint-brush-scale-set-to-default", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Set Brush Scale To Default Value", NULL, NULL,
+  { "tools-paint-brush-size-set-to-default", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Set Brush Size To Default Value", NULL, NULL,
     GIMP_ACTION_SELECT_SET_TO_DEFAULT, FALSE,
     NULL },
-  { "tools-paint-brush-scale-minimum", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Minimize Brush Scale", NULL, NULL,
+  { "tools-paint-brush-size-minimum", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Minimize Brush Size", NULL, NULL,
     GIMP_ACTION_SELECT_FIRST, FALSE,
     NULL },
-  { "tools-paint-brush-scale-maximum", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Maximize Brush Scale", NULL, NULL,
+  { "tools-paint-brush-size-maximum", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Maximize Brush Size", NULL, NULL,
     GIMP_ACTION_SELECT_LAST, FALSE,
     NULL },
-  { "tools-paint-brush-scale-decrease", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Decrease Brush Scale", NULL, NULL,
+  { "tools-paint-brush-size-decrease", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Decrease Brush Size", NULL, NULL,
     GIMP_ACTION_SELECT_PREVIOUS, FALSE,
     NULL },
-  { "tools-paint-brush-scale-increase", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Increase Brush Scale", NULL, NULL,
+  { "tools-paint-brush-size-increase", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Increase Brush Size", NULL, NULL,
     GIMP_ACTION_SELECT_NEXT, FALSE,
     NULL },
-  { "tools-paint-brush-scale-decrease-skip", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Decrease Brush Scale More", NULL, NULL,
+  { "tools-paint-brush-size-decrease-skip", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Decrease Brush Size More", NULL, NULL,
     GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
     NULL },
-  { "tools-paint-brush-scale-increase-skip", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Increase Brush Scale More", NULL, NULL,
+  { "tools-paint-brush-size-increase-skip", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Increase Brush Size More", NULL, NULL,
     GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
     NULL },
 };
@@ -172,12 +172,12 @@ static const GimpEnumActionEntry tools_paint_brush_angle_actions[] =
     "Increase Brush Angle More", NULL, NULL,
     GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
     NULL },
-  { "tools-paint-brush-scale-decrease-percent", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Decrease Brush Scale Relative", NULL, NULL,
+  { "tools-paint-brush-size-decrease-percent", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Decrease Brush Size Relative", NULL, NULL,
     GIMP_ACTION_SELECT_PERCENT_PREVIOUS, FALSE,
     NULL },
-  { "tools-paint-brush-scale-increase-percent", GIMP_STOCK_TOOL_PAINTBRUSH,
-    "Increase Brush Scale Relative", NULL, NULL,
+  { "tools-paint-brush-size-increase-percent", GIMP_STOCK_TOOL_PAINTBRUSH,
+    "Increase Brush Size Relative", NULL, NULL,
     GIMP_ACTION_SELECT_PERCENT_NEXT, FALSE,
     NULL },
 
@@ -669,9 +669,9 @@ tools_actions_setup (GimpActionGroup *group)
                                       G_CALLBACK (tools_color_average_radius_cmd_callback));
 
   gimp_action_group_add_enum_actions (group, NULL,
-                                      tools_paint_brush_scale_actions,
-                                      G_N_ELEMENTS (tools_paint_brush_scale_actions),
-                                      G_CALLBACK (tools_paint_brush_scale_cmd_callback));
+                                      tools_paint_brush_size_actions,
+                                      G_N_ELEMENTS (tools_paint_brush_size_actions),
+                                      G_CALLBACK (tools_paint_brush_size_cmd_callback));
 
   gimp_action_group_add_enum_actions (group, NULL,
                                       tools_paint_brush_angle_actions,
diff --git a/app/actions/tools-commands.c b/app/actions/tools-commands.c
index 453dbfb..d2e75ea 100644
--- a/app/actions/tools-commands.c
+++ b/app/actions/tools-commands.c
@@ -124,9 +124,9 @@ tools_color_average_radius_cmd_callback (GtkAction *action,
 }
 
 void
-tools_paint_brush_scale_cmd_callback (GtkAction *action,
-                                      gint       value,
-                                      gpointer   data)
+tools_paint_brush_size_cmd_callback (GtkAction *action,
+                                     gint       value,
+                                     gpointer   data)
 {
   GimpContext  *context;
   GimpToolInfo *tool_info;
@@ -139,8 +139,8 @@ tools_paint_brush_scale_cmd_callback (GtkAction *action,
       action_select_property ((GimpActionSelectType) value,
                               action_data_get_display (data),
                               G_OBJECT (tool_info->tool_options),
-                              "brush-scale",
-                              0.01, 0.1, 1.0, 0.1, FALSE);
+                              "brush-size",
+                              1.0, 10.0, 10.0, 1.0, FALSE);
     }
 }
 
diff --git a/app/actions/tools-commands.h b/app/actions/tools-commands.h
index c320b28..3e19b51 100644
--- a/app/actions/tools-commands.h
+++ b/app/actions/tools-commands.h
@@ -27,7 +27,7 @@ void   tools_color_average_radius_cmd_callback      (GtkAction   *action,
                                                      gint         value,
                                                      gpointer     data);
 
-void   tools_paint_brush_scale_cmd_callback         (GtkAction   *action,
+void   tools_paint_brush_size_cmd_callback          (GtkAction   *action,
                                                      gint         value,
                                                      gpointer     data);
 
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index dac01d8..0463d0f 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -366,7 +366,8 @@ gimp_brush_core_pre_paint (GimpPaintCore    *paint_core,
               fade_point = gimp_paint_options_get_fade (paint_options, image,
                                                         paint_core->pixel_dist);
 
-              scale = paint_options->brush_scale *
+              scale = paint_options->brush_size /
+                      MAX (core->main_brush->mask->width, core->main_brush->mask->height) *
                       gimp_dynamics_output_get_linear_value (core->dynamics->size_output,
                                                              &current_coords,
                                                              paint_options,
@@ -946,7 +947,8 @@ gimp_brush_core_create_boundary (GimpBrushCore    *core,
   g_return_if_fail (core->main_brush != NULL);
   g_return_if_fail (core->brush_bound_segs == NULL);
 
-  scale = paint_options->brush_scale;
+  scale = paint_options->brush_size /
+          MAX (core->main_brush->mask->width, core->main_brush->mask->height);
 
   if (scale > 0.0)
     {
@@ -1697,7 +1699,13 @@ gimp_brush_core_eval_transform_dynamics (GimpPaintCore     *paint_core,
   GimpImage *image;
   gdouble    fade_point = 1.0;
 
-  core->scale = paint_options->brush_scale;
+  if (core->main_brush)
+   {
+    core->scale = paint_options->brush_size /
+                  MAX (core->main_brush->mask->width, core->main_brush->mask->height);
+   }
+  else
+   core->scale = -1;
   core->angle = paint_options->brush_angle;
   core->aspect_ratio = paint_options->brush_aspect_ratio;
 
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index 1bb3b5a..78d9f78 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -37,7 +37,7 @@
 #include "gimp-intl.h"
 
 
-#define DEFAULT_BRUSH_SCALE            1.0
+#define DEFAULT_BRUSH_SIZE             20.0
 #define DEFAULT_BRUSH_ASPECT_RATIO     1.0
 #define DEFAULT_BRUSH_ANGLE            0.0
 
@@ -68,7 +68,7 @@ enum
 
   PROP_PAINT_INFO,
 
-  PROP_BRUSH_SCALE,
+  PROP_BRUSH_SIZE,
   PROP_BRUSH_ASPECT_RATIO,
   PROP_BRUSH_ANGLE,
 
@@ -136,9 +136,9 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
                                                         GIMP_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT_ONLY));
 
-  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_SCALE,
-                                   "brush-scale", _("Brush Scale"),
-                                   0.01, 10.0, DEFAULT_BRUSH_SCALE,
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_SIZE,
+                                   "brush-size", _("Brush Size"),
+                                   1.0, 10000.0, DEFAULT_BRUSH_SIZE,
                                    GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ASPECT_RATIO,
@@ -301,8 +301,8 @@ gimp_paint_options_set_property (GObject      *object,
       options->paint_info = g_value_dup_object (value);
       break;
 
-    case PROP_BRUSH_SCALE:
-      options->brush_scale = g_value_get_double (value);
+    case PROP_BRUSH_SIZE:
+      options->brush_size = g_value_get_double (value);
       break;
 
     case PROP_BRUSH_ASPECT_RATIO:
@@ -412,8 +412,8 @@ gimp_paint_options_get_property (GObject    *object,
       g_value_set_object (value, options->paint_info);
       break;
 
-    case PROP_BRUSH_SCALE:
-      g_value_set_double (value, options->brush_scale);
+    case PROP_BRUSH_SIZE:
+      g_value_set_double (value, options->brush_size);
       break;
 
     case PROP_BRUSH_ASPECT_RATIO:
diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h
index ff2ee5b..6f79c49 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -74,7 +74,7 @@ struct _GimpPaintOptions
 
   GimpPaintInfo            *paint_info;
 
-  gdouble                   brush_scale;
+  gdouble                   brush_size;
   gdouble                   brush_angle;
   gdouble                   brush_aspect_ratio;
 
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index c0c6f9b..9ccf71f 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -23,12 +23,16 @@
 
 #include "tools-types.h"
 
+#include "base/temp-buf.h"
+
+#include "core/gimpbrush.h"
 #include "core/gimptoolinfo.h"
 
 #include "paint/gimppaintoptions.h"
 
 #include "widgets/gimppropwidgets.h"
 #include "widgets/gimpviewablebox.h"
+#include "widgets/gimpwidgets-constructors.h"
 #include "widgets/gimpwidgets-utils.h"
 
 #include "gimpairbrushtool.h"
@@ -47,13 +51,18 @@
 #include "gimp-intl.h"
 
 
-static GtkWidget * fade_options_gui      (GimpPaintOptions *paint_options,
-                                          GType             tool_type);
-static GtkWidget * gradient_options_gui  (GimpPaintOptions *paint_options,
-                                          GType             tool_type,
-                                          GtkWidget        *incremental_toggle);
-static GtkWidget * jitter_options_gui    (GimpPaintOptions *paint_options,
-                                          GType             tool_type);
+
+
+static GtkWidget * fade_options_gui           (GimpPaintOptions *paint_options,
+                                               GType             tool_type);
+static GtkWidget * gradient_options_gui       (GimpPaintOptions *paint_options,
+                                               GType             tool_type,
+                                               GtkWidget        *incremental_toggle);
+static GtkWidget * jitter_options_gui         (GimpPaintOptions *paint_options,
+                                               GType             tool_type);
+
+static void gimp_paint_options_gui_reset_size (GtkWidget        *button,
+                                               GimpPaintOptions *paint_options);
 
 
 /*  public functions  */
@@ -124,13 +133,25 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
                                  _("Dynamics:"), 0.0, 0.5,
                                  button, 2, FALSE);
 
-      adj_scale = gimp_prop_scale_entry_new (config, "brush-scale",
+      adj_scale = gimp_prop_scale_entry_new (config, "brush-size",
                                              GTK_TABLE (table), 0, table_row++,
-                                             _("Scale:"),
+                                             _("Size:"),
                                              0.01, 0.1, 2,
                                              FALSE, 0.0, 0.0);
       gimp_scale_entry_set_logarithmic (adj_scale, TRUE);
 
+
+      button = gimp_stock_button_new (GTK_STOCK_REFRESH, _("Reset size"));
+
+      gimp_table_attach_aligned (GTK_TABLE (table), 0, table_row++,
+                                 "", 0.0, 0.5,
+                                 button, 2, FALSE);
+
+      gtk_widget_show (button);
+
+      g_signal_connect(button, "clicked",
+                       G_CALLBACK(gimp_paint_options_gui_reset_size), options);
+
       adj_aspect_ratio = gimp_prop_scale_entry_new (config, "brush-aspect-ratio",
                                                     GTK_TABLE (table), 0, table_row++,
                                                     /* Label for a slider that affects
@@ -318,3 +339,16 @@ gradient_options_gui (GimpPaintOptions *paint_options,
 
   return frame;
 }
+
+static void
+gimp_paint_options_gui_reset_size (GtkWidget        *button,
+                                   GimpPaintOptions *paint_options)
+{
+ GimpContext *context = GIMP_CONTEXT(paint_options);
+ GimpBrush *brush = gimp_context_get_brush (context);
+ if (brush)
+  {
+    paint_options->brush_size = MAX(brush->mask->width, brush->mask->height);
+    g_object_notify(G_OBJECT(paint_options), "brush-size");
+  }
+}



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