eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_icon.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
50 void D4D_IconOnMessage(D4D_MESSAGE* pMsg);
52 
54 {
55  D4D_DEFSTR("Icon"),
57  NULL,
59 };
60 
61 // temporary structure for icon coordinate calculation
62 typedef struct
63 {
64  D4D_POINT position;
65  D4D_POINT txtPos;
66  D4D_GEOMETRY contentGeom;
67 } D4D_ICON_TMP_VAL;
68 
69 #define _calc (*((D4D_ICON_TMP_VAL*)d4d_scratchPad))
70 
71 
72 static void D4D_IconValue2Coor(D4D_OBJECT* pThis)
73 {
74  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
75 
76  _calc.position = D4D_GetClientToScreenPoint(pThis, &pThis->position);
77  D4D_ComputeGeometry(&_calc.contentGeom, pThis);
78  _calc.txtPos = _calc.contentGeom.pnt;
79  _calc.txtPos.x += pIcon->txtOff.x;
80  _calc.txtPos.y += pIcon->txtOff.y;
81 
82 }
83 
84 /*******************************************************
85 *
86 * ICON Drawing routine
87 *
88 *******************************************************/
89 
90 static void D4D_IconOnDraw(D4D_MESSAGE* pMsg)
91 {
92  D4D_OBJECT* pThis = pMsg->pObject;
93  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
94  D4D_OBJECT_DRAWFLAGS draw = pMsg->prm.draw;
95  D4D_COLOR clrT, clrB;
96  D4D_BMP_PROPERTIES bmpProp;
97 
98  D4D_IconValue2Coor(pThis);
99 
101 
102  clrT = D4D_ObjectGetForeColor(pThis, draw);
103  clrB = D4D_ObjectGetBckgColor(pThis, draw);
104 
105  // Draw the frame
107  D4D_DrawFrame(pThis, clrT, clrB);
108 
109  // draw the bitmap
110  if(pIcon->pBmpX[pIcon->pData->index] != NULL)
111  D4D_DrawRBmpRect(&_calc.contentGeom.pnt,&_calc.contentGeom.sz, pIcon->pBmpX[pIcon->pData->index], bmpProp, clrB, (D4D_BOOL)(!D4D_IsEnabled(pThis)), pThis->radius);
112 
113  // draw the text
114  if(pIcon->textBuff.pText != NULL)
115  {
116  D4D_SIZE tmp_size;
117  tmp_size.cx = D4D_GetTextWidth(pIcon->textBuff.fontId, pIcon->textBuff.pText);
118  tmp_size.cy = D4D_GetFontHeight(pIcon->textBuff.fontId);
119 
120  D4D_DrawTextRect(&_calc.txtPos, &tmp_size, &pIcon->textBuff, clrT, clrB);
121  }
122 }
123 
124 /******************************************************************************
125 * Begin of D4D_ICON public functions
126 */
130 /**************************************************************************/
137 {
138  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
139  D4D_ICON_INDEX ix = 0;
140 
141 
142  while(pIcon->pBmpX[ix] != NULL)
143  {
144  ix++;
145  }
146 
147  return ix;
148 }
149 
150 /**************************************************************************/
158 {
159  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
160  D4D_ICON_DATA* pData = pIcon->pData;
161 
162  if(pData->index == index)
163  return ;
164 
165  if(D4D_IconGetBmpCount(pThis) == 0) // There is no loaded bitmaps - go out
166  return;
167 
168  if(index >= D4D_IconGetBmpCount(pThis)) // If value is bigger then count of BMPs
169  return;
170 
171  // remember new value
172  pData->index = index;
173 
175 
176  // notify user that the value has changed
177  if(pIcon->OnValueChanged)
178  pIcon->OnValueChanged((D4D_OBJECT*)pThis);
179 }
180 
181 
182 /**************************************************************************/
190 {
191  D4D_ICON_INDEX tmp_ix = (D4D_ICON_INDEX)(D4D_GET_ICON(pThis)->pData->index + incr);
192 
193  if(tmp_ix >= D4D_IconGetBmpCount(pThis))
194  tmp_ix = 0;
195 
196  D4D_IconSetIndex(pThis, tmp_ix);
197 }
198 
199 
200 /**************************************************************************/
207 {
208  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
209  return pIcon->pData->index;
210 }
211 
212 #if D4D_ICON_ENABLE_ANIMATION == D4D_TRUE
213 
214 /**************************************************************************/
222 {
223  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
224  D4D_ICON_DATA* pData = pIcon->pData;
225 
226  if(D4D_IconGetBmpCount(pThis))
227  {
228  pData->animationEnabled = D4D_TRUE;
229  pData->tickCounter = 0;
231  }
232 }
233 
234 /**************************************************************************/
242 {
243  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
244  D4D_ICON_DATA* pData = pIcon->pData;
245 
246  pData->animationEnabled = D4D_FALSE;
248 }
249 
250 
251 /**************************************************************************/
259 {
260  D4D_ICON* pIcon = D4D_GET_ICON(pThis);
261  D4D_ICON_DATA* pData = pIcon->pData;
262 
263  pData->tickCounterTrshld = cnt;
264 }
265 
266 #endif
267 
268 /******************************************************************************
269 * End of public functions */
271 /******************************************************************************/
272 
273 /**************************************************************/
283 /*******************************************************
284 *
285 * The main ICON message handler
286 *
287 *******************************************************/
288 
290 {
291 
292 #if D4D_ICON_ENABLE_ANIMATION == D4D_TRUE
293  D4D_ICON* pIcon = D4D_GET_ICON(pMsg->pObject);
294  D4D_ICON_DATA* pData = pIcon->pData;
295 #endif
296 
297  switch(pMsg->nMsgId)
298  {
299 
300 
301 
302  case D4D_MSG_DRAW:
303  D4D_IconOnDraw(pMsg);
304  break;
305 
306 #ifdef D4D_LLD_TCH
307  case D4D_MSG_TOUCHED:
308  D4D_FocusSet(pMsg->pScreen, pMsg->pObject);
309  break;
310 #endif
311 
312 #if D4D_ICON_ENABLE_ANIMATION == D4D_TRUE
313 
314  case D4D_MSG_ONINIT:
316 
318  break;
319 
320  case D4D_MSG_TIMETICK:
321  if(pData->animationEnabled)
322  {
323  if(++(pData->tickCounter) > pData->tickCounterTrshld)
324  {
325  pData->tickCounter = 0;
326  // update animation (change icon)
327  D4D_IconChangeIndex(pMsg->pObject, 1);
328  }
329  }
330  break;
331 #endif
332 
333  default:
334  // call the default behavior of all objects
335  D4D_ObjOnMessage(pMsg);
336  }
337 }
338 
339 /**************************************************************/
345 {
346  return &(D4D_GET_ICON(pThis)->textBuff);
347 }
348 
D4D_COLOR D4D_ObjectGetBckgColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current background color.
Definition: d4d_scheme.c:185
D4D_ICON_DATA * pData
Definition: d4d_icon.h:141
D4D_COLOR D4D_ObjectGetForeColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current fore color.
Definition: d4d_scheme.c:161
void D4D_IconOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_icon.c:289
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_ICON_ON_CHANGE OnValueChanged
Definition: d4d_icon.h:140
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
The string type. This structure contains all properties about string in eGUI.
Definition: d4d_string.h:100
#define D4D_DrawTextRect(ppt, psz, buffText, colorText, colorBkgd)
Function that draw text into defined rectangle on the screen.
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
Time Tick Occur message - is send with each time tick to object.
Definition: d4d_base.h:393
#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_OBJECT_FLAGS flags
runtime object flags
Definition: d4d_object.h:145
Word tickCounter
Definition: d4d_icon.h:127
#define D4D_OBJECT_DRAWFLAGS_COMPLETE
Draw complete flag.
Definition: d4d_base.h:361
const D4D_ICON_BMPS *const * pBmpX
Definition: d4d_icon.h:139
D4D Driver private header file.
#define D4D_GET_ICON(pObj)
Definition: d4d_icon.h:149
#define D4D_DEFSTR(str)
Macro that helps declare the strings in eGUI.
Definition: d4d_string.h:246
D4D_COOR cx
Size in axis X (width)
Definition: d4d_types.h:232
void D4D_IconAnimationStart(D4D_OBJECT_PTR pThis)
Function starts the animation of icon.
Definition: d4d_icon.c:221
D4D_POINT position
Position on the screen/object.
Definition: d4d_object.h:169
#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
void D4D_ObjOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_object.c:443
D4D_POINT txtOff
Definition: d4d_icon.h:138
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 NULL
Type definition of null pointer.
Definition: d4d_types.h:184
static void D4D_IconValue2Coor(D4D_OBJECT *pThis)
Definition: d4d_icon.c:72
D4D_TCHAR * pText
pointer to text array
Definition: d4d_string.h:102
D4D_COOR y
Coordination in axis Y.
Definition: d4d_types.h:226
#define D4D_OBJECT_F_NOTINIT
Definition: d4d_object.h:113
D4D_MSGID nMsgId
Type of message.
Definition: d4d_base.h:404
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
#define _calc
Definition: d4d_icon.c:69
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
D4D_ICON_INDEX D4D_IconGetIndex(D4D_OBJECT_PTR pThis)
Function returns current visible bitmap index.
Definition: d4d_icon.c:206
D4D_ICON_INDEX index
Definition: d4d_icon.h:123
#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
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
Type definition of eGUI size structure.
Definition: d4d_types.h:230
Byte D4D_ICON_INDEX
This is icon index variable, it used in API functions to choose the active icon in the list...
Definition: d4d_icon.h:108
D4D_COOR D4D_GetTextWidth(D4D_FONT ix, D4D_TCHAR *pText)
The function returns width of text in pixels.
Definition: d4d_string.c:357
D4D_STRING * D4D_IconGetTextBuffer(D4D_OBJECT *pThis)
Definition: d4d_icon.c:344
D4D_BOOL animationEnabled
Definition: d4d_icon.h:126
D4D_OBJECT_DRAWFLAGS draw
Contains draw flags - is valid with D4D_MSG_DRAW and D4D_MSG_DRAWDONE message.
Definition: d4d_base.h:408
void D4D_EnableTimeTicks(D4D_OBJECT_PTR pObj, D4D_BOOL bEnable)
Function enable or diasble receiving timeticks for an OBJECT.
Definition: d4d_object.c:172
void D4D_IconAnimationStop(D4D_OBJECT_PTR pThis)
Function stops the animation of icon.
Definition: d4d_icon.c:241
#define D4D_ICON_ANIMATION_TICK_COUNTER
This is icon animation time tick timeout (in ticks of eGUI time ticks - D4D_TimeTickPut), it can be changed in runtime. If not defined, it sets to ( 4 ) as a default.
Definition: d4d_icon.h:85
static void D4D_IconOnDraw(D4D_MESSAGE *pMsg)
Definition: d4d_icon.c:90
Type definition of eGUI geometry structure.
Definition: d4d_types.h:237
Word tickCounterTrshld
Definition: d4d_icon.h:128
D4D_STRING textBuff
Definition: d4d_icon.h:137
#define D4D_ALIGN_V_TOP_MASK
The vertical top aligment option mask (for texts and also bitmaps).
Definition: d4d_base.h:230
D4D_ICON_INDEX D4D_IconGetBmpCount(D4D_OBJECT_PTR pThis)
Function returns the icon bitmap count.
Definition: d4d_icon.c:136
const D4D_OBJECT_SYS_FUNCTION d4d_iconSysFunc
Definition: d4d_icon.c:53
void D4D_InvalidateObject(D4D_OBJECT_PTR pObject, D4D_BOOL bComplete)
Function invalidate object to redraw on screen.
Definition: d4d_object.c:71
Byte D4D_OBJECT_DRAWFLAGS
Drawing object flags type, handled to object in D4D_MSG_DRAW events.
Definition: d4d_base.h:359
void D4D_IconSetIndex(D4D_OBJECT_PTR pThis, D4D_ICON_INDEX index)
Function sets the new bitmap of icon by icon index.
Definition: d4d_icon.c:157
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
void D4D_IconAnimationSetCounts(D4D_OBJECT_PTR pThis, Word cnt)
Function sets the time tick tresholds for animation speed.
Definition: d4d_icon.c:258
struct D4D_SCREEN_S * pScreen
Pointer to screen who is receiver of this message.
Definition: d4d_base.h:403
void D4D_IconChangeIndex(D4D_OBJECT_PTR pThis, sByte incr)
Function sets the new bitmap of icon by icon index difference.
Definition: d4d_icon.c:189
D4D_FONT_SIZE D4D_GetFontHeight(D4D_FONT ix)
Definition: d4d_font.c:381
unsigned short Word
Type definition of Word (unsigned 16-bit).
Definition: d4d_types.h:159
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