From 5fb78dfbad10806a6e5b5bce56e8b4ac1523dd97 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sun, 12 Nov 2023 11:55:11 +0100 Subject: [PATCH] zoom-action: Use macros for subclassing boilerplate Part-of: --- clutter/clutter/clutter-autocleanups.h | 1 - clutter/clutter/clutter-zoom-action.c | 33 ++++++++++++++++---------- clutter/clutter/clutter-zoom-action.h | 25 +++++-------------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/clutter/clutter/clutter-autocleanups.h b/clutter/clutter/clutter-autocleanups.h index f211e2843..cf888a04e 100644 --- a/clutter/clutter/clutter-autocleanups.h +++ b/clutter/clutter/clutter-autocleanups.h @@ -67,7 +67,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTimeline, 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 (ClutterZoomAction, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActorBox, clutter_actor_box_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColor, clutter_color_free) diff --git a/clutter/clutter/clutter-zoom-action.c b/clutter/clutter/clutter-zoom-action.c index b2f3410f8..4de4aa5cd 100644 --- a/clutter/clutter/clutter-zoom-action.c +++ b/clutter/clutter/clutter-zoom-action.c @@ -69,7 +69,7 @@ typedef struct gfloat transformed_update_y; } ZoomPoint; -struct _ClutterZoomActionPrivate +typedef struct _ClutterZoomActionPrivate { ClutterStage *stage; @@ -87,7 +87,7 @@ struct _ClutterZoomActionPrivate gdouble initial_scale_y; gdouble zoom_initial_distance; -}; +} ClutterZoomActionPrivate; enum { @@ -142,7 +142,8 @@ static gboolean clutter_zoom_action_gesture_begin (ClutterGestureAction *action, ClutterActor *actor) { - ClutterZoomActionPrivate *priv = ((ClutterZoomAction *) action)->priv; + ClutterZoomActionPrivate *priv = + clutter_zoom_action_get_instance_private (CLUTTER_ZOOM_ACTION (action)); gfloat dx, dy; capture_point_initial_position (action, actor, 0, &priv->points[0]); @@ -179,7 +180,8 @@ static gboolean clutter_zoom_action_gesture_progress (ClutterGestureAction *action, ClutterActor *actor) { - ClutterZoomActionPrivate *priv = ((ClutterZoomAction *) action)->priv; + ClutterZoomActionPrivate *priv = + clutter_zoom_action_get_instance_private (CLUTTER_ZOOM_ACTION (action)); gdouble distance, new_scale; gfloat dx, dy; gboolean retval; @@ -210,7 +212,8 @@ static void clutter_zoom_action_gesture_cancel (ClutterGestureAction *action, ClutterActor *actor) { - ClutterZoomActionPrivate *priv = ((ClutterZoomAction *) action)->priv; + ClutterZoomActionPrivate *priv = + clutter_zoom_action_get_instance_private (CLUTTER_ZOOM_ACTION (action)); clutter_actor_set_translation (actor, priv->initial_x, @@ -275,12 +278,8 @@ clutter_zoom_action_class_init (ClutterZoomActionClass *klass) static void clutter_zoom_action_init (ClutterZoomAction *self) { - ClutterGestureAction *gesture; - - self->priv = clutter_zoom_action_get_instance_private (self); - - gesture = CLUTTER_GESTURE_ACTION (self); - clutter_gesture_action_set_n_touch_points (gesture, 2); + clutter_gesture_action_set_n_touch_points (CLUTTER_GESTURE_ACTION (self), + 2); } /** @@ -307,10 +306,14 @@ void clutter_zoom_action_get_focal_point (ClutterZoomAction *action, graphene_point_t *point) { + ClutterZoomActionPrivate *priv; + g_return_if_fail (CLUTTER_IS_ZOOM_ACTION (action)); g_return_if_fail (point != NULL); - *point = action->priv->focal_point; + priv = clutter_zoom_action_get_instance_private (action); + + *point = priv->focal_point; } /** @@ -325,8 +328,12 @@ void clutter_zoom_action_get_transformed_focal_point (ClutterZoomAction *action, graphene_point_t *point) { + ClutterZoomActionPrivate *priv; + g_return_if_fail (CLUTTER_IS_ZOOM_ACTION (action)); g_return_if_fail (point != NULL); - *point = action->priv->transformed_focal_point; + priv = clutter_zoom_action_get_instance_private (action); + + *point = priv->transformed_focal_point; } diff --git a/clutter/clutter/clutter-zoom-action.h b/clutter/clutter/clutter-zoom-action.h index b3b81ad42..acc019907 100644 --- a/clutter/clutter/clutter-zoom-action.h +++ b/clutter/clutter/clutter-zoom-action.h @@ -35,23 +35,13 @@ G_BEGIN_DECLS #define CLUTTER_TYPE_ZOOM_ACTION (clutter_zoom_action_get_type ()) -#define CLUTTER_ZOOM_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ZOOM_ACTION, ClutterZoomAction)) -#define CLUTTER_IS_ZOOM_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ZOOM_ACTION)) -#define CLUTTER_ZOOM_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_ZOOM_ACTION, ClutterZoomActionClass)) -#define CLUTTER_IS_ZOOM_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_ZOOM_ACTION)) -#define CLUTTER_ZOOM_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_ZOOM_ACTION, ClutterZoomActionClass)) -typedef struct _ClutterZoomAction ClutterZoomAction; -typedef struct _ClutterZoomActionPrivate ClutterZoomActionPrivate; -typedef struct _ClutterZoomActionClass ClutterZoomActionClass; - -struct _ClutterZoomAction -{ - /*< private >*/ - ClutterGestureAction parent_instance; - - ClutterZoomActionPrivate *priv; -}; +CLUTTER_EXPORT +G_DECLARE_DERIVABLE_TYPE (ClutterZoomAction, + clutter_zoom_action, + CLUTTER, + ZOOM_ACTION, + ClutterGestureAction) /** * ClutterZoomActionClass: @@ -66,9 +56,6 @@ struct _ClutterZoomActionClass ClutterGestureActionClass parent_class; }; -CLUTTER_EXPORT -GType clutter_zoom_action_get_type (void) G_GNUC_CONST; - CLUTTER_EXPORT ClutterAction * clutter_zoom_action_new (void);