From 109fbdbac9eb6e42fbc510d3e205589a8c8268ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Tue, 28 Jul 2020 20:39:55 +0200 Subject: [PATCH] clutter/actor: Add get_transformed_extents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The clutter_actor_get_transformed_position returns the position of the top left point of the actor, with the actor transformations. That means that if the actor is rotated 180ยบ it'll return the "screen" position top right. Using this to calculate if the actor is in the screen is causing problems when it's transformted. This patch adds a new function clutter_actor_get_transformed_extents, that will return the transformed actor bounding rect. This new function is used on the update_stage_views so the actor will get updated. this way rotated actors will be updated if they are on the screen. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1386 --- clutter/clutter/clutter-actor.c | 39 ++++++++++++++++++++++++++++----- clutter/clutter/clutter-actor.h | 5 +++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index 2dcb07df2..f9f41ab47 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -10295,6 +10295,38 @@ clutter_actor_get_fixed_position (ClutterActor *self, return FALSE; } +/** + * clutter_actor_get_transformed_extents: + * @self: A #ClutterActor + * @rect: (out): return location for the transformed bounding rect + * + * Gets the transformed bounding rect of an actor, in pixels relative to the stage. + */ +void +clutter_actor_get_transformed_extents (ClutterActor *self, + graphene_rect_t *rect) +{ + graphene_quad_t quad; + graphene_point3d_t v[4]; + ClutterActorBox box; + + box.x1 = 0; + box.y1 = 0; + box.x2 = clutter_actor_box_get_width (&self->priv->allocation); + box.y2 = clutter_actor_box_get_height (&self->priv->allocation); + if (_clutter_actor_transform_and_project_box (self, &box, v)) + { + graphene_quad_init (&quad, + (graphene_point_t *) &v[0], + (graphene_point_t *) &v[1], + (graphene_point_t *) &v[2], + (graphene_point_t *) &v[3]); + + if (rect) + graphene_quad_bounds (&quad, rect); + } +} + /** * clutter_actor_get_transformed_position: * @self: A #ClutterActor @@ -16183,12 +16215,7 @@ update_stage_views (ClutterActor *self) stage = CLUTTER_STAGE (_clutter_actor_get_stage_internal (self)); g_return_if_fail (stage); - clutter_actor_get_transformed_position (self, - &bounding_rect.origin.x, - &bounding_rect.origin.y); - clutter_actor_get_transformed_size (self, - &bounding_rect.size.width, - &bounding_rect.size.height); + clutter_actor_get_transformed_extents (self, &bounding_rect); if (bounding_rect.size.width == 0.0 || bounding_rect.size.height == 0.0) diff --git a/clutter/clutter/clutter-actor.h b/clutter/clutter/clutter-actor.h index d28983172..a37036b2a 100644 --- a/clutter/clutter/clutter-actor.h +++ b/clutter/clutter/clutter-actor.h @@ -813,6 +813,11 @@ void clutter_actor_set_child_transform CLUTTER_EXPORT void clutter_actor_get_child_transform (ClutterActor *self, ClutterMatrix *transform); + +CLUTTER_EXPORT +void clutter_actor_get_transformed_extents (ClutterActor *self, + graphene_rect_t *rect); + CLUTTER_EXPORT void clutter_actor_get_transformed_position (ClutterActor *self, gfloat *x,