2019-12-09 11:18:24 -07:00
|
|
|
#include <string.h>
|
|
|
|
#include "log.h"
|
|
|
|
#include "gfxtype.h"
|
|
|
|
|
|
|
|
BOOL G_set_rect(PRECT rect, int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
rect->left = left;
|
|
|
|
rect->top = top;
|
|
|
|
rect->right = right;
|
|
|
|
rect->bottom = bottom;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_set_rect_empty(PRECT rect)
|
|
|
|
{
|
|
|
|
memset(rect, 0, sizeof(RECT));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_inflate_rect(PRECT rect, int dx, int dy)
|
|
|
|
{
|
|
|
|
rect->left += dx;
|
|
|
|
rect->top += dy;
|
|
|
|
rect->right -= dx;
|
|
|
|
rect->bottom -= dy;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_offset_rect(PRECT rect, int dx, int dy)
|
|
|
|
{
|
|
|
|
rect->left += dx;
|
|
|
|
rect->top += dy;
|
|
|
|
rect->right += dx;
|
|
|
|
rect->bottom += dy;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_is_rect_empty(PCRECT rect)
|
|
|
|
{
|
2019-12-09 11:24:19 -07:00
|
|
|
return (rect->right <= rect->left) || (rect->bottom <= rect->top);
|
2019-12-09 11:18:24 -07:00
|
|
|
}
|
|
|
|
|
2019-12-09 17:02:04 -07:00
|
|
|
BOOL G_coords_in_rect(PCRECT rect, INT32 x, INT32 y)
|
|
|
|
{
|
|
|
|
return (rect->left <= x) && (x < rect->right) && (rect->top <= y) && (y < rect->bottom);
|
|
|
|
}
|
|
|
|
|
2019-12-09 11:18:24 -07:00
|
|
|
BOOL G_point_in_rect(PCRECT rect, PCPOINT pt)
|
|
|
|
{
|
2019-12-09 17:02:04 -07:00
|
|
|
return G_coords_in_rect(rect, pt->x, pt->y);
|
2019-12-09 11:18:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_rect_equal(PCRECT rect1, PCRECT rect2)
|
|
|
|
{
|
|
|
|
return (memcmp(rect1, rect2, sizeof(RECT)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_rect_intersect(PRECT dest, PCRECT src1, PCRECT src2)
|
|
|
|
{
|
|
|
|
if (G_is_rect_empty(src1) || G_is_rect_empty(src2))
|
|
|
|
{
|
|
|
|
memset(dest, 0, sizeof(RECT));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((src1->left >= src2->right) || (src2->left >= src1->right) || (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
|
|
|
|
{
|
|
|
|
memset(dest, 0, sizeof(RECT));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
dest->left = MAX(src1->left, src2->left);
|
|
|
|
dest->top = MAX(src1->top, src2->top);
|
|
|
|
dest->right = MIN(src1->right, src2->right);
|
|
|
|
dest->bottom = MIN(src1->bottom, src2->bottom);
|
|
|
|
ASSERT(dest->left <= dest->right);
|
|
|
|
ASSERT(dest->top <= dest->bottom);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL G_rect_union(PRECT dest, PCRECT src1, PCRECT src2)
|
|
|
|
{
|
|
|
|
if (G_is_rect_empty(src1))
|
|
|
|
{
|
|
|
|
memcpy(dest, src2, sizeof(RECT));
|
|
|
|
return !G_is_rect_empty(src2);
|
|
|
|
}
|
|
|
|
else if (G_is_rect_empty(src2))
|
|
|
|
{
|
|
|
|
memcpy(dest, src1, sizeof(RECT));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
dest->left = MIN(src1->left, src2->left);
|
|
|
|
dest->top = MIN(src1->top, src2->top);
|
|
|
|
dest->right = MAX(src1->right, src2->right);
|
|
|
|
dest->bottom = MAX(src1->bottom, src2->bottom);
|
|
|
|
return TRUE;
|
|
|
|
}
|