From 9d9d455bba31a5b0737e02f930f0b186d196b33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 1 Mar 2019 14:38:23 +0100 Subject: [PATCH] clutter/rect: Add utility function to scale the rectangle Scale coordinates and size of the rectangle by the passed value. https://gitlab.gnome.org/GNOME/mutter/merge_requests/3 --- clutter/clutter/clutter-base-types.c | 34 ++++++++++++++++++++++++---- clutter/clutter/clutter-types.h | 4 ++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/clutter/clutter/clutter-base-types.c b/clutter/clutter/clutter-base-types.c index f7ad5261e..aeb25c90e 100644 --- a/clutter/clutter/clutter-base-types.c +++ b/clutter/clutter/clutter-base-types.c @@ -1146,14 +1146,40 @@ clutter_rect_inset (ClutterRect *rect, rect->size.height = 0.f; } +/** + * clutter_rect_scale: + * @rect: a #ClutterRect + * @s_x: an horizontal scale value + * @s_y: a vertical scale value + * + * Scale the rectangle coordinates and size by @s_x horizontally and + * @s_y vertically. + */ +void +clutter_rect_scale (ClutterRect *rect, + float s_x, + float s_y) +{ + g_return_if_fail (rect != NULL); + g_return_if_fail (s_x > 0.f); + g_return_if_fail (s_y > 0.f); + + clutter_rect_normalize_internal (rect); + + rect->origin.x *= s_x; + rect->origin.y *= s_y; + rect->size.width *= s_x; + rect->size.height *= s_y; +} + /** * clutter_rect_clamp_to_pixel: * @rect: a #ClutterRect * - * Rounds the origin of @rect downwards to the nearest integer, and rounds - * the size of @rect upwards to the nearest integer, so that @rect is - * updated to the smallest rectangle capable of fully containing the - * original, fractional rectangle. + * Rounds the origin of @rect downwards to the nearest integer, and recompute the + * the size using the @rect origin and size rounded upwards to the nearest integer, + * so that @rect is updated to the smallest rectangle capable of fully containing + * the original, fractional rectangle in the coordinates space. * * Since: 1.12 */ diff --git a/clutter/clutter/clutter-types.h b/clutter/clutter/clutter-types.h index 74582ec26..0f0fb1c2a 100644 --- a/clutter/clutter/clutter-types.h +++ b/clutter/clutter/clutter-types.h @@ -361,6 +361,10 @@ void clutter_rect_inset (ClutterRect *rect float d_x, float d_y); CLUTTER_EXPORT +void clutter_rect_scale (ClutterRect *rect, + float s_x, + float s_y); +CLUTTER_EXPORT void clutter_rect_clamp_to_pixel (ClutterRect *rect); CLUTTER_EXPORT float clutter_rect_get_x (ClutterRect *rect);