From 96baac783f43da753fbe31b1767f740a8d6c5ecd Mon Sep 17 00:00:00 2001 From: zhenfeng zhao Date: Thu, 2 Jul 2009 14:45:32 -0300 Subject: [PATCH] Fade dynamics. Add fade as one more dynamics driving factor on GUI. Implement fading dynamics calculation. Let fade work with all driven factors. Add pixel_dist parameter to get_dynamic_x. Adjusted function calls for get_dynamic_x. * app/paint/gimppaintoptions.c: Add initialization for fading dynamics. Add fading related variables similar to Random. Adjust get_dynamics_mix function. Add fading calculation in get_dynamics_x functions. Adjust get_dynamic_x functions for fade dynamics. * app/paint/gimppaintoptions.h: Add fading_options in GimpDynamicOptions. * app/tools/gimppaintoptions-gui.c: Add the function fading_options_gui. * app/paint/gimpclone.c * app/paint/gimpdodgeburn.c * app/paint/gimperaser.c * app/paint/gimpheal.c * app/paint/gimppaintbrush.c * app/paint/gimpsmudge.c * app/paint/gimpairbrush.c * app/paint/gimpbrushcore.c * app/paint/gimpconvolve.c: Adjust function calls. get_dynamic_opacity function calls were adjusted to have one more parameter, paint_core->pixel_dist. some key words: get_dynamic_ pixel_dist paint_core->pixel_dist --- .gitignore | 9 + app/paint/gimpairbrush.c | 3 +- app/paint/gimpbrushcore.c | 18 +- app/paint/gimpclone.c | 6 +- app/paint/gimpconvolve.c | 3 +- app/paint/gimpdodgeburn.c | 6 +- app/paint/gimperaser.c | 6 +- app/paint/gimpheal.c | 6 +- app/paint/gimppaintbrush.c | 9 +- app/paint/gimppaintoptions.c | 336 ++++++++++++++++++++++++++++--- app/paint/gimppaintoptions.h | 22 +- app/paint/gimpsmudge.c | 9 +- app/tools/gimppaintoptions-gui.c | 77 ++++++- 13 files changed, 448 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 5ccb71df97..6b65d00075 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ +/.anjuta/ +/.anjuta_sym_db.db +/TODO.tasks +*.anjuta +*.c~ +*.h~ +*.patch +/app/ + /Makefile /Makefile.in /aclocal.m4 diff --git a/app/paint/gimpairbrush.c b/app/paint/gimpairbrush.c index 9d03136bef..4ea888ee35 100644 --- a/app/paint/gimpairbrush.c +++ b/app/paint/gimpairbrush.c @@ -146,7 +146,8 @@ gimp_airbrush_paint (GimpPaintCore *paint_core, airbrush->paint_options = paint_options; dynamic_rate = gimp_paint_options_get_dynamic_rate (paint_options, - coords); + coords, + paint_core->pixel_dist); timeout = 10000 / (options->rate * dynamic_rate); diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c index 1d424c1d43..a7d75a68ef 100644 --- a/app/paint/gimpbrushcore.c +++ b/app/paint/gimpbrushcore.c @@ -374,12 +374,15 @@ gimp_brush_core_start (GimpPaintCore *paint_core, if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_transforming_brush) { core->scale = gimp_paint_options_get_dynamic_size (paint_options, coords, - TRUE); + TRUE, + paint_core->pixel_dist); - core->angle = gimp_paint_options_get_dynamic_angle (paint_options, coords); + core->angle = gimp_paint_options_get_dynamic_angle (paint_options, coords, + paint_core->pixel_dist); core->aspect_ratio = - gimp_paint_options_get_dynamic_aspect_ratio (paint_options, coords); + gimp_paint_options_get_dynamic_aspect_ratio (paint_options, coords, + paint_core->pixel_dist); } core->spacing = (gdouble) gimp_brush_get_spacing (core->main_brush) / 100.0; @@ -722,12 +725,15 @@ gimp_brush_core_get_paint_area (GimpPaintCore *paint_core, if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_transforming_brush) { core->scale = gimp_paint_options_get_dynamic_size (paint_options, coords, - TRUE); + TRUE, + paint_core->pixel_dist); - core->angle = gimp_paint_options_get_dynamic_angle (paint_options, coords); + core->angle = gimp_paint_options_get_dynamic_angle (paint_options, coords, + paint_core->pixel_dist); core->aspect_ratio = - gimp_paint_options_get_dynamic_aspect_ratio (paint_options, coords); + gimp_paint_options_get_dynamic_aspect_ratio (paint_options, coords, + paint_core->pixel_dist); } core->scale = gimp_brush_core_clamp_brush_scale (core, core->scale); diff --git a/app/paint/gimpclone.c b/app/paint/gimpclone.c index dd6b7b830f..9fa6f464ca 100644 --- a/app/paint/gimpclone.c +++ b/app/paint/gimpclone.c @@ -238,9 +238,11 @@ gimp_clone_motion (GimpSourceCore *source_core, } } - opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords); + opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords, + paint_core->pixel_dist); - hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords); + hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords, + paint_core->pixel_dist); gimp_brush_core_paste_canvas (GIMP_BRUSH_CORE (paint_core), drawable, coords, diff --git a/app/paint/gimpconvolve.c b/app/paint/gimpconvolve.c index 7b2cde8bda..1a9e5919ee 100644 --- a/app/paint/gimpconvolve.c +++ b/app/paint/gimpconvolve.c @@ -154,7 +154,8 @@ gimp_convolve_motion (GimpPaintCore *paint_core, rate = options->rate; - rate *= gimp_paint_options_get_dynamic_rate (paint_options, coords); + rate *= gimp_paint_options_get_dynamic_rate (paint_options, coords, + paint_core->pixel_dist); gimp_convolve_calculate_matrix (convolve, options->type, brush_core->brush->mask->width / 2, diff --git a/app/paint/gimpdodgeburn.c b/app/paint/gimpdodgeburn.c index f09ff7b7f2..1db1f2bc92 100644 --- a/app/paint/gimpdodgeburn.c +++ b/app/paint/gimpdodgeburn.c @@ -246,9 +246,11 @@ gimp_dodge_burn_motion (GimpPaintCore *paint_core, g_free (temp_data); - opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords); + opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords, + paint_core->pixel_dist); - hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords); + hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords, + paint_core->pixel_dist); /* Replace the newly dodgedburned area (canvas_buf) to the image */ gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable, diff --git a/app/paint/gimperaser.c b/app/paint/gimperaser.c index a7013cab24..b843395aea 100644 --- a/app/paint/gimperaser.c +++ b/app/paint/gimperaser.c @@ -135,9 +135,11 @@ gimp_eraser_motion (GimpPaintCore *paint_core, color_pixels (temp_buf_get_data (area), col, area->width * area->height, area->bytes); - opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords); + opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords, + paint_core->pixel_dist); - hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords); + hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords, + paint_core->pixel_dist); gimp_brush_core_paste_canvas (GIMP_BRUSH_CORE (paint_core), drawable, coords, diff --git a/app/paint/gimpheal.c b/app/paint/gimpheal.c index 5b7021cd7b..56bbbbdc09 100644 --- a/app/paint/gimpheal.c +++ b/app/paint/gimpheal.c @@ -439,7 +439,8 @@ gimp_heal_motion (GimpSourceCore *source_core, TempBuf *mask_buf; gdouble hardness; - hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords); + hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords, + paint_core->pixel_dist); mask_buf = gimp_brush_core_get_brush_mask (GIMP_BRUSH_CORE (source_core), coords, @@ -547,7 +548,8 @@ gimp_heal_motion (GimpSourceCore *source_core, temp_buf_free (temp); - opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords); + opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords, + paint_core->pixel_dist); /* replace the canvas with our healed data */ gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable, diff --git a/app/paint/gimppaintbrush.c b/app/paint/gimppaintbrush.c index 4f55794974..32338efeb6 100644 --- a/app/paint/gimppaintbrush.c +++ b/app/paint/gimppaintbrush.c @@ -131,7 +131,8 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core, paint_appl_mode = paint_options->application_mode; - grad_point = gimp_paint_options_get_dynamic_color (paint_options, coords); + grad_point = gimp_paint_options_get_dynamic_color (paint_options, coords, + paint_core->pixel_dist); /* optionally take the color from the current gradient */ if (gimp_paint_options_get_gradient_color (paint_options, image, @@ -176,9 +177,11 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core, area->bytes); } - opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords); + opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords, + paint_core->pixel_dist); - hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords); + hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords, + paint_core->pixel_dist); /* 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 96dd74183a..a4ab6511c6 100644 --- a/app/paint/gimppaintoptions.c +++ b/app/paint/gimppaintoptions.c @@ -34,6 +34,7 @@ #include "gimp-intl.h" +#include "core/gimpcoords.h" #define DEFAULT_BRUSH_SCALE 1.0 #define DEFAULT_BRUSH_ASPECT_RATIO 1.0 @@ -94,6 +95,16 @@ #define DEFAULT_RANDOM_ANGLE FALSE #define DEFAULT_RANDOM_PRESCALE 1.0 +#define DEFAULT_FADING_OPACITY FALSE +#define DEFAULT_FADING_HARDNESS FALSE +#define DEFAULT_FADING_RATE FALSE +#define DEFAULT_FADING_SIZE FALSE +#define DEFAULT_FADING_INVERSE_SIZE FALSE +#define DEFAULT_FADING_ASPECT_RATIO FALSE +#define DEFAULT_FADING_COLOR FALSE +#define DEFAULT_FADING_ANGLE FALSE +#define DEFAULT_FADING_PRESCALE 1.0 + #define DEFAULT_USE_FADE FALSE #define DEFAULT_FADE_LENGTH 100.0 #define DEFAULT_FADE_UNIT GIMP_UNIT_PIXEL @@ -173,6 +184,16 @@ enum PROP_RANDOM_ANGLE, PROP_RANDOM_PRESCALE, + PROP_FADING_OPACITY, + PROP_FADING_HARDNESS, + PROP_FADING_RATE, + PROP_FADING_SIZE, + PROP_FADING_INVERSE_SIZE, + PROP_FADING_ASPECT_RATIO, + PROP_FADING_COLOR, + PROP_FADING_ANGLE, + PROP_FADING_PRESCALE, + PROP_USE_FADE, PROP_FADE_LENGTH, PROP_FADE_UNIT, @@ -216,7 +237,9 @@ static gdouble gimp_paint_options_get_dynamics_mix (gdouble mix1, gdouble mix4, gdouble mix4_scale, gdouble mix5, - gdouble mix5_scale); + gdouble mix5_scale, + gdouble mix6, + gdouble mix6_scale); G_DEFINE_TYPE (GimpPaintOptions, gimp_paint_options, GIMP_TYPE_TOOL_OPTIONS) @@ -451,6 +474,39 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass) 0.0, 1.0, DEFAULT_RANDOM_PRESCALE, GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_OPACITY, + "fading-opacity", NULL, + DEFAULT_FADING_OPACITY, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_HARDNESS, + "fading-hardness", NULL, + DEFAULT_FADING_HARDNESS, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_RATE, + "fading-rate", NULL, + DEFAULT_FADING_RATE, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_SIZE, + "fading-size", NULL, + DEFAULT_FADING_SIZE, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_COLOR, + "fading-color", NULL, + DEFAULT_FADING_COLOR, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_ANGLE, + "fading-angle", NULL, + DEFAULT_FADING_ANGLE, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_INVERSE_SIZE, + "fading-inverse-size", NULL, + DEFAULT_FADING_INVERSE_SIZE, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FADING_PRESCALE, + "fading-prescale", NULL, + 0.0, 1.0, DEFAULT_FADING_PRESCALE, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_FADE, "use-fade", NULL, DEFAULT_USE_FADE, @@ -476,6 +532,10 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass) "random-aspect-ratio", NULL, DEFAULT_RANDOM_ASPECT_RATIO, GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADING_ASPECT_RATIO, + "fading-aspect-ratio", NULL, + DEFAULT_FADING_ASPECT_RATIO, + GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_GRADIENT, "use-gradient", NULL, DEFAULT_USE_GRADIENT, @@ -545,6 +605,7 @@ gimp_paint_options_init (GimpPaintOptions *options) options->direction_options = g_slice_new0 (GimpDynamicOptions); options->tilt_options = g_slice_new0 (GimpDynamicOptions); options->random_options = g_slice_new0 (GimpDynamicOptions); + options->fading_options = g_slice_new0 (GimpDynamicOptions); options->fade_options = g_slice_new0 (GimpFadeOptions); options->jitter_options = g_slice_new0 (GimpJitterOptions); options->gradient_options = g_slice_new0 (GimpGradientOptions); @@ -563,6 +624,7 @@ gimp_paint_options_finalize (GObject *object) g_slice_free (GimpDynamicOptions, options->direction_options); g_slice_free (GimpDynamicOptions, options->tilt_options); g_slice_free (GimpDynamicOptions, options->random_options); + g_slice_free (GimpDynamicOptions, options->fading_options); g_slice_free (GimpFadeOptions, options->fade_options); g_slice_free (GimpJitterOptions, options->jitter_options); g_slice_free (GimpGradientOptions, options->gradient_options); @@ -582,6 +644,7 @@ gimp_paint_options_set_property (GObject *object, GimpDynamicOptions *direction_options = options->direction_options; GimpDynamicOptions *tilt_options = options->tilt_options; GimpDynamicOptions *random_options = options->random_options; + GimpDynamicOptions *fading_options = options->fading_options; GimpFadeOptions *fade_options = options->fade_options; GimpJitterOptions *jitter_options = options->jitter_options; GimpGradientOptions *gradient_options = options->gradient_options; @@ -795,6 +858,42 @@ gimp_paint_options_set_property (GObject *object, case PROP_RANDOM_PRESCALE: random_options->prescale = g_value_get_double (value); break; +/*Fading*/ + case PROP_FADING_OPACITY: + fading_options->opacity = g_value_get_boolean (value); + break; + + case PROP_FADING_HARDNESS: + fading_options->hardness = g_value_get_boolean (value); + break; + + case PROP_FADING_RATE: + fading_options->rate = g_value_get_boolean (value); + break; + + case PROP_FADING_SIZE: + fading_options->size = g_value_get_boolean (value); + break; + + case PROP_FADING_INVERSE_SIZE: + fading_options->inverse_size = g_value_get_boolean (value); + break; + + case PROP_FADING_ASPECT_RATIO: + fading_options->aspect_ratio = g_value_get_boolean (value); + break; + + case PROP_FADING_COLOR: + fading_options->color = g_value_get_boolean (value); + break; + + case PROP_FADING_ANGLE: + fading_options->angle = g_value_get_boolean (value); + break; + + case PROP_FADING_PRESCALE: + fading_options->prescale = g_value_get_double (value); + break; case PROP_USE_FADE: fade_options->use_fade = g_value_get_boolean (value); @@ -878,6 +977,7 @@ gimp_paint_options_get_property (GObject *object, GimpDynamicOptions *direction_options = options->direction_options; GimpDynamicOptions *tilt_options = options->tilt_options; GimpDynamicOptions *random_options = options->random_options; + GimpDynamicOptions *fading_options = options->fading_options; GimpFadeOptions *fade_options = options->fade_options; GimpJitterOptions *jitter_options = options->jitter_options; GimpGradientOptions *gradient_options = options->gradient_options; @@ -1093,6 +1193,44 @@ gimp_paint_options_get_property (GObject *object, g_value_set_double (value, random_options->prescale); break; +/*fading*/ + + case PROP_FADING_OPACITY: + g_value_set_boolean (value, fading_options->opacity); + break; + + case PROP_FADING_HARDNESS: + g_value_set_boolean (value, fading_options->hardness); + break; + + case PROP_FADING_RATE: + g_value_set_boolean (value, fading_options->rate); + break; + + case PROP_FADING_SIZE: + g_value_set_boolean (value, fading_options->size); + break; + + case PROP_FADING_INVERSE_SIZE: + g_value_set_boolean (value, fading_options->inverse_size); + break; + + case PROP_FADING_ASPECT_RATIO: + g_value_set_boolean (value, fading_options->aspect_ratio); + break; + + case PROP_FADING_COLOR: + g_value_set_boolean (value, fading_options->color); + break; + + case PROP_FADING_ANGLE: + g_value_set_boolean (value, fading_options->angle); + break; + + case PROP_FADING_PRESCALE: + g_value_set_double (value, fading_options->prescale); + break; + case PROP_USE_FADE: g_value_set_boolean (value, fade_options->use_fade); break; @@ -1210,6 +1348,8 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options, gdouble pixel_dist) { GimpFadeOptions *fade_options; + gdouble z = -1.0; + g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), GIMP_OPACITY_OPAQUE); @@ -1244,8 +1384,14 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options, MAX (xres, yres) / unit_factor); } break; - } + + //printf("fade_out: %f", fade_out); + //printf("pixel_dist: %f", pixel_dist); + } + //printf("fade_out: %f", fade_out); + //printf("pixel_dist: %f", pixel_dist); + /* factor in the fade out value */ if (fade_out > 0.0) { @@ -1253,10 +1399,11 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options, /* Model the amount of paint left as a gaussian curve */ x = pixel_dist / fade_out; + z = exp (- x * x * 5.541); + return z; /* ln (1/255) */ - return exp (- x * x * 5.541); /* ln (1/255) */ } - + return GIMP_OPACITY_TRANSPARENT; } @@ -1301,7 +1448,8 @@ gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options, paint_options->velocity_options->color || paint_options->direction_options->color || paint_options->tilt_options->color || - paint_options->random_options->color) + paint_options->random_options->color || + paint_options->fading_options->color) { gimp_gradient_get_color_at (gradient, GIMP_CONTEXT (paint_options), NULL, grad_point, @@ -1378,13 +1526,16 @@ gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options) paint_options->velocity_options->hardness || paint_options->random_options->hardness) return GIMP_BRUSH_PRESSURE; - + return GIMP_BRUSH_SOFT; } /* Calculates dynamics mix to be used for same parameter * (velocity/pressure/direction/tilt/random) mix Needed in may places and tools. + * + * Added one parameter: fading, the 6th driving factor. + * (velocity/pressure/direction/tilt/random/fading) */ static gdouble gimp_paint_options_get_dynamics_mix (gdouble mix1, @@ -1396,7 +1547,9 @@ gimp_paint_options_get_dynamics_mix (gdouble mix1, gdouble mix4, gdouble mix4_scale, gdouble mix5, - gdouble mix5_scale) + gdouble mix5_scale, + gdouble mix6, + gdouble mix6_scale) { gdouble scale_sum = 0.0; gdouble result = 1.0; @@ -1431,13 +1584,20 @@ gimp_paint_options_get_dynamics_mix (gdouble mix1, } else mix5 = 0.0; + if (mix6 > -1.0) + { + scale_sum += fabs (mix6_scale); + } + else mix6 = 0.0; + if (scale_sum > 0.0) { result = (mix1 * mix1_scale) / scale_sum + (mix2 * mix2_scale) / scale_sum + (mix3 * mix3_scale) / scale_sum + (mix4 * mix4_scale) / scale_sum + - (mix5 * mix5_scale) / scale_sum; + (mix5 * mix5_scale) / scale_sum + + (mix6 * mix6_scale) / scale_sum; } if (result < 0.0) @@ -1448,7 +1608,8 @@ gimp_paint_options_get_dynamics_mix (gdouble mix1, gdouble gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, - const GimpCoords *coords) + const GimpCoords *coords, + gdouble pixel_dist) { gdouble opacity = 1.0; @@ -1459,13 +1620,15 @@ gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, paint_options->velocity_options->opacity || paint_options->direction_options->opacity || paint_options->tilt_options->opacity || - paint_options->random_options->opacity) + paint_options->random_options->opacity|| + paint_options->fading_options->opacity) { gdouble pressure = -1.0; gdouble velocity = -1.0; gdouble direction = -1.0; gdouble tilt = -1.0; gdouble random = -1.0; + gdouble fading = -1.0; if (paint_options->pressure_options->opacity) @@ -1473,17 +1636,36 @@ gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, if (paint_options->velocity_options->opacity) velocity = GIMP_PAINT_VELOCITY_SCALE * (1 - coords->velocity); - + //printf("velocity: %f", velocity); + if (paint_options->random_options->opacity) random = g_random_double_range (0.0, 1.0); + //printf("%f", random); - if (paint_options->tilt_options->opacity) + if (paint_options->tilt_options->opacity) tilt = 1.0 - sqrt (SQR (coords->xtilt) + SQR (coords->ytilt)); if (paint_options->direction_options->opacity) direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */ - opacity = gimp_paint_options_get_dynamics_mix (pressure, + if (paint_options->fading_options->opacity) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + /* + printf("fade_out: %f", fade_out); + printf("pixel_dist: %f", pixel_dist); + printf("fading value: %f", fading); + */ + //printf("fading-cor: %f", coords->fading); + + } + + opacity = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, velocity, paint_options->velocity_options->prescale, @@ -1492,7 +1674,9 @@ gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); } return opacity; @@ -1501,7 +1685,8 @@ gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, gdouble gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, const GimpCoords *coords, - gboolean use_dynamics) + gboolean use_dynamics, + gdouble pixel_dist) { gdouble scale = 1.0; @@ -1512,7 +1697,8 @@ gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, gdouble direction = -1.0; gdouble random = -1.0; gdouble tilt = -1.0; - + gdouble fading = -1.0; + if (paint_options->pressure_options->size) { pressure = coords->pressure; @@ -1552,6 +1738,18 @@ gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, if (paint_options->direction_options->size) direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */ + + if (paint_options->fading_options->size || + paint_options->fading_options->inverse_size) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + } + scale = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, velocity, @@ -1561,7 +1759,9 @@ gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); if (scale < 1 / 64.0) scale = 1 / 8.0; @@ -1576,7 +1776,8 @@ gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, gdouble gimp_paint_options_get_dynamic_aspect_ratio (GimpPaintOptions *paint_options, - const GimpCoords *coords) + const GimpCoords *coords, + gdouble pixel_dist) { gdouble aspect_ratio = 1.0; @@ -1587,13 +1788,15 @@ gimp_paint_options_get_dynamic_aspect_ratio (GimpPaintOptions *paint_options, paint_options->velocity_options->aspect_ratio || paint_options->direction_options->aspect_ratio || paint_options->tilt_options->aspect_ratio || - paint_options->random_options->aspect_ratio) + paint_options->random_options->aspect_ratio || + paint_options->fading_options->aspect_ratio) { gdouble pressure = -1.0; gdouble velocity = -1.0; gdouble direction = -1.0; gdouble tilt = -1.0; gdouble random = -1.0; + gdouble fading = -1.0; if (paint_options->pressure_options->aspect_ratio) @@ -1628,6 +1831,16 @@ gimp_paint_options_get_dynamic_aspect_ratio (GimpPaintOptions *paint_options, direction = 1 / direction; } + if (paint_options->fading_options->aspect_ratio) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + } + aspect_ratio = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, velocity, @@ -1637,7 +1850,9 @@ gimp_paint_options_get_dynamic_aspect_ratio (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); } return paint_options->brush_aspect_ratio * aspect_ratio; @@ -1645,7 +1860,8 @@ gimp_paint_options_get_dynamic_aspect_ratio (GimpPaintOptions *paint_options, gdouble gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, - const GimpCoords *coords) + const GimpCoords *coords, + gdouble pixel_dist) { gdouble rate = 1.0; @@ -1663,6 +1879,7 @@ gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, gdouble direction = -1.0; gdouble random = -1.0; gdouble tilt = -1.0; + gdouble fading = -1.0; if (paint_options->pressure_options->rate) pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure; @@ -1679,6 +1896,16 @@ gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, if (paint_options->direction_options->rate) direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */ + if (paint_options->fading_options->rate) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + } + rate = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, velocity, @@ -1688,7 +1915,9 @@ gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); } return rate; @@ -1697,7 +1926,8 @@ gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, gdouble gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, - const GimpCoords *coords) + const GimpCoords *coords, + gdouble pixel_dist) { gdouble color = 1.0; @@ -1708,13 +1938,15 @@ gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, paint_options->velocity_options->color || paint_options->direction_options->color || paint_options->tilt_options->color || - paint_options->random_options->color) + paint_options->random_options->color || + paint_options->fading_options->color) { gdouble pressure = -1.0; gdouble velocity = -1.0; gdouble direction = -1.0; gdouble random = -1.0; gdouble tilt = -1.0; + gdouble fading = -1.0; if (paint_options->pressure_options->color) pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure; @@ -1731,6 +1963,16 @@ gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, if (paint_options->direction_options->color) direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */ + if (paint_options->fading_options->color) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + } + color = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, velocity, @@ -1740,7 +1982,9 @@ gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); } return color; @@ -1748,7 +1992,8 @@ gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, gdouble gimp_paint_options_get_dynamic_hardness (GimpPaintOptions *paint_options, - const GimpCoords *coords) + const GimpCoords *coords, + gdouble pixel_dist) { gdouble hardness = 1.0; @@ -1759,13 +2004,15 @@ gimp_paint_options_get_dynamic_hardness (GimpPaintOptions *paint_options, paint_options->velocity_options->hardness || paint_options->direction_options->hardness || paint_options->tilt_options->hardness || - paint_options->random_options->hardness) + paint_options->random_options->hardness || + paint_options->fading_options->hardness) { gdouble pressure = -1.0; gdouble velocity = -1.0; gdouble direction = -1.0; gdouble random = -1.0; gdouble tilt = -1.0; + gdouble fading = -1.0; if (paint_options->pressure_options->hardness) pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure; @@ -1782,6 +2029,16 @@ gimp_paint_options_get_dynamic_hardness (GimpPaintOptions *paint_options, if (paint_options->direction_options->hardness) direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */ + if (paint_options->fading_options->hardness) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + } + hardness = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, velocity, @@ -1791,7 +2048,9 @@ gimp_paint_options_get_dynamic_hardness (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); } return hardness; @@ -1799,7 +2058,8 @@ gimp_paint_options_get_dynamic_hardness (GimpPaintOptions *paint_options, gdouble gimp_paint_options_get_dynamic_angle (GimpPaintOptions *paint_options, - const GimpCoords *coords) + const GimpCoords *coords, + gdouble pixel_dist) { gdouble angle = 1.0; @@ -1810,14 +2070,15 @@ gimp_paint_options_get_dynamic_angle (GimpPaintOptions *paint_options, paint_options->velocity_options->angle || paint_options->direction_options->angle || paint_options->tilt_options->angle || - paint_options->random_options->angle) + paint_options->random_options->angle || + paint_options->fading_options->angle) { gdouble pressure = -1.0; gdouble velocity = -1.0; gdouble direction = -1.0; gdouble random = -1.0; gdouble tilt = -1.0; - + gdouble fading = -1.0; if (paint_options->pressure_options->angle) pressure = GIMP_PAINT_PRESSURE_SCALE * coords->pressure; @@ -1862,6 +2123,15 @@ gimp_paint_options_get_dynamic_angle (GimpPaintOptions *paint_options, if (paint_options->direction_options->angle) direction = coords->direction + 0.5; /* mixer does not mix negative angles right so we shift */ + if (paint_options->fading_options->rate) + { + gdouble p; + gdouble fade_out; + + fade_out = DEFAULT_FADE_LENGTH; + p = pixel_dist / fade_out; + fading = exp (- p * p * 5.541); + } angle = gimp_paint_options_get_dynamics_mix (pressure, paint_options->pressure_options->prescale, @@ -1872,7 +2142,9 @@ gimp_paint_options_get_dynamic_angle (GimpPaintOptions *paint_options, tilt, paint_options->tilt_options->prescale, direction, - paint_options->direction_options->prescale); + paint_options->direction_options->prescale, + fading, + paint_options->fading_options->prescale); angle = angle - 0.5; } diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h index e72a6325b6..bb70952e2f 100644 --- a/app/paint/gimppaintoptions.h +++ b/app/paint/gimppaintoptions.h @@ -103,6 +103,7 @@ struct _GimpPaintOptions GimpDynamicOptions *direction_options; GimpDynamicOptions *tilt_options; GimpDynamicOptions *random_options; + GimpDynamicOptions *fading_options; GimpFadeOptions *fade_options; GimpJitterOptions *jitter_options; @@ -144,27 +145,34 @@ GimpBrushApplicationMode gdouble gimp_paint_options_get_dynamic_opacity (GimpPaintOptions *paint_options, - const GimpCoords *coords); + const GimpCoords *coords, + gdouble pixel_dist); gdouble gimp_paint_options_get_dynamic_size (GimpPaintOptions *paint_options, const GimpCoords *coords, - gboolean use_dynamics); + gboolean use_dynamics, + gdouble pixel_dist); gdouble gimp_paint_options_get_dynamic_aspect_ratio (GimpPaintOptions *paint_options, - const GimpCoords *coords); + const GimpCoords *coords, + gdouble pixel_dist); gdouble gimp_paint_options_get_dynamic_rate (GimpPaintOptions *paint_options, - const GimpCoords *coords); + const GimpCoords *coords, + gdouble pixel_dist); gdouble gimp_paint_options_get_dynamic_color (GimpPaintOptions *paint_options, - const GimpCoords *coords); + const GimpCoords *coords, + gdouble pixel_dist); gdouble gimp_paint_options_get_dynamic_angle (GimpPaintOptions *paint_options, - const GimpCoords *coords); + const GimpCoords *coords, + gdouble pixel_dist); gdouble gimp_paint_options_get_dynamic_hardness(GimpPaintOptions *paint_options, - const GimpCoords *coords); + const GimpCoords *coords, + gdouble pixel_dist); #endif /* __GIMP_PAINT_OPTIONS_H__ */ diff --git a/app/paint/gimpsmudge.c b/app/paint/gimpsmudge.c index e526abfe31..878366482f 100644 --- a/app/paint/gimpsmudge.c +++ b/app/paint/gimpsmudge.c @@ -271,7 +271,8 @@ gimp_smudge_motion (GimpPaintCore *paint_core, area->x, area->y, area->width, area->height, FALSE); /* Enable dynamic rate */ - dynamic_rate = gimp_paint_options_get_dynamic_rate (paint_options, coords); + dynamic_rate = gimp_paint_options_get_dynamic_rate (paint_options, coords, + paint_core->pixel_dist); rate = (options->rate / 100.0) * dynamic_rate; /* The tempPR will be the built up buffer (for smudge) */ @@ -311,9 +312,11 @@ gimp_smudge_motion (GimpPaintCore *paint_core, else copy_region (&tempPR, &destPR); - opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords); + opacity *= gimp_paint_options_get_dynamic_opacity (paint_options, coords, + paint_core->pixel_dist); - hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords); + hardness = gimp_paint_options_get_dynamic_hardness (paint_options, coords, + paint_core->pixel_dist); gimp_brush_core_replace_canvas (GIMP_BRUSH_CORE (paint_core), drawable, coords, diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c index 3dd34ca63a..3ebc84cf32 100644 --- a/app/tools/gimppaintoptions-gui.c +++ b/app/tools/gimppaintoptions-gui.c @@ -76,6 +76,12 @@ static void random_options_gui (GimpPaintOptions *paint_options, GType tool_type, GtkTable *table, gint row); +/**/ +static void fading_options_gui (GimpPaintOptions *paint_options, + GType tool_type, + GtkTable *table, + gint row); +/**/ static GtkWidget * fade_options_gui (GimpPaintOptions *paint_options, GType tool_type); static GtkWidget * gradient_options_gui (GimpPaintOptions *paint_options, @@ -234,7 +240,7 @@ gimp_paint_options_gui (GimpToolOptions *tool_options) gtk_container_add (GTK_CONTAINER (frame), inner_frame); gtk_widget_show (inner_frame); - table = gtk_table_new (5, n_dynamics + 2, FALSE); + table = gtk_table_new (7, n_dynamics + 2, FALSE); gtk_container_add (GTK_CONTAINER (inner_frame), table); gtk_widget_show (table); @@ -268,6 +274,14 @@ gimp_paint_options_gui (GimpToolOptions *tool_options) GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); gtk_widget_show (label); +//@@Nicolas + + label = gtk_label_new (_("Fading - new:")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 6, 7, + GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); + gtk_widget_show (label); + pressure_options_gui (options, tool_type, GTK_TABLE (table), 1, dynamics_labels); @@ -284,6 +298,9 @@ gimp_paint_options_gui (GimpToolOptions *tool_options) random_options_gui (options, tool_type, GTK_TABLE (table), 5); + fading_options_gui (options, tool_type, + GTK_TABLE (table), 6); + /* EEK: pack the fixed *after* the buttons so the table calls * size-allocates on it *before* it places the toggles. Fixes * label positions in RTL mode. @@ -790,6 +807,64 @@ random_options_gui (GimpPaintOptions *paint_options, gtk_widget_show (scalebutton); } +static void +fading_options_gui (GimpPaintOptions *paint_options, + GType tool_type, + GtkTable *table, + gint row) +{ + GObject *config = G_OBJECT (paint_options); + gint column = 1; + GtkWidget *scalebutton; + + if (tool_has_opacity_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-opacity", + table, column++, row); + } + + if (tool_has_hardness_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-hardness", + table, column++, row); + } + + if (tool_has_rate_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-rate", + table, column++, row); + } + + if (tool_has_size_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-size", + table, column++, row); + } + + if (tool_has_aspect_ratio_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-aspect-ratio", + table, column++, row); + } + + if (tool_has_angle_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-angle", + table, column++, row); + } + + if (tool_has_color_dynamics (tool_type)) + { + dynamics_check_button_new (config, "fading-color", + table, column++, row); + } + + scalebutton = gimp_prop_scale_button_new (config, "fading-prescale"); + gtk_table_attach (table, scalebutton, column, column + 1, row, row + 1, + GTK_SHRINK, GTK_SHRINK, 0, 0); + gtk_widget_show (scalebutton); +} + static GtkWidget * fade_options_gui (GimpPaintOptions *paint_options, GType tool_type)