Commit 533481d2 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/core/gimpdashpattern.[ch] moved more code to the new files.

2005-05-19  Sven Neumann  <sven@gimp.org>

	* app/core/gimpdashpattern.[ch]
	* app/core/gimpstrokeoptions.c: moved more code to the new files.
parent 146e4eee
2005-05-19 Sven Neumann <sven@gimp.org>
* app/core/gimpdashpattern.[ch]
* app/core/gimpstrokeoptions.c: moved more code to the new files.
2005-05-19 Sven Neumann <sven@gimp.org>
* app/core/Makefile.am
......
......@@ -107,3 +107,67 @@ gimp_dash_pattern_from_preset (GimpDashPreset preset)
return pattern;
}
GArray *
gimp_dash_pattern_from_value (const GValue *value)
{
GValueArray *val_array;
g_return_val_if_fail (G_VALUE_HOLDS_BOXED (value), NULL);
val_array = g_value_get_boxed (value);
if (val_array == NULL || val_array->n_values == 0)
{
return NULL;
}
else
{
GArray *pattern;
gint i;
pattern = g_array_sized_new (FALSE, FALSE,
sizeof (gdouble), val_array->n_values);
for (i = 0; i < val_array->n_values; i++)
{
GValue *item = g_value_array_get_nth (val_array, i);
gdouble val;
g_return_val_if_fail (G_VALUE_HOLDS_DOUBLE (item), NULL);
val = g_value_get_double (item);
pattern = g_array_append_val (pattern, val);
}
return pattern;
}
}
void
gimp_dash_pattern_set_value (GArray *pattern,
GValue *value)
{
g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
if (pattern == NULL || pattern->len == 0)
{
g_value_set_boxed (value, NULL);
}
else
{
GValueArray *val_array = g_value_array_new (pattern->len);
GValue item = { 0, };
gint i;
g_value_init (&item, G_TYPE_DOUBLE);
for (i = 0; i < pattern->len; i++)
{
g_value_set_double (&item, g_array_index (pattern, gdouble, i));
g_value_array_append (val_array, &item);
}
g_value_set_boxed (value, val_array);
}
}
......@@ -25,6 +25,9 @@
GArray * gimp_dash_pattern_from_preset (GimpDashPreset preset);
GArray * gimp_dash_pattern_from_value (const GValue *value);
void gimp_dash_pattern_set_value (GArray *pattern,
GValue *value);
#endif /* __GIMP_DASH_PATTERN_H__ */
......@@ -55,16 +55,21 @@ enum
};
static void gimp_stroke_options_class_init (GimpStrokeOptionsClass *klass);
static void gimp_stroke_options_class_init (GimpStrokeOptionsClass *klass);
static void gimp_stroke_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_stroke_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_stroke_options_set_dash_info (GimpStrokeOptions *options,
GArray *pattern,
GimpDashPreset preset);
static void gimp_stroke_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_stroke_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static guint stroke_options_signals[LAST_SIGNAL] = { 0 };
......@@ -201,42 +206,9 @@ gimp_stroke_options_set_property (GObject *object,
options->dash_offset = g_value_get_double (value);
break;
case PROP_DASH_INFO:
{
GValueArray *val_array;
GValue *item;
gint i;
gdouble val;
if (options->dash_info)
g_array_free (options->dash_info, TRUE);
val_array = g_value_get_boxed (value);
if (val_array == NULL || val_array->n_values == 0)
{
options->dash_info = NULL;
}
else
{
options->dash_info = g_array_sized_new (FALSE, FALSE,
sizeof (gdouble),
val_array->n_values);
for (i=0; i < val_array->n_values; i++)
{
item = g_value_array_get_nth (val_array, i);
g_return_if_fail (G_VALUE_HOLDS_DOUBLE (item));
val = g_value_get_double (item);
options->dash_info = g_array_append_val (options->dash_info,
val);
}
}
g_signal_emit (options,
stroke_options_signals [DASH_INFO_CHANGED], 0,
GIMP_DASH_CUSTOM);
}
gimp_stroke_options_set_dash_info (options,
gimp_dash_pattern_from_value (value),
GIMP_DASH_CUSTOM);
break;
default:
......@@ -280,33 +252,7 @@ gimp_stroke_options_get_property (GObject *object,
g_value_set_double (value, options->dash_offset);
break;
case PROP_DASH_INFO:
{
GValueArray *val_array;
GValue item = { 0, };
gint i;
g_value_init (&item, G_TYPE_DOUBLE);
if (options->dash_info == NULL || options->dash_info->len == 0)
{
g_value_set_boxed (value, NULL);
}
else
{
val_array = g_value_array_new (options->dash_info->len);
for (i=0; i < options->dash_info->len; i++)
{
g_value_set_double (&item, g_array_index (options->dash_info,
gdouble,
i));
g_value_array_append (val_array, &item);
}
g_value_set_boxed (value, val_array);
}
}
gimp_dash_pattern_set_value (options->dash_info, value);
break;
default:
......@@ -322,13 +268,24 @@ gimp_stroke_options_set_dash_preset (GimpStrokeOptions *options,
if (preset == GIMP_DASH_CUSTOM)
return;
if (options->dash_info != NULL)
gimp_stroke_options_set_dash_info (options,
gimp_dash_pattern_from_preset (preset),
preset);
g_object_notify (G_OBJECT (options), "dash-info");
}
static void
gimp_stroke_options_set_dash_info (GimpStrokeOptions *options,
GArray *pattern,
GimpDashPreset preset)
{
if (options->dash_info)
g_array_free (options->dash_info, TRUE);
options->dash_info = gimp_dash_pattern_from_preset (preset);
options->dash_info = pattern;
g_signal_emit (options,
stroke_options_signals [DASH_INFO_CHANGED], 0,
preset);
g_object_notify (G_OBJECT (options), "dash-info");
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment