GUIslice  0.16.0
Embedded GUI in C
XRamp.h
Go to the documentation of this file.
1 #ifndef _GUISLICE_EX_XRAMP_H_
2 #define _GUISLICE_EX_XRAMP_H_
3 
4 #include "GUIslice.h"
5 
6 
7 // =======================================================================
8 // GUIslice library extension: Ramp gauge
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: Ramp Gauge
46 // - Demonstration of a gradient ramp (green-yellow-red) visual
47 // control similar to certain linear tachometers.
48 // - The ramp rises up and to the right according to the
49 // current value.
50 // - Note that this element is mainly intended as a demonstration
51 // example. Additional APIs would be recommended to make it
52 // more configurable.
53 // ============================================================================
54 
55 // Define unique identifier for extended element type
56 // - Select any number above GSLC_TYPE_BASE_EXTEND
57 #define GSLC_TYPEX_RAMP GSLC_TYPE_BASE_EXTEND + 62
58 
59 
60 // Extended element data structures
61 // - These data structures are maintained in the gslc_tsElem
62 // structure via the pXData pointer
63 
65 typedef struct {
66  // Range config
67  int16_t nMin;
68  int16_t nMax;
69 
70  // Current value
71  int16_t nVal;
72  // Previous value
73  int16_t nValLast;
75 
76  // Appearance config
77 
78 } gslc_tsXRamp;
79 
80 
100 gslc_tsElemRef* gslc_ElemXRampCreate(gslc_tsGui* pGui,int16_t nElemId,int16_t nPage,
101  gslc_tsXRamp* pXData,gslc_tsRect rElem,int16_t nMin,int16_t nMax,int16_t nVal,gslc_tsColor colGauge,bool bVert);
102 
103 
104 
115 void gslc_ElemXRampSetVal(gslc_tsGui* pGui,gslc_tsElemRef* pElemRef,int16_t nVal);
116 
117 
118 
129 bool gslc_ElemXRampDraw(void* pvGui,void* pvElemRef,gslc_teRedrawType eRedraw);
130 
131 
143 
144 // ============================================================================
145 
146 // ------------------------------------------------------------------------
147 // Read-only element macros
148 // ------------------------------------------------------------------------
149 
150 // Macro initializers for Read-Only Elements in Flash/PROGMEM
151 //
152 
153 
174 
175 
176 #if (GSLC_USE_PROGMEM)
177 
178 
179 #define gslc_ElemXRampCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
180  nMin_,nMax_,nVal_,colFrame_,colFill_) \
181  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
182  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
183  static gslc_tsXRamp sGauge##nElemId; \
184  sGauge##nElemId.nMin = nMin_; \
185  sGauge##nElemId.nMax = nMax_; \
186  sGauge##nElemId.nVal = nVal_; \
187  sGauge##nElemId.nValLast = nVal_; \
188  sGauge##nElemId.bValLastValid = false; \
189  static const gslc_tsElem sElem##nElemId PROGMEM = { \
190  nElemId, \
191  nFeatures##nElemId, \
192  GSLC_TYPEX_RAMP, \
193  (gslc_tsRect){nX,nY,nW,nH}, \
194  GSLC_GROUP_ID_NONE, \
195  colFrame_,colFill_,colFrame_,colFill_, \
196  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
197  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
198  NULL, \
199  NULL, \
200  0, \
201  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
202  GSLC_COL_WHITE, \
203  GSLC_COL_WHITE, \
204  GSLC_ALIGN_MID_MID, \
205  0, \
206  0, \
207  NULL, \
208  (void*)(&sGauge##nElemId), \
209  NULL, \
210  &gslc_ElemXRampDraw, \
211  NULL, \
212  NULL, \
213  }; \
214  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
215  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_PROG | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
216 
217 #else
218 
219 
220 #define gslc_ElemXRampCreate_P(pGui,nElemId,nPage,nX,nY,nW,nH,\
221  nMin_,nMax_,nVal_,colFrame_,colFill_) \
222  static const uint8_t nFeatures##nElemId = GSLC_ELEM_FEA_VALID | \
223  GSLC_ELEM_FEA_GLOW_EN | GSLC_ELEM_FEA_FILL_EN; \
224  static gslc_tsXRamp sGauge##nElemId; \
225  sGauge##nElemId.nMin = nMin_; \
226  sGauge##nElemId.nMax = nMax_; \
227  sGauge##nElemId.nVal = nVal_; \
228  sGauge##nElemId.nValLast = nVal_; \
229  sGauge##nElemId.bValLastValid = false; \
230  static const gslc_tsElem sElem##nElemId = { \
231  nElemId, \
232  nFeatures##nElemId, \
233  GSLC_TYPEX_RAMP, \
234  (gslc_tsRect){nX,nY,nW,nH}, \
235  GSLC_GROUP_ID_NONE, \
236  colFrame_,colFill_,colFrame_,colFill_, \
237  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
238  (gslc_tsImgRef){NULL,NULL,GSLC_IMGREF_NONE,NULL}, \
239  NULL, \
240  NULL, \
241  0, \
242  (gslc_teTxtFlags)(GSLC_TXT_DEFAULT), \
243  GSLC_COL_WHITE, \
244  GSLC_COL_WHITE, \
245  GSLC_ALIGN_MID_MID, \
246  0, \
247  0, \
248  NULL, \
249  (void*)(&sGauge##nElemId), \
250  NULL, \
251  &gslc_ElemXRampDraw, \
252  NULL, \
253  NULL, \
254  }; \
255  gslc_ElemAdd(pGui,nPage,(gslc_tsElem*)&sElem##nElemId, \
256  (gslc_teElemRefFlags)(GSLC_ELEMREF_SRC_CONST | GSLC_ELEMREF_VISIBLE | GSLC_ELEMREF_REDRAW_FULL));
257 
258 #endif
259 
260 #ifdef __cplusplus
261 }
262 #endif // __cplusplus
263 #endif // _GUISLICE_EX_XRAMP_H_
264 
int16_t nMax
Maximum control value.
Definition: XRamp.h:68
bool gslc_ElemXRampDrawHelp(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, gslc_teRedrawType eRedraw)
Helper function to draw a gauge with style: ramp.
Definition: XRamp.c:186
int16_t nValLast
Last value.
Definition: XRamp.h:73
gslc_teRedrawType
Redraw types.
Definition: GUIslice.h:370
int16_t nVal
Current control value.
Definition: XRamp.h:71
Extended data for Gauge element.
Definition: XRamp.h:65
gslc_tsElemRef * gslc_ElemXRampCreate(gslc_tsGui *pGui, int16_t nElemId, int16_t nPage, gslc_tsXRamp *pXData, gslc_tsRect rElem, int16_t nMin, int16_t nMax, int16_t nVal, gslc_tsColor colGauge, bool bVert)
Create a Ramp Gauge Element.
Definition: XRamp.c:83
Rectangular region. Defines X,Y corner coordinates plus dimensions.
Definition: GUIslice.h:519
bool gslc_ElemXRampDraw(void *pvGui, void *pvElemRef, gslc_teRedrawType eRedraw)
Draw a gauge element on the screen.
Definition: XRamp.c:158
int16_t nMin
Minimum control value.
Definition: XRamp.h:67
void gslc_ElemXRampSetVal(gslc_tsGui *pGui, gslc_tsElemRef *pElemRef, int16_t nVal)
Update a Gauge element's current value.
Definition: XRamp.c:129
Element reference structure.
Definition: GUIslice.h:578
GUI structure.
Definition: GUIslice.h:716
bool bValLastValid
Last value valid?
Definition: XRamp.h:74
Color structure. Defines RGB triplet.
Definition: GUIslice.h:534