[gimp] app: Making spacing available as dynamic parameter



commit 60705f79e93e5d74f0fc52b1f4e030a07446ab3f
Author: Alexia Death <alexiadeath gmail com>
Date:   Sat Dec 12 23:14:14 2009 +0200

    app: Making spacing available as dynamic parameter
    
    Spacing is now dynamically controllable. Unlike other parameters it
    made little sense to scale down from default spacing so it scales between
    current and maximum spacing.

 app/core/gimpdynamics.c          |   20 +++++++++++-
 app/core/gimpdynamics.h          |    1 +
 app/paint/gimpbrushcore.c        |   62 +++++++++++++++++++++++--------------
 app/widgets/gimpdynamicseditor.c |    6 +++-
 4 files changed, 63 insertions(+), 26 deletions(-)
---
diff --git a/app/core/gimpdynamics.c b/app/core/gimpdynamics.c
index 9dabdb5..204d19d 100644
--- a/app/core/gimpdynamics.c
+++ b/app/core/gimpdynamics.c
@@ -48,7 +48,8 @@ enum
   PROP_ASPECT_RATIO_OUTPUT,
   PROP_COLOR_OUTPUT,
   PROP_ANGLE_OUTPUT,
-  PROP_JITTER_OUTPUT
+  PROP_JITTER_OUTPUT,
+  PROP_SPACING_OUTPUT
 };
 
 
@@ -140,6 +141,11 @@ gimp_dynamics_class_init (GimpDynamicsClass *klass)
                                    "jitter-output", NULL,
                                    GIMP_TYPE_DYNAMICS_OUTPUT,
                                    GIMP_CONFIG_PARAM_AGGREGATE);
+
+  GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_SPACING_OUTPUT,
+                                   "spacing-output", NULL,
+                                   GIMP_TYPE_DYNAMICS_OUTPUT,
+                                   GIMP_CONFIG_PARAM_AGGREGATE);
 }
 
 static void
@@ -161,6 +167,8 @@ gimp_dynamics_init (GimpDynamics *dynamics)
                                                                "angle-output");
   dynamics->jitter_output       = gimp_dynamics_create_output (dynamics,
                                                                "jitter-output");
+  dynamics->spacing_output      = gimp_dynamics_create_output (dynamics,
+                                                               "spacing-output");
 }
 
 static void
@@ -176,6 +184,7 @@ gimp_dynamics_finalize (GObject *object)
   g_object_unref (dynamics->color_output);
   g_object_unref (dynamics->angle_output);
   g_object_unref (dynamics->jitter_output);
