GUIslice  0.16.0
Embedded GUI in C
XProgress.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XPROGRESS_H_
2 #define _GUISLICE_EX_XPROGRESS_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Progress Bar
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: Progress Bar
46 // - Basic progress bar with support for vertical / horizontal orientation and
47 // fill direction. Also provides an indicator of negative regions, depending
48 // on the configured range.
49 // ============================================================================
50 
51 // Define unique identifier for extended element type
52 // - Select any number above GSLC_TYPE_BASE_EXTEND
53 #define GSLC_TYPEX_PROGRESS GSLC_TYPE_BASE_EXTEND + 60
54 
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
75  bool bVert;
76  bool bFlip;
77 
79 
80 
100 gslc_tsElemRef* gslc_ElemXProgressCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
101  gslc_tsXProgress* pXData,gslc_tsRect rElem,int16_t nMin,int16_t nMax,int16_t nVal,gslc_tsColor colGauge,bool bVert);
102 
103 
114 void gslc_ElemXProgressSetVal(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal);
115 
116 
129 void gslc_ElemXProgressSetFlip(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,bool bFlip);
130 
131 
142 
143 
154 bool gslc_ElemXProgressDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
155 
156 
168 
169 
170 // ============================================================================
171 
172 // ------------------------------------------------------------------------
173 // Read-only element macros
174 // ------------------------------------------------------------------------
175 
176 // Macro initializers for Read-Only Elements in Flash/PROGMEM
177 //
178 
179 
203 
204 
205 #if (GSLC_USE_PROGMEM)
206 
207 
208 #define gslc_ElemXProgressCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
209  nMin_,nMax_,nVal_,colFrame_,colFill_,colGauge_,bVert_) \
210  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
211  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
212  static gslc_tsXProgress sGauge##nElemId; \
213  sGauge##nElemId.nMin = nMin_; \
214  sGauge##nElemId.nMax = nMax_; \
215  sGauge##nElemId.nVal = nVal_; \
216  sGauge##nElemId.nValLast = nVal_; \
217  sGauge##nElemId.bValLastValid = false; \
218  sGauge##nElemId.colGauge = colGauge_; \
219  sGauge##nElemId.bVert = bVert_; \
220  sGauge##nElemId.bFlip = false; \
221  static const gslc_tsElem sElem##nElemId PROGMEM = { \
222  nElemId, \
223  nFeatures##nElemId, \
224  GSLC_TYPEX_PROGRESS, \
225  (gslc_tsRect){nX,nY,nW,nH}, \
226  GSLC_GROUP_ID_NONE, \
227  colFrame_,colFill_,colFrame_,colFill_, \
228  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
229  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
230  NULL, \
231  NULL, \
232  0, \
233  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
234  GSLC_COL_WHITE, \
235  GSLC_COL_WHITE, \
236  GSLC_ALIGN_MID_MID, \
237  0, \
238  0, \
239  NULL, \
240  (void*)(&sGauge##nElemId), \
241  NULL, \
242  &gslc_ElemXProgressDraw, \
243  NULL, \
244  NULL, \
245  }; \
246  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
247  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
248 
249 #else
250 
251 
252 #define gslc_ElemXProgressCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
253  nMin_,nMax_,nVal_,colFrame_,colFill_,colGauge_,bVert_) \
254  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
255  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
256  static gslc_tsXProgress sGauge##nElemId; \
257  sGauge##nElemId.nMin = nMin_; \
258  sGauge##nElemId.nMax = nMax_; \
259  sGauge##nElemId.nVal = nVal_; \
260  sGauge##nElemId.nValLast = nVal_; \
261  sGauge##nElemId.bValLastValid = false; \
262  sGauge##nElemId.colGauge = colGauge_; \
263  sGauge##nElemId.bVert = bVert_; \
264  sGauge##nElemId.bFlip = false; \
265  static const gslc_tsElem sElem##nElemId = { \
266  nElemId, \
267  nFeatures##nElemId, \
268  GSLC_TYPEX_PROGRESS, \
269  (gslc_tsRect){nX,nY,nW,nH}, \
270  GSLC_GROUP_ID_NONE, \
271  colFrame_,colFill_,colFrame_,colFill_, \
272  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
273  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
274  NULL, \
275  NULL, \
276  0, \
277  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
278  GSLC_COL_WHITE, \
279  GSLC_COL_WHITE, \
280  GSLC_ALIGN_MID_MID, \
281  0, \
282  0, \
283  NULL, \
284  (void*)(&sGauge##nElemId), \
285  NULL, \
286  &gslc_ElemXProgressDraw, \
287  NULL, \
288  NULL, \
289  }; \
290  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
291  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
292 
293 #endif
294 
295 #ifdef __cplusplus
296 }
297 #endif // __cplusplus
298 #endif // _GUISLICE_EX_XPROGRESS_H_
299 
gslc_tsElemRef * gslc_ElemXProgressCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXProgress *pXData, gslc_tsRect rElem, int16_t nMin, int16_t nMax, int16_t nVal, gslc_tsColor colGauge, bool bVert)
Create a Progress Bar Element.
Definition: XProgress.c:79
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
gslc_tsColor colGauge
Color of gauge fill bar.
Definition: XProgress.h:74
bool bVert
Vertical if true, else Horizontal.
Definition: XProgress.h:75
void gslc_ElemXProgressSetVal(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nVal)
Update a Gauge element's current value.
Definition: XProgress.c:125
bool gslc_ElemXProgressDrawHelp(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_teRedrawType eRedraw)
Helper function to draw a gauge with style: progress bar.
Definition: XProgress.c:225
int16_t nVal
Current control value.
Definition: XProgress.h:68
int16_t nValLast
Last value.
Definition: XProgress.h:70
int16_t nMin
Minimum control value.
Definition: XProgress.h:64
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
void gslc_ElemXProgressSetGaugeCol(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_tsColor colGauge)
Set the gauge color.
Definition: XProgress.c:173
bool gslc_ElemXProgressDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a gauge element on the screen.
Definition: XProgress.c:197
Element reference structure.
Definition: GUIslice.h:578
Extended data for Gauge element.
Definition: XProgress.h:62
bool bValLastValid
Last value valid?
Definition: XProgress.h:71
int16_t nMax
Maximum control value.
Definition: XProgress.h:65
void gslc_ElemXProgressSetFlip(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, bool bFlip)
Set a Gauge element's fill direction.
Definition: XProgress.c:154
GUI structure.
Definition: GUIslice.h:716
bool bFlip
Reverse direction of gauge.
Definition: XProgress.h:76
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534