eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_progress_bar.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 ***************************************************************************/
46 #include "d4d.h"
48 
49 //Internal API
51 
53 {
54  D4D_DEFSTR("Progress Bar"),
56  NULL,
57  NULL
58 };
59 
60 // temporary structure for bar coordinate calculation
61 typedef struct
62 {
63  D4D_POINT position;
64  D4D_GEOMETRY contentGeom;
65  D4D_POINT barXY;
66  D4D_SIZE barSize;
67  D4D_COOR resultC1;
68  D4D_COOR resultC2;
69  D4D_COOR inner_radius;
70 } D4D_PROGRESS_BAR_TMP_VAL;
71 
72 
73 
74 #define _calc (*((D4D_PROGRESS_BAR_TMP_VAL*)d4d_scratchPad))
75 
76 //static D4D_PROGRESS_BAR_TMP_VAL _calc;
77 
79 
80 /*******************************************************
81 *
82 * calculate pointer endpoint from basepoint, limits and value
83 *
84 *******************************************************/
85 
87 {
88  D4D_PROGRESS_BAR* pPrgrsBar = D4D_GET_PROGRESS_BAR(pThis);
89  _calc.position = D4D_GetClientToScreenPoint(pThis, &pThis->position);
90 
91  D4D_ComputeGeometry(&_calc.contentGeom, pThis);
92 
93  _calc.barXY.x = (D4D_COOR)(_calc.contentGeom.pnt.x + D4D_PRGRS_BAR_BAR_OFF);
94  _calc.barXY.y = (D4D_COOR)(_calc.contentGeom.pnt.y + D4D_PRGRS_BAR_BAR_OFF);
95 
96  _calc.barSize = _calc.contentGeom.sz;
97 
98  _calc.barSize.cx -= (D4D_COOR)(2 * D4D_PRGRS_BAR_BAR_OFF);
99  _calc.barSize.cy -= (D4D_COOR)(2 * D4D_PRGRS_BAR_BAR_OFF);
100 
101  // value and origin coordinates
102  _calc.resultC1 = (D4D_COOR)(_calc.barXY.x + D4D_MulDivUU(pPrgrsBar->pData->value, _calc.barSize.cx, D4D_COLOR_PRGRS_BAR_MAX_VAL));
103 
104  _calc.resultC2 = _calc.resultC1;
105 
106 #if D4D_ROUND_CORNER_ENABLE == D4D_TRUE
107 
108  if(pThis->radius - D4D_PRGRS_BAR_BAR_OFF)
109  {
110  _calc.inner_radius = (D4D_COOR)(pThis->radius - D4D_PRGRS_BAR_BAR_OFF);
111 
112  if((_calc.resultC2 - _calc.inner_radius) < _calc.barXY.x)
113  _calc.resultC2 = _calc.barXY.x;
114  else
115  _calc.resultC2 -= _calc.inner_radius;
116 
117  if((_calc.barXY.x + _calc.barSize.cx - _calc.resultC2) < (2 * _calc.inner_radius))
118  _calc.resultC2 = (D4D_COOR)(_calc.barXY.x + _calc.barSize.cx - (2 * _calc.inner_radius));
119 
120  if((_calc.resultC1 - _calc.barXY.x) < (2 * _calc.inner_radius))
121  _calc.resultC1 = (D4D_COOR)(_calc.barXY.x + (2 * _calc.inner_radius));
122  }
123  else
124  _calc.inner_radius = 0;
125 
126 #endif
127 
128 }
129 
130 
131 /*******************************************************
132 *
133 * PROGRESS_BAR Drawing routine
134 *
135 *******************************************************/
136 
137 static void D4D_PrgrsBarOnDraw(D4D_MESSAGE* pMsg)
138 {
139  D4D_OBJECT* pThis = pMsg->pObject;
140  D4D_PROGRESS_BAR* pPrgrsBar = D4D_GET_PROGRESS_BAR(pThis);
141  D4D_CLR_SCHEME *pScheme_tmp = D4D_ObjectGetScheme(pThis);
142  D4D_COLOR clrBar = pPrgrsBar->pData->colorBar;
143  D4D_COLOR clrBarBckg = pScheme_tmp->objectDepend.progressBar.barBckg;
144  D4D_OBJECT_DRAWFLAGS draw = pMsg->prm.draw;
145  D4D_COLOR clrT = D4D_ObjectGetForeColor(pThis, draw);
147 
148  #ifdef D4D_DEBUG
149  // sanity check
151  #endif
152 
153  // bar coordinate calculation
154  D4D_PrgrsBarValue2Coor(pThis);
155 
156  // when background redraw is needed
158  D4D_RBox(&_calc.position, &pThis->size, D4D_LINE_THIN, clrT, clrB, pThis->radius);
159 
160  // Draw the frame
161  if(draw & (D4D_OBJECT_DRAWFLAGS_COMPLETE | D4D_OBJECT_DRAWFLAGS_STATE))
162  D4D_DrawFrame(pThis, clrT, clrB);
163 
164  // if progress_bar is disabled draw progress_bar in grey scale
165  if(!D4D_IsEnabled(pThis))
166  {
167  clrBar = D4D_GetGreyScale(clrBar);
168  clrBarBckg = D4D_GetGreyScale(clrBarBckg);
169  }
170 
171  if(!pPrgrsBar->pData->drawActiveOnly)
172  D4D_FillRRectXY(_calc.resultC2, _calc.barXY.y, (D4D_COOR)(_calc.barXY.x + _calc.barSize.cx - 1), (D4D_COOR)(_calc.barXY.y + _calc.barSize.cy - 1), clrBarBckg, _calc.inner_radius);
173 
174  // draw active part of the bar
176  D4D_FillRRectColorScaleXY(_calc.barXY.x, _calc.barXY.y, _calc.resultC1, (D4D_COOR)(_calc.barXY.y + _calc.barSize.cy - 1), pScheme_tmp->objectDepend.progressBar.barFore, clrBar, D4D_DIR_RIGHT, _calc.inner_radius);
177  else
178  D4D_FillRRectXY(_calc.barXY.x, _calc.barXY.y, _calc.resultC1, (D4D_COOR)(_calc.barXY.y + _calc.barSize.cy - 1), clrBar, _calc.inner_radius);
179 
180  }
181 
182 
183 
184 
186 {
187  D4D_CLR_SCHEME *pScheme_tmp = D4D_ObjectGetScheme(pThis);
188 
190 }
191 
192 
193 /*******************************************************
194 *
195 * Set PROGRESS_BAR value
196 *
197 *******************************************************/
198 
200 {
201  D4D_PROGRESS_BAR* pPrgrsBar = D4D_GET_PROGRESS_BAR(pThis);
202  D4D_PROGRESS_BAR_DATA* pData = pPrgrsBar->pData;
203 
204  if(pData->value == value)
205  return ;
206 
207  if(pData->value <= value)
208  pPrgrsBar->pData->drawActiveOnly = D4D_TRUE;
209  else
210  pPrgrsBar->pData->drawActiveOnly = D4D_FALSE;
211 
212  // remember new value
213  pData->value = value;
214 
216  {
217  pData->colorBar = D4D_PrgrsBarComputeColorBar((D4D_OBJECT*)pThis, value);
218  }
219 
221 }
222 
224 {
225  D4D_PROGRESS_BAR* pPrgrsBar = D4D_GET_PROGRESS_BAR(pThis);
226  return pPrgrsBar->pData->value;
227 }
228 
229 /*******************************************************
230 *
231 * Set PROGRESS_BAR bar color
232 *
233 *******************************************************/
234 
236 {
237  D4D_PROGRESS_BAR* pPrgrsBar = D4D_GET_PROGRESS_BAR(pThis);
238  D4D_PROGRESS_BAR_DATA* pData = pPrgrsBar->pData;
239 
241  return;
242 
243  if(pData->colorBar == color)
244  return ;
245 
246  // remember new color
247  pData->colorBar = color;
248 
250 }
251 
253 {
254  D4D_PROGRESS_BAR* pPrgrsBar = D4D_GET_PROGRESS_BAR(pThis);
255  return pPrgrsBar->pData->colorBar;
256 }
257 
258 
259 /*******************************************************
260 *
261 * Modify PROGRESS_BAR value by a value
262 *
263 *******************************************************/
264 
266 {
267  D4D_PROGRESS_BAR_VALUE value = D4D_GET_PROGRESS_BAR(pThis)->pData->value;
268 
269  // change the value
270  value += incr;
271 
272  if(value > D4D_COLOR_PRGRS_BAR_MAX_VAL)
274 
276 }
277 
278 
279 
280 /**************************************************************/
290 /*******************************************************
291 *
292 * The main PROGRESS_BAR message handler
293 *
294 *******************************************************/
295 
297 {
298  D4D_CLR_SCHEME *pScheme_tmp = D4D_ObjectGetScheme(pMsg->pObject);
299 
300  switch(pMsg->nMsgId)
301  {
302  case D4D_MSG_DRAW:
303  D4D_PrgrsBarOnDraw(pMsg);
304  break;
305 
306 
307  case D4D_MSG_ONINIT:
309 
311  D4D_GET_PROGRESS_BAR(pMsg->pObject)->pData->colorBar = pScheme_tmp->objectDepend.progressBar.barFore;
312  else
313  D4D_GET_PROGRESS_BAR(pMsg->pObject)->pData->colorBar = D4D_PrgrsBarComputeColorBar(pMsg->pObject, D4D_GET_PROGRESS_BAR(pMsg->pObject)->pData->value);
314  break;
315 
316  default:
317  // call the default behavior of all objects
318  D4D_ObjOnMessage(pMsg);
319  }
320 }
321 
D4D_COLOR D4D_GetCrossColor(D4D_COLOR startColor, D4D_COLOR endColor, Byte value)
Compute cross color between two basic color in 256 steps.
Definition: d4d_scheme.c:243
void D4D_RBox(D4D_POINT *ppt, D4D_SIZE *psz, D4D_LINETYPE ltype, D4D_COLOR colorLine, D4D_COLOR colorFill, D4D_COOR radius)
Function draw filled rectangle with outline on the screen with round corners.
D4D_COLOR D4D_ObjectGetBckgFillColor(D4D_OBJECT *pObj)
Function return object current fill background color.
Definition: d4d_scheme.c:225
#define D4D_GET_PROGRESS_BAR(pObj)
D4D_COLOR D4D_ObjectGetForeColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current fore color.
Definition: d4d_scheme.c:161
void D4D_PrgrsBarSetValue(D4D_OBJECT_PTR pThis, D4D_PROGRESS_BAR_VALUE value)
D4D_CLR_SCHEME_OBJ objectDepend
Sub structure of object non standard colors.
Definition: d4d_scheme.h:589
Type definition of eGUI point structure.
Definition: d4d_types.h:223
On Init message - is send for first time when the object is inicialized.
Definition: d4d_base.h:370
D4D object messages structure.
Definition: d4d_base.h:400
D4D_OBJECT_DATA_PTR pData
Pointer on runtime object data.
Definition: d4d_object.h:180
D4D_COLOR barFore
The progress bar, bar fore start color for case that the D4D_PRGRS_BAR_F_BAR_SCALECOLOR flag is enabl...
Definition: d4d_scheme.h:558
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
D4D_OBJECT_INITFLAGS initFlags
The initializations object flags.
Definition: d4d_object.h:178
D4D_COLOR barEnd
The progress bar, bar fore end color for case that the D4D_PRGRS_BAR_F_BAR_SCALECOLOR flag is enabled...
Definition: d4d_scheme.h:559
#define _calc
static void D4D_PrgrsBarValue2Coor(D4D_OBJECT *pThis)
#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.
Byte D4D_PROGRESS_BAR_VALUE
Type definition of progress bar value type - this is standard type used for progress bar data input...
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.
#define D4D_PRGRS_BAR_BAR_OFF
This is offset value of active work area of progress bar. If not defined, it sets to 5 pixels as a de...
D4D_OBJECT_FLAGS flags
runtime object flags
Definition: d4d_object.h:145
D4D_COLOR barBckg
The progress bar, bar background color.
Definition: d4d_scheme.h:557
#define D4D_OBJECT_DRAWFLAGS_COMPLETE
Draw complete flag.
Definition: d4d_base.h:361
#define D4D_SCRATCHPAD_SIZE
Call back function raised by any new input event (touch, mouse, keys).
Definition: d4d_base.h:579
D4D Driver private header file.
#define D4D_DEFSTR(str)
Macro that helps declare the strings in eGUI.
Definition: d4d_string.h:246
void D4D_PrgrsBarOnMessage(D4D_MESSAGE *pMsg)
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
Direction RIGHT.
Definition: d4d_types.h:311
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
const D4D_OBJECT_SYS_FUNCTION d4d_progress_barSysFunc
#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
void D4D_ObjOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_object.c:443
D4D_PROGRESS_BAR_VALUE D4D_PrgrsBarGetValue(D4D_OBJECT_PTR pThis)
#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
#define D4D_OBJECT_F_NOTINIT
Definition: d4d_object.h:113
void D4D_PrgrsBarChangeValue(D4D_OBJECT_PTR pThis, D4D_PROGRESS_BAR_VALUE incr)
D4D_MSGID nMsgId
Type of message.
Definition: d4d_base.h:404
D4D_SIZE size
Size of the object.
Definition: d4d_object.h:170
D4D_PROGRESS_BAR_DATA * pData
Byte D4D_MulDivUU8(Byte u1, Byte u2, Byte d)
Simple proportion unsigned calculation - 8 bit.
Definition: d4d_math.c:206
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
void D4D_FillRRectColorScaleXY(D4D_COOR x1, D4D_COOR y1, D4D_COOR x2, D4D_COOR y2, D4D_COLOR startColor, D4D_COLOR endColor, D4D_DIRECTION direction, D4D_COOR radius)
Function draw filled rectangle with round corners with changing color (cross color from start to end ...
static D4D_COLOR D4D_PrgrsBarComputeColorBar(D4D_OBJECT *pThis, D4D_PROGRESS_BAR_VALUE value)
void D4D_ComputeGeometry(D4D_GEOMETRY *pGeometry, D4D_OBJECT *pObject)
Definition: d4d_base.c:1047
The object system function needed for each object - this is part of D4D_OBJECT main structure...
Definition: d4d_object.h:134
Type definition of eGUI size structure.
Definition: d4d_types.h:230
D4D_OBJECT_DRAWFLAGS draw
Contains draw flags - is valid with D4D_MSG_DRAW and D4D_MSG_DRAWDONE message.
Definition: d4d_base.h:408
static void D4D_PrgrsBarOnDraw(D4D_MESSAGE *pMsg)
Type definition of eGUI geometry structure.
Definition: d4d_types.h:237
Line type thin.
Definition: d4d_types.h:293
void D4D_InvalidateObject(D4D_OBJECT_PTR pObject, D4D_BOOL bComplete)
Function invalidate object to redraw on screen.
Definition: d4d_object.c:71
D4D_COLOR D4D_PrgrsBarGetBarColor(D4D_OBJECT_PTR pThis)
void D4D_FillRRectXY(D4D_COOR x1, D4D_COOR y1, D4D_COOR x2, D4D_COOR y2, D4D_COLOR color, D4D_COOR radius)
Function draw filled rectangle on the screen with round corners.
#define D4D_PRGRS_BAR_F_BAR_SCALECOLOR
This option enable little bit different type of drawing bar, the color is gradually changed from fore...
#define D4D_MulDivUU
Definition: d4d_math.h:103
D4D_CLR_SCHEME_PRGRS_BAR progressBar
The non standard colors of progerss bar object.
Definition: d4d_scheme.h:571
Byte D4D_OBJECT_DRAWFLAGS
Drawing object flags type, handled to object in D4D_MSG_DRAW events.
Definition: d4d_base.h:359
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
D4D_COLOR D4D_GetGreyScale(D4D_COLOR color)
Compute the grayscale color.
Definition: d4d_scheme.c:333
#define D4D_PRGRS_BAR_F_BAR_AUTOCOLOR
This flag specifies the behavior of the progress bar. If it is set, the color of a progress bar depen...
union D4D_MESSAGE_S::@0 prm
Additional data for some type of messages.
void D4D_PrgrsBarSetBarColor(D4D_OBJECT_PTR pThis, D4D_COLOR color)
D4D_BOOL D4D_IsEnabled(D4D_OBJECT *pObject)
Function find out if the object is enabled or not.
Definition: d4d_object.c:303
#define D4D_COLOR_PRGRS_BAR_MAX_VAL
This is progress bar maximal value definition. If not defined, it sets to 100 (to reflect standard pe...
D4D_PROGRESS_BAR_VALUE value