+  g_object_unref (dynamics->spacing_output);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -236,6 +245,11 @@ gimp_dynamics_set_property (GObject      *object,
       dest_output = dynamics->jitter_output;
       break;
 
+    case PROP_SPACING_OUTPUT:
+      src_output  = g_value_get_object (value);
+      dest_output = dynamics->spacing_output;
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -295,6 +309,10 @@ gimp_dynamics_get_property (GObject    *object,
       g_value_set_object (value, dynamics->jitter_output);
       break;
 
+    case PROP_SPACING_OUTPUT:
+      g_value_set_object (value, dynamics->spacing_output);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
diff --git a/app/core/gimpdynamics.h b/app/core/gimpdynamics.h
index c865d52..695244a 100644
--- a/app/core/gimpdynamics.h
+++ b/app/core/gimpdynamics.h
@@ -44,6 +44,7 @@ struct _GimpDynamics
   GimpDynamicsOutput *color_output;
   GimpDynamicsOutput *angle_output;
   GimpDynamicsOutput *jitter_output;
+  GimpDynamicsOutput *spacing_output;
 };
 
 struct _GimpDynamicsClass
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index d415c2d..cecdc9d 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -501,12 +501,34 @@ gimp_brush_core_interpolate (GimpPaintCore    *paint_core,
   gdouble        pixel_initial;
   gdouble        xd, yd;
   gdouble        mag;
+  gdouble        dyn_spacing;
+  gdouble        fade_point;
+  gboolean       use_dyn_spacing;
 
   g_return_if_fail (GIMP_IS_BRUSH (core->brush));
 
   gimp_paint_core_get_last_coords (paint_core, &last_coords);
   gimp_paint_core_get_current_coords (paint_core, &current_coords);
 
+  fade_point = gimp_paint_options_get_fade (paint_options, image,
+                                            paint_core->pixel_dist);
+
+  use_dyn_spacing = gimp_dynamics_output_is_enabled (core->dynamics->spacing_output);
+
+  if (use_dyn_spacing)
+    {
+      dyn_spacing = gimp_dynamics_output_get_linear_value (core->dynamics->spacing_output,
+                                                           &current_coords,
+                                                           fade_point);
+      /* Dynamic spacing assumes that the value set in core is the min value
+       * and the max is full 200% spacing. This approach differs ofrom the usual
+       * factor from user input approach because making spacing smaller than
+       * the nominal value is unlikely and spacing has a hard defined max.
+       */
+      dyn_spacing = core->spacing + ((2.0 - core->spacing) * ( 1.0 - dyn_spacing));
+
+      dyn_spacing = MAX (core->spacing, dyn_spacing); /*Limiting spacing to minimum 1%*/
+    }
   gimp_avoid_exact_integer (&last_coords.x);
   gimp_avoid_exact_integer (&last_coords.y);
   gimp_avoid_exact_integer (&current_coords.x);
@@ -551,25 +573,6 @@ gimp_brush_core_interpolate (GimpPaintCore    *paint_core,
   pixel_dist    = gimp_vector2_length (&delta_vec);
   pixel_initial = paint_core->pixel_dist;
 
-  /*  FIXME: need to adapt the spacing to the size                      */
-  /*   lastscale = MIN (last_coords.pressure, 1/256);                   */
-  /*   curscale = MIN (current_coords.pressure,  1/256);                */
-  /*   spacing = core->spacing * sqrt (0.5 * (lastscale + curscale));   */
-
-  /*  Compute spacing parameters such that a brush position will be
-   *  made each time the line crosses the *center* of a pixel row or
-   *  column, according to whether the line is mostly horizontal or
-   *  mostly vertical. The term "stripe" will mean "column" if the
-   *  line is horizontalish; "row" if the line is verticalish.
-   *
-   *  We start by deriving coefficients for a new parameter 's':
-   *      s = t * st_factor + st_offset
-   *  such that the "nice" brush positions are the ones with *integer*
-   *  s values. (Actually the value of s will be 1/2 less than the nice
-   *  brush position's x or y coordinate - note that st_factor may
-   *  be negative!)
-   */
-
   if (delta_vec.x * delta_vec.x > delta_vec.y * delta_vec.y)
     {
       st_factor = delta_vec.x;
@@ -581,7 +584,22 @@ gimp_brush_core_interpolate (GimpPaintCore    *paint_core,
       st_offset = last_coords.y - 0.5;
     }
 
-  if (fabs (st_factor) > dist / core->spacing)
+  if (use_dyn_spacing)
+    {
+      gint s0;
+
+      num_points = dist / dyn_spacing;
+
+      s0 = (gint) floor (st_offset + 0.5);
+
+      t0 = (s0 - st_offset) / st_factor;
+
+      dt = dyn_spacing / dist;
+
+      if (num_points == 0)
+        return;
+    }
+  else if (fabs (st_factor) > dist / core->spacing)
     {
       /*  The stripe principle leads to brush positions that are spaced
        *  *closer* than the official brush spacing. Use the official
@@ -723,14 +741,10 @@ gimp_brush_core_interpolate (GimpPaintCore    *paint_core,
 
       if (core->jitter > 0.0)
         {
-          gdouble fade_point;
           gdouble dyn_jitter;
           gdouble jitter_dist;
           gint32  jitter_angle;
 
-          fade_point = gimp_paint_options_get_fade (paint_options, image,
-                                                    paint_core->pixel_dist);
-
           dyn_jitter = core->jitter * gimp_dynamics_output_get_linear_value (core->dynamics->jitter_output,
                                                                              &current_coords,
                                                                              fade_point);
diff --git a/app/widgets/gimpdynamicseditor.c b/app/widgets/gimpdynamicseditor.c
index 782b808..3c2730d 100644
--- a/app/widgets/gimpdynamicseditor.c
+++ b/app/widgets/gimpdynamicseditor.c
@@ -106,7 +106,7 @@ gimp_dynamics_editor_init (GimpDynamicsEditor *editor)
                     G_CALLBACK (gimp_dynamics_editor_notify_model),
                     editor);
 
-  editor->table = gtk_table_new (9, n_inputs + 2, FALSE);
+  editor->table = gtk_table_new (10, n_inputs + 2, FALSE);
   gtk_box_pack_start (GTK_BOX (data_editor), editor->table, TRUE, TRUE, 0);
   gtk_widget_show (editor->table);
 
@@ -157,6 +157,10 @@ gimp_dynamics_editor_init (GimpDynamicsEditor *editor)
                                        GTK_TABLE (editor->table),
                                        8, NULL);
 
+  gimp_dynamics_editor_add_output_row (G_OBJECT (dynamics->spacing_output),
+                                       _("Spacing"),
+                                       GTK_TABLE (editor->table),
+                                       9, NULL);
   fixed = gtk_fixed_new ();
   gtk_table_attach (GTK_TABLE (editor->table), fixed, 0, n_inputs + 2, 0, 1,
                     GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);



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