tcMenu
DrawableDashboard.h
Go to the documentation of this file.
1 
2 #ifndef TCMENU_DRAWABLE_DASHBOARD_H
3 #define TCMENU_DRAWABLE_DASHBOARD_H
4 
10 #include "BaseRenderers.h"
11 #include <tcUnicodeHelper.h>
14 
21 public:
25  enum DashAlign {
26  TITLE_LEFT_VALUE_LEFT, TITLE_LEFT_VALUE_RIGHT,
27  NO_TITLE_VALUE_LEFT, NO_TITLE_VALUE_RIGHT,
28  TITLE_RIGHT_VALUE_LEFT, TITLE_RIGHT_VALUE_RIGHT,
29  };
30 protected:
31  DashAlign alignment;
32  color_t fgColor;
33  color_t bgColor;
34  DeviceFontDrawingMode fontMode;
35 public:
44  DashDrawParameters(color_t fgColor_, color_t bgColor_, const GFXfont* font_, DashAlign align = TITLE_RIGHT_VALUE_RIGHT);
53  DashDrawParameters(color_t fgColor_, color_t bgColor_, const UnicodeFont* font_, DashAlign align = TITLE_RIGHT_VALUE_RIGHT);
62  DashDrawParameters(color_t fgColor_, color_t bgColor_, const NativeFontDesc& font_, DashAlign align = TITLE_RIGHT_VALUE_RIGHT);
63 
67  bool isTitleDrawn() { return alignment != NO_TITLE_VALUE_LEFT && alignment != NO_TITLE_VALUE_RIGHT; }
71  bool isTitleLeftAlign() { return alignment == TITLE_LEFT_VALUE_LEFT || alignment == TITLE_LEFT_VALUE_RIGHT; }
75  bool isValueLeftAlign() { return alignment == TITLE_RIGHT_VALUE_LEFT || alignment == TITLE_LEFT_VALUE_LEFT || alignment == NO_TITLE_VALUE_LEFT; }
76 
80  const DeviceFontDrawingMode& getFontMode() const { return fontMode; }
81 
86  virtual color_t getBgColor(MenuItem *item, bool updated) { return bgColor; }
91  virtual color_t getFgColor(MenuItem *item, bool updated) { return fgColor; }
92 
97  virtual color_t getTitleBgColor(MenuItem *item, bool updated) { return bgColor; }
102  virtual color_t getTitleFgColor(MenuItem *item, bool updated) { return fgColor; }
103 };
104 
109 private:
110  color_t fgUpdateColor;
111  color_t bgUpdateColor;
112 public:
113  DashDrawParametersUpdate(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
114  const GFXfont* font_, DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
115  DashDrawParameters(fgColor_, bgColor_, font_, align), fgUpdateColor(fgUpdateColor_),
116  bgUpdateColor(bgUpdateColor_) {}
117  DashDrawParametersUpdate(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
118  const UnicodeFont* font_, DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
119  DashDrawParameters(fgColor_, bgColor_, font_, align), fgUpdateColor(fgUpdateColor_),
120  bgUpdateColor(bgUpdateColor_) {}
121  DashDrawParametersUpdate(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
122  const NativeFontDesc& font_, DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
123  DashDrawParameters(fgColor_, bgColor_, font_, align), fgUpdateColor(fgUpdateColor_),
124  bgUpdateColor(bgUpdateColor_) {}
125 
126  color_t getBgColor(MenuItem* item, bool updated) override { return updated ? bgUpdateColor : bgColor; }
127 
128  color_t getFgColor(MenuItem* item, bool updated) override { return updated ? fgUpdateColor : fgColor; }
129 };
130 
139 public:
140  struct IntColorRange {
141  color_t fgColor;
142  color_t bgColor;
143  int minValue;
144  int maxValue;
145  };
146 private:
147  const IntColorRange* colorRanges;
148  int numOfRanges;
149  bool useUpdateColor;
150 public:
151  DashDrawParametersIntUpdateRange(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
152  const GFXfont *font_, const IntColorRange colorRanges_[], int numberRanges,
153  DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
154  DashDrawParametersUpdate(fgColor_, bgColor_, fgUpdateColor_, bgUpdateColor_, font_, align),
155  colorRanges(colorRanges_), numOfRanges(numberRanges), useUpdateColor(fgColor_ != fgUpdateColor_ || bgColor_ != bgUpdateColor_) { }
156 
157  DashDrawParametersIntUpdateRange(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
158  const UnicodeFont *font_, const IntColorRange colorRanges_[], int numberRanges,
159  DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
160  DashDrawParametersUpdate(fgColor_, bgColor_, fgUpdateColor_, bgUpdateColor_, font_, align),
161  colorRanges(colorRanges_), numOfRanges(numberRanges), useUpdateColor(fgColor_ != fgUpdateColor_ || bgColor_ != bgUpdateColor_) { }
162 
163  DashDrawParametersIntUpdateRange(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
164  const NativeFontDesc& font_, const IntColorRange colorRanges_[], int numberRanges,
165  DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
166  DashDrawParametersUpdate(fgColor_, bgColor_, fgUpdateColor_, bgUpdateColor_, font_, align),
167  colorRanges(colorRanges_), numOfRanges(numberRanges), useUpdateColor(fgColor_ != fgUpdateColor_ || bgColor_ != bgUpdateColor_) { }
168 private:
169  int findIndexForChoice(MenuItem* item);
170  color_t getBgColor(MenuItem *item, bool updated) override;
171  color_t getFgColor(MenuItem *item, bool updated) override;
172 };
173 
182 public:
184  const char* text;
185  color_t fgColor;
186  color_t bgColor;
187  };
188 private:
189  const TextColorOverride* colorOverrides;
190  int numOfRanges;
191  bool useUpdateColor;
192 public:
193  DashDrawParametersTextUpdateRange(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
194  const GFXfont *font_, const TextColorOverride colorOverrides_[], int numberRanges,
195  DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
196  DashDrawParametersUpdate(fgColor_, bgColor_, fgUpdateColor_, bgUpdateColor_, font_, align), colorOverrides(colorOverrides_),
197  numOfRanges(numberRanges), useUpdateColor(fgColor_ != fgUpdateColor_ || bgColor_ != bgUpdateColor_) {}
198 
199  DashDrawParametersTextUpdateRange(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
200  const UnicodeFont *font_, const TextColorOverride colorOverrides_[], int numberRanges,
201  DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
202  DashDrawParametersUpdate(fgColor_, bgColor_, fgUpdateColor_, bgUpdateColor_, font_, align), colorOverrides(colorOverrides_),
203  numOfRanges(numberRanges), useUpdateColor(fgColor_ != fgUpdateColor_ || bgColor_ != bgUpdateColor_) {}
204 
205  DashDrawParametersTextUpdateRange(color_t fgColor_, color_t bgColor_, color_t fgUpdateColor_, color_t bgUpdateColor_,
206  const NativeFontDesc &font_, const TextColorOverride colorOverrides_[], int numberRanges,
207  DashAlign align = TITLE_RIGHT_VALUE_RIGHT) :
208  DashDrawParametersUpdate(fgColor_, bgColor_, fgUpdateColor_, bgUpdateColor_, font_, align), colorOverrides(colorOverrides_),
209  numOfRanges(numberRanges), useUpdateColor(fgColor_ != fgUpdateColor_ || bgColor_ != bgUpdateColor_) {}
210 private:
211  int findIndexForChoice(MenuItem* item);
212  color_t getBgColor(MenuItem *item, bool updated) override;
213  color_t getFgColor(MenuItem *item, bool updated) override;
214 };
215 
216 // forward reference
217 class DrawableDashboard;
218 
224 private:
225  DrawableDashboard* dashboard;
226  MenuItem *item;
227  Coord screenLoc;
228  DashDrawParameters *parameters;
229  int updateCountDown;
230  Coord titleExtents;
231  int numChars;
232  int valueWidth;
233  int countDownTicks;
234  int baseline;
235  char titleText[20];
236 public:
237  DashMenuItem() : dashboard(nullptr), item(nullptr), screenLoc(0, 0), parameters(nullptr), updateCountDown(0), titleExtents(0, 0),
238  numChars(0), valueWidth(0), countDownTicks(0), baseline(0), titleText() {}
239  DashMenuItem(DrawableDashboard* dashboard, MenuItem *theItem, Coord topLeft, DashDrawParameters* params, int numCharsInValue, const char* titleOverride, int countDownTicks);
240  DashMenuItem(const DashMenuItem &other) = default;
241  DashMenuItem& operator= (const DashMenuItem& other) = default;
242 
243  uint16_t getKey() const {
244  return item != nullptr ? item->getId() : 0;
245  }
246 
247  bool needsPainting();
248  void paintTitle(DeviceDrawable* canvasDrawable);
249  void paintItem(DeviceDrawable* canvasDrawable);
250 };
251 
259 public:
263  virtual void dashboardDidClose() {}
268  virtual bool dashboardWillOpen(BaseMenuRenderer* /*where*/) { return false; }
272  virtual void dashboardDidOpen(BaseMenuRenderer* /*where*/) {}
277  virtual void dashboardWillDraw(unsigned int /*currentValue*/, RenderPressMode /*mode*/) {}
282  virtual void dashboardDidDraw(unsigned int /*currentValue*/, RenderPressMode /*mode*/) {}
286  virtual void displayDidReset() {}
287 };
288 
298 public:
300  enum DashboardMode: uint8_t { DASH_ON_RESET_CLICK_EXIT, DASH_ON_RESET_MANUAL_EXIT, DASH_FULLY_MANUAL, DASH_MANUAL_START_CLICK_EXIT };
301 private:
302  DrawableDashboardDelegate *delegate = nullptr;
303  TitleWidget* firstWidget;
304  BaseGraphicalRenderer *renderer;
305  DeviceDrawable *drawable;
306  BtreeList<uint16_t, DashMenuItem> drawingItems;
307  color_t screenBg = 0;
308  color_t coreItemFg = 0;
309  DashboardMode drawingMode;
310  bool running;
311 public:
312  DrawableDashboard(DeviceDrawable *device, BaseGraphicalRenderer* renderer, TitleWidget* widgets, DashboardMode drawingMode)
313  : firstWidget(widgets), renderer(renderer), drawable(device), drawingItems(), drawingMode(drawingMode), running(false) { }
314  ~DrawableDashboard() override = default;
315  void setBaseColors(color_t screenBgCol, color_t coreFgCol) {
316  screenBg = screenBgCol;
317  coreItemFg = coreFgCol;
318  }
319  void setDelegate(DrawableDashboardDelegate* dashDelegate) { this->delegate = dashDelegate; }
320 
321  void clearItems() { drawingItems.clear(); }
322  void addDrawingItem(MenuItem *theItem, Coord topLeft, DashDrawParameters* params, int numCharsInValue,
323  const char* titleOverrideText = nullptr, int updateTicks = 5);
324  void stop();
325  void reset() override;
326  void started(BaseMenuRenderer *currentRenderer) override;
327 
334  void renderLoop(unsigned int currentValue, RenderPressMode userClick) override;
335 
336  void drawWidgets(bool force);
337 
338  uint8_t getDisplayNumber() { return renderer->getDisplayNumber(); }
339 };
340 
341 #endif //TCMENU_DRAWABLE_DASHBOARD_H
The base definitions and classes shared by all TcMenu renderers.
RenderPressMode
Definition: BaseRenderers.h:50
A few helper classes that provides useful functions on top of a tcMenu device drawable.
uint32_t color_t
Definition: DrawingPrimitives.h:29
the interface that all graphics devices should implement to do the actual graphics rendering.
Definition: BaseRenderers.h:282
Definition: BaseRenderers.h:76
Definition: DrawableDashboard.h:20
DashDrawParameters(color_t fgColor_, color_t bgColor_, const GFXfont *font_, DashAlign align=TITLE_RIGHT_VALUE_RIGHT)
Creates a dash parameter that has a background, foreground, font, and alignment. In this case the fon...
DashDrawParameters(color_t fgColor_, color_t bgColor_, const NativeFontDesc &font_, DashAlign align=TITLE_RIGHT_VALUE_RIGHT)
Creates a dash parameter that has a background, foreground, font, and alignment. In this case the fon...
bool isValueLeftAlign()
Definition: DrawableDashboard.h:75
DashAlign
Definition: DrawableDashboard.h:25
virtual color_t getFgColor(MenuItem *item, bool updated)
Definition: DrawableDashboard.h:91
DashDrawParameters(color_t fgColor_, color_t bgColor_, const UnicodeFont *font_, DashAlign align=TITLE_RIGHT_VALUE_RIGHT)
Creates a dash parameter that has a background, foreground, font, and alignment. In this case the fon...
virtual color_t getTitleFgColor(MenuItem *item, bool updated)
Definition: DrawableDashboard.h:102
bool isTitleLeftAlign()
Definition: DrawableDashboard.h:71
virtual color_t getTitleBgColor(MenuItem *item, bool updated)
Definition: DrawableDashboard.h:97
virtual color_t getBgColor(MenuItem *item, bool updated)
Definition: DrawableDashboard.h:86
bool isTitleDrawn()
Definition: DrawableDashboard.h:67
const DeviceFontDrawingMode & getFontMode() const
Definition: DrawableDashboard.h:80
Definition: DrawableDashboard.h:138
Definition: DrawableDashboard.h:140
Definition: DrawableDashboard.h:181
Definition: DrawableDashboard.h:183
Definition: DrawableDashboard.h:108
color_t getFgColor(MenuItem *item, bool updated) override
Definition: DrawableDashboard.h:128
color_t getBgColor(MenuItem *item, bool updated) override
Definition: DrawableDashboard.h:126
Definition: DrawableDashboard.h:223
Definition: DrawableDashboard.h:258
virtual void dashboardDidOpen(BaseMenuRenderer *)
Definition: DrawableDashboard.h:272
virtual void dashboardWillDraw(unsigned int, RenderPressMode)
Definition: DrawableDashboard.h:277
virtual void dashboardDidDraw(unsigned int, RenderPressMode)
Definition: DrawableDashboard.h:282
virtual bool dashboardWillOpen(BaseMenuRenderer *)
Definition: DrawableDashboard.h:268
virtual void dashboardDidClose()
Definition: DrawableDashboard.h:263
virtual void displayDidReset()
Definition: DrawableDashboard.h:286
Definition: DrawableDashboard.h:297
DashboardMode
Definition: DrawableDashboard.h:300
void renderLoop(unsigned int currentValue, RenderPressMode userClick) override
Definition: DrawableDashboard.cpp:53
void started(BaseMenuRenderer *currentRenderer) override
Definition: DrawableDashboard.cpp:26
void reset() override
Definition: DrawableDashboard.cpp:19
Definition: MenuItems.h:329
menuid_t getId() const
Definition: MenuItems.cpp:81
Definition: BaseRenderers.h:126