[gimp] app: add explicit paint options sliders for hardness and force



commit 4421070a6ac11285b512756c1f484ee0e0f01007
Author: Alexia Death <alexiadeath gmail com>
Date:   Mon Nov 17 13:07:55 2014 +0200

    app: add explicit paint options sliders for hardness and force

 app/paint/gimpbrushcore.c        |   12 ++++---
 app/paint/gimppaintbrush.c       |   11 +++---
 app/paint/gimppaintoptions.c     |   72 ++++++++++++++++++++++++++++++++++++-
 app/paint/gimppaintoptions.h     |    6 +++
 app/tools/gimppaintoptions-gui.c |   42 ++++++++++++++++++++++
 5 files changed, 131 insertions(+), 12 deletions(-)
---
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index eeccb4d..b52879f 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -1523,6 +1523,8 @@ gimp_brush_core_eval_transform_dynamics (GimpBrushCore     *core,
   core->angle        = paint_options->brush_angle;
   core->aspect_ratio = paint_options->brush_aspect_ratio;
 
+  core->hardness     = paint_options->brush_hardness;
+
   if (! GIMP_IS_DYNAMICS (core->dynamics))
     return;
 
@@ -1553,11 +1555,11 @@ gimp_brush_core_eval_transform_dynamics (GimpBrushCore     *core,
                                                       paint_options,
                                                       fade_point);
 
-      core->hardness = gimp_dynamics_get_linear_value (core->dynamics,
-                                                       GIMP_DYNAMICS_OUTPUT_HARDNESS,
-                                                       coords,
-                                                       paint_options,
-                                                       fade_point);
+      core->hardness *= gimp_dynamics_get_linear_value (core->dynamics,
+                                                        GIMP_DYNAMICS_OUTPUT_HARDNESS,
+                                                        coords,
+                                                        paint_options,
+                                                        fade_point);
 
       output = gimp_dynamics_get_output (core->dynamics,
                                          GIMP_DYNAMICS_OUTPUT_ASPECT_RATIO);
diff --git a/app/paint/gimppaintbrush.c b/app/paint/gimppaintbrush.c
index b860106..70063b1 100644
--- a/app/paint/gimppaintbrush.c
+++ b/app/paint/gimppaintbrush.c
@@ -197,11 +197,12 @@ _gimp_paintbrush_motion (GimpPaintCore    *paint_core,
       g_object_unref (color);
     }
 
-  force = gimp_dynamics_get_linear_value (dynamics,
-                                          GIMP_DYNAMICS_OUTPUT_FORCE,
-                                          coords,
-                                          paint_options,
-                                          fade_point);
+  force = MAX (paint_options->brush_force,
+               gimp_dynamics_get_linear_value (dynamics,
+                                               GIMP_DYNAMICS_OUTPUT_FORCE,
+                                               coords,
+                                               paint_options,
+                                               fade_point));
 
   /* finally, let the brush core paste the colored area on the canvas */
   gimp_brush_core_paste_canvas (brush_core, drawable,
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index d2ec5bb..91a3ed8 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -28,6 +28,7 @@
 
 #include "core/gimp.h"
 #include "core/gimpbrush.h"
+#include "core/gimpbrushgenerated.h"
 #include "core/gimpimage.h"
 #include "core/gimpdynamics.h"
 #include "core/gimpdynamicsoutput.h"
@@ -46,6 +47,9 @@
 #define DEFAULT_BRUSH_ANGLE            0.0
 #define DEFAULT_BRUSH_SPACING          10.0
 
+#define DEFAULT_BRUSH_HARDNESS         1.0 /*Generated brushes have their own*/
+#define DEFAULT_BRUSH_FORCE            0.0
+
 #define DEFAULT_APPLICATION_MODE       GIMP_PAINT_CONSTANT
 #define DEFAULT_HARD                   FALSE
 
@@ -84,6 +88,8 @@ enum
   PROP_BRUSH_ASPECT_RATIO,
   PROP_BRUSH_ANGLE,
   PROP_BRUSH_SPACING,
+  PROP_BRUSH_HARDNESS,
+  PROP_BRUSH_FORCE,
 
   PROP_APPLICATION_MODE,
   PROP_HARD,
@@ -183,6 +189,16 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
                                    1.0, 5000.0, DEFAULT_BRUSH_SPACING,
                                    GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_HARDNESS,
+                                   "brush-hardness", _("Brush Hardness"),
+                                   0.0, 1.0, DEFAULT_BRUSH_HARDNESS,
+                                   GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_FORCE,
+                                   "brush-force", _("Brush Force"),
+                                   0.0, 1.0, DEFAULT_BRUSH_FORCE,
+                                   GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_APPLICATION_MODE,
                                  "application-mode", _("Every stamp has its own opacity"),
                                  GIMP_TYPE_PAINT_APPLICATION_MODE,
@@ -377,6 +393,14 @@ gimp_paint_options_set_property (GObject      *object,
       options->brush_spacing = g_value_get_double (value);
       break;
 
+    case PROP_BRUSH_HARDNESS:
+      options->brush_hardness = g_value_get_double (value);
+      break;
+
+    case PROP_BRUSH_FORCE:
+      options->brush_force = g_value_get_double (value);
+      break;
+
     case PROP_APPLICATION_MODE:
       options->application_mode = g_value_get_enum (value);
       break;
@@ -509,6 +533,14 @@ gimp_paint_options_get_property (GObject    *object,
       g_value_set_double (value, options->brush_spacing);
       break;
 
+    case PROP_BRUSH_HARDNESS:
+      g_value_set_double (value, options->brush_hardness);
+      break;
+
+    case PROP_BRUSH_FORCE:
+      g_value_set_double (value, options->brush_force);
+      break;
+
     case PROP_APPLICATION_MODE:
       g_value_set_enum (value, options->application_mode);
       break;
@@ -746,6 +778,7 @@ gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options)
 {
   GimpDynamics       *dynamics;
   GimpDynamicsOutput *force_output;
+  gboolean            dynamic_force;
 
   g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), GIMP_BRUSH_SOFT);
 
@@ -758,9 +791,11 @@ gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options)
                                            GIMP_DYNAMICS_OUTPUT_FORCE);
 
   if (!force_output)
