transition: Use macros for subclassing boilerplate

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3387>
This commit is contained in:
Bilal Elmoussaoui 2023-11-10 14:30:57 +01:00
parent e9c1f1c642
commit dc0a4c554a
3 changed files with 43 additions and 35 deletions

View File

@ -65,7 +65,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTapAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTextBuffer, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTransitionGroup, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTransition, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActorBox, clutter_actor_box_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColor, clutter_color_free)

View File

@ -42,13 +42,13 @@
#include <gobject/gvaluecollector.h>
struct _ClutterTransitionPrivate
typedef struct _ClutterTransitionPrivate
{
ClutterInterval *interval;
ClutterAnimatable *animatable;
guint remove_on_complete : 1;
};
} ClutterTransitionPrivate;
enum
{
@ -106,7 +106,8 @@ clutter_transition_new_frame (ClutterTimeline *timeline,
gint elapsed G_GNUC_UNUSED)
{
ClutterTransition *transition = CLUTTER_TRANSITION (timeline);
ClutterTransitionPrivate *priv = transition->priv;
ClutterTransitionPrivate *priv =
clutter_transition_get_instance_private (transition);
gdouble progress;
if (priv->interval == NULL ||
@ -125,7 +126,9 @@ static void
clutter_transition_stopped (ClutterTimeline *timeline,
gboolean is_finished)
{
ClutterTransitionPrivate *priv = CLUTTER_TRANSITION (timeline)->priv;
ClutterTransition *transition = CLUTTER_TRANSITION (timeline);
ClutterTransitionPrivate *priv =
clutter_transition_get_instance_private (transition);
if (is_finished &&
priv->animatable != NULL &&
@ -171,7 +174,9 @@ clutter_transition_get_property (GObject *gobject,
GValue *value,
GParamSpec *pspec)
{
ClutterTransitionPrivate *priv = CLUTTER_TRANSITION (gobject)->priv;
ClutterTransition *transition = CLUTTER_TRANSITION (gobject);
ClutterTransitionPrivate *priv =
clutter_transition_get_instance_private (transition);
switch (prop_id)
{
@ -196,8 +201,9 @@ clutter_transition_get_property (GObject *gobject,
static void
clutter_transition_dispose (GObject *gobject)
{
ClutterTransitionPrivate *priv = CLUTTER_TRANSITION (gobject)->priv;
ClutterTransition *transition = CLUTTER_TRANSITION (gobject);
ClutterTransitionPrivate *priv =
clutter_transition_get_instance_private (transition);
if (priv->animatable != NULL)
clutter_transition_detach (CLUTTER_TRANSITION (gobject),
priv->animatable);
@ -274,7 +280,6 @@ clutter_transition_class_init (ClutterTransitionClass *klass)
static void
clutter_transition_init (ClutterTransition *self)
{
self->priv = clutter_transition_get_instance_private (self);
}
/**
@ -296,7 +301,7 @@ clutter_transition_set_interval (ClutterTransition *transition,
g_return_if_fail (CLUTTER_IS_TRANSITION (transition));
g_return_if_fail (interval == NULL || CLUTTER_IS_INTERVAL (interval));
priv = transition->priv;
priv = clutter_transition_get_instance_private (transition);
if (priv->interval == interval)
return;
@ -322,9 +327,13 @@ clutter_transition_set_interval (ClutterTransition *transition,
ClutterInterval *
clutter_transition_get_interval (ClutterTransition *transition)
{
ClutterTransitionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_TRANSITION (transition), NULL);
return transition->priv->interval;
priv = clutter_transition_get_instance_private (transition);
return priv->interval;
}
/**
@ -351,7 +360,7 @@ clutter_transition_set_animatable (ClutterTransition *transition,
g_return_if_fail (CLUTTER_IS_TRANSITION (transition));
g_return_if_fail (animatable == NULL || CLUTTER_IS_ANIMATABLE (animatable));
priv = transition->priv;
priv = clutter_transition_get_instance_private (transition);
if (priv->animatable == animatable)
return;
@ -384,9 +393,13 @@ clutter_transition_set_animatable (ClutterTransition *transition,
ClutterAnimatable *
clutter_transition_get_animatable (ClutterTransition *transition)
{
ClutterTransitionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_TRANSITION (transition), NULL);
return transition->priv->animatable;
priv = clutter_transition_get_instance_private (transition);
return priv->animatable;
}
/**
@ -402,14 +415,17 @@ void
clutter_transition_set_remove_on_complete (ClutterTransition *transition,
gboolean remove_complete)
{
ClutterTransitionPrivate *priv;
g_return_if_fail (CLUTTER_IS_TRANSITION (transition));
priv = clutter_transition_get_instance_private (transition);
remove_complete = !!remove_complete;
if (transition->priv->remove_on_complete == remove_complete)
if (priv->remove_on_complete == remove_complete)
return;
transition->priv->remove_on_complete = remove_complete;
priv->remove_on_complete = remove_complete;
g_object_notify_by_pspec (G_OBJECT (transition),
obj_props[PROP_REMOVE_ON_COMPLETE]);
@ -427,9 +443,13 @@ clutter_transition_set_remove_on_complete (ClutterTransition *transition,
gboolean
clutter_transition_get_remove_on_complete (ClutterTransition *transition)
{
ClutterTransitionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_TRANSITION (transition), FALSE);
return transition->priv->remove_on_complete;
priv = clutter_transition_get_instance_private (transition);
return priv->remove_on_complete;
}
typedef void (* IntervalSetFunc) (ClutterInterval *interval,
@ -440,7 +460,8 @@ clutter_transition_set_value (ClutterTransition *transition,
IntervalSetFunc interval_set_func,
const GValue *value)
{
ClutterTransitionPrivate *priv = transition->priv;
ClutterTransitionPrivate *priv =
clutter_transition_get_instance_private (transition);
GType interval_type;
if (priv->interval == NULL)

View File

@ -33,22 +33,13 @@
G_BEGIN_DECLS
#define CLUTTER_TYPE_TRANSITION (clutter_transition_get_type ())
#define CLUTTER_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_TRANSITION, ClutterTransition))
#define CLUTTER_IS_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_TRANSITION))
#define CLUTTER_TRANSITION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_TRANSITION, ClutterTransitionClass))
#define CLUTTER_IS_TRANSITION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_TRANSITION))
#define CLUTTER_TRANSITION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_TRANSITION, ClutterTransitionClass))
typedef struct _ClutterTransitionPrivate ClutterTransitionPrivate;
typedef struct _ClutterTransitionClass ClutterTransitionClass;
struct _ClutterTransition
{
/*< private >*/
ClutterTimeline parent_instance;
ClutterTransitionPrivate *priv;
};
CLUTTER_EXPORT
G_DECLARE_DERIVABLE_TYPE (ClutterTransition,
clutter_transition,
CLUTTER,
TRANSITION,
ClutterTimeline)
/**
* ClutterTransitionClass:
@ -79,9 +70,6 @@ struct _ClutterTransitionClass
gdouble progress);
};
CLUTTER_EXPORT
GType clutter_transition_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT
void clutter_transition_set_interval (ClutterTransition *transition,
ClutterInterval *interval);