From 5fda650281eec30f577cbfffecb394a2b0d8e082 Mon Sep 17 00:00:00 2001 From: Alexia Death Date: Tue, 9 Mar 2010 22:22:38 +0200 Subject: [PATCH] app: Support for wheel input found in highend wacom tablets&tools --- app/core/gimpdynamicsoutput.c | 77 +++++++++++++++++++++++--- app/core/gimpdynamicsoutput.h | 2 + app/widgets/gimpdynamicseditor.c | 12 +++- app/widgets/gimpdynamicsoutputeditor.c | 29 ++++++++++ 4 files changed, 110 insertions(+), 10 deletions(-) diff --git a/app/core/gimpdynamicsoutput.c b/app/core/gimpdynamicsoutput.c index a55ccea4f5..af1331d178 100644 --- a/app/core/gimpdynamicsoutput.c +++ b/app/core/gimpdynamicsoutput.c @@ -39,6 +39,7 @@ #define DEFAULT_USE_VELOCITY FALSE #define DEFAULT_USE_DIRECTION FALSE #define DEFAULT_USE_TILT FALSE +#define DEFAULT_USE_WHEEL FALSE #define DEFAULT_USE_RANDOM FALSE #define DEFAULT_USE_FADE FALSE @@ -52,12 +53,14 @@ enum PROP_USE_VELOCITY, PROP_USE_DIRECTION, PROP_USE_TILT, + PROP_USE_WHEEL, PROP_USE_RANDOM, PROP_USE_FADE, PROP_PRESSURE_CURVE, PROP_VELOCITY_CURVE, PROP_DIRECTION_CURVE, PROP_TILT_CURVE, + PROP_WHEEL_CURVE, PROP_RANDOM_CURVE, PROP_FADE_CURVE }; @@ -126,6 +129,12 @@ gimp_dynamics_output_class_init (GimpDynamicsOutputClass *klass) DEFAULT_USE_TILT, GIMP_PARAM_STATIC_STRINGS); + + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_WHEEL, + "use-wheel", NULL, + DEFAULT_USE_TILT, + GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_USE_RANDOM, "use-random", NULL, DEFAULT_USE_RANDOM, @@ -156,6 +165,11 @@ gimp_dynamics_output_class_init (GimpDynamicsOutputClass *klass) GIMP_TYPE_CURVE, GIMP_CONFIG_PARAM_AGGREGATE); + GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_WHEEL_CURVE, + "wheel-curve", NULL, + GIMP_TYPE_CURVE, + GIMP_CONFIG_PARAM_AGGREGATE); + GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_RANDOM_CURVE, "random-curve", NULL, GIMP_TYPE_CURVE, @@ -179,6 +193,8 @@ gimp_dynamics_output_init (GimpDynamicsOutput *output) "direction-curve"); output->tilt_curve = gimp_dynamics_output_create_curve (output, "tilt-curve"); + output->wheel_curve = gimp_dynamics_output_create_curve (output, + "wheel-curve"); output->random_curve = gimp_dynamics_output_create_curve (output, "random-curve"); output->fade_curve = gimp_dynamics_output_create_curve (output, @@ -194,6 +210,7 @@ gimp_dynamics_output_finalize (GObject *object) g_object_unref (output->velocity_curve); g_object_unref (output->direction_curve); g_object_unref (output->tilt_curve); + g_object_unref (output->wheel_curve); g_object_unref (output->random_curve); g_object_unref (output->fade_curve); @@ -230,6 +247,10 @@ gimp_dynamics_output_set_property (GObject *object, output->use_tilt = g_value_get_boolean (value); break; + case PROP_USE_WHEEL: + output->use_wheel = g_value_get_boolean (value); + break; + case PROP_USE_RANDOM: output->use_random = g_value_get_boolean (value); break; @@ -258,6 +279,11 @@ gimp_dynamics_output_set_property (GObject *object, output->tilt_curve); break; + case PROP_WHEEL_CURVE: + gimp_dynamics_output_copy_curve (g_value_get_object (value), + output->wheel_curve); + break; + case PROP_RANDOM_CURVE: gimp_dynamics_output_copy_curve (g_value_get_object (value), output->random_curve); @@ -304,6 +330,10 @@ gimp_dynamics_output_get_property (GObject *object, g_value_set_boolean (value, output->use_tilt); break; + case PROP_USE_WHEEL: + g_value_set_boolean (value, output->use_wheel); + break; + case PROP_USE_RANDOM: g_value_set_boolean (value, output->use_random); break; @@ -328,6 +358,10 @@ gimp_dynamics_output_get_property (GObject *object, g_value_set_object (value, output->tilt_curve); break; + case PROP_WHEEL_CURVE: + g_value_set_object (value, output->wheel_curve); + break; + case PROP_RANDOM_CURVE: g_value_set_object (value, output->random_curve); break; @@ -364,6 +398,7 @@ gimp_dynamics_output_is_enabled (GimpDynamicsOutput *output) output->use_velocity || output->use_direction || output->use_tilt || + output->use_wheel || output->use_random || output->use_fade); } @@ -406,6 +441,18 @@ gimp_dynamics_output_get_linear_value (GimpDynamicsOutput *output, factors++; } + if (output->use_wheel) + { + gdouble wheel; + if (coords->wheel >= 0.5) + wheel = (coords->wheel - 0.5) * 2; + else + wheel = 1 - coords->wheel * 2; + + total += gimp_curve_map_value (output->wheel_curve, wheel); + factors++; + } + if (output->use_random) { total += gimp_curve_map_value (output->random_curve, @@ -503,6 +550,14 @@ gimp_dynamics_output_get_angular_value (GimpDynamicsOutput *output, factors++; } + if (output->use_wheel) + { + gdouble angle = 1.0 - fmod(0.5 + coords->wheel, 1); + + total += gimp_curve_map_value (output->wheel_curve, angle); + factors++; + } + if (output->use_random) { total += gimp_curve_map_value (output->random_curve, @@ -544,26 +599,26 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output, if (output->use_pressure) { - total += gimp_curve_map_value (output->pressure_curve, 2 * coords->pressure); + total += 2 * gimp_curve_map_value (output->pressure_curve, coords->pressure); factors++; } if (output->use_velocity) { - total += gimp_curve_map_value (output->velocity_curve, 2 * coords->velocity); + total += 2 * gimp_curve_map_value (output->velocity_curve, coords->velocity); factors++; } if (output->use_direction) { - gdouble direction = 0.0; + gdouble direction = gimp_curve_map_value (output->direction_curve, coords->direction); - direction = fmod (1 + coords->direction, 0.5) / 0.25; + direction = fmod (1 + direction, 0.5) / 0.25; if ((coords->direction > 0.0) && (coords->direction < 0.5)) direction = 1 / direction; - total += gimp_curve_map_value (output->direction_curve, direction); + total += direction; factors++; } @@ -575,16 +630,23 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output, factors++; } + if (output->use_wheel) + { + total += 2 * gimp_curve_map_value (output->wheel_curve, coords->wheel); + factors++; + } + if (output->use_random) { - gdouble random = g_random_double_range (0.0, 1.0); + gdouble random = gimp_curve_map_value (output->random_curve, + g_random_double_range (0.0, 1.0)); if (random <= 0.5) random = 1 / (random / 0.5 * (2.0 - 1.0) + 1.0); else random = (random - 0.5) / (1.0 - 0.5) * (2.0 - 1.0) + 1.0; - total += gimp_curve_map_value (output->random_curve, random); + total += random; factors++; } @@ -606,6 +668,7 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output, g_printerr ("Dynamics queried(aspect). Result: %f, factors: %d, total: %f\n", result, factors, total); #endif + if (result < 0.25) result = 0.25; return result; } diff --git a/app/core/gimpdynamicsoutput.h b/app/core/gimpdynamicsoutput.h index d807a504c1..6750fa5e13 100644 --- a/app/core/gimpdynamicsoutput.h +++ b/app/core/gimpdynamicsoutput.h @@ -42,6 +42,7 @@ struct _GimpDynamicsOutput gboolean use_velocity; gboolean use_direction; gboolean use_tilt; + gboolean use_wheel; gboolean use_random; gboolean use_fade; @@ -49,6 +50,7 @@ struct _GimpDynamicsOutput GimpCurve *velocity_curve; GimpCurve *direction_curve; GimpCurve *tilt_curve; + GimpCurve *wheel_curve; GimpCurve *random_curve; GimpCurve *fade_curve; }; diff --git a/app/widgets/gimpdynamicseditor.c b/app/widgets/gimpdynamicseditor.c index fb069fe9dc..09410a08e5 100644 --- a/app/widgets/gimpdynamicseditor.c +++ b/app/widgets/gimpdynamicseditor.c @@ -98,7 +98,7 @@ gimp_dynamics_editor_init (GimpDynamicsEditor *editor) GimpDataEditor *data_editor = GIMP_DATA_EDITOR (editor); GimpDynamics *dynamics; GtkWidget *fixed; - GtkWidget *input_labels[6]; + GtkWidget *input_labels[7]; GtkWidget *frame; gint n_inputs = G_N_ELEMENTS (input_labels); gint i; @@ -147,8 +147,9 @@ gimp_dynamics_editor_init (GimpDynamicsEditor *editor) input_labels[1] = gtk_label_new (_("Velocity")); input_labels[2] = gtk_label_new (_("Direction")); input_labels[3] = gtk_label_new (_("Tilt")); - input_labels[4] = gtk_label_new (_("Random")); - input_labels[5] = gtk_label_new (_("Fade")); + input_labels[4] = gtk_label_new (_("Wheel")); + input_labels[5] = gtk_label_new (_("Random")); + input_labels[6] = gtk_label_new (_("Fade")); fixed = gtk_fixed_new (); @@ -320,6 +321,11 @@ gimp_dynamics_editor_add_output_row (GObject *config, column++; + button = dynamics_check_button_new (config, "use-wheel", + table, column, row); + + column++; + button = dynamics_check_button_new (config, "use-random", table, column, row); diff --git a/app/widgets/gimpdynamicsoutputeditor.c b/app/widgets/gimpdynamicsoutputeditor.c index 6556b3a470..7da8af2017 100644 --- a/app/widgets/gimpdynamicsoutputeditor.c +++ b/app/widgets/gimpdynamicsoutputeditor.c @@ -60,6 +60,7 @@ enum INPUT_VELOCITY, INPUT_DIRECTION, INPUT_TILT, + INPUT_WHEEL, INPUT_RANDOM, INPUT_FADE, N_INPUTS @@ -233,6 +234,13 @@ gimp_dynamics_output_editor_constructor (GType type, INPUT_COLUMN_NAME, _("Tilt"), -1); + gtk_list_store_insert_with_values (private->input_list, + NULL, INPUT_WHEEL, + INPUT_COLUMN_INDEX, INPUT_WHEEL, + INPUT_COLUMN_USE_INPUT, private->output->use_wheel, + INPUT_COLUMN_NAME, _("Wheel"), + -1); + gtk_list_store_insert_with_values (private->input_list, NULL, INPUT_RANDOM, INPUT_COLUMN_INDEX, INPUT_RANDOM, @@ -487,6 +495,19 @@ gimp_dynamics_output_editor_activate_input (gint input, &bg_color); } + if (input == INPUT_WHEEL) + { + gimp_curve_view_set_curve (GIMP_CURVE_VIEW (private->curve_view), + private->output->wheel_curve); + private->active_curve = private->output->wheel_curve; + } + else if (private->output->use_wheel) + { + gimp_curve_view_add_background (GIMP_CURVE_VIEW (private->curve_view), + private->output->wheel_curve, + &bg_color); + } + if (input == INPUT_RANDOM) { gimp_curve_view_set_curve (GIMP_CURVE_VIEW (private->curve_view), @@ -544,6 +565,11 @@ gimp_dynamics_output_editor_use_input (gint input, private->output->use_tilt = value; g_object_notify (G_OBJECT (private->output), "use-tilt"); } + if (input == INPUT_WHEEL) + { + private->output->use_wheel = value; + g_object_notify (G_OBJECT (private->output), "use-wheel"); + } if (input == INPUT_RANDOM) { private->output->use_random = value; @@ -600,6 +626,9 @@ gimp_dynamics_output_editor_notify_output (GimpDynamicsOutput *output, case INPUT_TILT: value = output->use_tilt; break; + case INPUT_WHEEL: + value = output->use_wheel; + break; case INPUT_RANDOM: value = output->use_random; break;