GUIslice  0.16.0
Embedded GUI in C
XGauge.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XGAUGE_H_
2 #define _GUISLICE_EX_XGAUGE_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Gauge control (See replacement warning below)
9 // - Calvin Hass
10 // - https://www.impulseadventure.com/elec/guislice-gui.html
11 // - https://github.com/ImpulseAdventure/GUIslice
12 // =======================================================================
13 //
14 // The MIT License
15 //
16 // Copyright 2016-2020 Calvin Hass
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining a copy
19 // of this software and associated documentation files (the "Software"), to deal
20 // in the Software without restriction, including without limitation the rights
21 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22 // copies of the Software, and to permit persons to whom the Software is
23 // furnished to do so, subject to the following conditions:
24 //
25 // The above copyright notice and this permission notice shall be included in
26 // all copies or substantial portions of the Software.
27 //
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 // THE SOFTWARE.
35 //
36 // =======================================================================
38 
39 // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
40 // WARNING: The XGauge element has been replaced by XProgress / XRadial / XRamp
41 // Please update your code according to the migration notes in:
42 // https://github.com/ImpulseAdventure/GUIslice/pull/157
43 // XGauge may be removed in a future release.
44 // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif // __cplusplus
49 
50 
51 // ============================================================================
52 // Extended Element: Gauge
53 // ============================================================================
54 
55 // Define unique identifier for extended element type
56 // - Select any number above GSLC_TYPE_BASE_EXTEND
57 #define GSLC_TYPEX_GAUGE GSLC_TYPE_BASE_EXTEND + 0
58 
59 
61 typedef enum {
66 
67 // Extended element data structures
68 // - These data structures are maintained in the gslc_tsElem
69 // structure via the pXData pointer
70 
72 typedef struct {
73  // Range config
74  int16_t nMin;
75  int16_t nMax;
76 
77  // Current value
78  int16_t nVal;
79  // Previous value
80  int16_t nValLast;
82 
83  // Appearance config
84  gslc_teXGaugeStyle nStyle;
87  uint16_t nTickCnt;
88  uint16_t nTickLen;
89  bool bVert;
90  bool bFlip;
91  uint16_t nIndicLen;
92  uint16_t nIndicTip;
93  bool bIndicFill;
94 
96 
97 
122 gslc_tsElemRef* gslc_ElemXGaugeCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
123  gslc_tsXGauge* pXData,gslc_tsRect rElem,int16_t nMin,int16_t nMax,int16_t nVal,gslc_tsColor colGauge,bool bVert);
124 
125 
137 void gslc_ElemXGaugeSetStyle(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,gslc_teXGaugeStyle nType);
138 
139 
153  uint16_t nIndicLen,uint16_t nIndicTip,bool bIndicFill);
154 
155 
167 void gslc_ElemXGaugeSetTicks(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,gslc_tsColor colTick,uint16_t nTickCnt,uint16_t nTickLen);
168 
169 
180 void gslc_ElemXGaugeUpdate(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal);
181 
182 
195 void gslc_ElemXGaugeSetFlip(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,bool bFlip);
196 
197 
208 bool gslc_ElemXGaugeDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
209 
210 
222 
223 #if (GSLC_FEATURE_XGAUGE_RADIAL)
224 bool gslc_ElemXGaugeDrawRadial(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,gslc_teRedrawType eRedraw);
235 #endif
236 
237 #if (GSLC_FEATURE_XGAUGE_RAMP)
238 bool gslc_ElemXGaugeDrawRamp(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,gslc_teRedrawType eRedraw);
249 #endif
250 
251 // ============================================================================
252 
253 // ------------------------------------------------------------------------
254 // Read-only element macros
255 // ------------------------------------------------------------------------
256 
257 // Macro initializers for Read-Only Elements in Flash/PROGMEM
258 //
259 
260 
284 
285 
286 #if (GSLC_USE_PROGMEM)
287 
288 
289 #define gslc_ElemXGaugeCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
290  nMin_,nMax_,nVal_,colFrame_,colFill_,colGauge_,bVert_) \
291  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
292  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
293  static gslc_tsXGauge sGauge##nElemId; \
294  sGauge##nElemId.nMin = nMin_; \
295  sGauge##nElemId.nMax = nMax_; \
296  sGauge##nElemId.nVal = nVal_; \
297  sGauge##nElemId.nValLast = nVal_; \
298  sGauge##nElemId.bValLastValid = false; \
299  sGauge##nElemId.nStyle = GSLCX_GAUGE_STYLE_PROG_BAR; \
300  sGauge##nElemId.colGauge = colGauge_; \
301  sGauge##nElemId.colTick = GSLC_COL_GRAY; \
302  sGauge##nElemId.nTickCnt = 8; \
303  sGauge##nElemId.nTickLen = 5; \
304  sGauge##nElemId.bVert = bVert_; \
305  sGauge##nElemId.bFlip = false; \
306  sGauge##nElemId.nIndicLen = 10; \
307  sGauge##nElemId.nIndicTip = 3; \
308  sGauge##nElemId.bIndicFill = false; \
309  static const gslc_tsElem sElem##nElemId PROGMEM = { \
310  nElemId, \
311  nFeatures##nElemId, \
312  GSLC_TYPEX_GAUGE, \
313  (gslc_tsRect){nX,nY,nW,nH}, \
314  GSLC_GROUP_ID_NONE, \
315  colFrame_,colFill_,colFrame_,colFill_, \
316  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
317  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
318  NULL, \
319  NULL, \
320  0, \
321  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
322  GSLC_COL_WHITE, \
323  GSLC_COL_WHITE, \
324  GSLC_ALIGN_MID_MID, \
325  0, \
326  0, \
327  NULL, \
328  (void*)(&sGauge##nElemId), \
329  NULL, \
330  &gslc_ElemXGaugeDraw, \
331  NULL, \
332  NULL, \
333  }; \
334  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
335  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
336 
337 #else
338 
339 
340 #define gslc_ElemXGaugeCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
341  nMin_,nMax_,nVal_,colFrame_,colFill_,colGauge_,bVert_) \
342  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
343  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
344  static gslc_tsXGauge sGauge##nElemId; \
345  sGauge##nElemId.nMin = nMin_; \
346  sGauge##nElemId.nMax = nMax_; \
347  sGauge##nElemId.nVal = nVal_; \
348  sGauge##nElemId.nValLast = nVal_; \
349  sGauge##nElemId.bValLastValid = false; \
350  sGauge##nElemId.nStyle = GSLCX_GAUGE_STYLE_PROG_BAR; \
351  sGauge##nElemId.colGauge = colGauge_; \
352  sGauge##nElemId.colTick = GSLC_COL_GRAY; \
353  sGauge##nElemId.nTickCnt = 8; \
354  sGauge##nElemId.nTickLen = 5; \
355  sGauge##nElemId.bVert = bVert_; \
356  sGauge##nElemId.bFlip = false; \
357  sGauge##nElemId.nIndicLen = 10; \
358  sGauge##nElemId.nIndicTip = 3; \
359  sGauge##nElemId.bIndicFill = false; \
360  static const gslc_tsElem sElem##nElemId = { \
361  nElemId, \
362  nFeatures##nElemId, \
363  GSLC_TYPEX_GAUGE, \
364  (gslc_tsRect){nX,nY,nW,nH}, \
365  GSLC_GROUP_ID_NONE, \
366  colFrame_,colFill_,colFrame_,colFill_, \
367  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
368  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
369  NULL, \
370  NULL, \
371  0, \
372  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
373  GSLC_COL_WHITE, \
374  GSLC_COL_WHITE, \
375  GSLC_ALIGN_MID_MID, \
376  0, \
377  0, \
378  NULL, \
379  (void*)(&sGauge##nElemId), \
380  NULL, \
381  &gslc_ElemXGaugeDraw, \
382  NULL, \
383  NULL, \
384  }; \
385  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
386  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
387 
388 #endif
389 
390 #ifdef __cplusplus
391 }
392 #endif // __cplusplus
393 #endif // _GUISLICE_EX_XGAUGE_H_
394 
gslc_teXGaugeStyle nStyle
Gauge sub-type.
Definition: XGauge.h:84
bool bVert
Vertical if true, else Horizontal.
Definition: XGauge.h:89
int16_t nVal
Current control value.
Definition: XGauge.h:78
Ramp indicator.
Definition: XGauge.h:64
int16_t nMax
Maximum control value.
Definition: XGauge.h:75
int16_t nValLast
Last value.
Definition: XGauge.h:80
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
uint16_t nTickCnt
Number of gauge tick marks.
Definition: XGauge.h:87
gslc_teXGaugeStyle
Gauge drawing style.
Definition: XGauge.h:61
Radial indicator.
Definition: XGauge.h:63
gslc_tsColor colTick
Color of gauge tick marks.
Definition: XGauge.h:86
bool gslc_ElemXGaugeDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a gauge element on the screen.
Definition: XGauge.c:255
bool bValLastValid
Last value valid?
Definition: XGauge.h:81
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
void gslc_ElemXGaugeSetIndicator(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_tsColor colGauge, uint16_t nIndicLen, uint16_t nIndicTip, bool bIndicFill)
Configure the appearance of the Gauge indicator.
Definition: XGauge.c:157
Progress bar.
Definition: XGauge.h:62
uint16_t nTickLen
Length of gauge tick marks.
Definition: XGauge.h:88
gslc_tsColor colGauge
Color of gauge fill bar.
Definition: XGauge.h:85
int16_t nMin
Minimum control value.
Definition: XGauge.h:74
Extended data for Gauge element.
Definition: XGauge.h:72
bool bFlip
Reverse direction of gauge.
Definition: XGauge.h:90
void gslc_ElemXGaugeUpdate(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nVal)
Update a Gauge element's current value.
Definition: XGauge.c:198
Element reference structure.
Definition: GUIslice.h:578
uint16_t nIndicTip
Size of tip at end of indicator.
Definition: XGauge.h:92
void gslc_ElemXGaugeSetTicks(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_tsColor colTick, uint16_t nTickCnt, uint16_t nTickLen)
Configure the appearance of the Gauge ticks.
Definition: XGauge.c:178
GUI structure.
Definition: GUIslice.h:716
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
bool gslc_ElemXGaugeDrawProgressBar(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_teRedrawType eRedraw)
Helper function to draw a gauge with style: progress bar.
Definition: XGauge.c:306
void gslc_ElemXGaugeSetFlip(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bFlip)
Set a Gauge element's fill direction.
Definition: XGauge.c:228
void gslc_ElemXGaugeSetStyle(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_teXGaugeStyle nType)
Configure the style of a Gauge element.
Definition: XGauge.c:140
bool bIndicFill
Fill the indicator if true.
Definition: XGauge.h:93
uint16_t nIndicLen
Indicator length.
Definition: XGauge.h:91
gslc_tsElemRef * gslc_ElemXGaugeCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXGauge *pXData, gslc_tsRect rElem, int16_t nMin, int16_t nMax, int16_t nVal, gslc_tsColor colGauge, bool bVert)
Create a Gauge Element.
Definition: XGauge.c:86