app: move all GimpDynamicsOutput members to private

This commit is contained in:
Michael Natterer
2011-03-03 11:48:35 +01:00
parent 672286515c
commit c31d675ac1
2 changed files with 158 additions and 132 deletions

View File

@ -66,6 +66,35 @@ enum
}; };
typedef struct _GimpDynamicsOutputPrivate GimpDynamicsOutputPrivate;
struct _GimpDynamicsOutputPrivate
{
GimpDynamicsOutputType type;
gboolean use_pressure;
gboolean use_velocity;
gboolean use_direction;
gboolean use_tilt;
gboolean use_wheel;
gboolean use_random;
gboolean use_fade;
GimpCurve *pressure_curve;
GimpCurve *velocity_curve;
GimpCurve *direction_curve;
GimpCurve *tilt_curve;
GimpCurve *wheel_curve;
GimpCurve *random_curve;
GimpCurve *fade_curve;
};
#define GET_PRIVATE(output) \
G_TYPE_INSTANCE_GET_PRIVATE (output, \
GIMP_TYPE_DYNAMICS_OUTPUT, \
GimpDynamicsOutputPrivate)
static void gimp_dynamics_output_finalize (GObject *object); static void gimp_dynamics_output_finalize (GObject *object);
static void gimp_dynamics_output_set_property (GObject *object, static void gimp_dynamics_output_set_property (GObject *object,
guint property_id, guint property_id,
@ -180,39 +209,42 @@ gimp_dynamics_output_class_init (GimpDynamicsOutputClass *klass)
GIMP_TYPE_CURVE, GIMP_TYPE_CURVE,
GIMP_CONFIG_PARAM_AGGREGATE); GIMP_CONFIG_PARAM_AGGREGATE);
g_type_class_add_private (klass, sizeof (GimpDynamicsOutputPrivate));
} }
static void static void
gimp_dynamics_output_init (GimpDynamicsOutput *output) gimp_dynamics_output_init (GimpDynamicsOutput *output)
{ {
output->pressure_curve = gimp_dynamics_output_create_curve (output, GimpDynamicsOutputPrivate *private = GET_PRIVATE (output);
"pressure-curve");
output->velocity_curve = gimp_dynamics_output_create_curve (output, private->pressure_curve = gimp_dynamics_output_create_curve (output,
"velocity-curve"); "pressure-curve");
output->direction_curve = gimp_dynamics_output_create_curve (output, private->velocity_curve = gimp_dynamics_output_create_curve (output,
"direction-curve"); "velocity-curve");
output->tilt_curve = gimp_dynamics_output_create_curve (output, private->direction_curve = gimp_dynamics_output_create_curve (output,
"tilt-curve"); "direction-curve");
output->wheel_curve = gimp_dynamics_output_create_curve (output, private->tilt_curve = gimp_dynamics_output_create_curve (output,
"wheel-curve"); "tilt-curve");
output->random_curve = gimp_dynamics_output_create_curve (output, private->wheel_curve = gimp_dynamics_output_create_curve (output,
"random-curve"); "wheel-curve");
output->fade_curve = gimp_dynamics_output_create_curve (output, private->random_curve = gimp_dynamics_output_create_curve (output,
"fade-curve"); "random-curve");
private->fade_curve = gimp_dynamics_output_create_curve (output,
"fade-curve");
} }
static void static void
gimp_dynamics_output_finalize (GObject *object) gimp_dynamics_output_finalize (GObject *object)
{ {
GimpDynamicsOutput *output = GIMP_DYNAMICS_OUTPUT (object); GimpDynamicsOutputPrivate *private = GET_PRIVATE (object);
g_object_unref (output->pressure_curve); g_object_unref (private->pressure_curve);
g_object_unref (output->velocity_curve); g_object_unref (private->velocity_curve);
g_object_unref (output->direction_curve); g_object_unref (private->direction_curve);
g_object_unref (output->tilt_curve); g_object_unref (private->tilt_curve);
g_object_unref (output->wheel_curve); g_object_unref (private->wheel_curve);
g_object_unref (output->random_curve); g_object_unref (private->random_curve);
g_object_unref (output->fade_curve); g_object_unref (private->fade_curve);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -223,75 +255,75 @@ gimp_dynamics_output_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpDynamicsOutput *output = GIMP_DYNAMICS_OUTPUT (object); GimpDynamicsOutputPrivate *private = GET_PRIVATE (object);
switch (property_id) switch (property_id)
{ {
case PROP_TYPE: case PROP_TYPE:
output->type = g_value_get_enum (value); private->type = g_value_get_enum (value);
break; break;
case PROP_USE_PRESSURE: case PROP_USE_PRESSURE:
output->use_pressure = g_value_get_boolean (value); private->use_pressure = g_value_get_boolean (value);
break; break;
case PROP_USE_VELOCITY: case PROP_USE_VELOCITY:
output->use_velocity = g_value_get_boolean (value); private->use_velocity = g_value_get_boolean (value);
break; break;
case PROP_USE_DIRECTION: case PROP_USE_DIRECTION:
output->use_direction = g_value_get_boolean (value); private->use_direction = g_value_get_boolean (value);
break; break;
case PROP_USE_TILT: case PROP_USE_TILT:
output->use_tilt = g_value_get_boolean (value); private->use_tilt = g_value_get_boolean (value);
break; break;
case PROP_USE_WHEEL: case PROP_USE_WHEEL:
output->use_wheel = g_value_get_boolean (value); private->use_wheel = g_value_get_boolean (value);
break; break;
case PROP_USE_RANDOM: case PROP_USE_RANDOM:
output->use_random = g_value_get_boolean (value); private->use_random = g_value_get_boolean (value);
break; break;
case PROP_USE_FADE: case PROP_USE_FADE:
output->use_fade = g_value_get_boolean (value); private->use_fade = g_value_get_boolean (value);
break; break;
case PROP_PRESSURE_CURVE: case PROP_PRESSURE_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->pressure_curve); private->pressure_curve);
break; break;
case PROP_VELOCITY_CURVE: case PROP_VELOCITY_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->velocity_curve); private->velocity_curve);
break; break;
case PROP_DIRECTION_CURVE: case PROP_DIRECTION_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->direction_curve); private->direction_curve);
break; break;
case PROP_TILT_CURVE: case PROP_TILT_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->tilt_curve); private->tilt_curve);
break; break;
case PROP_WHEEL_CURVE: case PROP_WHEEL_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->wheel_curve); private->wheel_curve);
break; break;
case PROP_RANDOM_CURVE: case PROP_RANDOM_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->random_curve); private->random_curve);
break; break;
case PROP_FADE_CURVE: case PROP_FADE_CURVE:
gimp_dynamics_output_copy_curve (g_value_get_object (value), gimp_dynamics_output_copy_curve (g_value_get_object (value),
output->fade_curve); private->fade_curve);
break; break;
default: default:
@ -306,68 +338,68 @@ gimp_dynamics_output_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpDynamicsOutput *output = GIMP_DYNAMICS_OUTPUT (object); GimpDynamicsOutputPrivate *private = GET_PRIVATE (object);
switch (property_id) switch (property_id)
{ {
case PROP_TYPE: case PROP_TYPE:
g_value_set_enum (value, output->type); g_value_set_enum (value, private->type);
break; break;
case PROP_USE_PRESSURE: case PROP_USE_PRESSURE:
g_value_set_boolean (value, output->use_pressure); g_value_set_boolean (value, private->use_pressure);
break; break;
case PROP_USE_VELOCITY: case PROP_USE_VELOCITY:
g_value_set_boolean (value, output->use_velocity); g_value_set_boolean (value, private->use_velocity);
break; break;
case PROP_USE_DIRECTION: case PROP_USE_DIRECTION:
g_value_set_boolean (value, output->use_direction); g_value_set_boolean (value, private->use_direction);
break; break;
case PROP_USE_TILT: case PROP_USE_TILT:
g_value_set_boolean (value, output->use_tilt); g_value_set_boolean (value, private->use_tilt);
break; break;
case PROP_USE_WHEEL: case PROP_USE_WHEEL:
g_value_set_boolean (value, output->use_wheel); g_value_set_boolean (value, private->use_wheel);
break; break;
case PROP_USE_RANDOM: case PROP_USE_RANDOM:
g_value_set_boolean (value, output->use_random); g_value_set_boolean (value, private->use_random);
break; break;
case PROP_USE_FADE: case PROP_USE_FADE:
g_value_set_boolean (value, output->use_fade); g_value_set_boolean (value, private->use_fade);
break; break;
case PROP_PRESSURE_CURVE: case PROP_PRESSURE_CURVE:
g_value_set_object (value, output->pressure_curve); g_value_set_object (value, private->pressure_curve);
break; break;
case PROP_VELOCITY_CURVE: case PROP_VELOCITY_CURVE:
g_value_set_object (value, output->velocity_curve); g_value_set_object (value, private->velocity_curve);
break; break;
case PROP_DIRECTION_CURVE: case PROP_DIRECTION_CURVE:
g_value_set_object (value, output->direction_curve); g_value_set_object (value, private->direction_curve);
break; break;
case PROP_TILT_CURVE: case PROP_TILT_CURVE:
g_value_set_object (value, output->tilt_curve); g_value_set_object (value, private->tilt_curve);
break; break;
case PROP_WHEEL_CURVE: case PROP_WHEEL_CURVE:
g_value_set_object (value, output->wheel_curve); g_value_set_object (value, private->wheel_curve);
break; break;
case PROP_RANDOM_CURVE: case PROP_RANDOM_CURVE:
g_value_set_object (value, output->random_curve); g_value_set_object (value, private->random_curve);
break; break;
case PROP_FADE_CURVE: case PROP_FADE_CURVE:
g_value_set_object (value, output->fade_curve); g_value_set_object (value, private->fade_curve);
break; break;
default: default:
@ -394,13 +426,15 @@ gimp_dynamics_output_new (const gchar *name,
gboolean gboolean
gimp_dynamics_output_is_enabled (GimpDynamicsOutput *output) gimp_dynamics_output_is_enabled (GimpDynamicsOutput *output)
{ {
return (output->use_pressure || GimpDynamicsOutputPrivate *private = GET_PRIVATE (output);
output->use_velocity ||
output->use_direction || return (private->use_pressure ||
output->use_tilt || private->use_velocity ||
output->use_wheel || private->use_direction ||
output->use_random || private->use_tilt ||
output->use_fade); private->use_wheel ||
private->use_random ||
private->use_fade);
} }
gdouble gdouble
@ -409,39 +443,41 @@ gimp_dynamics_output_get_linear_value (GimpDynamicsOutput *output,
GimpPaintOptions *options, GimpPaintOptions *options,
gdouble fade_point) gdouble fade_point)
{ {
gdouble total = 0.0; GimpDynamicsOutputPrivate *private = GET_PRIVATE (output);
gdouble result = 1.0; gdouble total = 0.0;
gint factors = 0; gdouble result = 1.0;
gint factors = 0;
if (output->use_pressure) if (private->use_pressure)
{ {
total += gimp_curve_map_value (output->pressure_curve, coords->pressure); total += gimp_curve_map_value (private->pressure_curve,
coords->pressure);
factors++; factors++;
} }
if (output->use_velocity) if (private->use_velocity)
{ {
total += gimp_curve_map_value (output->velocity_curve, total += gimp_curve_map_value (private->velocity_curve,
(1.0 - coords->velocity)); (1.0 - coords->velocity));
factors++; factors++;
} }
if (output->use_direction) if (private->use_direction)
{ {
total += gimp_curve_map_value (output->direction_curve, total += gimp_curve_map_value (private->direction_curve,
fmod (coords->direction + 0.5, 1)); fmod (coords->direction + 0.5, 1));
factors++; factors++;
} }
if (output->use_tilt) if (private->use_tilt)
{ {
total += gimp_curve_map_value (output->tilt_curve, total += gimp_curve_map_value (private->tilt_curve,
(1.0 - sqrt (SQR (coords->xtilt) + (1.0 - sqrt (SQR (coords->xtilt) +
SQR (coords->ytilt)))); SQR (coords->ytilt))));
factors++; factors++;
} }
if (output->use_wheel) if (private->use_wheel)
{ {
gdouble wheel; gdouble wheel;
if (coords->wheel >= 0.5) if (coords->wheel >= 0.5)
@ -449,20 +485,20 @@ gimp_dynamics_output_get_linear_value (GimpDynamicsOutput *output,
else else
wheel = 1 - coords->wheel * 2; wheel = 1 - coords->wheel * 2;
total += gimp_curve_map_value (output->wheel_curve, wheel); total += gimp_curve_map_value (private->wheel_curve, wheel);
factors++; factors++;
} }
if (output->use_random) if (private->use_random)
{ {
total += gimp_curve_map_value (output->random_curve, total += gimp_curve_map_value (private->random_curve,
g_random_double_range (0.0, 1.0)); g_random_double_range (0.0, 1.0));
factors++; factors++;
} }
if (output->use_fade) if (private->use_fade)
{ {
total += gimp_curve_map_value (output->fade_curve, fade_point); total += gimp_curve_map_value (private->fade_curve, fade_point);
factors++; factors++;
} }
@ -484,33 +520,36 @@ gimp_dynamics_output_get_angular_value (GimpDynamicsOutput *output,
GimpPaintOptions *options, GimpPaintOptions *options,
gdouble fade_point) gdouble fade_point)
{ {
gdouble total = 0.0; GimpDynamicsOutputPrivate *private = GET_PRIVATE (output);
gdouble result = 0.0; /* angles are additive, so we retun zero for no change. */ gdouble total = 0.0;
gint factors = 0; gdouble result = 0.0; /* angles are additive, so we retun zero for no change. */
gint factors = 0;
if (output->use_pressure) if (private->use_pressure)
{ {
total += gimp_curve_map_value (output->pressure_curve, coords->pressure); total += gimp_curve_map_value (private->pressure_curve,
coords->pressure);
factors++; factors++;
} }
if (output->use_velocity) if (private->use_velocity)
{ {
total += gimp_curve_map_value (output->velocity_curve, total += gimp_curve_map_value (private->velocity_curve,
(1.0 - coords->velocity)); (1.0 - coords->velocity));
factors++; factors++;
} }
if (output->use_direction) if (private->use_direction)
{ {
total += gimp_curve_map_value (output->direction_curve, coords->direction); total += gimp_curve_map_value (private->direction_curve,
coords->direction);
factors++; factors++;
} }
/* For tilt to make sense, it needs to be converted to an angle, not /* For tilt to make sense, it needs to be converted to an angle, not
* just a vector * just a vector
*/ */
if (output->use_tilt) if (private->use_tilt)
{ {
gdouble tilt_x = coords->xtilt; gdouble tilt_x = coords->xtilt;
gdouble tilt_y = coords->ytilt; gdouble tilt_y = coords->ytilt;
@ -542,28 +581,28 @@ gimp_dynamics_output_get_angular_value (GimpDynamicsOutput *output,
while (tilt < 0.0) while (tilt < 0.0)
tilt += 1.0; tilt += 1.0;
total += gimp_curve_map_value (output->tilt_curve, tilt); total += gimp_curve_map_value (private->tilt_curve, tilt);
factors++; factors++;
} }
if (output->use_wheel) if (private->use_wheel)
{ {
gdouble angle = 1.0 - fmod(0.5 + coords->wheel, 1); gdouble angle = 1.0 - fmod(0.5 + coords->wheel, 1);
total += gimp_curve_map_value (output->wheel_curve, angle); total += gimp_curve_map_value (private->wheel_curve, angle);
factors++; factors++;
} }
if (output->use_random) if (private->use_random)
{ {
total += gimp_curve_map_value (output->random_curve, total += gimp_curve_map_value (private->random_curve,
g_random_double_range (0.0, 1.0)); g_random_double_range (0.0, 1.0));
factors++; factors++;
} }
if (output->use_fade) if (private->use_fade)
{ {
total += gimp_curve_map_value (output->fade_curve, fade_point); total += gimp_curve_map_value (private->fade_curve, fade_point);
factors++; factors++;
} }
@ -585,26 +624,30 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
GimpPaintOptions *options, GimpPaintOptions *options,
gdouble fade_point) gdouble fade_point)
{ {
gdouble total = 0.0; GimpDynamicsOutputPrivate *private = GET_PRIVATE (output);
gint factors = 0; gdouble total = 0.0;
gdouble sign = 1.0; gint factors = 0;
gdouble result = 1.0; gdouble sign = 1.0;
gdouble result = 1.0;
if (output->use_pressure) if (private->use_pressure)
{ {
total += gimp_curve_map_value (output->pressure_curve, coords->pressure); total += gimp_curve_map_value (private->pressure_curve,
coords->pressure);
factors++; factors++;
} }
if (output->use_velocity) if (private->use_velocity)
{ {
total += gimp_curve_map_value (output->velocity_curve, coords->velocity); total += gimp_curve_map_value (private->velocity_curve,
coords->velocity);
factors++; factors++;
} }
if (output->use_direction) if (private->use_direction)
{ {
gdouble direction = gimp_curve_map_value (output->direction_curve, coords->direction); gdouble direction = gimp_curve_map_value (private->direction_curve,
coords->direction);
if (((direction > 0.875) && (direction <= 1.0)) || if (((direction > 0.875) && (direction <= 1.0)) ||
((direction > 0.0) && (direction < 0.125)) || ((direction > 0.0) && (direction < 0.125)) ||
@ -615,11 +658,11 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
factors++; factors++;
} }
if (output->use_tilt) if (private->use_tilt)
{ {
gdouble tilt_value = MAX (fabs (coords->xtilt), fabs (coords->ytilt)); gdouble tilt_value = MAX (fabs (coords->xtilt), fabs (coords->ytilt));
tilt_value = gimp_curve_map_value (output->tilt_curve, tilt_value = gimp_curve_map_value (private->tilt_curve,
tilt_value); tilt_value);
total += tilt_value; total += tilt_value;
@ -627,9 +670,10 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
factors++; factors++;
} }
if (output->use_wheel) if (private->use_wheel)
{ {
gdouble wheel = gimp_curve_map_value (output->wheel_curve, coords->wheel); gdouble wheel = gimp_curve_map_value (private->wheel_curve,
coords->wheel);
if (((wheel > 0.875) && (wheel <= 1.0)) || if (((wheel > 0.875) && (wheel <= 1.0)) ||
((wheel > 0.0) && (wheel < 0.125)) || ((wheel > 0.0) && (wheel < 0.125)) ||
@ -641,18 +685,18 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
} }
if (output->use_random) if (private->use_random)
{ {
gdouble random = gimp_curve_map_value (output->random_curve, gdouble random = gimp_curve_map_value (private->random_curve,
g_random_double_range (0.0, 1.0)); g_random_double_range (0.0, 1.0));
total += random; total += random;
factors++; factors++;
} }
if (output->use_fade) if (private->use_fade)
{ {
total += gimp_curve_map_value (output->fade_curve, fade_point); total += gimp_curve_map_value (private->fade_curve, fade_point);
factors++; factors++;
} }

View File

@ -34,25 +34,7 @@ typedef struct _GimpDynamicsOutputClass GimpDynamicsOutputClass;
struct _GimpDynamicsOutput struct _GimpDynamicsOutput
{ {
GimpObject parent_instance; GimpObject parent_instance;
GimpDynamicsOutputType type;
gboolean use_pressure;
gboolean use_velocity;
gboolean use_direction;
gboolean use_tilt;
gboolean use_wheel;
gboolean use_random;
gboolean use_fade;
GimpCurve *pressure_curve;
GimpCurve *velocity_curve;
GimpCurve *direction_curve;
GimpCurve *tilt_curve;
GimpCurve *wheel_curve;
GimpCurve *random_curve;
GimpCurve *fade_curve;
}; };
struct _GimpDynamicsOutputClass struct _GimpDynamicsOutputClass