Commit d574cf59 authored by Robert Mader's avatar Robert Mader Committed by Jonas Ådahl

boxes: Add API to crop and scale a MetaRectangle

!323
parent 47402d84
......@@ -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 */
......@@ -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));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment