16 #include "Utilities.h" 24 class Size :
public std::array<int, 2> {
30 constexpr
explicit Size(std::array<int, 2> value) noexcept: std::array<int, 2>(value) {}
33 constexpr
explicit Size(
int value = 0) noexcept:
Size(
std::array<
int, 2>({value, value})) {}
39 constexpr
Size(
const Size &) =
default;
45 constexpr
Size& operator=(
const Size &) =
default;
48 constexpr
Size& operator=(
Size &&) =
default;
50 constexpr
explicit Size(
const std::tuple<int,int> &t) noexcept
51 :
Size(std::get<0>(t), std::get<1>(t)) {}
55 width() = std::get<0>(t);
61 constexpr
int &
width() {
return operator[](0); }
64 [[nodiscard]] constexpr
int width() const noexcept {
return operator[](0); }
67 constexpr
int &
height() {
return operator[](1); }
70 [[nodiscard]] constexpr
int height() const noexcept {
return operator[](1); }
77 switch (orientation) {
80 case Orientation::Horizontal:
82 case Orientation::Vertical:
93 switch (orientation) {
96 case Orientation::Horizontal:
98 case Orientation::Vertical:
108 switch (orientation) {
111 case Orientation::Horizontal:
113 case Orientation::Vertical:
124 switch (orientation) {
127 case Orientation::Horizontal:
129 case Orientation::Vertical:
150 class Position :
public std::array<int, 2> {
156 constexpr
explicit Position(std::array<int, 2> value) noexcept: std::array<int, 2>(value) {}
177 constexpr
int &
x() {
return operator[](0); }
180 [[nodiscard]] constexpr
int x() const noexcept {
return operator[](0); }
183 constexpr
int &
y() {
return operator[](1); }
186 [[nodiscard]] constexpr
int y() const noexcept {
return operator[](1); }
193 switch (orientation) {
196 case Orientation::Horizontal:
198 case Orientation::Vertical:
209 switch (orientation) {
212 case Orientation::Horizontal:
214 case Orientation::Vertical:
224 switch (orientation) {
227 case Orientation::Horizontal:
229 case Orientation::Vertical:
240 switch (orientation) {
243 case Orientation::Horizontal:
245 case Orientation::Vertical:
253 return Position{x() + position.x(), y() + position.y()};
258 return Position{x() - position.x(), y() - position.y()};
267 [[nodiscard]] constexpr
int abs() const noexcept {
268 return x() * x() + y() * y();
276 class Rectangle :
public std::array<int, 4> {
281 constexpr
explicit Rectangle(std::array<int, 4> value) noexcept: std::array<int, 4>(value) {}
285 std::array<
int, 4>({value, value, value, value})) {}
308 constexpr
Rectangle(
const std::optional<Position> &pos,
const std::optional<Size> &size) : Rectangle() {
314 width() = size->width();
315 height() = size->height();
320 constexpr
int &
x() {
return operator[](0); }
323 [[nodiscard]] constexpr
int x() const noexcept {
return operator[](0); }
326 constexpr
int &
y() {
return operator[](1); }
329 [[nodiscard]] constexpr
int y() const noexcept {
return operator[](1); }
332 constexpr
int &
width() {
return operator[](2); }
335 [[nodiscard]] constexpr
int width() const noexcept {
return operator[](2); }
338 constexpr
int &
height() {
return operator[](3); }
341 [[nodiscard]] constexpr
int height() const noexcept {
return operator[](3); }
343 constexpr
int &positionPrimary(
Orientation orientation) {
344 if (orientation == Orientation::Horizontal)
345 return operator[](0);
347 return operator[](1);
350 constexpr
int &positionSecondary(
Orientation orientation) {
351 if (orientation == Orientation::Horizontal)
352 return operator[](1);
354 return operator[](0);
357 constexpr
int &sizePrimary(
Orientation orientation) {
358 if (orientation == Orientation::Horizontal)
359 return operator[](2);
361 return operator[](3);
364 constexpr
int &sizeSecondary(
Orientation orientation) {
365 if (orientation == Orientation::Horizontal)
366 return operator[](3);
368 return operator[](2);
381 [[nodiscard]] constexpr SDL_Rect toSdlRect()
const noexcept {
392 width() = size.width();
414 r.x() += deltaPos.x();
415 r.y() += deltaPos.y();
423 r += deltaPos.value();
424 r.
width() -= deltaPos->x();
425 r.height() -= deltaPos->y();
432 return pos.x() >= x() && pos.x() < x() +
width() && pos.y() >= y() && pos.y() < y() +
height();
441 return x() > o.x() + o.width() ||
442 o.x() > x() +
width() ||
443 y() > o.y() + o.height() ||
453 return !noOverlap(o);
460 auto x5 = std::max(x(), o.x());
461 auto y5 = std::max(y(), o.y());
465 auto x6 = std::min(x()+
width(), o.x()+o.
width());
469 if (x5 > x6 || y5 > y6) {
473 return Rectangle{x5, y5, x6 - x5, y6 - y5};
481 class Padding :
public std::array<int,4> {
486 constexpr
explicit Padding(std::array<int, 4> value) noexcept: std::array<int, 4>(value) {}
490 std::array<
int, 4>({value, value, value, value})) {}
494 std::array<int, 4>({left, top, right, bottom})) {}
497 [[nodiscard]] constexpr
int left() const noexcept {
return (*
this)[0]; }
498 [[nodiscard]] constexpr
int right() const noexcept {
return (*
this)[1]; }
499 [[nodiscard]] constexpr
int top() const noexcept {
return (*
this)[2]; }
500 [[nodiscard]] constexpr
int bottom() const noexcept {
return (*
this)[3]; }
501 [[nodiscard]] constexpr
int width() const noexcept {
return left() + right(); }
502 [[nodiscard]] constexpr
int height() const noexcept {
return top() + bottom(); }
509 int&
left() noexcept {
return (*
this)[0]; }
510 int&
right() noexcept {
return (*
this)[1]; }
511 int&
top() noexcept {
return (*
this)[2]; }
512 int&
bottom() noexcept {
return (*
this)[3]; }
515 std::copy(other.cbegin(), other.cend(), this->begin());
519 constexpr
Padding& operator=(
int value) noexcept {
520 for (
auto &v : *
this) {
540 constexpr
Line() noexcept : mPoint0(), mPoint1() {}
550 constexpr
Line(
const Line &) =
default;
556 constexpr
Line& operator=(
const Line &) =
default;
559 constexpr
Line &operator=(
Line &&) =
default;
572 template<
typename T,
size_t N>
573 inline std::ostream &operator<<(std::ostream &strm, const std::array<T, N> &array) {
574 return rose::util::printScreenMetric<T, N>(strm, array);
585 inline std::ostream &operator<<(std::ostream &strm, const std::optional<T> &opt) {
587 if constexpr (std::is_same_v<T, rose::Rectangle>)
588 rose::util::printScreenMetric<int, 4>(strm, opt.value());
589 if constexpr (std::is_same_v<T, rose::Position> || std::is_same_v<T, rose::Size>)
590 rose::util::printScreenMetric<int,2>(strm, opt.value());
constexpr Size & operator=(const std::tuple< int, int > t) noexcept
Copy assign tuple.
Definition: ScreenMetrics.h:54
constexpr int secondary(Orientation orientation) const noexcept
Value for secondary axis value.
Definition: ScreenMetrics.h:123
constexpr Rectangle(const std::optional< Position > &pos, const std::optional< Size > &size)
Constructor initialize to the value of std::optional Position and Size.
Definition: ScreenMetrics.h:308
constexpr Size(int width, int height) noexcept
Constructor sets value to descrete values.
Definition: ScreenMetrics.h:36
constexpr Rectangle & operator=(const Position &position)
Assign a Position to a Rectangle.
Definition: ScreenMetrics.h:398
constexpr Rectangle moveOrigin(const std::optional< Position > &deltaPos) const
Move the origin of a Rectangle by an optional deltaPos and reduce the size of the rectangle by a corr...
Definition: ScreenMetrics.h:420
constexpr bool noOverlap(const Rectangle &o) const noexcept
Determine if there is no overlap between two Rectangle objects.
Definition: ScreenMetrics.h:440
static const Position Zero
A zero position.
Definition: ScreenMetrics.h:153
constexpr int height() const noexcept
Value access to height.
Definition: ScreenMetrics.h:341
constexpr int height() const noexcept
Value accessor for height.
Definition: ScreenMetrics.h:70
static const Rectangle Zero
A rectangle with position and size of zero.
Definition: ScreenMetrics.h:278
Not set to a valid value.
constexpr int primary(Orientation orientation) const noexcept
Value for primary axis value.
Definition: ScreenMetrics.h:208
constexpr int primary(Orientation orientation) const noexcept
Value for primary axis value.
Definition: ScreenMetrics.h:92
int & primary(Orientation orientation)
Reference for primary axis value.
Definition: ScreenMetrics.h:76
constexpr Rectangle(const Position &pos, const Size &size)
Constructor initialize to the value of a Position and Size.
Definition: ScreenMetrics.h:304
constexpr int secondary(Orientation orientation) const noexcept
Value for secondary axis value.
Definition: ScreenMetrics.h:239
constexpr Rectangle operator+(const Position &deltaPos)
Add a Position to a Rectangle.
Definition: ScreenMetrics.h:412
constexpr int abs() const noexcept
Compute the square of the scalar distance of a position from the origin.
Definition: ScreenMetrics.h:267
constexpr Position padPos() const noexcept
Get the position of the padding.
Definition: ScreenMetrics.h:507
constexpr int & x()
Reference access to x.
Definition: ScreenMetrics.h:320
constexpr Line() noexcept
Construct line of zero length.
Definition: ScreenMetrics.h:540
constexpr int bottom() const noexcept
Get the bottom padding.
Definition: ScreenMetrics.h:500
constexpr Size padSize() const noexcept
Get the total size of the padding.
Definition: ScreenMetrics.h:505
An abstraction of a line defined by two end points.
Definition: ScreenMetrics.h:531
constexpr Size operator-(const Size &size) const noexcept
Subtraction operator.
Definition: ScreenMetrics.h:141
constexpr int & width()
Reference accessor for width.
Definition: ScreenMetrics.h:61
constexpr bool overlap(const Rectangle &o) const noexcept
Determine if there is overlap between to Rectangle objects by inverting noOverlap().
Definition: ScreenMetrics.h:452
constexpr int left() const noexcept
Get the left padding.
Definition: ScreenMetrics.h:497
A position in integer (x, y) co-ordinates.
Definition: Types.h:95
constexpr int width() const noexcept
Value accessor for width.
Definition: ScreenMetrics.h:64
Constants and Enumerations.
Abstraction of space consumed around an object for space, borders, etc.
Definition: Types.h:454
constexpr int & width()
Reference access to width.
Definition: ScreenMetrics.h:332
constexpr Position operator+(const Position &position) const noexcept
Addition operator.
Definition: ScreenMetrics.h:252
constexpr Padding(int left, int top, int right, int bottom) noexcept
Constructor initialize to descrete x, y, width, and height values.
Definition: ScreenMetrics.h:493
constexpr Line(const Position &p0, const Position &p1)
Construct a line from p0 to p1.
Definition: ScreenMetrics.h:547
constexpr Rectangle(std::array< int, 4 > value) noexcept
Constructor initialize to the value of an array.
Definition: ScreenMetrics.h:281
int & secondary(Orientation orientation)
Reference for secondary axis value.
Definition: ScreenMetrics.h:223
constexpr Position operator-(const Position &position) const noexcept
Subtraction operator.
Definition: ScreenMetrics.h:257
constexpr Rectangle & operator=(const Size &size)
Assign a Size to a Rectangle.
Definition: ScreenMetrics.h:391
int & secondary(Orientation orientation)
Reference for secondary axis value.
Definition: ScreenMetrics.h:107
constexpr Size getSize() const noexcept
Get the Size of a Rectangle.
Definition: ScreenMetrics.h:372
constexpr Position getPosition() const noexcept
Get the Position of a Rectangle.
Definition: ScreenMetrics.h:377
constexpr int x() const noexcept
Value access to x.
Definition: ScreenMetrics.h:180
constexpr Rectangle(int value=0) noexcept
Default constructor initializes x and y to 0 or to a specified value.
Definition: ScreenMetrics.h:284
constexpr bool contains(Position pos) const noexcept
Determine if a Rectangle contains a Position.
Definition: ScreenMetrics.h:431
constexpr int top() const noexcept
Get the top padding.
Definition: ScreenMetrics.h:499
Position mPoint1
The other endpoint of the line.
Definition: ScreenMetrics.h:534
constexpr int & y()
Reference access to y.
Definition: ScreenMetrics.h:326
Orientation
Possible values for Widget orientation.
Definition: Types.h:41
int & bottom() noexcept
Access the bottom padding.
Definition: ScreenMetrics.h:512
constexpr int height() const noexcept
Get the height of the padding.
Definition: ScreenMetrics.h:502
constexpr int y() const noexcept
Value access to y.
Definition: ScreenMetrics.h:329
constexpr int width() const noexcept
Value access to width.
Definition: ScreenMetrics.h:335
constexpr int right() const noexcept
Get the right padding.
Definition: ScreenMetrics.h:498
constexpr Rectangle(int x, int y, int width, int height) noexcept
Constructor initialize to descrete x, y, width, and height values.
Definition: ScreenMetrics.h:288
A composite of a Position and a Size.
Definition: Types.h:307
static const Size Zero
A zero size.
Definition: ScreenMetrics.h:27
int & primary(Orientation orientation)
Reference for primary axis value.
Definition: ScreenMetrics.h:192
int & left() noexcept
Access the left padding.
Definition: ScreenMetrics.h:509
constexpr Rectangle & operator+=(const Position &deltaPos)
Move a Rectangle by a delta Position.
Definition: ScreenMetrics.h:405
int & top() noexcept
Access the top padding.
Definition: ScreenMetrics.h:511
static const Padding Zero
A rectangle with position and size of zero.
Definition: ScreenMetrics.h:483
constexpr Position(int x, int y) noexcept
Constructor initialize to descrete x and y values.
Definition: ScreenMetrics.h:162
A size in integer dimensions.
Definition: Types.h:230
constexpr int width() const noexcept
Get the width of the padding.
Definition: ScreenMetrics.h:501
Position mPoint0
One endpoint of the line.
Definition: ScreenMetrics.h:533
constexpr Size operator+(const Size &size) const noexcept
Addition operator.
Definition: ScreenMetrics.h:136
constexpr Padding(std::array< int, 4 > value) noexcept
Constructor initialize to the value of an array.
Definition: ScreenMetrics.h:486
constexpr Padding(int value=0) noexcept
Default constructor initializes x and y to 0 or to a specified value.
Definition: ScreenMetrics.h:489
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
constexpr int & x()
Reference access to x.
Definition: ScreenMetrics.h:177
int & right() noexcept
Access the right padding.
Definition: ScreenMetrics.h:510
constexpr Position(int value=0) noexcept
Default constructor initializes x and y to 0 or to a specified value.
Definition: ScreenMetrics.h:159
constexpr Size(int value=0) noexcept
Default constructor initializes width and height to 0 or to a specified value.
Definition: ScreenMetrics.h:33
constexpr int y() const noexcept
Value access to y.
Definition: ScreenMetrics.h:186
constexpr int x() const noexcept
Value access to x.
Definition: ScreenMetrics.h:323
constexpr Size(std::array< int, 2 > value) noexcept
Constructor sets value to contents of an array.
Definition: ScreenMetrics.h:30
constexpr Position(std::array< int, 2 > value) noexcept
Constructor initialize to the value of an array.
Definition: ScreenMetrics.h:156
constexpr int & height()
Reference access to height.
Definition: ScreenMetrics.h:338
constexpr int & height()
Reference accessor for height.
Definition: ScreenMetrics.h:67
constexpr int & y()
Reference access to y.
Definition: ScreenMetrics.h:183