[mutter] boxes: Add API to crop and scale a MetaRectangle
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] boxes: Add API to crop and scale a MetaRectangle
- Date: Wed, 6 Feb 2019 12:36:57 +0000 (UTC)
commit d574cf59f1d5df77a9b71b9f3220beb7658b5d33
Author: Robert Mader <robert mader posteo de>
Date: Sat Jan 5 16:39:55 2019 +0100
boxes: Add API to crop and scale a MetaRectangle
https://gitlab.gnome.org/GNOME/mutter/merge_requests/323
src/core/boxes-private.h | 6 ++++++
src/core/boxes.c | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
---
diff --git a/src/core/boxes-private.h b/src/core/boxes-private.h
index 5f38e6634..d80cdacd3 100644
--- a/src/core/boxes-private.h
+++ b/src/core/boxes-private.h
@@ -274,4 +274,10 @@ void meta_rectangle_transform (const MetaRectangle *rect,
int height,
MetaRectangle *dest);
+void meta_rectangle_crop_and_scale (const MetaRectangle *rect,
+ ClutterRect *src_rect,
+ int dst_width,
+ int dst_height,
+ MetaRectangle *dest);
+
#endif /* META_BOXES_PRIVATE_H */
diff --git a/src/core/boxes.c b/src/core/boxes.c
index 7cb476d45..938ec51e9 100644
--- a/src/core/boxes.c
+++ b/src/core/boxes.c
@@ -33,6 +33,7 @@
#include "backends/meta-monitor-transform.h"
#include "core/boxes-private.h"
+#include <math.h>
#include <X11/Xutil.h>
#include "meta/util.h"
@@ -2149,3 +2150,18 @@ meta_rectangle_transform (const MetaRectangle *rect,
break;
}
}
+
+void
+meta_rectangle_crop_and_scale (const MetaRectangle *rect,
+ ClutterRect *src_rect,
+ int dst_width,
+ int dst_height,
+ MetaRectangle *dest)
+{
+ dest->x = floorf (rect->x * (src_rect->size.width / dst_width) +
+ src_rect->origin.x);
+ dest->y = floorf (rect->y * (src_rect->size.height / dst_height) +
+ src_rect->origin.y);
+ dest->width = ceilf (rect->width * (src_rect->size.width / dst_width));
+ dest->height = ceilf (rect->height * (src_rect->size.height / dst_height));
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]