Bill Skaggs <weskaggs@primate.ucdavis.edu>

* gimp/app/paint/gimpbrushcore.c
	* gimp/app/paint/gimpbrushcore.h
	* gimp/app/paint/gimpclone.c
	* gimp/app/paint/gimppaintbrush.c
	* gimp/app/paint/gimppaintoptions.c
	* gimp/app/paint/gimppaintoptions.h
	* gimp/app/tools/gimppaintoptions-gui.c: Apply patch from
	Adrian Likins to add "jitter" to paint tools (bug #163049),
	with small fixes for coding style and default jitter set
	to 0.2 instead of 0.0.
This commit is contained in:
William Skaggs 2005-10-03 19:03:14 +00:00
parent e8538fb97b
commit d452942483
9 changed files with 173 additions and 4 deletions

View File

@ -1,3 +1,16 @@
2005-10-03 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* gimp/app/paint/gimpbrushcore.c
* gimp/app/paint/gimpbrushcore.h
* gimp/app/paint/gimpclone.c
* gimp/app/paint/gimppaintbrush.c
* gimp/app/paint/gimppaintoptions.c
* gimp/app/paint/gimppaintoptions.h
* gimp/app/tools/gimppaintoptions-gui.c: Apply patch from
Adrian Likins to add "jitter" to paint tools (bug #163049),
with small fixes for coding style and default jitter set
to 0.2 instead of 0.0.
2005-10-02 DindinX <dindinx@gimp.org>
* libgimp/gimpzoompreview.[ch]: added a new function:

View File

@ -420,6 +420,8 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
gdouble pixel_initial;
gdouble xd, yd;
gdouble mag;
gdouble jitter_x = 0.0;
gdouble jitter_y = 0.0;
gimp_avoid_exact_integer (&paint_core->last_coords.x);
gimp_avoid_exact_integer (&paint_core->last_coords.y);
@ -615,8 +617,16 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
gdouble t = t0 + n * dt;
gdouble p = (gdouble) n / num_points;
paint_core->cur_coords.x = paint_core->last_coords.x + t * delta_vec.x;
paint_core->cur_coords.y = paint_core->last_coords.y + t * delta_vec.y;
if (core->jitter > 0.0)
{
jitter_x = g_random_double_range (-core->jitter, core->jitter);
jitter_y = g_random_double_range (-core->jitter, core->jitter);
}
paint_core->cur_coords.x = paint_core->last_coords.x
+ t * delta_vec.x + (jitter_x * core->brush->x_axis.x);
paint_core->cur_coords.y = paint_core->last_coords.y
+ t * delta_vec.y + (jitter_y * core->brush->y_axis.y);
paint_core->cur_coords.pressure = paint_core->last_coords.pressure + p * delta_pressure;

View File

@ -69,6 +69,8 @@ struct _GimpBrushCore
MaskBuf *last_brush_mask;
gboolean cache_invalid;
gdouble jitter;
/* don't use these... */
BoundSeg *brush_bound_segs;

View File

@ -262,14 +262,20 @@ gimp_clone_motion (GimpPaintCore *paint_core,
gdouble opacity;
gint offset_x;
gint offset_y;
gdouble jitter;
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
opacity = gimp_paint_options_get_fade (paint_options, gimage,
paint_core->pixel_dist);
if (opacity == 0.0)
return;
jitter = gimp_paint_options_get_jitter (paint_options, gimage);
if (jitter > 0.0)
GIMP_BRUSH_CORE (clone)->jitter = jitter;
/* make local copies because we change them */
offset_x = clone->offset_x;
offset_y = clone->offset_y;

View File

@ -144,6 +144,7 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
TempBuf *area;
guchar col[MAX_CHANNELS];
GimpPaintApplicationMode paint_appl_mode;
gdouble jitter;
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
@ -152,6 +153,20 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
if (opacity == 0.0)
return;
jitter = gimp_paint_options_get_jitter (paint_options, gimage);
if (jitter > 0.0)
{
/*
* jitter_x = g_random_double_range(-jitter, jitter);
* jitter_y = g_random_double_range(-jitter, jitter);
*/
GIMP_BRUSH_CORE (brush_core)->jitter = jitter;
#if 0
GIMP_PAINT_CORE (brush_core)->cur_coords.y
= paint_core->last_coords.y + (jitter_y * brush_core->brush->y_axis.y);
#endif
}
paint_appl_mode = paint_options->application_mode;
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);

View File

@ -48,6 +48,9 @@
#define DEFAULT_FADE_LENGTH 100.0
#define DEFAULT_FADE_UNIT GIMP_UNIT_PIXEL
#define DEFAULT_USE_JITTER FALSE
#define DEFAULT_JITTER_AMOUNT 0.2
#define DEFAULT_USE_GRADIENT FALSE
#define DEFAULT_GRADIENT_REVERSE FALSE
#define DEFAULT_GRADIENT_REPEAT GIMP_REPEAT_TRIANGULAR
@ -75,7 +78,9 @@ enum
PROP_GRADIENT_REVERSE,
PROP_GRADIENT_REPEAT,
PROP_GRADIENT_LENGTH,
PROP_GRADIENT_UNIT
PROP_GRADIENT_UNIT,
PROP_USE_JITTER,
PROP_JITTER_AMOUNT
};
@ -197,6 +202,15 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
TRUE, TRUE, DEFAULT_FADE_UNIT,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_JITTER,
"use-jitter", NULL,
DEFAULT_USE_JITTER,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_JITTER_AMOUNT,
"jitter-amount", NULL,
0.0, 50.0, DEFAULT_JITTER_AMOUNT,
0);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_GRADIENT,
"use-gradient", NULL,
DEFAULT_USE_GRADIENT, 0);
@ -226,6 +240,7 @@ gimp_paint_options_init (GimpPaintOptions *options)
options->pressure_options = g_new0 (GimpPressureOptions, 1);
options->fade_options = g_new0 (GimpFadeOptions, 1);
options->gradient_options = g_new0 (GimpGradientOptions, 1);
options->jitter_options = g_new0 (GimpJitterOptions, 1);
}
static void
@ -239,6 +254,7 @@ gimp_paint_options_finalize (GObject *object)
g_free (options->pressure_options);
g_free (options->fade_options);
g_free (options->gradient_options);
g_free (options->jitter_options);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -253,10 +269,12 @@ gimp_paint_options_set_property (GObject *object,
GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options;
GimpJitterOptions *jitter_options;
pressure_options = options->pressure_options;
fade_options = options->fade_options;
gradient_options = options->gradient_options;
jitter_options = options->jitter_options;
switch (property_id)
{
@ -303,6 +321,13 @@ gimp_paint_options_set_property (GObject *object,
fade_options->fade_unit = g_value_get_int (value);
break;
case PROP_USE_JITTER:
jitter_options->use_jitter = g_value_get_boolean (value);
break;
case PROP_JITTER_AMOUNT:
jitter_options->jitter_amount = g_value_get_double (value);
break;
case PROP_USE_GRADIENT:
gradient_options->use_gradient = g_value_get_boolean (value);
break;
@ -335,10 +360,12 @@ gimp_paint_options_get_property (GObject *object,
GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options;
GimpJitterOptions *jitter_options;
pressure_options = options->pressure_options;
fade_options = options->fade_options;
gradient_options = options->gradient_options;
jitter_options = options->jitter_options;
switch (property_id)
{
@ -385,6 +412,13 @@ gimp_paint_options_get_property (GObject *object,
g_value_set_int (value, fade_options->fade_unit);
break;
case PROP_USE_JITTER:
g_value_set_boolean (value, jitter_options->use_jitter);
break;
case PROP_JITTER_AMOUNT:
g_value_set_double (value, jitter_options->jitter_amount);
break;
case PROP_USE_GRADIENT:
g_value_set_boolean (value, gradient_options->use_gradient);
break;
@ -499,6 +533,20 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
return GIMP_OPACITY_OPAQUE;
}
gdouble
gimp_paint_options_get_jitter (GimpPaintOptions *paint_options,
GimpImage *gimage)
{
GimpJitterOptions *jitter_options;
jitter_options = paint_options->jitter_options;
if (jitter_options->use_jitter)
return jitter_options->jitter_amount;
return 0.0;
}
gboolean
gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
GimpImage *gimage,

View File

@ -33,6 +33,7 @@
typedef struct _GimpPressureOptions GimpPressureOptions;
typedef struct _GimpFadeOptions GimpFadeOptions;
typedef struct _GimpGradientOptions GimpGradientOptions;
typedef struct _GimpJitterOptions GimpJitterOptions;
struct _GimpPressureOptions
{
@ -52,6 +53,12 @@ struct _GimpFadeOptions
GimpUnit fade_unit;
};
struct _GimpJitterOptions
{
gboolean use_jitter;
gdouble jitter_amount;
};
struct _GimpGradientOptions
{
gboolean use_gradient;
@ -86,6 +93,7 @@ struct _GimpPaintOptions
GimpPressureOptions *pressure_options;
GimpFadeOptions *fade_options;
GimpGradientOptions *gradient_options;
GimpJitterOptions *jitter_options;
};
struct _GimpPaintOptionsClass
@ -108,6 +116,9 @@ gboolean gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
gdouble pixel_dist,
GimpRGB *color);
gdouble gimp_paint_options_get_jitter (GimpPaintOptions *paint_options,
GimpImage *gimage);
GimpBrushApplicationMode
gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options);

View File

@ -262,14 +262,20 @@ gimp_clone_motion (GimpPaintCore *paint_core,
gdouble opacity;
gint offset_x;
gint offset_y;
gdouble jitter;
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
opacity = gimp_paint_options_get_fade (paint_options, gimage,
paint_core->pixel_dist);
if (opacity == 0.0)
return;
jitter = gimp_paint_options_get_jitter (paint_options, gimage);
if (jitter > 0.0)
GIMP_BRUSH_CORE (clone)->jitter = jitter;
/* make local copies because we change them */
offset_x = clone->offset_x;
offset_y = clone->offset_y;

View File

@ -64,7 +64,9 @@ static GtkWidget * gradient_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options,
GType tool_type,
GtkWidget *incremental_toggle);
static GtkWidget * jitter_options_gui (GimpJitterOptions *jitter,
GimpPaintOptions *paint_options,
GType tool_type);
/* public functions */
@ -151,6 +153,14 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
gtk_widget_show (frame);
}
frame = jitter_options_gui (options->jitter_options,
options, tool_type);
if (frame)
{
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
/* the "incremental" toggle */
if (tool_type == GIMP_TYPE_PENCIL_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
@ -357,6 +367,54 @@ fade_options_gui (GimpFadeOptions *fade,
return frame;
}
static GtkWidget *
jitter_options_gui (GimpJitterOptions *jitter,
GimpPaintOptions *paint_options,
GType tool_type)
{
GObject *config = G_OBJECT (paint_options);
GtkWidget *frame = NULL;
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *button;
if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGE_BURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
frame = gimp_frame_new (NULL);
button = gimp_prop_check_button_new (config, "use-jitter",
_("Apply Jitter"));
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button);
table = gtk_table_new (1, 2, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
if (jitter->use_jitter)
gtk_widget_show (table);
g_signal_connect_object (button, "toggled",
G_CALLBACK (gimp_toggle_button_set_visible),
table, 0);
spinbutton = gimp_prop_spin_button_new (config, "jitter-amount",
0.01, 0.1, 2);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 6);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Amount:"), 0.0, 0.5,
spinbutton, 1, FALSE);
}
return frame;
}
static GtkWidget *
gradient_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options,