mirror of https://github.com/GNOME/gimp.git
app/core/gimpdashpattern.[ch] moved more code out of GimpDashEditor to
2005-05-19 Sven Neumann <sven@gimp.org> * app/core/gimpdashpattern.[ch] * app/widgets/gimpdasheditor.c: moved more code out of GimpDashEditor to gimpdashpattern.c. Fixed bug in last commit.
This commit is contained in:
parent
c7ba1dfc71
commit
9bb255a3cf
|
@ -1,3 +1,9 @@
|
|||
2005-05-19 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* 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 <sven@gimp.org>
|
||||
|
||||
* app/core/gimpdashpattern.[ch]
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue