Luna/libui/src/Rect.cpp

33 lines
815 B
C++
Raw Normal View History

2023-08-03 10:19:45 +00:00
#include <ui/Rect.h>
namespace ui
{
bool Rect::contains(Point point)
{
2023-08-03 15:38:49 +00:00
return (point.x >= pos.x) && (point.y >= pos.y) && (point.x <= (pos.x + width)) &&
(point.y <= (pos.y + height));
2023-08-03 10:19:45 +00:00
}
Point Rect::normalize(Point point)
{
2023-08-03 15:38:49 +00:00
if (point.x < pos.x) point.x = pos.x;
if (point.y < pos.y) point.y = pos.y;
if (point.x > pos.x + width) point.x = pos.x + width;
if (point.y > pos.y + height) point.y = pos.y + height;
2023-08-03 10:19:45 +00:00
return point;
}
2023-08-03 15:38:49 +00:00
2023-08-04 11:08:02 +00:00
Point Rect::relative(Point point)
{
point = normalize(point);
point.x -= pos.x;
point.y -= pos.y;
return point;
}
2023-08-03 15:38:49 +00:00
Rect Rect::absolute()
{
return Rect { ui::Point { pos.x < 0 ? 0 : pos.x, pos.y < 0 ? 0 : pos.y }, width, height };
}
2023-08-03 10:19:45 +00:00
};