GUIslice  0.16.0
Embedded GUI in C
XRadial.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XRADIAL_H_
2 #define _GUISLICE_EX_XRADIAL_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Radial control
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 #ifdef __cplusplus
40 extern "C" {
41 #endif // __cplusplus
42 
43 
44 // ============================================================================
45 // Extended Element: Radial Gauge
46 // - A circular gauge that can be used to show direction or other
47 // rotational values. Tick marks can be optionally drawn
48 // around the gauge.
49 // - Size, color and fill of the needle can be configured.
50 // ============================================================================
51 
52 // Define unique identifier for extended element type
53 // - Select any number above GSLC_TYPE_BASE_EXTEND
54 #define GSLC_TYPEX_RADIAL GSLC_TYPE_BASE_EXTEND + 61
55 
56 
57 // Extended element data structures
58 // - These data structures are maintained in the gslc_tsElem
59 // structure via the pXData pointer
60 
62 typedef struct {
63  // Range config
64  int16_t nMin;
65  int16_t nMax;
66 
67  // Current value
68  int16_t nVal;
69  // Previous value
70  int16_t nValLast;
72 
73  // Appearance config
76  uint16_t nTickCnt;
77  uint16_t nTickLen;
78  bool bFlip;
79  uint16_t nIndicLen;
80  uint16_t nIndicTip;
81  bool bIndicFill;
82 
84 
85 
103 gslc_tsElemRef* gslc_ElemXRadialCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
104  gslc_tsXRadial* pXData,gslc_tsRect rElem,int16_t nMin,int16_t nMax,int16_t nVal,gslc_tsColor colGauge);
105 
106 
107 
121  uint16_t nIndicLen,uint16_t nIndicTip,bool bIndicFill);
122 
123 
135 void gslc_ElemXRadialSetTicks(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,gslc_tsColor colTick,uint16_t nTickCnt,uint16_t nTickLen);
136 
137 
148 void gslc_ElemXRadialSetVal(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal);
149 
150 
162 void gslc_ElemXRadialSetFlip(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,bool bFlip);
163 
164 
175 bool gslc_ElemXRadialDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
176 
177 
189 
190 
191 // ============================================================================
192 
193 // ------------------------------------------------------------------------
194 // Read-only element macros
195 // ------------------------------------------------------------------------
196 
197 // Macro initializers for Read-Only Elements in Flash/PROGMEM
198 //
199 
221 
222 
223 #if (GSLC_USE_PROGMEM)
224 
225 
226 #define gslc_ElemXRadialCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
227  nMin_,nMax_,nVal_,colFrame_,colFill_,colGauge_) \
228  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
229  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
230  static gslc_tsXRadial sGauge##nElemId; \
231  sGauge##nElemId.nMin = nMin_; \
232  sGauge##nElemId.nMax = nMax_; \
233  sGauge##nElemId.nVal = nVal_; \
234  sGauge##nElemId.nValLast = nVal_; \
235  sGauge##nElemId.bValLastValid = false; \
236  sGauge##nElemId.colGauge = colGauge_; \
237  sGauge##nElemId.colTick = GSLC_COL_GRAY; \
238  sGauge##nElemId.nTickCnt = 8; \
239  sGauge##nElemId.nTickLen = 5; \
240  sGauge##nElemId.bFlip = false; \
241  sGauge##nElemId.nIndicLen = 10; \
242  sGauge##nElemId.nIndicTip = 3; \
243  sGauge##nElemId.bIndicFill = false; \
244  static const gslc_tsElem sElem##nElemId PROGMEM = { \
245  nElemId, \
246  nFeatures##nElemId, \
247  GSLC_TYPEX_RADIAL, \
248  (gslc_tsRect){nX,nY,nW,nH}, \
249  GSLC_GROUP_ID_NONE, \
250  colFrame_,colFill_,colFrame_,colFill_, \
251  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
252  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
253  NULL, \
254  NULL, \
255  0, \
256  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
257  GSLC_COL_WHITE, \
258  GSLC_COL_WHITE, \
259  GSLC_ALIGN_MID_MID, \
260  0, \
261  0, \
262  NULL, \
263  (void*)(&sGauge##nElemId), \
264  NULL, \
265  &gslc_ElemXRadialDraw, \
266  NULL, \
267  NULL, \
268  }; \
269  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
270  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
271 
272 #else
273 
274 
275 #define gslc_ElemXRadialCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
276  nMin_,nMax_,nVal_,colFrame_,colFill_,colGauge_) \
277  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
278  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
279  static gslc_tsXRadial sGauge##nElemId; \
280  sGauge##nElemId.nMin = nMin_; \
281  sGauge##nElemId.nMax = nMax_; \
282  sGauge##nElemId.nVal = nVal_; \
283  sGauge##nElemId.nValLast = nVal_; \
284  sGauge##nElemId.bValLastValid = false; \
285  sGauge##nElemId.colGauge = colGauge_; \
286  sGauge##nElemId.colTick = GSLC_COL_GRAY; \
287  sGauge##nElemId.nTickCnt = 8; \
288  sGauge##nElemId.nTickLen = 5; \
289  sGauge##nElemId.bFlip = false; \
290  sGauge##nElemId.nIndicLen = 10; \
291  sGauge##nElemId.nIndicTip = 3; \
292  sGauge##nElemId.bIndicFill = false; \
293  static const gslc_tsElem sElem##nElemId = { \
294  nElemId, \
295  nFeatures##nElemId, \
296  GSLC_TYPEX_RADIAL, \
297  (gslc_tsRect){nX,nY,nW,nH}, \
298  GSLC_GROUP_ID_NONE, \
299  colFrame_,colFill_,colFrame_,colFill_, \
300  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
301  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
302  NULL, \
303  NULL, \
304  0, \
305  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
306  GSLC_COL_WHITE, \
307  GSLC_COL_WHITE, \
308  GSLC_ALIGN_MID_MID, \
309  0, \
310  0, \
311  NULL, \
312  (void*)(&sGauge##nElemId), \
313  NULL, \
314  &gslc_ElemXRadialDraw, \
315  NULL, \
316  NULL, \
317  }; \
318  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
319  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
320 
321 #endif
322 
323 #ifdef __cplusplus
324 }
325 #endif // __cplusplus
326 #endif // _GUISLICE_EX_XRADIAL_H_
327 
void gslc_ElemXRadialSetVal(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nVal)
Update a Gauge element's current value.
Definition: XRadial.c:172
bool bFlip
Reverse direction of gauge.
Definition: XRadial.h:78
bool gslc_ElemXRadialDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a gauge element on the screen.
Definition: XRadial.c:225
int16_t nMax
Maximum control value.
Definition: XRadial.h:65
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
bool gslc_ElemXRadialDrawRadial(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_teRedrawType eRedraw)
Helper function to draw a gauge with style: radial.
Definition: XRadial.c:297
bool bIndicFill
Fill the indicator if true.
Definition: XRadial.h:81
uint16_t nIndicLen
Indicator length.
Definition: XRadial.h:79
uint16_t nIndicTip
Size of tip at end of indicator.
Definition: XRadial.h:80
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
Extended data for Gauge element.
Definition: XRadial.h:62
bool bValLastValid
Last value valid?
Definition: XRadial.h:71
gslc_tsColor colGauge
Color of gauge fill bar.
Definition: XRadial.h:74
gslc_tsElemRef * gslc_ElemXRadialCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXRadial *pXData, gslc_tsRect rElem, int16_t nMin, int16_t nMax, int16_t nVal, gslc_tsColor colGauge)
Create a Radial Gauge Element.
Definition: XRadial.c:82
uint16_t nTickCnt
Number of gauge tick marks.
Definition: XRadial.h:76
Element reference structure.
Definition: GUIslice.h:578
void gslc_ElemXRadialSetFlip(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bFlip)
Set a Gauge element's rotation direction.
Definition: XRadial.c:199
void gslc_ElemXRadialSetTicks(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_tsColor colTick, uint16_t nTickCnt, uint16_t nTickLen)
Configure the appearance of the Gauge ticks.
Definition: XRadial.c:153
gslc_tsColor colTick
Color of gauge tick marks.
Definition: XRadial.h:75
int16_t nVal
Current control value.
Definition: XRadial.h:68
uint16_t nTickLen
Length of gauge tick marks.
Definition: XRadial.h:77
void gslc_ElemXRadialSetIndicator(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: XRadial.c:133
GUI structure.
Definition: GUIslice.h:716
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534
int16_t nMin
Minimum control value.
Definition: XRadial.h:64
int16_t nValLast
Last value.
Definition: XRadial.h:70