Add two convenience methods for region point conversion

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2021-07-26 15:45:08 +10:00
parent 6095a0d99f
commit 15316dd2ab
3 changed files with 31 additions and 4 deletions

View file

@ -279,9 +279,6 @@ ei_region_set_offset(struct ei_region *region, uint32_t x, uint32_t y);
void
ei_region_set_physical_scale(struct ei_region *region, double scale);
bool
ei_region_contains(struct ei_region *region, double x, double y);
_printf_(6, 7) void
ei_log_msg(struct ei *ei,
enum ei_log_priority priority,

View file

@ -79,9 +79,21 @@ ei_region_set_size(struct ei_region *region, uint32_t w, uint32_t h)
region->height = h;
}
bool
_public_ bool
ei_region_contains(struct ei_region *r, double x, double y)
{
return (x >= r->x && x < r->x + r->width &&
y >= r->y && y < r->y + r->height);
}
_public_ bool
ei_region_convert_point(struct ei_region *r, double *x, double *y)
{
if (ei_region_contains(r, *x, *y)) {
*x -= r->x;
*y -= r->y;
return true;
}
return false;
}

View file

@ -825,6 +825,24 @@ ei_region_get_width(struct ei_region *region);
uint32_t
ei_region_get_height(struct ei_region *region);
/**
* Return true if the point x/y (in desktop-wide coordinates) is within @a
* region.
*/
bool
ei_region_contains(struct ei_region *region, double x, double y);
/**
* Convert the point x/y in a desktop-wide coordinate system into the
* corresponding point relative to the offset of the given region.
* If the point is inside the region, this function returns true and @a x and @a
* y are set to the points with region offset subtracted.
* If the point is outside the region, this function returns false and @a x
* and @a y are left unmodified.
*/
bool
ei_region_convert_point(struct ei_region *region, double *x, double *y);
/**
* Return the physical scale for this region. The default scale is 1.0.
*