Use G_DEFINE_BOXED_TYPE for all boxed types

We actually need a couple more macros for registering GValue
transformation functions. Those should be added to upstream
GLib.
This commit is contained in:
Emmanuele Bassi 2010-10-08 15:21:57 +01:00
parent 09a830d294
commit 7dd09e2186
13 changed files with 123 additions and 280 deletions

View File

@ -74,43 +74,6 @@ clutter_actor_box_free (ClutterActorBox *box)
g_slice_free (ClutterActorBox, box);
}
static gboolean
clutter_actor_box_progress (const GValue *a,
const GValue *b,
gdouble factor,
GValue *retval)
{
ClutterActorBox res = { 0, };
clutter_actor_box_interpolate (g_value_get_boxed (a),
g_value_get_boxed (b),
factor,
&res);
g_value_set_boxed (retval, &res);
return TRUE;
}
GType
clutter_actor_box_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
{
our_type =
g_boxed_type_register_static (I_("ClutterActorBox"),
(GBoxedCopyFunc) clutter_actor_box_copy,
(GBoxedFreeFunc) clutter_actor_box_free);
clutter_interval_register_progress_func (our_type,
clutter_actor_box_progress);
}
return our_type;
}
/**
* clutter_actor_box_equal:
* @box_a: a #ClutterActorBox
@ -438,3 +401,26 @@ clutter_actor_box_union (const ClutterActorBox *a,
result->x2 = MAX (a->x2, b->x2);
result->y2 = MAX (a->y2, b->y2);
}
static gboolean
clutter_actor_box_progress (const GValue *a,
const GValue *b,
gdouble factor,
GValue *retval)
{
ClutterActorBox res = { 0, };
clutter_actor_box_interpolate (g_value_get_boxed (a),
g_value_get_boxed (b),
factor,
&res);
g_value_set_boxed (retval, &res);
return TRUE;
}
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterActorBox, clutter_actor_box,
clutter_actor_box_copy,
clutter_actor_box_free,
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_actor_box_progress));

View File

@ -9142,46 +9142,6 @@ clutter_geometry_free (ClutterGeometry *geometry)
g_slice_free (ClutterGeometry, geometry);
}
static gboolean
clutter_geometry_progress (const GValue *a,
const GValue *b,
gdouble progress,
GValue *retval)
{
const ClutterGeometry *a_geom = g_value_get_boxed (a);
const ClutterGeometry *b_geom = g_value_get_boxed (b);
ClutterGeometry res = { 0, };
res.x = a_geom->x + (b_geom->x - a_geom->x) * progress;
res.y = a_geom->y + (b_geom->y - a_geom->y) * progress;
res.width = a_geom->width + (b_geom->width - a_geom->width) * progress;
res.height = a_geom->height + (b_geom->height - a_geom->height) * progress;
g_value_set_boxed (retval, &res);
return TRUE;
}
GType
clutter_geometry_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
{
our_type =
g_boxed_type_register_static (I_("ClutterGeometry"),
(GBoxedCopyFunc) clutter_geometry_copy,
(GBoxedFreeFunc) clutter_geometry_free);
clutter_interval_register_progress_func (our_type,
clutter_geometry_progress);
}
return our_type;
}
/**
* clutter_geometry_union:
* @geometry_a: a #ClutterGeometry
@ -9237,6 +9197,32 @@ clutter_geometry_intersects (const ClutterGeometry *geometry0,
return TRUE;
}
static gboolean
clutter_geometry_progress (const GValue *a,
const GValue *b,
gdouble progress,
GValue *retval)
{
const ClutterGeometry *a_geom = g_value_get_boxed (a);
const ClutterGeometry *b_geom = g_value_get_boxed (b);
ClutterGeometry res = { 0, };
res.x = a_geom->x + (b_geom->x - a_geom->x) * progress;
res.y = a_geom->y + (b_geom->y - a_geom->y) * progress;
res.width = a_geom->width + (b_geom->width - a_geom->width) * progress;
res.height = a_geom->height + (b_geom->height - a_geom->height) * progress;
g_value_set_boxed (retval, &res);
return TRUE;
}
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterGeometry, clutter_geometry,
clutter_geometry_copy,
clutter_geometry_free,
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_geometry_progress));
/*
* ClutterVertices
*/
@ -9349,24 +9335,10 @@ clutter_vertex_progress (const GValue *a,
return TRUE;
}
GType
clutter_vertex_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
{
our_type =
g_boxed_type_register_static (I_("ClutterVertex"),
(GBoxedCopyFunc) clutter_vertex_copy,
(GBoxedFreeFunc) clutter_vertex_free);
clutter_interval_register_progress_func (our_type,
clutter_vertex_progress);
}
return our_type;
}
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterVertex, clutter_vertex,
clutter_vertex_copy,
clutter_vertex_free,
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_vertex_progress));
/******************************************************************************/

