Rose
Types.h
1 
8 #pragma once
9 
10 #include <chrono>
11 #include <exception>
12 #include <memory>
13 #include <sstream>
14 #include <functional>
15 #include <map>
16 #include <tuple>
17 #include <variant>
18 #include <cstdint>
19 #include <uuid/uuid.h>
20 #include <SDL2/SDL.h>
21 #include "Constants.h"
22 #include "Math.h"
23 
24 namespace rose {
25 #ifdef DISPLAY800X480
26  static constexpr int DISPLAY_WIDTH = 800;
27  static constexpr int DISPLAY_HEIGHT = 480;
28  static constexpr int EARTH_BIG_W = 660;
29  static constexpr int EARTH_BIG_H = 330;
30  static constexpr std::string_view EARTH_BIG_S = "660x330";
31 #define EARTH_BIG_S 660x330
32 #else
33  static constexpr int DISPLAY_WIDTH = 800;
34  static constexpr int DISPLAY_HEIGHT = 480;
35  static constexpr int EARTH_BIG_W = 660;
36  static constexpr int EARTH_BIG_H = 330;
37 #define EARTH_BIG_S 660x330
38 #endif
39 
43  using FontSize = int;
44 
48  using ImageId = uint32_t;
49 
53  using SignalToken = uint32_t;
54 
56  using LinearScaleSignalType = std::pair<float, SignalToken>;
57 
62  struct StartOffset {
64  };
65 
70  struct FillToEnd {
71  bool mFillToEnd;
72  };
73 
78  struct InternalSpace {
80  };
81 
88  };
89 
94  class GeoPosition : public std::array<double, 2> {
95  public:
96  constexpr GeoPosition() noexcept: std::array<double,2>({0., 0.}) {}
97 
98  constexpr GeoPosition(double lat, double lon) noexcept
99  : std::array<double,2>({std::clamp(lat,-90.,90.),
100  std::clamp(lon,-180.,180.)}) {}
101 
102  constexpr explicit GeoPosition(std::tuple<double,double> geo) : GeoPosition(std::get<0>(geo), std::get<1>(geo)) {}
103 
104  GeoPosition& operator=(const std::tuple<double,double>& geo) {
105  at(0) = std::get<0>(geo);
106  at(1) = std::get<1>(geo);
107  return *this;
108  }
109 
110  [[nodiscard]] GeoPosition radians() const {
111  GeoPosition r{util::deg2rad(at(0)), util::deg2rad(at(1))};
112  return r;
113  }
114 
115  constexpr double& lat() noexcept {
116  return at(0);
117  }
118 
119  constexpr double& lon() noexcept {
120  return at(1);
121  }
122 
123  [[nodiscard]] constexpr double lat() const noexcept {
124  return at(0);
125  }
126 
127  [[nodiscard]] constexpr double lon() const noexcept {
128  return at(1);
129  }
130  };
131 
136  class Elastic {
137  protected:
139 
140  public:
141 
143  Elastic() = default;
144 
146  explicit Elastic(Orientation orientation) : mElastic(orientation) {}
147 
149  bool horizontal() { return mElastic == Orientation::Horizontal || mElastic == Orientation::Both; }
150 
152  bool vertical() { return mElastic == Orientation::Vertical || mElastic == Orientation::Both; }
153 
155  bool primary(Orientation orientation) { return mElastic == Orientation::Both || mElastic == orientation; }
156 
158  bool secondary(Orientation orientation) {
159  if (mElastic == Orientation::Both)
160  return true;
161  if (orientation == Orientation::Horizontal && mElastic == Orientation::Vertical)
162  return true;
163  if (orientation == Orientation::Vertical && mElastic == Orientation::Horizontal)
164  return true;
165  return false;
166  }
167  };
168 
173  struct FontName {
174  std::string fontName{};
175  FontName() : fontName() {}
176  explicit FontName(const char *string) : fontName(string) {}
177  explicit FontName(const std::string_view stringView) : fontName(stringView) {}
178  explicit FontName(std::string string) : fontName(std::move(string)) {}
179  };
180 
185  class RoseLogicError : public std::logic_error {
186  public:
188  explicit RoseLogicError(const std::string &what) : std::logic_error(what) {}
189 
191  explicit RoseLogicError(std::string_view what) : std::logic_error(std::string(what)) {}
192 
194  explicit RoseLogicError(const char *what) : std::logic_error(std::string(what)) {}
195  };
196 
201  class RoseRuntimeError : public std::runtime_error {
202  public:
204  explicit RoseRuntimeError(const std::string &what) : std::runtime_error(what) {}
205 
207  explicit RoseRuntimeError(std::string_view what) : std::runtime_error(std::string(what)) {}
208 
210  explicit RoseRuntimeError(const char *what) : std::runtime_error(std::string(what)) {}
211  };
212 }
int mInternalSpace
The internal spacing value, pixels.
Definition: Types.h:79
Thrown when a structural logic error is detected at runtime.
Definition: Types.h:185
RoseLogicError(std::string_view what)
Constructor.
Definition: Types.h:191
uint32_t SignalToken
A type definition for SignalToken used to identify the source of a Signal.
Definition: Types.h:53
int mMinimumOrthogonal
The minimum orthogonal size.
Definition: Types.h:87
int mStartOffset
The start offset value, pixels.
Definition: Types.h:63
Not set to a valid value.
Elastic(Orientation orientation)
Construct an elastic value from an Orientation.
Definition: Types.h:146
A structure to pass a Font name to a Widget through a manipulator.
Definition: Text.h:28
RoseLogicError(const std::string &what)
Constructor.
Definition: Types.h:188
RoseRuntimeError(std::string_view what)
Constructor.
Definition: Types.h:207
A manipulator to set the fill to end flag on a Box widget or subclasses.
Definition: Types.h:70
std::pair< float, SignalToken > LinearScaleSignalType
Type definition for the LinearScale Signal type.
Definition: Types.h:56
A manipulator to specify the internal spacing between children along the primary axis.
Definition: Types.h:78
bool mFillToEnd
The value of the fill to end flag.
Definition: Types.h:71
int FontSize
Type specifier to pass a Font size to a Widget through a manipulator.
Definition: Types.h:43
An abstraction of a geographic position.
Definition: MapProjection.h:165
Both axis – for Elastic.
Constants and Enumerations.
bool vertical()
Test for elasticity along the Vertical axis.
Definition: Types.h:152
RoseRuntimeError(const char *what)
Constructor.
Definition: Types.h:210
Orientation
Possible values for Widget orientation.
Definition: Types.h:41
A manipulator to specify the minimum orthogonal size of a Widget, if supported.
Definition: Types.h:86
bool secondary(Orientation orientation)
Test for elasticity along the Secondary axis.
Definition: Types.h:158
bool horizontal()
Test for elasticity along the Horizontal axis.
Definition: Types.h:149
A stream manipulator to set a Widget elastic value.
Definition: Types.h:136
RoseLogicError(const char *what)
Constructor.
Definition: Types.h:194
RoseRuntimeError(const std::string &what)
Constructor.
Definition: Types.h:204
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
bool primary(Orientation orientation)
Test for elasticity along the Primary axis.
Definition: Types.h:155
A manipulator to specify the an offset for the first child of a Container along the primary axis...
Definition: Types.h:62
Thrown when a runtime error has occurred.
Definition: Types.h:201