Rose
Gauge.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "Frame.h"
11 #include "Signals.h"
12 #include "Utilities.h"
13 
14 namespace rose {
15 
25  enum class GaugeIndex : unsigned long {
26  LowerBound = 0,
27  LowWarning,
28  LowNormal,
29  HighNormal,
30  HighWarning,
31  UpperBound,
32  };
33 
34  constexpr inline auto indexValue(const GaugeIndex &g) {
35  using IntType = typename std::underlying_type<GaugeIndex>::type;
36  return static_cast<IntType>(g);
37  }
38 
45  inline GaugeIndex& operator++( GaugeIndex &gaugeIndex ) {
46  using IntType = typename std::underlying_type<GaugeIndex>::type;
47  if (gaugeIndex == GaugeIndex::UpperBound)
48  throw std::domain_error("Incrementing GaugeIndex beyond UpperBound.");
49  gaugeIndex = static_cast<GaugeIndex>( static_cast<IntType>(gaugeIndex) + 1 );
50  return gaugeIndex;
51  }
52 
60  inline GaugeIndex operator+(const GaugeIndex &gaugeIndex, unsigned long increment) {
61  using IntType = typename std::underlying_type<GaugeIndex>::type;
62  if (static_cast<IntType>(gaugeIndex) + increment > indexValue(GaugeIndex::UpperBound))
63  throw std::domain_error("Incrementing GaugeIndex beyond UpperBound.");
64  return static_cast<GaugeIndex>(static_cast<IntType>(gaugeIndex) + increment);
65  }
66 
67  using GaugeValueLimits = std::array<float,6>;
68  using GaugeValueHues = std::array<uint32_t,5>;
69 
74  class Gauge : public Frame {
75  protected:
80  class GaugeInterior : public Widget {
81  protected:
82  friend class Gauge;
83  bool mTextureValid{false};
84  sdl::Texture mTexture{};
86 
87  static array<int, 6>
88  computeValueBands(GaugeValueLimits gaugeValueLimits, Rectangle rect, Orientation orientation);
89 
90  public:
91  GaugeInterior() = default;
92  ~GaugeInterior() override = default;
93  GaugeInterior(const Gauge &) = delete;
94  GaugeInterior& operator=(const GaugeInterior &) = delete;
95  GaugeInterior(GaugeInterior &&) = delete;
96  GaugeInterior& operator=(GaugeInterior &&) = delete;
97 
101  Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override;
102 
104  void draw(sdl::Renderer &renderer, Rectangle parentRect) override;
105 
107  void setOrientation(Orientation orientation) override { mOrientation = orientation; }
108  };
109 
110  friend class GaugeInterior;
111 
118  static constexpr GaugeValueLimits defaultLimits = {0.f, 0.1f, 0.2f,
119  0.8f, 0.9f, 1.f};
120 
126  static constexpr GaugeValueHues defaultHues = { 300, 240, 120,
127  60, 10};
128  float mValue{0.f};
129  sdl::Texture mTexture{};
130  int mStripLength{0};
131  ImageId mIndicator{RoseImageInvalid};
132 
138 
144 
146 
147  public:
148  ~Gauge() override = default;
149  Gauge(const Gauge &) = delete;
150  Gauge& operator=(const Gauge &) = delete;
151  Gauge(Gauge &&) = delete;
152  Gauge& operator=(Gauge &&) = delete;
153 
158  explicit Gauge(ImageId imageId = RoseImageInvalid);
159 
165  Gauge(const GaugeValueLimits &gaugeValueLimits, const GaugeValueHues &gaugeValueHuess, ImageId imageId = RoseImageInvalid);
166 
172  Gauge(GaugeValueLimits &&gaugeValueLimits, GaugeValueHues &&gaugeValueHues, ImageId imageId = RoseImageInvalid);
173 
177  void initializeComposite() override;
178 
182  Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override;
183 
187  void draw(sdl::Renderer &renderer, Rectangle parentRect) override;
188 
189  std::shared_ptr<Slot<float>> valueRx;
190 
195  void setValue(float value);
196 
197  void setOrientation(Orientation orientation) override;
198  };
199 }
200 
Manages the interior of the Gauge.
Definition: Gauge.h:80
GaugeIndex & operator++(GaugeIndex &gaugeIndex)
GaugeIndex pre-increment operator.
Definition: Gauge.h:45
Invalid image ID.
Definition: Constants.h:172
The top of the warning band value and HighEmergency color.
The top of the normal band value and HighWarning color.
std::array< uint32_t, 5 > GaugeValueHues
Type of Gauge colors.
Definition: Gauge.h:68
Not set to a valid value.
GaugeIndex
Definition: Gauge.h:25
Index to the maximum displayable value.
void setOrientation(Orientation orientation) override
See Widget::setOrientation();.
Definition: Gauge.h:107
Index to the minimum displayable value and LowEmergency color.
An encapsulation of the SDL_Texture structure.
Definition: Texture.h:40
std::shared_ptr< Slot< float > > valueRx
A Slot to receive values on.
Definition: Gauge.h:189
Definition: Frame.h:214
std::array< float, 6 > GaugeValueLimits
Type of Gauge values.
Definition: Gauge.h:67
GaugeValueHues mValueHues
The colors for the five possible value bands.
Definition: Gauge.h:143
Display a numeric value as a graphic indicator.
Definition: Gauge.h:74
The bottom of the normal band value and Normal color.
Orientation
Possible values for Widget orientation.
Definition: Types.h:41
The bottom of the warning band value and and LowWarning color.
A composite of a Position and a Size.
Definition: Types.h:307
GaugeIndex operator+(const GaugeIndex &gaugeIndex, unsigned long increment)
Add an unsigned integer to a GaugeIndex.
Definition: Gauge.h:60
An element of the application user interface.
Definition: Visual.h:451
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
GaugeValueLimits mValueLimits
The limits and color areas of the Gauge.
Definition: Gauge.h:137
Establish an intra-application signaling protocol.