You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
#ifndef MONOFORMAT_GFX_HPP
|
|
#define MONOFORMAT_GFX_HPP
|
|
|
|
#include <cstdint>
|
|
|
|
namespace monoformat {
|
|
|
|
struct Point {
|
|
std::int32_t x{};
|
|
std::int32_t y{};
|
|
|
|
friend inline Point operator+(Point const& a, Point const& b) noexcept {
|
|
return {a.x + b.x, a.y + b.y};
|
|
}
|
|
|
|
friend inline Point operator-(Point const& a, Point const& b) noexcept {
|
|
return {a.x - b.x, a.y - b.y};
|
|
}
|
|
|
|
inline Point& operator+=(Point const& b) noexcept {
|
|
x += b.x;
|
|
y += b.y;
|
|
return *this;
|
|
}
|
|
|
|
inline Point& operator-=(Point const& b) noexcept {
|
|
x -= b.x;
|
|
y -= b.y;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
struct Size {
|
|
std::uint32_t width{};
|
|
std::uint32_t height{};
|
|
};
|
|
|
|
struct Rectangle {
|
|
Point topLeft{};
|
|
Size size{};
|
|
|
|
Point getBottomRight() const noexcept {
|
|
return {topLeft.x + static_cast<std::int32_t>(size.width) - 1, topLeft.y + static_cast<std::int32_t>(size.height) - 1};
|
|
}
|
|
|
|
static Rectangle fromCorners(Point topLeft, Point bottomRight) {
|
|
Size sz{static_cast<std::uint32_t>(bottomRight.x - topLeft.x + 1), static_cast<std::uint32_t>(bottomRight.y - topLeft.y + 1)};
|
|
return Rectangle{topLeft, sz};
|
|
}
|
|
};
|
|
|
|
} // namespace monoformat
|
|
|
|
#endif // MONOFORMAT_GFX_HPP
|
|
|