mirror of https://github.com/GNOME/gimp.git
register GIMP_TYPE_DASH_PATTERN as boxed type. Added "new" to function
2007-01-12 Michael Natterer <mitch@gimp.org> * app/core/gimpdashpattern.[ch]: register GIMP_TYPE_DASH_PATTERN as boxed type. Added "new" to function names which create dash patterns. Changed and renamed GValue functions to functions which convert the dash pattern between GArray and GValueArray. * app/core/gimpstrokeoptions.c * app/widgets/gimpcellrendererdashes.c * app/widgets/gimpstrokeeditor.c: changed accordingly. * app/widgets/gimpdasheditor.c: ditto. Get rid of the recently added manual memory management. The list store manages boxed types all by itself. svn path=/trunk/; revision=21698
This commit is contained in:
parent
517b0c35ab
commit
09f47a0aec
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2007-01-12 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/gimpdashpattern.[ch]: register GIMP_TYPE_DASH_PATTERN
|
||||
as boxed type. Added "new" to function names which create dash
|
||||
patterns. Changed and renamed GValue functions to functions which
|
||||
convert the dash pattern between GArray and GValueArray.
|
||||
|
||||
* app/core/gimpstrokeoptions.c
|
||||
* app/widgets/gimpcellrendererdashes.c
|
||||
* app/widgets/gimpstrokeeditor.c: changed accordingly.
|
||||
|
||||
* app/widgets/gimpdasheditor.c: ditto. Get rid of the recently
|
||||
added manual memory management. The list store manages boxed types
|
||||
all by itself.
|
||||
|
||||
2007-01-12 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* tools/pdbgen/pdb/display.pdb
|
||||
|
|
|
@ -29,8 +29,21 @@
|
|||
#include "gimpdashpattern.h"
|
||||
|
||||
|
||||
GType
|
||||
gimp_dash_pattern_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
|
||||
if (! type)
|
||||
type = g_boxed_type_register_static ("GimpDashPattern",
|
||||
(GBoxedCopyFunc) gimp_dash_pattern_copy,
|
||||
(GBoxedFreeFunc) gimp_dash_pattern_free);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
GArray *
|
||||
gimp_dash_pattern_from_preset (GimpDashPreset preset)
|
||||
gimp_dash_pattern_new_from_preset (GimpDashPreset preset)
|
||||
{
|
||||
GArray *pattern;
|
||||
gdouble dash;
|
||||
|
@ -110,7 +123,7 @@ gimp_dash_pattern_from_preset (GimpDashPreset preset)
|
|||
|
||||
if (pattern->len < 2)
|
||||
{
|
||||
g_array_free (pattern, TRUE);
|
||||
gimp_dash_pattern_free (pattern);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -118,7 +131,7 @@ gimp_dash_pattern_from_preset (GimpDashPreset preset)
|
|||
}
|
||||
|
||||
GArray *
|
||||
gimp_dash_pattern_from_segments (const gboolean *segments,
|
||||
gimp_dash_pattern_new_from_segments (const gboolean *segments,
|
||||
gint n_segments,
|
||||
gdouble dash_length)
|
||||
{
|
||||
|
@ -150,7 +163,7 @@ gimp_dash_pattern_from_segments (const gboolean *segments,
|
|||
|
||||
if (pattern->len < 2)
|
||||
{
|
||||
g_array_free (pattern, TRUE);
|
||||
gimp_dash_pattern_free (pattern);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -158,7 +171,7 @@ gimp_dash_pattern_from_segments (const gboolean *segments,
|
|||
}
|
||||
|
||||
void
|
||||
gimp_dash_pattern_segments_set (GArray *pattern,
|
||||
gimp_dash_pattern_fill_segments (GArray *pattern,
|
||||
gboolean *segments,
|
||||
gint n_segments)
|
||||
{
|
||||
|
@ -201,16 +214,10 @@ gimp_dash_pattern_segments_set (GArray *pattern,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
GArray *
|
||||
gimp_dash_pattern_from_value (const GValue *value)
|
||||
gimp_dash_pattern_from_value_array (GValueArray *value_array)
|
||||
{
|
||||
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)
|
||||
if (value_array == NULL || value_array->n_values == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -220,11 +227,11 @@ gimp_dash_pattern_from_value (const GValue *value)
|
|||
gint i;
|
||||
|
||||
pattern = g_array_sized_new (FALSE, FALSE,
|
||||
sizeof (gdouble), val_array->n_values);
|
||||
sizeof (gdouble), value_array->n_values);
|
||||
|
||||
for (i = 0; i < val_array->n_values; i++)
|
||||
for (i = 0; i < value_array->n_values; i++)
|
||||
{
|
||||
GValue *item = g_value_array_get_nth (val_array, i);
|
||||
GValue *item = g_value_array_get_nth (value_array, i);
|
||||
gdouble val;
|
||||
|
||||
g_return_val_if_fail (G_VALUE_HOLDS_DOUBLE (item), NULL);
|
||||
|
@ -238,19 +245,16 @@ gimp_dash_pattern_from_value (const GValue *value)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_dash_pattern_value_set (GArray *pattern,
|
||||
GValue *value)
|
||||
GValueArray *
|
||||
gimp_dash_pattern_to_value_array (GArray *pattern)
|
||||
{
|
||||
g_return_if_fail (G_VALUE_HOLDS_BOXED (value));
|
||||
|
||||
if (pattern == NULL || pattern->len == 0)
|
||||
{
|
||||
g_value_set_boxed (value, NULL);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
GValueArray *val_array = g_value_array_new (pattern->len);
|
||||
GValueArray *value_array = g_value_array_new (pattern->len);
|
||||
GValue item = { 0, };
|
||||
gint i;
|
||||
|
||||
|
@ -259,10 +263,12 @@ gimp_dash_pattern_value_set (GArray *pattern,
|
|||
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_array_append (value_array, &item);
|
||||
}
|
||||
|
||||
g_value_set_boxed (value, val_array);
|
||||
g_value_unset (&item);
|
||||
|
||||
return value_array;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,18 +24,23 @@
|
|||
#define __GIMP_DASH_PATTERN_H__
|
||||
|
||||
|
||||
GArray * gimp_dash_pattern_from_preset (GimpDashPreset preset);
|
||||
#define GIMP_TYPE_DASH_PATTERN (gimp_dash_pattern_get_type ())
|
||||
#define GIMP_VALUE_HOLDS_DASH_PATTERN(value) (G_TYPE_CHECK_VALUE_TYPE ((value), GIMP_TYPE_DASH_PATTERN))
|
||||
|
||||
GArray * gimp_dash_pattern_from_segments (const gboolean *segments,
|
||||
|
||||
GType gimp_dash_pattern_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GArray * gimp_dash_pattern_new_from_preset (GimpDashPreset preset);
|
||||
GArray * gimp_dash_pattern_new_from_segments (const gboolean *segments,
|
||||
gint n_segments,
|
||||
gdouble dash_length);
|
||||
void gimp_dash_pattern_segments_set (GArray *pattern,
|
||||
|
||||
void gimp_dash_pattern_fill_segments (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);
|
||||
GArray * gimp_dash_pattern_from_value_array (GValueArray *value_array);
|
||||
GValueArray * gimp_dash_pattern_to_value_array (GArray *pattern);
|
||||
|
||||
GArray * gimp_dash_pattern_copy (GArray *pattern);
|
||||
void gimp_dash_pattern_free (GArray *pattern);
|
||||
|
|
|
@ -181,9 +181,14 @@ gimp_stroke_options_set_property (GObject *object,
|
|||
options->dash_offset = g_value_get_double (value);
|
||||
break;
|
||||
case PROP_DASH_INFO:
|
||||
gimp_stroke_options_set_dash_pattern (options,
|
||||
GIMP_DASH_CUSTOM,
|
||||
gimp_dash_pattern_from_value (value));
|
||||
{
|
||||
GValueArray *value_array = g_value_get_boxed (value);
|
||||
GArray *pattern;
|
||||
|
||||
pattern = gimp_dash_pattern_from_value_array (value_array);
|
||||
gimp_stroke_options_set_dash_pattern (options, GIMP_DASH_CUSTOM,
|
||||
pattern);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -227,7 +232,12 @@ gimp_stroke_options_get_property (GObject *object,
|
|||
g_value_set_double (value, options->dash_offset);
|
||||
break;
|
||||
case PROP_DASH_INFO:
|
||||
gimp_dash_pattern_value_set (options->dash_info, value);
|
||||
{
|
||||
GValueArray *value_array;
|
||||
|
||||
value_array = gimp_dash_pattern_to_value_array (options->dash_info);
|
||||
g_value_take_boxed (value, value_array);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -256,16 +266,15 @@ gimp_stroke_options_set_dash_pattern (GimpStrokeOptions *options,
|
|||
g_return_if_fail (preset == GIMP_DASH_CUSTOM || pattern == NULL);
|
||||
|
||||
if (preset != GIMP_DASH_CUSTOM)
|
||||
pattern = gimp_dash_pattern_from_preset (preset);
|
||||
pattern = gimp_dash_pattern_new_from_preset (preset);
|
||||
|
||||
if (options->dash_info)
|
||||
g_array_free (options->dash_info, TRUE);
|
||||
gimp_dash_pattern_free (options->dash_info);
|
||||
|
||||
options->dash_info = pattern;
|
||||
|
||||
g_object_notify (G_OBJECT (options), "dash-info");
|
||||
|
||||
g_signal_emit (options,
|
||||
stroke_options_signals [DASH_INFO_CHANGED], 0,
|
||||
g_signal_emit (options, stroke_options_signals [DASH_INFO_CHANGED], 0,
|
||||
preset);
|
||||
}
|
||||
|
|
|
@ -89,7 +89,8 @@ gimp_cell_renderer_dashes_class_init (GimpCellRendererDashesClass *klass)
|
|||
cell_class->render = gimp_cell_renderer_dashes_render;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_PATTERN,
|
||||
g_param_spec_pointer ("pattern", NULL, NULL,
|
||||
g_param_spec_boxed ("pattern", NULL, NULL,
|
||||
GIMP_TYPE_DASH_PATTERN,
|
||||
GIMP_PARAM_WRITABLE));
|
||||
}
|
||||
|
||||
|
@ -129,7 +130,7 @@ gimp_cell_renderer_dashes_set_property (GObject *object,
|
|||
switch (param_id)
|
||||
{
|
||||
case PROP_PATTERN:
|
||||
gimp_dash_pattern_segments_set (g_value_get_pointer (value),
|
||||
gimp_dash_pattern_fill_segments (g_value_get_boxed (value),
|
||||
dashes->segments, N_SEGMENTS);
|
||||
break;
|
||||
|
||||
|
|
|
@ -448,14 +448,14 @@ update_segments_from_options (GimpDashEditor *editor)
|
|||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (editor));
|
||||
|
||||
gimp_dash_pattern_segments_set (editor->stroke_options->dash_info,
|
||||
gimp_dash_pattern_fill_segments (editor->stroke_options->dash_info,
|
||||
editor->segments, editor->n_segments);
|
||||
}
|
||||
|
||||
static void
|
||||
update_options_from_segments (GimpDashEditor *editor)
|
||||
{
|
||||
GArray *pattern = gimp_dash_pattern_from_segments (editor->segments,
|
||||
GArray *pattern = gimp_dash_pattern_new_from_segments (editor->segments,
|
||||
editor->n_segments,
|
||||
editor->dash_length);
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ static void gimp_stroke_editor_dash_preset (GtkWidget *widget,
|
|||
|
||||
static void gimp_stroke_editor_combo_fill (GimpStrokeOptions *options,
|
||||
GtkComboBox *box);
|
||||
static void gimp_stroke_editor_combo_void (GtkComboBox *box);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpStrokeEditor, gimp_stroke_editor, GTK_TYPE_VBOX)
|
||||
|
@ -86,6 +85,7 @@ gimp_stroke_editor_class_init (GimpStrokeEditorClass *klass)
|
|||
GIMP_TYPE_STROKE_OPTIONS,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_RESOLUTION,
|
||||
g_param_spec_double ("resolution", NULL, NULL,
|
||||
GIMP_MIN_RESOLUTION,
|
||||
|
@ -113,7 +113,7 @@ gimp_stroke_editor_set_property (GObject *object,
|
|||
case PROP_OPTIONS:
|
||||
if (editor->options)
|
||||
g_object_unref (editor->options);
|
||||
editor->options = GIMP_STROKE_OPTIONS (g_value_dup_object (value));
|
||||
editor->options = g_value_dup_object (value);
|
||||
break;
|
||||
case PROP_RESOLUTION:
|
||||
editor->resolution = g_value_get_double (value);
|
||||
|
@ -154,6 +154,8 @@ gimp_stroke_editor_constructor (GType type,
|
|||
GObjectConstructParam *params)
|
||||
{
|
||||
GimpStrokeEditor *editor;
|
||||
GimpEnumStore *store;
|
||||
GEnumValue *value;
|
||||
GtkWidget *box;
|
||||
GtkWidget *size;
|
||||
GtkWidget *label;
|
||||
|
@ -270,7 +272,28 @@ gimp_stroke_editor_constructor (GType type,
|
|||
NULL);
|
||||
|
||||
|
||||
box = gimp_enum_combo_box_new (GIMP_TYPE_DASH_PRESET);
|
||||
store = g_object_new (GIMP_TYPE_ENUM_STORE,
|
||||
"enum-type", GIMP_TYPE_DASH_PRESET,
|
||||
"user-data-type", GIMP_TYPE_DASH_PATTERN,
|
||||
NULL);
|
||||
|
||||
for (value = store->enum_class->values; value->value_name; value++)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
const gchar *desc;
|
||||
|
||||
desc = gimp_enum_value_get_desc (store->enum_class, value);
|
||||
|
||||
gtk_list_store_append (GTK_LIST_STORE (store), &iter);
|
||||
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
|
||||
GIMP_INT_STORE_VALUE, value->value,
|
||||
GIMP_INT_STORE_LABEL, desc,
|
||||
-1);
|
||||
}
|
||||
|
||||
box = gimp_enum_combo_box_new_with_model (store);
|
||||
g_object_unref (store);
|
||||
|
||||
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (box), GIMP_DASH_CUSTOM);
|
||||
gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
|
||||
_("Dash _preset:"), 0.0, 0.5,
|
||||
|
@ -285,9 +308,6 @@ gimp_stroke_editor_constructor (GType type,
|
|||
|
||||
gimp_stroke_editor_combo_fill (editor->options, GTK_COMBO_BOX (box));
|
||||
|
||||
g_signal_connect (box, "destroy",
|
||||
G_CALLBACK (gimp_stroke_editor_combo_void),
|
||||
NULL);
|
||||
g_signal_connect (box, "changed",
|
||||
G_CALLBACK (gimp_stroke_editor_dash_preset),
|
||||
editor->options);
|
||||
|
@ -372,16 +392,8 @@ gimp_stroke_editor_combo_update (GtkTreeModel *model,
|
|||
|
||||
if (gimp_int_store_lookup_by_value (model, GIMP_DASH_CUSTOM, &iter))
|
||||
{
|
||||
GArray *pattern;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
GIMP_INT_STORE_USER_DATA, &pattern,
|
||||
-1);
|
||||
gimp_dash_pattern_free (pattern);
|
||||
|
||||
pattern = gimp_dash_pattern_copy (options->dash_info);
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
GIMP_INT_STORE_USER_DATA, pattern,
|
||||
GIMP_INT_STORE_USER_DATA, options->dash_info,
|
||||
-1);
|
||||
}
|
||||
}
|
||||
|
@ -398,7 +410,6 @@ gimp_stroke_editor_combo_fill (GimpStrokeOptions *options,
|
|||
iter_valid;
|
||||
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
||||
{
|
||||
GArray *pattern;
|
||||
gint value;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
|
@ -407,7 +418,9 @@ gimp_stroke_editor_combo_fill (GimpStrokeOptions *options,
|
|||
|
||||
if (value == GIMP_DASH_CUSTOM)
|
||||
{
|
||||
pattern = gimp_dash_pattern_copy (options->dash_info);
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
GIMP_INT_STORE_USER_DATA, options->dash_info,
|
||||
-1);
|
||||
|
||||
g_signal_connect_object (options, "notify::dash-info",
|
||||
G_CALLBACK (gimp_stroke_editor_combo_update),
|
||||
|
@ -415,35 +428,12 @@ gimp_stroke_editor_combo_fill (GimpStrokeOptions *options,
|
|||
}
|
||||
else
|
||||
{
|
||||
pattern = gimp_dash_pattern_from_preset (value);
|
||||
}
|
||||
GArray *pattern = gimp_dash_pattern_new_from_preset (value);
|
||||
|
||||
if (pattern)
|
||||
{
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
GIMP_INT_STORE_USER_DATA, pattern,
|
||||
-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_stroke_editor_combo_void (GtkComboBox *box)
|
||||
{
|
||||
GtkTreeModel *model = gtk_combo_box_get_model (box);
|
||||
GtkTreeIter iter;
|
||||
gboolean iter_valid;
|
||||
|
||||
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
|
||||
iter_valid;
|
||||
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
||||
{
|
||||
GArray *pattern;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
GIMP_INT_STORE_USER_DATA, &pattern,
|
||||
-1);
|
||||
|
||||
gimp_dash_pattern_free (pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue