app: wrap GimpBezierDesc in a boxed type to make property handling easier

This commit is contained in:
Michael Natterer 2010-10-08 18:52:28 +02:00
parent 914ac9aa11
commit 6b8141d548
5 changed files with 38 additions and 43 deletions

View File

@ -104,7 +104,8 @@ gimp_canvas_path_class_init (GimpCanvasPathClass *klass)
item_class->stroke = gimp_canvas_path_stroke; item_class->stroke = gimp_canvas_path_stroke;
g_object_class_install_property (object_class, PROP_PATH, g_object_class_install_property (object_class, PROP_PATH,
g_param_spec_pointer ("path", NULL, NULL, g_param_spec_boxed ("path", NULL, NULL,
GIMP_TYPE_BEZIER_DESC,
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_FILLED, g_object_class_install_property (object_class, PROP_FILLED,
@ -133,7 +134,7 @@ gimp_canvas_path_finalize (GObject *object)
if (private->path) if (private->path)
{ {
gimp_bezier_desc_free (private->path, TRUE); gimp_bezier_desc_free (private->path);
private->path = NULL; private->path = NULL;
} }
@ -151,18 +152,9 @@ gimp_canvas_path_set_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_PATH: case PROP_PATH:
{
cairo_path_t *path = g_value_get_pointer (value);
if (private->path) if (private->path)
{ gimp_bezier_desc_free (private->path);
gimp_bezier_desc_free (private->path, TRUE); private->path = g_value_dup_boxed (value);
private->path = NULL;
}
if (path)
private->path = gimp_bezier_desc_copy (path);
}
break; break;
case PROP_FILLED: case PROP_FILLED:
private->filled = g_value_get_boolean (value); private->filled = g_value_get_boolean (value);
@ -188,7 +180,7 @@ gimp_canvas_path_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_PATH: case PROP_PATH:
g_value_set_pointer (value, private->path); g_value_set_boxed (value, private->path);
break; break;
case PROP_FILLED: case PROP_FILLED:
g_value_set_boolean (value, private->filled); g_value_set_boolean (value, private->filled);

View File

@ -28,6 +28,19 @@
#include "gimpbezierdesc.h" #include "gimpbezierdesc.h"
GType
gimp_bezier_desc_get_type (void)
{
static GType type = 0;
if (! type)
type = g_boxed_type_register_static ("GimpBezierDesc",
(GBoxedCopyFunc) gimp_bezier_desc_copy,
(GBoxedFreeFunc) gimp_bezier_desc_free);
return type;
}
GimpBezierDesc * GimpBezierDesc *
gimp_bezier_desc_new (cairo_path_data_t *data, gimp_bezier_desc_new (cairo_path_data_t *data,
gint n_data) gint n_data)
@ -55,25 +68,11 @@ gimp_bezier_desc_copy (const GimpBezierDesc *desc)
desc->num_data); desc->num_data);
} }
cairo_path_data_t * void
gimp_bezier_desc_free (GimpBezierDesc *desc, gimp_bezier_desc_free (GimpBezierDesc *desc)
gboolean free_data)
{ {
cairo_path_data_t *data; g_return_if_fail (desc != NULL);
g_return_val_if_fail (desc != NULL, NULL);
if (free_data)
{
g_free (desc->data); g_free (desc->data);
data = NULL;
}
else
{
data = desc->data;
}
g_slice_free (GimpBezierDesc, desc); g_slice_free (GimpBezierDesc, desc);
return data;
} }

View File

@ -22,12 +22,16 @@
#define __GIMP_BEZIER_DESC_H__ #define __GIMP_BEZIER_DESC_H__
#define GIMP_TYPE_BEZIER_DESC (gimp_bezier_desc_get_type ())
GType gimp_bezier_desc_get_type (void) G_GNUC_CONST;
/* takes ownership of "data" */ /* takes ownership of "data" */
GimpBezierDesc * gimp_bezier_desc_new (cairo_path_data_t *data, GimpBezierDesc * gimp_bezier_desc_new (cairo_path_data_t *data,
gint n_data); gint n_data);
GimpBezierDesc * gimp_bezier_desc_copy (const GimpBezierDesc *desc); GimpBezierDesc * gimp_bezier_desc_copy (const GimpBezierDesc *desc);
cairo_path_data_t * gimp_bezier_desc_free (GimpBezierDesc *desc, void gimp_bezier_desc_free (GimpBezierDesc *desc);
gboolean free_data);
#endif /* __GIMP_BEZIER_DESC_H__ */ #endif /* __GIMP_BEZIER_DESC_H__ */

View File

@ -261,7 +261,7 @@ gimp_vectors_finalize (GObject *object)
if (vectors->bezier_desc) if (vectors->bezier_desc)
{ {
gimp_bezier_desc_free (vectors->bezier_desc, TRUE); gimp_bezier_desc_free (vectors->bezier_desc);
vectors->bezier_desc = NULL; vectors->bezier_desc = NULL;
} }
@ -613,7 +613,7 @@ gimp_vectors_real_freeze (GimpVectors *vectors)
/* release cached bezier representation */ /* release cached bezier representation */
if (vectors->bezier_desc) if (vectors->bezier_desc)
{ {
gimp_bezier_desc_free (vectors->bezier_desc, TRUE); gimp_bezier_desc_free (vectors->bezier_desc);
vectors->bezier_desc = NULL; vectors->bezier_desc = NULL;
} }
@ -1158,7 +1158,7 @@ gimp_vectors_real_make_bezier (const GimpVectors *vectors)
{ {
cmd_array = g_array_append_vals (cmd_array, bezdesc->data, cmd_array = g_array_append_vals (cmd_array, bezdesc->data,
bezdesc->num_data); bezdesc->num_data);
gimp_bezier_desc_free (bezdesc, TRUE); gimp_bezier_desc_free (bezdesc);
} }
} }