2023-08-03 10:19:45 +00:00
|
|
|
#pragma once
|
|
|
|
#include <ui/Point.h>
|
|
|
|
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief A simple rectangle.
|
|
|
|
*/
|
|
|
|
struct Rect
|
|
|
|
{
|
2023-08-03 15:38:49 +00:00
|
|
|
Point pos;
|
2023-08-03 10:19:45 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2023-08-03 15:38:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if a point is contained in this rectangle.
|
|
|
|
*
|
|
|
|
* @param point The point to check.
|
|
|
|
* @return true The point is contained inside the rectangle.
|
|
|
|
* @return false The point is not contained inside the rectangle.
|
|
|
|
*/
|
2023-08-03 10:19:45 +00:00
|
|
|
bool contains(Point point);
|
2023-08-03 15:38:49 +00:00
|
|
|
|
2023-08-06 10:44:16 +00:00
|
|
|
/**
|
|
|
|
* @brief Check if another rectangle is contained in this one.
|
|
|
|
*
|
|
|
|
* @param point The rectangle to check.
|
|
|
|
* @return true The other rectangle is contained inside this one.
|
|
|
|
* @return false The other rectangle is not contained inside this one.
|
|
|
|
*/
|
|
|
|
bool contains(Rect rect);
|
|
|
|
|
2023-08-03 15:38:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Normalize a point to fit inside this rectangle.
|
|
|
|
*
|
|
|
|
* @param point The original point.
|
|
|
|
* @return Point The normalized point.
|
|
|
|
*/
|
2023-08-03 10:19:45 +00:00
|
|
|
Point normalize(Point point);
|
2023-08-03 15:38:49 +00:00
|
|
|
|
2023-08-04 11:08:02 +00:00
|
|
|
/**
|
|
|
|
* @brief Transform an absolute position to a position relative to this rectangle.
|
|
|
|
*
|
|
|
|
* @param pos The original absolute position.
|
|
|
|
* @return Point The position relative to this rectangle.
|
|
|
|
*/
|
|
|
|
Point relative(Point pos);
|
|
|
|
|
2023-08-04 14:03:25 +00:00
|
|
|
/**
|
|
|
|
* @brief Transform a position relative to this rectangle to an absolute position.
|
|
|
|
*
|
|
|
|
* @param pos The original relative position.
|
|
|
|
* @return Point The absolute position.
|
|
|
|
*/
|
|
|
|
Point absolute(Point pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Transform another rectangle relative to this one to an absolute rectangle.
|
|
|
|
*
|
|
|
|
* @param rect The original relative rectangle.
|
|
|
|
* @return Point The absolute rectangle.
|
|
|
|
*/
|
|
|
|
Rect absolute(Rect rect);
|
|
|
|
|
2023-08-03 15:38:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Return a copy of this rectangle with no negative values (normalized to 0).
|
|
|
|
*
|
|
|
|
* @return Rect The new rectangle.
|
|
|
|
*/
|
2023-08-04 14:03:25 +00:00
|
|
|
Rect normalized();
|
2023-08-03 10:19:45 +00:00
|
|
|
};
|
|
|
|
}
|