[gimp] Adding repeat option to fade.
- From: Alexia Death <alexiade src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp] Adding repeat option to fade.
- Date: Sun, 6 Dec 2009 18:06:51 +0000 (UTC)
commit a736b8f972a821903b71d08bed394abbb8d47beb
Author: Alexia Death <alexiadeath gmail com>
Date: Sun Dec 6 20:03:39 2009 +0200
Adding repeat option to fade.
Now fade can be applied either as sawtooth or triangular wave.
Also fade can be reversed.
app/paint/gimppaintoptions.c | 65 ++++++++++++++++++++++++++++++++------
app/paint/gimppaintoptions.h | 8 +++--
app/tools/gimppaintoptions-gui.c | 17 +++++++++-
3 files changed, 76 insertions(+), 14 deletions(-)
---
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index ca00406..7794af5 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -46,6 +46,8 @@
#define DEFAULT_USE_FADE FALSE
#define DEFAULT_FADE_LENGTH 100.0
+#define DEFAULT_FADE_REVERSE FALSE
+#define DEFAULT_FADE_REPEAT GIMP_REPEAT_NONE
#define DEFAULT_FADE_UNIT GIMP_UNIT_PIXEL
#define DEFAULT_USE_JITTER FALSE
@@ -57,6 +59,8 @@
#define DEFAULT_GRADIENT_LENGTH 100.0
#define DEFAULT_GRADIENT_UNIT GIMP_UNIT_PIXEL
+#define DYNAMIC_MAX_VALUE 1.0
+#define DYNAMIC_MIN_VALUE 0.0
enum
{
@@ -73,6 +77,8 @@ enum
PROP_USE_FADE,
PROP_FADE_LENGTH,
+ PROP_FADE_REVERSE,
+ PROP_FADE_REPEAT,
PROP_FADE_UNIT,
PROP_USE_JITTER,
@@ -165,6 +171,15 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
"fade-unit", NULL,
TRUE, TRUE, DEFAULT_FADE_UNIT,
GIMP_PARAM_STATIC_STRINGS);
+ GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FADE_REVERSE,
+ "fade-reverse", NULL,
+ DEFAULT_FADE_REVERSE,
+ GIMP_PARAM_STATIC_STRINGS);
+ GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_FADE_REPEAT,
+ "fade-repeat", NULL,
+ GIMP_TYPE_REPEAT_MODE,
+ DEFAULT_FADE_REPEAT,
+ GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_JITTER,
"use-jitter", NULL,
@@ -303,6 +318,14 @@ gimp_paint_options_set_property (GObject *object,
fade_options->fade_length = g_value_get_double (value);
break;
+ case PROP_FADE_REVERSE:
+ fade_options->fade_reverse = g_value_get_boolean (value);
+ break;
+
+ case PROP_FADE_REPEAT:
+ fade_options->fade_repeat = g_value_get_enum (value);
+ break;
+
case PROP_FADE_UNIT:
fade_options->fade_unit = g_value_get_int (value);
break;
@@ -410,6 +433,14 @@ gimp_paint_options_get_property (GObject *object,
g_value_set_double (value, fade_options->fade_length);
break;
+ case PROP_FADE_REVERSE:
+ g_value_set_boolean (value, fade_options->fade_reverse);
+ break;
+
+ case PROP_FADE_REPEAT:
+ g_value_set_enum (value, fade_options->fade_repeat);
+ break;
+
case PROP_FADE_UNIT:
g_value_set_int (value, fade_options->fade_unit);
break;
@@ -523,8 +554,8 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options),
- GIMP_OPACITY_OPAQUE);
- g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_OPACITY_OPAQUE);
+ DYNAMIC_MAX_VALUE);
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), DYNAMIC_MAX_VALUE);
fade_options = paint_options->fade_options;
@@ -532,6 +563,8 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
{
gdouble fade_out = 0.0;
gdouble unit_factor;
+ gdouble pos;
+
switch (fade_options->fade_unit)
{
@@ -562,19 +595,31 @@ gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
/* factor in the fade out value */
if (fade_out > 0.0)
{
- gdouble x;
+ pos = pixel_dist / fade_out;
+ }
+ else
+ pos = DYNAMIC_MAX_VALUE;
- /* 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) */
+ /* for no repeat, set pos close to 1.0 after the first chunk */
+ if (fade_options->fade_repeat == GIMP_REPEAT_NONE && pos >= DYNAMIC_MAX_VALUE)
+ pos = DYNAMIC_MAX_VALUE - 0.0000001;
- }
+ if (((gint) pos & 1) &&
+ fade_options->fade_repeat != GIMP_REPEAT_SAWTOOTH)
+ pos = DYNAMIC_MAX_VALUE - (pos - (gint) pos);
+ else
+ pos = pos - (gint) pos;
+
+ /* Model the amount of paint left as a gaussian curve */
+ z = exp (- pos * pos * 5.541);
+
+ if (fade_options->fade_reverse)
+ z = 1.0 - z;
- return GIMP_OPACITY_TRANSPARENT;
+ return z; /* ln (1/255) */
}
- return GIMP_OPACITY_OPAQUE;
+ return DYNAMIC_MIN_VALUE;
}
gdouble
diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h
index e49b0f0..6db9c00 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -37,9 +37,11 @@ typedef struct _GimpGradientOptions GimpGradientOptions;
struct _GimpFadeOptions
{
- gboolean use_fade;
- gdouble fade_length;
- GimpUnit fade_unit;
+ gboolean use_fade;
+ gboolean fade_reverse;
+ gdouble fade_length;
+ GimpUnit fade_unit;
+ GimpRepeatMode fade_repeat;
};
struct _GimpJitterOptions
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index f1fd392..2a530c2 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -202,8 +202,10 @@ fade_options_gui (GimpPaintOptions *paint_options,
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *menu;
+ GtkWidget *combo;
+ GtkWidget *checkbox;
- table = gtk_table_new (1, 3, FALSE);
+ table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
frame = gimp_prop_expanding_frame_new (config, "use-fade",
@@ -228,6 +230,19 @@ fade_options_gui (GimpPaintOptions *paint_options,
g_object_set_data (G_OBJECT (menu), "set_digits", spinbutton);
gimp_unit_menu_set_pixel_digits (GIMP_UNIT_MENU (menu), 0);
+ /* the repeat type */
+ combo = gimp_prop_enum_combo_box_new (config, "fade-repeat", 0, 0);
+ gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
+ _("Repeat:"), 0.0, 0.5,
+ combo, 2, FALSE);
+
+ checkbox = gimp_prop_check_button_new (config,
+ "fade-reverse",
+ _("Reverse"));
+ gtk_table_attach (GTK_TABLE (table), checkbox, 0, 2, 3, 4,
+ GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
+ gtk_widget_show (checkbox);
+
return frame;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]