eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_gauge.c
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
47 #include "d4d.h"
49 
50 
51 // Internal API
52 void D4D_GaugOnMessage(D4D_MESSAGE* pMsg);
54 
56 {
57  D4D_DEFSTR("Gauge"),
59  NULL,
61 };
62 
63 // temporary structure for pointer coordinates calculations
64 typedef struct D4D_GAUGE_VAL2PT_S
65 {
66  D4D_POINT position;
67  D4D_GEOMETRY contentGeom;
68  D4D_POINT hubXY;
69  D4D_POINT currPointXY;
70  D4D_POINT lastPointXY;
72 
73 
74 #define _calc (*((D4D_GAUGE_VAL2PT*)d4d_scratchPad))
75 
76 /*******************************************************
77 *
78 * calculate pointer endpoint from basepoint, limits and value
79 *
80 * global structure _calc is used to exchange in/out data
81 *
82 *******************************************************/
83 
85  D4D_GAUGE_DATA* pData = pGaug->pData;
86  D4D_POINT tmp_res;
87 
88  Byte angle;
89  sByte sin;
90  sByte cos;
91 
92  // Compute angle in allowed angle range from allowed value range
93  angle = (Byte)D4D_MulDivUU8((Byte)(value - pData->limits.valueMin),
94  (Byte)(pData->limits.angleMax - pData->limits.angleMin),
95  (Byte)(pData->limits.valueMax - pData->limits.valueMin));
96 
97 
98  // Take care direction
99  if(pData->trend == D4D_CLOCK_WISE)
100  angle += pData->limits.angleMin;
101  else
102  angle = (Byte)(pData->limits.angleMax - angle);
103 
104  // Compute sin value and cos value of computed pointer angle
105  sin = D4D_Sin(angle);
106  cos = D4D_Cos(angle);
107 
108  // Compute and fill up result point
109  tmp_res = _calc.hubXY;
110  tmp_res.x -= D4D_MulDivSU(cos, pGaug->pointerLen, 128);
111  tmp_res.y -= D4D_MulDivSU(sin, pGaug->pointerLen, 128);
112 
113  return tmp_res;
114 }
115 
116 static void D4D_GaugValue2Point(D4D_OBJECT* pThis)
117 {
118  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
119  D4D_GAUGE_DATA* pData = pGaug->pData;
120 
121  D4D_ComputeGeometry(&_calc.contentGeom, pThis);
122 
123  _calc.position = D4D_GetClientToScreenPoint(pThis, &pThis->position);
124 
125  if(pGaug->hubOff.x)
126  _calc.hubXY.x = (D4D_COOR)(_calc.contentGeom.pnt.x + pGaug->hubOff.x);
127  else
128  _calc.hubXY.x = (D4D_COOR)(_calc.contentGeom.pnt.x + _calc.contentGeom.sz.cx / 2);
129 
130  if(pGaug->hubOff.y)
131  _calc.hubXY.y = (D4D_COOR)(_calc.contentGeom.pnt.y + pGaug->hubOff.y);
132  else
133  _calc.hubXY.y = (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.contentGeom.sz.cy / 2);
134 
135  _calc.currPointXY = D4D_GaugeGetAnglePoint(pGaug, pData->value);
136  _calc.lastPointXY = D4D_GaugeGetAnglePoint(pGaug, pData->valueLast);
137 }
138 
139 /*******************************************************
140 *
141 * GAUGE Drawing routine
142 *
143 *******************************************************/
144 
145 static void D4D_GaugOnDraw(D4D_MESSAGE* pMsg)
146 {
147  D4D_OBJECT* pThis = pMsg->pObject;
148  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
149  D4D_GAUGE_DATA* pData = pGaug->pData;
150  D4D_OBJECT_DRAWFLAGS draw = pMsg->prm.draw;
151 
152  D4D_CLR_SCHEME *pScheme_tmp = D4D_ObjectGetScheme(pThis);
153  D4D_BMP_PROPERTIES bmpProp;
154  D4D_COLOR clrT = D4D_ObjectGetForeColor(pThis, draw);
156 
158 
159  #ifdef D4D_DEBUG
160  // sanity check
162  #endif
163 
164  D4D_GaugValue2Point(pThis);
165 
167  {
168  // draw the bitmap
169  if(pGaug->pBmpBkgd != NULL)
170  D4D_DrawRBmpRect(&_calc.contentGeom.pnt, &_calc.contentGeom.sz, pGaug->pBmpBkgd, bmpProp, clrB, (D4D_BOOL)!D4D_IsEnabled(pThis), pThis->radius);
171  else
172  D4D_FillRRect(&_calc.position, &pThis->size, clrB, pThis->radius);
173  }
174 
175  // Draw the frame
176  if(draw & (D4D_OBJECT_DRAWFLAGS_COMPLETE | D4D_OBJECT_DRAWFLAGS_STATE))
177  D4D_DrawFrame(pThis, clrT, clrB);
178 
179  if(!(draw & D4D_OBJECT_DRAWFLAGS_COMPLETE))
180  {
181  D4D_MoveTo(&_calc.hubXY);
183  }
184  // draw the text
185  if(((pThis->initFlags & D4D_GAUGE_F_REDRAW_TEXT) || (draw & D4D_OBJECT_DRAWFLAGS_COMPLETE)) && pGaug->textBuff.pText != NULL)
186  {
187  D4D_POINT tmp_point;
188  D4D_SIZE tmp_size;
189  tmp_point.x = (D4D_COOR)(_calc.contentGeom.pnt.x + pGaug->txtOff.x);
190  tmp_point.y = (D4D_COOR)(_calc.contentGeom.pnt.y + pGaug->txtOff.y);
191 
192  tmp_size.cx = D4D_GetTextWidth(pGaug->textBuff.fontId, pGaug->textBuff.pText);
193  tmp_size.cy = D4D_GetFontHeight(pGaug->textBuff.fontId);
194 
195 
196  D4D_DrawTextRect(&tmp_point, &tmp_size, &pGaug->textBuff,
198  }
199 
200  // draw the hub circle
201  if(pThis->initFlags & D4D_GAUGE_F_HUB)
202  {
203  if(D4D_IsEnabled(pThis))
205  else
207  }
208  // draw the pointer on value
209  D4D_MoveTo(&_calc.hubXY);
210 
211  if(D4D_IsEnabled(pThis))
213  else
215 
216  // remember the last value drawn
217  pData->valueLast = pData->value;
218 }
219 
220 
221 /******************************************************************************
222 * Begin of D4D_GAUGE public functions
223 */
227 /**************************************************************************/
235 {
236  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
237  D4D_GAUGE_DATA* pData = pGaug->pData;
238 
239  if(pGaug->pData->value == value)
240  return ;
241 
242  // keep within limits
243  value = D4D_LimitS8(value, pData->limits.valueMin, pData->limits.valueMax);
244 
245  // remember new value
246  pGaug->pData->value = value;
248 
249  // notify user that the value has changed
250  if(pGaug->OnValueChanged)
251  pGaug->OnValueChanged((D4D_OBJECT*)pThis);
252 }
253 
254 /**************************************************************************/
261 {
262  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
263  return pGaug->pData->value;
264 }
265 
266 
267 /**************************************************************************/
275 {
276  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
277  D4D_GAUGE_DATA* pData = pGaug->pData;
278 
279  pGaug->pData->limits = *pLimits;
280 
281  if(pData->limits.valueMin > pData->limits.valueMax)
282  {
283  D4D_GAUGE_VALUE value_tmp = pData->limits.valueMin;
284 
285  pData->limits.valueMin = pData->limits.valueMax;
286 
287  pData->limits.valueMax = value_tmp;
288 
289  if(pData->trend != D4D_ANTI_CLOCK_WISE)
290  pData->trend = D4D_ANTI_CLOCK_WISE;
291 
292  }
293 
294  // keep value within limits
295  pData->value = D4D_LimitS8(pData->value, pData->limits.valueMin, pData->limits.valueMax);
296 
298 
299  // notify user that the value has changed
300  if(pGaug->OnValueChanged)
301  pGaug->OnValueChanged((D4D_OBJECT*)pThis);
302 }
303 
304 
305 /**************************************************************************/
313 {
314  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
315  *pLimits = pGaug->pData->limits;
316 }
317 
318 /**************************************************************************/
326 {
327  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
328  D4D_GAUGE_DATA* pData = pGaug->pData;
329 
330  if(trend != pData->trend)
331  {
332  pData->valueLast = pData->value;
333  pData->trend = trend;
334 
336 
337  if(pGaug->OnValueChanged)
338  pGaug->OnValueChanged((D4D_OBJECT*)pThis);
339  }
340 }
341 
342 /**************************************************************************/
349 {
350  D4D_GAUGE* pGaug = D4D_GET_GAUGE(pThis);
351  return pGaug->pData->trend;
352 }
353 /******************************************************************************
354 * End of public functions */
356 /******************************************************************************/
357 
358 /**************************************************************/
368 /*******************************************************
369 *
370 * The main GAUGE message handler
371 *
372 *******************************************************/
373 
375 {
376  switch(pMsg->nMsgId)
377  {
378  case D4D_MSG_DRAW:
379  D4D_GaugOnDraw(pMsg);
380  break;
381 #ifdef D4D_LLD_TCH
382  case D4D_MSG_TOUCHED:
383  D4D_FocusSet(pMsg->pScreen, pMsg->pObject);
384  break;
385 #endif
386  default:
387  // call the default behavior of all objects
388  D4D_ObjOnMessage(pMsg);
389  }
390 }
391 
392 /**************************************************************/
398 {
399  return &(D4D_GET_GAUGE(pThis)->textBuff);
400 }
D4D_LINETYPE
Type definition of eGUI line type.
Definition: d4d_types.h:291
D4D_COLOR D4D_ObjectGetBckgFillColor(D4D_OBJECT *pObj)
Function return object current fill background color.
Definition: d4d_scheme.c:225
D4D_COLOR D4D_ObjectGetForeColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current fore color.
Definition: d4d_scheme.c:161
#define D4D_ALIGN_V_CENTER_MASK
The vertical center aligment option mask (for texts and also bitmaps).
Definition: d4d_base.h:234
#define D4D_GAUGE_F_REDRAW_TEXT
This flags force the redrawing gauge text after each redraw of new value. This is usable in case that...
Definition: d4d_gauge.h:87
D4D_CLR_SCHEME_OBJ objectDepend
Sub structure of object non standard colors.
Definition: d4d_scheme.h:589
D4D_COLOR pointer
The gauge pointer color.
Definition: d4d_scheme.h:526
Type definition of eGUI point structure.
Definition: d4d_types.h:223
D4D object messages structure.
Definition: d4d_base.h:400
D4D_CLR_SCHEME_GAUG gauge
The non standard colors of gauge object.
Definition: d4d_scheme.h:567
struct D4D_GAUGE_VAL2PT_S D4D_GAUGE_VAL2PT
D4D_STRING * D4D_GaugeGetTextBuffer(D4D_OBJECT *pThis)
Definition: d4d_gauge.c:397
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
void D4D_GaugSetDir(D4D_OBJECT_PTR pThis, D4D_TREND trend)
The function set the trend/direction of gauge.
Definition: d4d_gauge.c:325
The string type. This structure contains all properties about string in eGUI.
Definition: d4d_string.h:100
D4D_OBJECT_INITFLAGS initFlags
The initializations object flags.
Definition: d4d_object.h:178
#define D4D_DrawTextRect(ppt, psz, buffText, colorText, colorBkgd)
Function that draw text into defined rectangle on the screen.
D4D_GAUGE_ON_CHANGE OnValueChanged
Definition: d4d_gauge.h:170
The gauge limits structure that defines input value range and for this range specify the final angles...
Definition: d4d_gauge.h:136
Byte D4D_BMP_PROPERTIES
D4D_BMP_PROPERTIES type of image properties.
Definition: d4d_bmp.h:117
D4D_FONT fontId
index of used font
Definition: d4d_string.h:104
D4D_GAUGE_DATA * pData
Definition: d4d_gauge.h:172
D4D_GAUGE_VALUE valueLast
Definition: d4d_gauge.h:155
void D4D_GaugOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_gauge.c:374
D4D_GAUGE_VALUE value
Definition: d4d_gauge.h:154
#define D4D_TRUE
This is definition of boolean operation value in eGUI - TRUE.
Definition: d4d_types.h:106
void D4D_DrawFrame(D4D_OBJECT *pObject, D4D_COLOR clrT, D4D_COLOR clrB)
Function draw standard object frame based on the object settings and current state.
struct D4D_OBJECT_S * pObject
Pointer to object who is receiver of this message. If the receiver is just screen this field must be ...
Definition: d4d_base.h:402
D4D Driver main header file.
D4D_GAUGE_ANGLE angleMin
line angle from 0x00 to 0xFF
Definition: d4d_gauge.h:140
static void D4D_GaugOnDraw(D4D_MESSAGE *pMsg)
Definition: d4d_gauge.c:145
D4D_TREND
Type definition of eGUI trend type.
Definition: d4d_types.h:316
#define D4D_OBJECT_DRAWFLAGS_COMPLETE
Draw complete flag.
Definition: d4d_base.h:361
sByte D4D_LimitS8(sByte val, sByte min, sByte max)
Calculation of limitation value (signed) - 8 bit.
Definition: d4d_math.c:448
#define D4D_SCRATCHPAD_SIZE
Call back function raised by any new input event (touch, mouse, keys).
Definition: d4d_base.h:579
D4D_GAUGE_VALUE D4D_GaugGetValue(D4D_OBJECT_PTR pThis)
The function gets the current value of gauge.
Definition: d4d_gauge.c:260
#define D4D_MulDivSU
Definition: d4d_math.h:104
D4D_GAUGE_VALUE valueMin
minimal value (corresponds to angleMin)
Definition: d4d_gauge.h:138
D4D Driver private header file.
#define D4D_DEFSTR(str)
Macro that helps declare the strings in eGUI.
Definition: d4d_string.h:246
This is the main structure of the color scheme in the D4D. It contains all the necessary colors to ru...
Definition: d4d_scheme.h:578
static void D4D_GaugValue2Point(D4D_OBJECT *pThis)
Definition: d4d_gauge.c:116
D4D_COOR cx
Size in axis X (width)
Definition: d4d_types.h:232
const D4D_OBJECT_SYS_FUNCTION d4d_gaugeSysFunc
Definition: d4d_gauge.c:55
Byte D4D_COOR
Type definition of eGUI coordination variables.
Definition: d4d_types.h:219
D4D_POINT position
Position on the screen/object.
Definition: d4d_object.h:169
#define _calc
Definition: d4d_gauge.c:74
#define D4D_OBJECT_DRAWFLAGS_STATE
Draw just change of state flag.
Definition: d4d_base.h:364
D4D_COOR radius
Object corners radius.
Definition: d4d_object.h:171
#define D4D_DrawRBmpRect(ppt,psz, pBmp, bmpProp, colorBkgd, greyScale, radius)
Definition: d4d.h:188
unsigned char Byte
Type definition of Byte (unsigned 8-bit).
Definition: d4d_types.h:151
void D4D_GaugSetLimits(D4D_OBJECT_PTR pThis, const D4D_GAUGE_LIMITS *pLimits)
The function sets the new limits values of gauge.
Definition: d4d_gauge.c:274
#define D4D_GAUGE_F_HUB
This flag enables draw of the HUB.
Definition: d4d_gauge.h:88
D4D_TREND trend
Definition: d4d_gauge.h:156
void D4D_ObjOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_object.c:443
void D4D_FillCircle(D4D_POINT *pCenter, D4D_COOR r, D4D_COLOR color)
Function draw filled circle on the screen.
sByte D4D_Sin(Byte x)
Sine calculation using lookup table.
Definition: d4d_math.c:472
void D4D_FocusSet(const D4D_SCREEN *pScreen, D4D_OBJECT_PTR pObject)
The function set the obejct focus to new object.
Definition: d4d_screen.c:430
#define D4D_GAUGE_HUB_RADIUS
This is size of gauge hub in pixels. If not defined, it sets to 3 pixel as a default.
Definition: d4d_gauge.h:61
D4D_POINT hubOff
Definition: d4d_gauge.h:166
Line type thick.
Definition: d4d_types.h:294
D4D_GAUGE_LIMITS limits
Definition: d4d_gauge.h:157
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
#define D4D_ASSERT(cond)
Definition: d4d_base.h:583
D4D_CLR_SCHEME * D4D_ObjectGetScheme(D4D_OBJECT *pObj)
Function return the pointer to current use object scheme of object.
Definition: d4d_scheme.c:109
D4D_TCHAR * pText
pointer to text array
Definition: d4d_string.h:102
D4D_COOR y
Coordination in axis Y.
Definition: d4d_types.h:226
void D4D_GaugSetValue(D4D_OBJECT_PTR pThis, D4D_GAUGE_VALUE value)
The function sets the new value of gauge.
Definition: d4d_gauge.c:234
D4D_MSGID nMsgId
Type of message.
Definition: d4d_base.h:404
D4D_SIZE size
Size of the object.
Definition: d4d_object.h:170
Byte D4D_MulDivUU8(Byte u1, Byte u2, Byte d)
Simple proportion unsigned calculation - 8 bit.
Definition: d4d_math.c:206
D4D_GAUGE_VALUE valueMax
maximal value (corresponds to angleMax)
Definition: d4d_gauge.h:139
D4D_POINT D4D_GetClientToScreenPoint(D4D_OBJECT *pObject, D4D_POINT *nClientPoint)
The function convert client point on the screen to the global screen point.
Definition: d4d_screen.c:536
The object main structure type definition.
Definition: d4d_object.h:167
Draw message - is send when the object should be redrawed.
Definition: d4d_base.h:371
signed char sByte
Type definition of sByte (signed 8-bit).
Definition: d4d_types.h:155
#define D4D_ALIGN_H_CENTER_MASK
The horizontal center aligment option mask (for texts and also bitmaps).
Definition: d4d_base.h:225
void D4D_ComputeGeometry(D4D_GEOMETRY *pGeometry, D4D_OBJECT *pObject)
Definition: d4d_base.c:1047
D4D_COOR cy
Size in axis Y (height)
Definition: d4d_types.h:233
The object system function needed for each object - this is part of D4D_OBJECT main structure...
Definition: d4d_object.h:134
Trend Anti Clock Wise.
Definition: d4d_types.h:319
Trend Clock Wise.
Definition: d4d_types.h:318
Touched message - is send when the object is touched by touch screen driver.
Definition: d4d_base.h:379
LWord D4D_BOOL
Type definition of eGUI boolean.
Definition: d4d_types.h:204
D4D_COOR pointerLen
Definition: d4d_gauge.h:167
Type definition of eGUI size structure.
Definition: d4d_types.h:230
sByte D4D_GAUGE_VALUE
The gauge value variable, is used to hadle inputs of gauga functions API.
Definition: d4d_gauge.h:130
const D4D_BMP * pBmpBkgd
Definition: d4d_gauge.h:168
D4D_COOR D4D_GetTextWidth(D4D_FONT ix, D4D_TCHAR *pText)
The function returns width of text in pixels.
Definition: d4d_string.c:357
D4D_OBJECT_DRAWFLAGS draw
Contains draw flags - is valid with D4D_MSG_DRAW and D4D_MSG_DRAWDONE message.
Definition: d4d_base.h:408
sByte D4D_Cos(Byte x)
Cosine calculation using lookup table.
Definition: d4d_math.c:502
void D4D_FillRRect(D4D_POINT *ppt, D4D_SIZE *psz, D4D_COLOR color, D4D_COOR radius)
Function draw filled rectangle on the screen with round corners.
Type definition of eGUI geometry structure.
Definition: d4d_types.h:237
Line type thin.
Definition: d4d_types.h:293
D4D_POINT txtOff
Definition: d4d_gauge.h:165
D4D_STRING textBuff
Definition: d4d_gauge.h:164
D4D_GAUGE_ANGLE angleMax
line angle from 0x00 to 0xFF
Definition: d4d_gauge.h:141
D4D_COLOR hub
The gauge hub color.
Definition: d4d_scheme.h:525
void D4D_GaugGetLimits(D4D_OBJECT_PTR pThis, D4D_GAUGE_LIMITS *pLimits)
The function gets the values of gauge limit structure.
Definition: d4d_gauge.c:312
D4D_COLOR bckg
The object background color in standard state.
Definition: d4d_scheme.h:581
D4D_TREND D4D_GaugGetDir(D4D_OBJECT_PTR pThis)
The function gets the trend/direction of gauge object.
Definition: d4d_gauge.c:348
void D4D_InvalidateObject(D4D_OBJECT_PTR pObject, D4D_BOOL bComplete)
Function invalidate object to redraw on screen.
Definition: d4d_object.c:71
#define D4D_GET_GAUGE(pObj)
Definition: d4d_gauge.h:181
Byte D4D_OBJECT_DRAWFLAGS
Drawing object flags type, handled to object in D4D_MSG_DRAW events.
Definition: d4d_base.h:359
void D4D_LineTo(D4D_POINT *ppt, D4D_LINETYPE ltype, D4D_COLOR color)
Function draw line on the screen.
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
static D4D_POINT D4D_GaugeGetAnglePoint(D4D_GAUGE *pGaug, D4D_GAUGE_VALUE value)
Definition: d4d_gauge.c:84
struct D4D_SCREEN_S * pScreen
Pointer to screen who is receiver of this message.
Definition: d4d_base.h:403
D4D_COLOR D4D_GetGreyScale(D4D_COLOR color)
Compute the grayscale color.
Definition: d4d_scheme.c:333
D4D_FONT_SIZE D4D_GetFontHeight(D4D_FONT ix)
Definition: d4d_font.c:381
void D4D_MoveTo(D4D_POINT *ppt)
Function move logic cursor to new position.
D4D_COOR x
Coordination in axis X.
Definition: d4d_types.h:225
union D4D_MESSAGE_S::@0 prm
Additional data for some type of messages.
D4D_BOOL D4D_IsEnabled(D4D_OBJECT *pObject)
Function find out if the object is enabled or not.
Definition: d4d_object.c:303
#define D4D_GAUGE_F_THICK_POINTER
This flag switch the pointer to thick line.
Definition: d4d_gauge.h:89