View File

@ -1989,19 +1989,9 @@ clutter_animator_property_set_interpolation (ClutterAnimator *animator,
}
}
GType
clutter_animator_key_get_type (void)
{
static GType our_type = 0;
if (!our_type)
our_type = g_boxed_type_register_static (I_("ClutterAnimatorKey"),
clutter_animator_key_copy,
clutter_animator_key_free);
return our_type;
}
G_DEFINE_BOXED_TYPE (ClutterAnimatorKey, clutter_animator_key,
clutter_animator_key_copy,
clutter_animator_key_free);
/**
* clutter_animator_key_get_object:

View File

@ -141,21 +141,9 @@ clutter_knot_equal (const ClutterKnot *knot_a,
return knot_a->x == knot_b->x && knot_a->y == knot_b->y;
}
GType
clutter_knot_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (!our_type))
{
our_type =
g_boxed_type_register_static (I_("ClutterKnot"),
(GBoxedCopyFunc) clutter_knot_copy,
(GBoxedFreeFunc) clutter_knot_free);
}
return our_type;
}
G_DEFINE_BOXED_TYPE (ClutterKnot, clutter_knot,
clutter_knot_copy,
clutter_knot_free);
static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);

View File

@ -701,29 +701,12 @@ clutter_value_transform_string_color (const GValue *src,
clutter_value_set_color (dest, NULL);
}
GType
clutter_color_get_type (void)
{
static GType _clutter_color_type = 0;
if (G_UNLIKELY (_clutter_color_type == 0))
{
_clutter_color_type =
g_boxed_type_register_static (I_("ClutterColor"),
(GBoxedCopyFunc) clutter_color_copy,
(GBoxedFreeFunc) clutter_color_free);
g_value_register_transform_func (_clutter_color_type, G_TYPE_STRING,
clutter_value_transform_color_string);
g_value_register_transform_func (G_TYPE_STRING, _clutter_color_type,
clutter_value_transform_string_color);
clutter_interval_register_progress_func (_clutter_color_type,
clutter_color_progress);
}
return _clutter_color_type;
}
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterColor, clutter_color,
clutter_color_copy,
clutter_color_free,
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_STRING, clutter_value_transform_color_string)
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_STRING, clutter_value_transform_string_color)
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_color_progress));
/**
* clutter_value_set_color:

View File

@ -51,6 +51,10 @@ typedef struct _ClutterEventPrivate {
static GHashTable *all_events = NULL;
G_DEFINE_BOXED_TYPE (ClutterEvent, clutter_event,
clutter_event_copy,
clutter_event_free);
static gboolean
is_event_allocated (const ClutterEvent *event)
{
@ -630,18 +634,6 @@ clutter_event_get_device (const ClutterEvent *event)
return device;
}
GType
clutter_event_get_type (void)
{
static GType our_type = 0;
if (!our_type)
our_type = g_boxed_type_register_static (I_("ClutterEvent"),
(GBoxedCopyFunc) clutter_event_copy,
(GBoxedFreeFunc) clutter_event_free);
return our_type;
}
/**
* clutter_event_new:
* @type: The type of event.

View File

@ -32,19 +32,9 @@
#include "clutter-private.h"
GType
clutter_paint_volume_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
our_type =
g_boxed_type_register_static (I_("ClutterPaintVolume"),
(GBoxedCopyFunc) clutter_paint_volume_copy,
(GBoxedFreeFunc) clutter_paint_volume_free);
return our_type;
}
G_DEFINE_BOXED_TYPE (ClutterPaintVolume, clutter_paint_volume,
clutter_paint_volume_copy,
clutter_paint_volume_free);
/*<private>
* _clutter_paint_volume_new:

View File

@ -87,13 +87,6 @@
#include "clutter-bezier.h"
#include "clutter-private.h"
static void clutter_path_register_transforms (GType type);
G_DEFINE_TYPE_WITH_CODE (ClutterPath,
clutter_path,
G_TYPE_INITIALLY_UNOWNED,
clutter_path_register_transforms (g_define_type_id));
#define CLUTTER_PATH_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_PATH, \
ClutterPathPrivate))
@ -143,6 +136,21 @@ static void clutter_path_node_full_free (ClutterPathNodeFull *node);
static void clutter_path_finalize (GObject *object);
static void clutter_value_transform_path_string (const GValue *src,
GValue *dest);
static void clutter_value_transform_string_path (const GValue *src,
GValue *dest);
G_DEFINE_BOXED_TYPE (ClutterPathNode, clutter_path_node,
clutter_path_node_copy,
clutter_path_node_free);
G_DEFINE_TYPE_WITH_CODE (ClutterPath,
clutter_path,
G_TYPE_INITIALLY_UNOWNED,
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_STRING, clutter_value_transform_path_string)
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_STRING, clutter_value_transform_string_path));
static void
clutter_path_get_property (GObject *gobject,
guint prop_id,
@ -240,16 +248,6 @@ clutter_value_transform_string_path (const GValue *src,
g_value_take_object (dest, new_path);
}
static void
clutter_path_register_transforms (GType type)
{
g_value_register_transform_func (type, G_TYPE_STRING,
clutter_value_transform_path_string);
g_value_register_transform_func (G_TYPE_STRING, type,
clutter_value_transform_string_path);
}
static void
clutter_path_finalize (GObject *object)
{
@ -1583,19 +1581,3 @@ clutter_path_node_equal (const ClutterPathNode *node_a,
return TRUE;
}
GType
clutter_path_node_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (!our_type))
{
our_type =
g_boxed_type_register_static (I_("ClutterPathNode"),
(GBoxedCopyFunc) clutter_path_node_copy,
(GBoxedFreeFunc) clutter_path_node_free);
}
return our_type;
}

View File

@ -56,6 +56,24 @@ G_BEGIN_DECLS
typedef struct _ClutterMainContext ClutterMainContext;
#define _clutter_notify_by_pspec(obj, pspec) \
g_object_notify_by_pspec ((obj), (pspec))
#define _clutter_object_class_install_properties(oclass, n_pspecs, pspecs) \
g_object_class_install_properties ((oclass), (n_pspecs), (pspecs))
#define CLUTTER_REGISTER_VALUE_TRANSFORM_TO(TYPE_TO,func) { \
g_value_register_transform_func (g_define_type_id, TYPE_TO, func); \
}
#define CLUTTER_REGISTER_VALUE_TRANSFORM_FROM(TYPE_FROM,func) { \
g_value_register_transform_func (TYPE_FROM, g_define_type_id, func); \
}
#define CLUTTER_REGISTER_INTERVAL_PROGRESS(func) { \
clutter_interval_register_progress_func (g_define_type_id, func); \
}
#define CLUTTER_PRIVATE_FLAGS(a) (((ClutterActor *) (a))->private_flags)
#define CLUTTER_SET_PRIVATE_FLAGS(a,f) (CLUTTER_PRIVATE_FLAGS (a) |= (f))
#define CLUTTER_UNSET_PRIVATE_FLAGS(a,f) (CLUTTER_PRIVATE_FLAGS (a) &= ~(f))
@ -537,12 +555,6 @@ void _clutter_event_set_platform_data (ClutterEvent *event,
gpointer data);
gpointer _clutter_event_get_platform_data (const ClutterEvent *event);
#define _clutter_notify_by_pspec(obj, pspec) \
g_object_notify_by_pspec ((obj), (pspec))
#define _clutter_object_class_install_properties(oclass, n_pspecs, pspecs) \
g_object_class_install_properties ((oclass), (n_pspecs), (pspecs))
void _clutter_paint_volume_init_static (ClutterActor *actor,
ClutterPaintVolume *pv);
ClutterPaintVolume *_clutter_paint_volume_new (ClutterActor *actor);

View File

@ -2549,17 +2549,9 @@ clutter_perspective_free (gpointer data)
g_slice_free (ClutterPerspective, data);
}
GType
clutter_perspective_get_type (void)
{
static GType our_type = 0;
if (!our_type)
our_type = g_boxed_type_register_static (I_("ClutterPerspective"),
clutter_perspective_copy,
clutter_perspective_free);
return our_type;
}
G_DEFINE_BOXED_TYPE (ClutterPerspective, clutter_perspective,
clutter_perspective_copy,
clutter_perspective_free);
static gpointer
clutter_fog_copy (gpointer data)
@ -2577,18 +2569,7 @@ clutter_fog_free (gpointer data)
g_slice_free (ClutterFog, data);
}
GType
clutter_fog_get_type (void)
{
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
our_type = g_boxed_type_register_static (I_("ClutterFog"),
clutter_fog_copy,
clutter_fog_free);
return our_type;
}
G_DEFINE_BOXED_TYPE (ClutterFog, clutter_fog, clutter_fog_copy, clutter_fog_free);
/**
* clutter_stage_new:

View File

@ -1360,18 +1360,9 @@ clutter_state_key_copy (gpointer boxed)
return boxed;
}
GType
clutter_state_key_get_type (void)
{
static GType our_type = 0;
if (!our_type)
our_type = g_boxed_type_register_static (I_("ClutterStateKey"),
clutter_state_key_copy,
clutter_state_key_free);
return our_type;
}
G_DEFINE_BOXED_TYPE (ClutterStateKey, clutter_state_key,
clutter_state_key_copy,
clutter_state_key_free);
/**
* clutter_state_key_get_pre_delay:

View File

@ -29,6 +29,7 @@
G_BEGIN_DECLS
#define CLUTTER_TYPE_STATE_KEY (clutter_state_key_get_type ())
#define CLUTTER_TYPE_STATE (clutter_state_get_type ())
#define CLUTTER_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_STATE, ClutterState))
#define CLUTTER_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_STATE, ClutterStateClass))

View File

@ -731,41 +731,16 @@ clutter_value_transform_string_units (const GValue *src,
clutter_value_set_units (dest, &units);
}
GType
clutter_units_get_type (void)
{
static volatile gsize clutter_units_type__volatile = 0;
if (g_once_init_enter (&clutter_units_type__volatile))
{
GType clutter_units_type =
g_boxed_type_register_static (I_("ClutterUnits"),
(GBoxedCopyFunc) clutter_units_copy,
(GBoxedFreeFunc) clutter_units_free);
g_value_register_transform_func (clutter_units_type, G_TYPE_INT,
clutter_value_transform_units_int);
g_value_register_transform_func (G_TYPE_INT, clutter_units_type,
clutter_value_transform_int_units);
g_value_register_transform_func (clutter_units_type, G_TYPE_FLOAT,
clutter_value_transform_units_float);
g_value_register_transform_func (G_TYPE_FLOAT, clutter_units_type,
clutter_value_transform_float_units);
g_value_register_transform_func (clutter_units_type, G_TYPE_STRING,
clutter_value_transform_units_string);
g_value_register_transform_func (G_TYPE_STRING, clutter_units_type,
clutter_value_transform_string_units);
clutter_interval_register_progress_func (clutter_units_type,
clutter_units_progress);
g_once_init_leave (&clutter_units_type__volatile, clutter_units_type);
}
return clutter_units_type__volatile;
}
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterUnits, clutter_units,
clutter_units_copy,
clutter_units_free,
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_INT, clutter_value_transform_units_int)
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_FLOAT, clutter_value_transform_units_float)
CLUTTER_REGISTER_VALUE_TRANSFORM_TO (G_TYPE_STRING, clutter_value_transform_units_string)
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_INT, clutter_value_transform_int_units)
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_FLOAT, clutter_value_transform_float_units)
CLUTTER_REGISTER_VALUE_TRANSFORM_FROM (G_TYPE_STRING, clutter_value_transform_string_units)
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_units_progress));
/**
* clutter_value_set_units: