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 (ClutterTextBuffer, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, 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 (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 (ClutterActorBox, clutter_actor_box_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColor, clutter_color_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColor, clutter_color_free)

View File

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

View File

@ -33,22 +33,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define CLUTTER_TYPE_TRANSITION (clutter_transition_get_type ()) #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; CLUTTER_EXPORT
typedef struct _ClutterTransitionClass ClutterTransitionClass; G_DECLARE_DERIVABLE_TYPE (ClutterTransition,
clutter_transition,
struct _ClutterTransition CLUTTER,
{ TRANSITION,
/*< private >*/ ClutterTimeline)
ClutterTimeline parent_instance;
ClutterTransitionPrivate *priv;
};
/** /**
* ClutterTransitionClass: * ClutterTransitionClass:
@ -79,9 +70,6 @@ struct _ClutterTransitionClass
gdouble progress); gdouble progress);
}; };
CLUTTER_EXPORT
GType clutter_transition_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_transition_set_interval (ClutterTransition *transition, void clutter_transition_set_interval (ClutterTransition *transition,
ClutterInterval *interval); ClutterInterval *interval);