18 template<
typename I =
int>
19 constexpr I WINDOWPOS_UNDEFINED_DISPLAY(uint display=0) {
20 return static_cast<I
>(SDL_WINDOWPOS_UNDEFINED_MASK | display);
23 template<
typename I =
int>
24 constexpr I WINDOWPOS_CENTERED_DISPLAY(uint display=0) {
25 return static_cast<I
>(SDL_WINDOWPOS_CENTERED_MASK | display);
28 static constexpr
int WINDOWPOS_UNDEFINED = WINDOWPOS_UNDEFINED_DISPLAY();
29 static constexpr
int WINDOWPOS_CENTERED = WINDOWPOS_CENTERED_DISPLAY();
70 static constexpr std::string_view SetAppSize{
"SetAppSize"};
71 static constexpr std::string_view SetAppPosition{
"SetAppPosition"};
72 static constexpr std::string_view SetAppState{
"SetAppState"};
76 std::pair<color::RGBA,color::RGBA> backgroundPair;
77 std::pair<BorderStyle,BorderStyle> borderStylePair;
80 return invert ? backgroundPair.second : backgroundPair.first;
84 return invert ? borderStylePair.second : borderStylePair.first;
98 constexpr
Position() noexcept =
default;
101 constexpr
Position(O X, O Y) noexcept {
102 if constexpr (std::is_same_v<T,O>) {
105 }
else if constexpr (std::is_integral_v<T> && std::is_floating_point_v<O>) {
109 x =
static_cast<T
>(X);
110 y =
static_cast<T
>(Y);
119 constexpr
explicit Position(T p) noexcept : x(p), y(p) {}
122 template <
typename O>
124 if constexpr (std::is_same_v<T,O>) {
126 }
else if constexpr (std::is_integral_v<T> && std::is_floating_point_v<O>) {
129 return Position{x +
static_cast<T
>(p.x), y + static_cast<T>(p.y)};
134 template <
typename O>
136 if constexpr (std::is_same_v<T,O>) {
138 }
else if constexpr (std::is_integral_v<T> && std::is_floating_point_v<O>) {
141 return Position{x -
static_cast<T
>(p.x), y - static_cast<T>(p.y)};
152 if constexpr (std::is_same_v<T,O>) {
154 }
else if constexpr (std::is_integral_v<O> && std::is_floating_point_v<T>) {
157 return Position<O>{
static_cast<O
>(x), static_cast<O>(y)};
163 return x != other.x || y != other.y;
168 return x == other.x && y == other.y;
173 return x <= other.x && y <= other.y;
178 return o == Orientation::Horizontal ? x : y;
183 return o == Orientation::Horizontal ? y : x;
188 return o == Orientation::Horizontal ? x : y;
193 return o == Orientation::Horizontal ? y : x;
202 auto dX = other.x - x;
203 auto dY = other.y - y;
204 return dX*dX + dY*dY;
233 constexpr
Size() noexcept =
default;
234 constexpr
Size(
int W,
int H) noexcept : w(W), h(H) {}
235 constexpr
Size(
const Size &p) =
default;
237 constexpr
Size& operator=(
const Size &p) =
default;
238 constexpr
Size& operator=(
Size &&p) =
default;
240 constexpr
explicit Size(
int size) noexcept : w(size), h(size) {}
242 constexpr
explicit Size(
const std::tuple<int,int> &size) noexcept :
Size(std::get<0>(size), std::get<1>(size)) {}
244 constexpr
Size& operator=(std::tuple<int,int> &size) noexcept {
245 w = std::get<0>(size);
246 h = std::get<0>(size);
250 explicit operator bool()
const {
return w > 0 && h > 0; }
252 bool operator!=(
const Size &other)
const noexcept {
253 return w != other.w || h != other.h;
256 bool operator==(
const Size &other)
const noexcept {
257 return w == other.w && h == other.h;
260 bool operator<(
const Size &other)
const noexcept {
261 return w < other.w && h < other.h;
264 bool operator<=(
const Size &other)
const noexcept {
265 return w <= other.w && h <= other.h;
268 bool operator>=(
const Size &other)
const noexcept {
269 return !(operator<(other));
273 return Size{w + other.w, h + other.h};
276 Size operator-(
const Size &other)
const noexcept {
277 return Size{w - other.w, h - other.h};
280 Size operator/(
const int divisor)
const {
281 return Size{w / divisor, h / divisor};
285 return o == Orientation::Horizontal ? w : h;
289 return o == Orientation::Horizontal ? h : w;
292 [[nodiscard]] constexpr
int primary(
Orientation o)
const noexcept {
293 return o == Orientation::Horizontal ? w : h;
296 [[nodiscard]] constexpr
int secondary(
Orientation o)
const noexcept {
297 return o == Orientation::Horizontal ? h : w;
308 int x{0}, y{0}, w{0}, h{0};
310 constexpr
Rectangle() noexcept =
default;
311 constexpr
Rectangle(
int X,
int Y,
int W,
int H) noexcept : x(X), y(Y), w(W), h(H) {}
337 return Rectangle{ x, y, w + s.w, h + s.h};
342 return Rectangle{ x, y, w - s.w, h - s.h};
367 auto [tl,br] = primeCorners();
368 auto [bl,tr] = crossCorners();
369 return std::make_tuple(tl,tr,bl,br);
373 [[nodiscard]] constexpr
bool contains(Position<int> pos)
const noexcept {
374 return pos.x >= x && pos.x < x + w && pos.y >= y && pos.y < y + h;
383 return x > o.x + o.w || o.x > x + w || y > o.y + o.h || o.y > y + h;
392 return !noOverlap(o);
399 auto x5 = std::max(x, o.x);
400 auto y5 = std::max(y, o.y);
404 auto x6 = std::min(x+w, o.x+o.w);
405 auto y6 = std::min(y+h, o.y+o.h);
408 if (x5 > x6 || y5 > y6) {
412 return Rectangle{x5, y5, x6 - x5, y6 - y5};
416 return o == Orientation::Horizontal ? w : h;
420 return o == Orientation::Horizontal ? h : w;
424 return o == Orientation::Horizontal ? x : y;
428 return o == Orientation::Horizontal ? y : x;
431 [[nodiscard]] constexpr
int sizePri(
Orientation o)
const noexcept {
432 return o == Orientation::Horizontal ? w : h;
435 [[nodiscard]] constexpr
int sizeSec(
Orientation o)
const noexcept {
436 return o == Orientation::Horizontal ? h : w;
439 [[nodiscard]] constexpr
int posPri(
Orientation o)
const noexcept {
440 return o == Orientation::Horizontal ? x : y;
443 [[nodiscard]] constexpr
int posSec(
Orientation o)
const noexcept {
444 return o == Orientation::Horizontal ? y : x;
455 int t{0}, b{0}, l{0}, r{0};
457 constexpr
Padding() noexcept =
default;
459 constexpr
explicit Padding(
int p) noexcept : t(p), b(p), l(p), r(p) {}
461 constexpr
Padding(
int h,
int v) noexcept : t(v), b(v), l(h), r(h) {}
463 constexpr
Padding(
int top,
int bot,
int left,
int right) noexcept : t(top), b(bot), l(left), r(right) {}
465 [[nodiscard]] constexpr
int vertical()
const noexcept {
return t + b; }
467 [[nodiscard]] constexpr
int horizontal()
const noexcept {
return l + r; }
471 [[nodiscard]] constexpr
Size size()
const noexcept {
return Size{horizontal(), vertical()}; }
474 return o == Orientation::Horizontal ? l : t;
478 return o == Orientation::Horizontal ? r : b;
482 return o == Orientation::Horizontal ? t : l;
486 return o == Orientation::Horizontal ? b : r;
489 [[nodiscard]] constexpr
int priLead(
Orientation o)
const noexcept {
490 return o == Orientation::Horizontal ? l : t;
493 [[nodiscard]] constexpr
int priLag(
Orientation o)
const noexcept {
494 return o == Orientation::Horizontal ? r : b;
497 [[nodiscard]] constexpr
int secLead(
Orientation o)
const noexcept {
498 return o == Orientation::Horizontal ? t : l;
501 [[nodiscard]] constexpr
int secLag(
Orientation o)
const noexcept {
502 return o == Orientation::Horizontal ? b : r;
506 std::array<char, 8> utf8(
int c);
510 inline std::ostream& operator<<(std::ostream& strm,
const rose::Size &size) {
511 strm <<
'(' << size.w <<
',' << size.h <<
')';
517 inline std::ostream& operator<<(std::ostream& strm, const rose::Position<T> &pos) {
518 strm <<
'(' << pos.x <<
',' << pos.y <<
')';
523 inline std::ostream& operator<<(std::ostream& strm,
const rose::Rectangle &rec) {
524 strm <<
'(' << rec.x <<
',' << rec.y <<
',' << rec.w <<
',' << rec.h <<
')';
529 inline std::ostream& operator<<(std::ostream& strm,
const rose::Padding &pad) {
530 strm <<
'[' << pad.t <<
',' << pad.l <<
',' << pad.b <<
',' << pad.r <<
']';
std::pair< Position< int >, Position< int > > primeCorners() const noexcept
Get the Positions of top-left and bottom-right corners defined by the Rectangle.
Definition: Types.h:356
std::pair< Position< int >, Position< int > > crossCorners() const noexcept
Get the Positions of the top-right and bottom-left corners defined by the Rectangle.
Definition: Types.h:361
void swap() noexcept
Swap the x and y components.
Definition: Types.h:208
T & secondary(Orientation o) noexcept
Access the secondary component for the given Orientation.
Definition: Types.h:182
int roundToInt(T value, T multiplier=1.)
Round a floating point value to an integer.
Definition: Math.h:34
The renderer uses hardware acceleration.
Definition: Types.h:36
constexpr bool contains(Position< int > pos) const noexcept
Determine if a Rectangle contains a Position.
Definition: Types.h:373
bool operator!=(const Position &other) const noexcept
Inequality operator.
Definition: Types.h:162
constexpr bool noOverlap(const Rectangle &o) const noexcept
Determine if there is no overlap between two Rectangle objects.
Definition: Types.h:382
constexpr T secondary(Orientation o) const noexcept
Return the secondary component for the given Orientation.
Definition: Types.h:192
Red Green Blue Alpha representation of a color.
Definition: Color.h:64
constexpr T rSqr(const Position &other) const noexcept
Compute the distance squared from this position to another.
Definition: Types.h:201
Not set to a valid value.
std::tuple< Position< int >, Position< int >, Position< int >, Position< int > > corners() const noexcept
Get the Positions of all four corners defined by the Rectangle, top to bottom, left to right...
Definition: Types.h:366
The renderer is a software fallback.
Definition: Types.h:35
T & primary(Orientation o) noexcept
Access the primary component for a given Orientation.
Definition: Types.h:177
A notched border that looks like a trench surrounding the frame.
Definition: Frame.h:28
constexpr T primary(Orientation o) const noexcept
Return the primary component for a given Orientation.
Definition: Types.h:187
CornerStyle
Types of corners supported.
Definition: Types.h:63
bool operator==(const Position &other) const noexcept
Equality operator.
Definition: Types.h:167
Present is synchronized with the refresh rate.
Definition: Types.h:37
bool operator<=(const Position &other) const noexcept
Less than or Equal to operator.
Definition: Types.h:172
constexpr Position operator-(const Position< O > &p) const noexcept
Subtract position other from this.
Definition: Types.h:135
constexpr bool overlap(const Rectangle &o) const noexcept
Determine if there is overlap between to Rectangle objects by inverting noOverlap().
Definition: Types.h:391
A position in integer (x, y) co-ordinates.
Definition: Types.h:95
constexpr Position< T > mirrorY() const noexcept
Mirror Position on Y axis.
Definition: Types.h:218
Abstraction of space consumed around an object for space, borders, etc.
Definition: Types.h:454
Definition: SettingsNames.h:13
Position< int > position() const noexcept
Get a Position from a Rectangle.
Definition: Types.h:346
A beveled border that gives the illusion the frame stands up from the display.
Definition: Frame.h:25
constexpr Position< T > mirrorX() const noexcept
Mirror Position on X axis.
Definition: Types.h:213
Orientation
Possible values for Widget orientation.
Definition: Types.h:41
A notched border that looks like a ridge surrounding the frame.
Definition: Frame.h:27
A composite of a Position and a Size.
Definition: Types.h:307
RendererFlags
Flags used when creating a rendering context.
Definition: Types.h:34
GaugeIndex operator+(const GaugeIndex &gaugeIndex, unsigned long increment)
Add an unsigned integer to a GaugeIndex.
Definition: Gauge.h:60
The renderer supports rendering to texture.
Definition: Types.h:38
A size in integer dimensions.
Definition: Types.h:230
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
BorderStyle
The types of border supported.
Definition: Types.h:50
Position< O > as() const
Return this position after converting to type O.
Definition: Types.h:151
constexpr Position operator+(const Position< O > &p) const noexcept
Add two positions together.
Definition: Types.h:123
Size size() const noexcept
Get a Size from a Rectangle.
Definition: Types.h:351