From 6e3223a0ccfa7944075854d791a4ea84853bd3fa Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 10 Nov 2023 17:05:48 +0100 Subject: [PATCH] property-transition: Use macros for subclassing boilerplate Part-of: --- clutter/clutter/clutter-autocleanups.h | 1 - clutter/clutter/clutter-property-transition.c | 36 +++++++++++-------- clutter/clutter/clutter-property-transition.h | 24 ++++--------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/clutter/clutter/clutter-autocleanups.h b/clutter/clutter/clutter-autocleanups.h index 6f3013b60..686e6597d 100644 --- a/clutter/clutter/clutter-autocleanups.h +++ b/clutter/clutter/clutter-autocleanups.h @@ -46,7 +46,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInterval, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterKeyframeTransition, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterOffscreenEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPageTurnEffect, g_object_unref) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPropertyTransition, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterShaderEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterStage, g_object_unref) diff --git a/clutter/clutter/clutter-property-transition.c b/clutter/clutter/clutter-property-transition.c index 4fa0b0e10..f05fa09bb 100644 --- a/clutter/clutter/clutter-property-transition.c +++ b/clutter/clutter/clutter-property-transition.c @@ -38,12 +38,12 @@ #include "clutter/clutter-private.h" #include "clutter/clutter-transition.h" -struct _ClutterPropertyTransitionPrivate +typedef struct _ClutterPropertyTransitionPrivate { char *property_name; GParamSpec *pspec; -}; +} ClutterPropertyTransitionPrivate; enum { @@ -63,7 +63,8 @@ clutter_property_transition_ensure_interval (ClutterPropertyTransition *transiti ClutterAnimatable *animatable, ClutterInterval *interval) { - ClutterPropertyTransitionPrivate *priv = transition->priv; + ClutterPropertyTransitionPrivate *priv = + clutter_property_transition_get_instance_private (transition); GValue *value_p; if (clutter_interval_is_valid (interval)) @@ -95,7 +96,8 @@ clutter_property_transition_attached (ClutterTransition *transition, ClutterAnimatable *animatable) { ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition); - ClutterPropertyTransitionPrivate *priv = self->priv; + ClutterPropertyTransitionPrivate *priv = + clutter_property_transition_get_instance_private (self); ClutterInterval *interval; if (priv->property_name == NULL) @@ -119,9 +121,10 @@ clutter_property_transition_detached (ClutterTransition *transition, ClutterAnimatable *animatable) { ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition); - ClutterPropertyTransitionPrivate *priv = self->priv; + ClutterPropertyTransitionPrivate *priv = + clutter_property_transition_get_instance_private (self); - priv->pspec = NULL; + priv->pspec = NULL; } static void @@ -131,7 +134,8 @@ clutter_property_transition_compute_value (ClutterTransition *transition, gdouble progress) { ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (transition); - ClutterPropertyTransitionPrivate *priv = self->priv; + ClutterPropertyTransitionPrivate *priv = + clutter_property_transition_get_instance_private (self); GValue value = G_VALUE_INIT; GType p_type, i_type; gboolean res; @@ -214,7 +218,9 @@ clutter_property_transition_get_property (GObject *gobject, GValue *value, GParamSpec *pspec) { - ClutterPropertyTransitionPrivate *priv = CLUTTER_PROPERTY_TRANSITION (gobject)->priv; + ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (gobject); + ClutterPropertyTransitionPrivate *priv = + clutter_property_transition_get_instance_private (self); switch (prop_id) { @@ -230,9 +236,9 @@ clutter_property_transition_get_property (GObject *gobject, static void clutter_property_transition_finalize (GObject *gobject) { - ClutterPropertyTransitionPrivate *priv; - - priv = CLUTTER_PROPERTY_TRANSITION (gobject)->priv; + ClutterPropertyTransition *self = CLUTTER_PROPERTY_TRANSITION (gobject); + ClutterPropertyTransitionPrivate *priv = + clutter_property_transition_get_instance_private (self); g_free (priv->property_name); @@ -269,7 +275,6 @@ clutter_property_transition_class_init (ClutterPropertyTransitionClass *klass) static void clutter_property_transition_init (ClutterPropertyTransition *self) { - self->priv = clutter_property_transition_get_instance_private (self); } /** @@ -325,7 +330,7 @@ clutter_property_transition_set_property_name (ClutterPropertyTransition *transi g_return_if_fail (CLUTTER_IS_PROPERTY_TRANSITION (transition)); - priv = transition->priv; + priv = clutter_property_transition_get_instance_private (transition); if (g_strcmp0 (priv->property_name, property_name) == 0) return; @@ -360,7 +365,10 @@ clutter_property_transition_set_property_name (ClutterPropertyTransition *transi const char * clutter_property_transition_get_property_name (ClutterPropertyTransition *transition) { + ClutterPropertyTransitionPrivate *priv; + g_return_val_if_fail (CLUTTER_IS_PROPERTY_TRANSITION (transition), NULL); - return transition->priv->property_name; + priv = clutter_property_transition_get_instance_private (transition); + return priv->property_name; } diff --git a/clutter/clutter/clutter-property-transition.h b/clutter/clutter/clutter-property-transition.h index a51ba1990..95adf9b91 100644 --- a/clutter/clutter/clutter-property-transition.h +++ b/clutter/clutter/clutter-property-transition.h @@ -33,22 +33,13 @@ G_BEGIN_DECLS #define CLUTTER_TYPE_PROPERTY_TRANSITION (clutter_property_transition_get_type ()) -#define CLUTTER_PROPERTY_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_PROPERTY_TRANSITION, ClutterPropertyTransition)) -#define CLUTTER_IS_PROPERTY_TRANSITION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_PROPERTY_TRANSITION)) -#define CLUTTER_PROPERTY_TRANSITION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_PROPERTY_TRANSITION, ClutterPropertyTransitionClass)) -#define CLUTTER_IS_PROPERTY_TRANSITION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_PROPERTY_TRANSITION)) -#define CLUTTER_PROPERTY_TRANSITION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_PROPERTY_TRANSITION, ClutterPropertyTransitionClass)) -typedef struct _ClutterPropertyTransitionPrivate ClutterPropertyTransitionPrivate; -typedef struct _ClutterPropertyTransitionClass ClutterPropertyTransitionClass; - -struct _ClutterPropertyTransition -{ - /*< private >*/ - ClutterTransition parent_instance; - - ClutterPropertyTransitionPrivate *priv; -}; +CLUTTER_EXPORT +G_DECLARE_DERIVABLE_TYPE (ClutterPropertyTransition, + clutter_property_transition, + CLUTTER, + PROPERTY_TRANSITION, + ClutterTransition) /** * ClutterPropertyTransitionClass: @@ -62,9 +53,6 @@ struct _ClutterPropertyTransitionClass ClutterTransitionClass parent_class; }; -CLUTTER_EXPORT -GType clutter_property_transition_get_type (void) G_GNUC_CONST; - CLUTTER_EXPORT ClutterTransition * clutter_property_transition_new_for_actor (ClutterActor *actor, const char *property_name);