-    return GIMP_BRUSH_SOFT;
+    dynamic_force = FALSE;
+  else
+    dynamic_force = gimp_dynamics_output_is_enabled (force_output);
 
-  if (gimp_dynamics_output_is_enabled (force_output))
+  if (dynamic_force || (paint_options->brush_force > 0.0))
     return GIMP_BRUSH_PRESSURE;
 
   return GIMP_BRUSH_SOFT;
@@ -808,6 +843,33 @@ gimp_paint_options_set_default_brush_spacing (GimpPaintOptions *paint_options,
 }
 
 void
+gimp_paint_options_set_default_brush_hardness (GimpPaintOptions *paint_options,
+                                               GimpBrush        *brush)
+{
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
+  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));
+
+  if (! brush)
+    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
+
+  if (GIMP_IS_BRUSH_GENERATED(brush))
+    {
+      GimpBrushGenerated *generated_brush = GIMP_BRUSH_GENERATED(brush);
+
+      g_object_set (paint_options,
+                    "brush-hardness", (gdouble) gimp_brush_generated_get_hardness (generated_brush),
+                    NULL);
+    }
+  else
+    {
+      g_object_set (paint_options,
+                    "brush-hardness", DEFAULT_BRUSH_HARDNESS,
+                    NULL);
+    }
+}
+
+
+void
 gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
                                      GimpPaintOptions *dest)
 {
@@ -815,6 +877,8 @@ gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
   gdouble  brush_angle;
   gdouble  brush_aspect_ratio;
   gdouble  brush_spacing;
+  gdouble  brush_hardness;
+  gdouble  brush_force;
   gboolean brush_zoom;
 
   g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
@@ -826,6 +890,8 @@ gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
                 "brush-angle", &brush_angle,
                 "brush-aspect-ratio", &brush_aspect_ratio,
                 "brush-spacing", &brush_spacing,
+                "brush-hardness", &brush_hardness,
+                "brush-force", &brush_force,
                 NULL);
 
   g_object_set (dest,
@@ -834,6 +900,8 @@ gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
                 "brush-angle", brush_angle,
                 "brush-aspect-ratio", brush_aspect_ratio,
                 "brush-spacing", brush_spacing,
+                "brush-hardness", brush_hardness,
+                "brush-force", brush_force,
                 NULL);
 }
 
diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h
index dbc4e97..f0ecd63 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -87,6 +87,8 @@ struct _GimpPaintOptions
   gdouble                   brush_angle;
   gdouble                   brush_aspect_ratio;
   gdouble                   brush_spacing;
+  gdouble                   brush_hardness;
+  gdouble                   brush_force;
 
   GimpPaintApplicationMode  application_mode;
   GimpPaintApplicationMode  application_mode_save;
@@ -144,6 +146,10 @@ void    gimp_paint_options_set_default_brush_spacing
                                                (GimpPaintOptions *paint_options,
                                                 GimpBrush        *brush);
 
+void    gimp_paint_options_set_default_brush_hardness
+                                               (GimpPaintOptions *paint_options,
+                                                GimpBrush        *brush);
+
 void    gimp_paint_options_copy_brush_props    (GimpPaintOptions *src,
                                                 GimpPaintOptions *dest);
 void    gimp_paint_options_copy_dynamics_props (GimpPaintOptions *src,
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 5d2c77c..0717b20 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -60,6 +60,11 @@ static void gimp_paint_options_gui_reset_angle (GtkWidget        *button,
 static void gimp_paint_options_gui_reset_spacing
                                                (GtkWidget        *button,
                                                 GimpPaintOptions *paint_options);
+static void gimp_paint_options_gui_reset_hardness
+                                               (GtkWidget        *button,
+                                                GimpPaintOptions *paint_options);
+static void gimp_paint_options_gui_reset_force (GtkWidget        *button,
+                                                GimpPaintOptions *paint_options);
 
 static GtkWidget * dynamics_options_gui        (GimpPaintOptions *paint_options,
                                                 GType             tool_type);
@@ -176,6 +181,24 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
       gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
       gtk_widget_show (hbox);
 
+/*Brush hardness spinner*/
+      hbox = gimp_paint_options_gui_scale_with_reset_button
+                                (config, "brush-hardness", _("Hardness"),
+                                 _("Reset hardness to default"),
+                                 0.01, 0.1, 0.0, 1.0, 1.0,
+                                 G_CALLBACK (gimp_paint_options_gui_reset_hardness));
+      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+      gtk_widget_show (hbox);
+
+/*Brush hardness spinner*/
+      hbox = gimp_paint_options_gui_scale_with_reset_button
+                                (config, "brush-force", _("Force"),
+                                 _("Reset force to default"),
+                                 0.01, 0.1, 0.0, 1.0, 1.0,
+                                 G_CALLBACK (gimp_paint_options_gui_reset_force));
+      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+      gtk_widget_show (hbox);
+
       button = gimp_prop_dynamics_box_new (NULL, GIMP_CONTEXT (tool_options),
                                            _("Dynamics"), 2,
                                            "dynamics-view-type",
@@ -423,6 +446,25 @@ gimp_paint_options_gui_reset_spacing (GtkWidget        *button,
     gimp_paint_options_set_default_brush_spacing (paint_options, brush);
 }
 
+static void
+gimp_paint_options_gui_reset_hardness (GtkWidget        *button,
+                                       GimpPaintOptions *paint_options)
+{
+  GimpBrush *brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
+
+  if (brush)
+    gimp_paint_options_set_default_brush_hardness (paint_options, brush);
+}
+
+static void
+gimp_paint_options_gui_reset_force (GtkWidget        *button,
+                                    GimpPaintOptions *paint_options)
+{
+  g_object_set (paint_options,
+                "brush-force", 0.0,
+                NULL);
+}
+
 static GtkWidget *
 gimp_paint_options_gui_scale_with_reset_button (GObject   *config,
                                                 gchar     *prop_name,


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