diff --git a/ChangeLog b/ChangeLog index 75793fc300..e4d9da8a78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-05-19 Sven Neumann + + * app/core/gimpdashpattern.[ch] + * app/widgets/gimpdasheditor.c: moved more code out of + GimpDashEditor to gimpdashpattern.c. Fixed bug in last commit. + 2005-05-19 Sven Neumann * app/core/gimpdashpattern.[ch] diff --git a/app/core/gimpdashpattern.c b/app/core/gimpdashpattern.c index 64fb89d699..ea2cbd7406 100644 --- a/app/core/gimpdashpattern.c +++ b/app/core/gimpdashpattern.c @@ -148,6 +148,51 @@ gimp_dash_pattern_from_segments (const gboolean *segments, return pattern; } +void +gimp_dash_pattern_segments_set (GArray *pattern, + gboolean *segments, + gint n_segments) +{ + gdouble factor; + gdouble sum; + gint i, j; + gboolean paint; + + g_return_if_fail (segments != NULL || n_segments == 0); + + if (pattern == NULL || pattern->len <= 1) + { + for (i = 0; i < n_segments; i++) + segments[i] = TRUE; + + return; + } + + for (i = 0, sum = 0; i < pattern->len ; i++) + { + sum += g_array_index (pattern, gdouble, i); + } + + factor = ((gdouble) n_segments) / sum; + + j = 0; + sum = g_array_index (pattern, gdouble, j) * factor; + paint = TRUE; + + for (i = 0; i < n_segments ; i++) + { + while (j < pattern->len && sum <= i) + { + paint = ! paint; + j++; + sum += g_array_index (pattern, gdouble, j) * factor; + } + + segments[i] = paint; + } +} + + GArray * gimp_dash_pattern_from_value (const GValue *value) { diff --git a/app/core/gimpdashpattern.h b/app/core/gimpdashpattern.h index 9a0e81b107..7d2db9db47 100644 --- a/app/core/gimpdashpattern.h +++ b/app/core/gimpdashpattern.h @@ -25,9 +25,14 @@ GArray * gimp_dash_pattern_from_preset (GimpDashPreset preset); + GArray * gimp_dash_pattern_from_segments (const gboolean *segments, gint n_segments, gdouble dash_length); +void gimp_dash_pattern_segments_set (GArray *pattern, + gboolean *segments, + gint n_segments); + GArray * gimp_dash_pattern_from_value (const GValue *value); void gimp_dash_pattern_value_set (GArray *pattern, GValue *value); diff --git a/app/widgets/gimpdasheditor.c b/app/widgets/gimpdasheditor.c index 2821aa6934..474ccf910d 100644 --- a/app/widgets/gimpdasheditor.c +++ b/app/widgets/gimpdasheditor.c @@ -472,11 +472,6 @@ gimp_dash_editor_shift_left (GimpDashEditor *editor) static void update_segments_from_options (GimpDashEditor *editor) { - gdouble factor, sum = 0; - gint i, j; - gboolean paint; - GArray *dash_info; - if (editor->stroke_options == NULL || editor->segments == NULL) return; @@ -484,54 +479,30 @@ update_segments_from_options (GimpDashEditor *editor) gtk_widget_queue_draw (GTK_WIDGET (editor)); - dash_info = editor->stroke_options->dash_info; - - if (dash_info == NULL || dash_info->len <= 1) - { - for (i = 0; i < editor->n_segments; i++) - editor->segments[i] = TRUE; - - return; - } - - for (i = 0; i < dash_info->len ; i++) - { - sum += g_array_index (dash_info, gdouble, i); - } - - factor = ((gdouble) editor->n_segments) / sum; - - j = 0; - sum = g_array_index (dash_info, gdouble, j) * factor; - paint = TRUE; - - for (i = 0; i < editor->n_segments ; i++) - { - while (j < dash_info->len && sum <= i) - { - paint = ! paint; - j++; - sum += g_array_index (dash_info, gdouble, j) * factor; - } - - editor->segments[i] = paint; - } + gimp_dash_pattern_segments_set (editor->stroke_options->dash_info, + editor->segments, editor->n_segments); } static void update_options_from_segments (GimpDashEditor *editor) { - GArray *dash_info; + GArray *pattern; + GValue value = { 0, }; - dash_info = gimp_dash_pattern_from_segments (editor->segments, - editor->n_segments, - editor->dash_length); + pattern = gimp_dash_pattern_from_segments (editor->segments, + editor->n_segments, + editor->dash_length); - g_object_set (G_OBJECT (editor->stroke_options), - "dash-info", dash_info, - NULL); + g_value_init (&value, G_TYPE_VALUE_ARRAY); - g_array_free (dash_info, TRUE); + gimp_dash_pattern_value_set (pattern, &value); + + g_array_free (pattern, TRUE); + + g_object_set_property (G_OBJECT (editor->stroke_options), + "dash-info", &value); + + g_value_unset (&value); } static void