boxes: Add API to crop and scale a MetaRectangle

https://gitlab.gnome.org/GNOME/mutter/merge_requests/323
This commit is contained in:
Robert Mader 2019-01-05 16:39:55 +01:00 committed by Jonas Ådahl
parent 47402d848d
commit d574cf59f1
2 changed files with 22 additions and 0 deletions

View File

@ -274,4 +274,10 @@ void meta_rectangle_transform (const MetaRectangle *rect,
int height, int height,
MetaRectangle *dest); 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 */ #endif /* META_BOXES_PRIVATE_H */

View File

@ -33,6 +33,7 @@
#include "backends/meta-monitor-transform.h" #include "backends/meta-monitor-transform.h"
#include "core/boxes-private.h" #include "core/boxes-private.h"
#include <math.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "meta/util.h" #include "meta/util.h"
@ -2149,3 +2150,18 @@ meta_rectangle_transform (const MetaRectangle *rect,
break; 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));
}