eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_check_box.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
52 
54 {
55  D4D_DEFSTR("Check Box"),
57  NULL,
59 };
60 
61 typedef struct
62 {
64  D4D_GEOMETRY contentGeom;
65  D4D_GEOMETRY BmpGeom;
66  D4D_GEOMETRY TxtGeom;
67  D4D_COOR iconRadius;
68 } D4D_CHECKBOX_TMP_VAL;
69 
70 #define _calc (*((D4D_CHECKBOX_TMP_VAL*)d4d_scratchPad))
71 
72 //static D4D_CHECKBOX_TMP_VAL _calc;
73 
75 {
76  D4D_CHECKBOX* pCheckB = D4D_GET_CHECKBOX(pThis);
77  D4D_SIZE sizeBmpEnabled;
78  D4D_COOR tmp_BorderOffset;
79 
80  _calc.position = D4D_GetClientToScreenPoint(pThis, &pThis->position);
81  D4D_ComputeGeometry(&(_calc.contentGeom), pThis);
82 
83  sizeBmpEnabled = D4D_GetBmpSize(pCheckB->pBmpChecked);
84 
85  _calc.BmpGeom = _calc.contentGeom;
86 
87  if(!sizeBmpEnabled.cx || !sizeBmpEnabled.cy)
88  {
89  _calc.BmpGeom.sz.cy = (D4D_COOR)((_calc.BmpGeom.sz.cy * 2) / 3);
90  _calc.BmpGeom.sz.cx = _calc.BmpGeom.sz.cy;
91  }else
92  _calc.BmpGeom.sz = sizeBmpEnabled;
93 
94  tmp_BorderOffset = (D4D_COOR)((_calc.contentGeom.sz.cy - _calc.BmpGeom.sz.cy) / 2);
95  _calc.BmpGeom.pnt.x += tmp_BorderOffset;
96  _calc.BmpGeom.pnt.y += tmp_BorderOffset;
97 
98  if(pCheckB->textBuff.pText)
99  {
100  _calc.TxtGeom = _calc.contentGeom;
101 
102  _calc.TxtGeom.pnt.x = (D4D_COOR) (_calc.BmpGeom.pnt.x + _calc.BmpGeom.sz.cx + D4D_CHECKBOX_TEXT_OFFSET);
103  _calc.TxtGeom.sz.cx -= (D4D_COOR) (_calc.TxtGeom.pnt.x - _calc.contentGeom.pnt.x);
104  #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
105  _calc.TxtGeom.sz.cx -= (D4D_COOR) (pThis->radius / 2);
106  #endif
107  }
108 
109 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
110  _calc.iconRadius = pThis->radius;
111 #endif
112 
113 }
114 
115 
116 /*******************************************************
117 *
118 * CHECK BOX Drawing routine
119 *
120 *******************************************************/
121 
122 static void D4D_CheckBoxOnDraw(D4D_MESSAGE* pMsg)
123 {
124  D4D_OBJECT* pThis = pMsg->pObject;
125  D4D_CHECKBOX* pCheckB = D4D_GET_CHECKBOX(pThis);
127  D4D_OBJECT_DRAWFLAGS draw = pMsg->prm.draw;
128  D4D_COLOR clrT, clrB;
129  D4D_CLR_SCHEME* pScheme = D4D_ObjectGetScheme(pThis);
130  D4D_BMP_PROPERTIES bmpProp;
131 
133 
134  D4D_CheckBoxValue2Coor(pThis);
135 
136  clrT = D4D_ObjectGetForeColor(pThis, draw);
137  clrB = D4D_ObjectGetBckgFillColor(pThis);
138 
140  D4D_FillRRect(&_calc.position, &pThis->size, clrB, pThis->radius);
141 
142  // Draw the frame
143  if(draw & (D4D_OBJECT_DRAWFLAGS_COMPLETE | D4D_OBJECT_DRAWFLAGS_STATE))
144  D4D_DrawFrame(pThis, clrT, clrB);
145 
146  // normal bitmap (also may be NULL if simple rect button is needed
147  if(*pStatus & D4D_CHECKBOX_STATUS_CHECKED_MASK)
148  {
149  if(pCheckB->pBmpChecked != NULL)
150  D4D_DrawRBmpRect(&_calc.BmpGeom.pnt, &_calc.BmpGeom.sz, pCheckB->pBmpChecked, bmpProp, pScheme->objectDepend.checkBox.iconBckg, (D4D_BOOL)!D4D_IsEnabled(pThis), _calc.iconRadius); // draw the bitmap
151  else
152  {
153  D4D_POINT tmp_point = _calc.BmpGeom.pnt;
154  D4D_SIZE tmp_size = _calc.BmpGeom.sz;
155  if(tmp_size.cy - 2 > 0)
156  {
157  tmp_point.x++;
158  tmp_point.y++;
159 
160  tmp_size.cx -= 2;
161  tmp_size.cy -= 2;
162 
163  D4D_RBox(&tmp_point, &tmp_size, D4D_LINE_THICK, clrB, clrT, _calc.iconRadius);
164  }
165  }
166  }
167  // no bitmap
168  else
169  {
170  if(pCheckB->pBmpUnChecked)
171  {
172  // draw the bitmap
173  D4D_DrawRBmpRect(&_calc.BmpGeom.pnt, &_calc.BmpGeom.sz, pCheckB->pBmpUnChecked, bmpProp, pScheme->objectDepend.checkBox.iconBckg, (D4D_BOOL)!D4D_IsEnabled(pThis), _calc.iconRadius);
174  }else
175  {
176  // draw just a color rectangle instead of bitmap
177 
178  D4D_FillRRect(&_calc.BmpGeom.pnt, &_calc.BmpGeom.sz, pScheme->objectDepend.checkBox.iconBckg, _calc.iconRadius);
179  }
180  }
181 
183  D4D_RRect(&_calc.BmpGeom.pnt, &_calc.BmpGeom.sz, D4D_LINE_THIN, clrT, _calc.iconRadius);
184 
185  // draw the text
186  if(pCheckB->textBuff.pText)
187  D4D_DrawTextRect(&_calc.TxtGeom.pnt, &_calc.TxtGeom.sz, &pCheckB->textBuff, clrT, D4D_ObjectGetBckgColor(pThis, draw));
188 
189 }
190 
191 /*******************************************************
192 *
193 * CHECK BOX key handling routine
194 *
195 *******************************************************/
196 
198 {
200 
201  // invoke "Click" event when enter key is pressed
202  if(pMsg->prm.key == D4D_KEY_SCANCODE_ENTER)
203  {
206  }
207 }
208 
209 /*******************************************************
210 *
211 * CHECK BOX key handling routine
212 *
213 *******************************************************/
214 
216 {
217  D4D_OBJECT* pThis = pMsg->pObject;
219 
220  // invoke "Click" event when enter key is pressed
221  if(pMsg->prm.key == D4D_KEY_SCANCODE_ENTER)
222  {
223  if(*pStatus & D4D_CHECKBOX_STATUS_PRESSED_MASK)
224  {
225  D4D_CHECKBOX* pCheckB = D4D_GET_CHECKBOX(pMsg->pObject);
226  *pStatus &= ~D4D_CHECKBOX_STATUS_PRESSED_MASK;
227 
228  if(*pStatus & D4D_CHECKBOX_STATUS_CHECKED_MASK)
229  *pStatus &= ~D4D_CHECKBOX_STATUS_CHECKED_MASK;
230  else
232 
233  if(pCheckB->OnChange)
234  pCheckB->OnChange(pThis);
235  }
237  }
238 }
239 
240 /*******************************************************
241 *
242 * CHECK BOX focus handling routine
243 *
244 *******************************************************/
245 
247 {
249 
251 }
252 
253 /*******************************************************
254 *
255 * CHECK BOX Touched Button handling routine
256 *
257 *******************************************************/
258 #if defined(D4D_LLD_TCH) || defined(D4D_LLD_MOUSE)
259  static void D4D_CheckBoxTouched(D4D_MESSAGE* pMsg)
260  {
262  {
263  if((D4D_GetFocusedObject(pMsg->pScreen) == pMsg->pObject) || (pMsg->pObject->pData->flags & D4D_OBJECT_F_FASTTOUCH))
264  {
266  D4D_CHECKBOX* pCheckB = D4D_GET_CHECKBOX(pMsg->pObject);
267 
268  if(*pStatus & D4D_CHECKBOX_STATUS_CHECKED_MASK)
269  *pStatus &= ~D4D_CHECKBOX_STATUS_CHECKED_MASK;
270  else
272 
273  if(pCheckB->OnChange)
274  pCheckB->OnChange(pMsg->pObject);
275 
277  }
278  D4D_FocusSet(pMsg->pScreen, pMsg->pObject);
279  }
280  }
281 #endif
282 
283 /******************************************************************************
284 * Begin of D4D_CHECK_BOX public functions
285 */
289 /**************************************************************************/
297 {
299  D4D_CHECKBOX* pCheckB = D4D_GET_CHECKBOX(pThis);
300 
301  if(((*pStatus & D4D_CHECKBOX_STATUS_CHECKED_MASK) && value) || (!(*pStatus & D4D_CHECKBOX_STATUS_CHECKED_MASK) && !value))
302  return ;
303 
304  // remember new value
305  if(value)
307  else
308  *pStatus &= ~D4D_CHECKBOX_STATUS_CHECKED_MASK;
309 
311 
312  // notify user that the value has changed
313  if(pCheckB->OnChange)
314  pCheckB->OnChange((D4D_OBJECT*)pThis);
315 }
316 
317 /**************************************************************************/
324 {
326 
327  return (D4D_BOOL)(*pStatus & D4D_CHECKBOX_STATUS_CHECKED_MASK);
328 }
329 
330 /******************************************************************************
331 * End of public functions */
333 /******************************************************************************/
334 
335 
336 /**************************************************************/
346 /*******************************************************
347 *
348 * The main CHECK BOX message handler
349 *
350 *******************************************************/
351 
353 {
354  switch(pMsg->nMsgId)
355  {
356  case D4D_MSG_DRAW:
357  D4D_CheckBoxOnDraw(pMsg);
358  break;
359 
360  case D4D_MSG_KEYDOWN:
361  D4D_CheckBoxOnKeyDown(pMsg);
362  break;
363 
364  case D4D_MSG_KEYUP:
365  D4D_CheckBoxOnKeyUp(pMsg);
366  break;
367 
368  case D4D_MSG_KILLFOCUS:
369  D4D_CheckBoxKillFocus(pMsg);
370  break;
371 
372 #if defined(D4D_LLD_TCH) || defined(D4D_LLD_MOUSE)
374  if(D4D_GetMouseHoverObject() != pMsg->pObject)
375  break;
376  case D4D_MSG_TOUCHED:
377  D4D_CheckBoxTouched(pMsg);
378  break;
379 #endif
380 
381  default:
382  // call the default behavior
383  D4D_ObjOnMessage(pMsg);
384  }
385 }
386 
387 /**************************************************************/
393 {
394  return &(D4D_GET_CHECKBOX(pThis)->textBuff);
395 }
D4D_COLOR D4D_ObjectGetBckgColor(D4D_OBJECT *pObj, D4D_OBJECT_DRAWFLAGS draw)
Function return object current background color.
Definition: d4d_scheme.c:185
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
void D4D_CheckBoxOnMessage(D4D_MESSAGE *pMsg)
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
D4D_STRING textBuff
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
void D4D_CheckBoxSetValue(D4D_OBJECT_PTR pThis, D4D_BOOL value)
Function Sets the the check box value.
D4D object messages structure.
Definition: d4d_base.h:400
#define D4D_GetMouseHoverObject()
Definition: d4d_mouse.h:225
D4D_OBJECT_DATA_PTR pData
Pointer on runtime object data.
Definition: d4d_object.h:180
#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
D4D_OBJECT_INITFLAGS initFlags
The initializations object flags.
Definition: d4d_object.h:178
static void D4D_CheckBoxOnKeyUp(D4D_MESSAGE *pMsg)
#define D4D_OBJECT_F_TABSTOP
Object can be focused.
Definition: d4d_object.h:74
#define D4D_DrawTextRect(ppt, psz, buffText, colorText, colorBkgd)
Function that draw text into defined rectangle on the screen.
#define D4D_GET_CHECKBOX_STATUS(pObj)
#define D4D_CHECKBOX_TEXT_OFFSET
This is pixel count of check box text border offset. If not defined, it sets to 4 pixel as a default...
Definition: d4d_check_box.h:66
Byte D4D_BMP_PROPERTIES
D4D_BMP_PROPERTIES type of image properties.
Definition: d4d_bmp.h:117
#define D4D_GET_CHECKBOX(pObj)
#define D4D_CHECKBOX_STATUS_PRESSED_MASK
D4D_CLR_SCHEME_CHECKB checkBox
The non standard colors of check box object.
Definition: d4d_scheme.h:569
#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
Key Up message - is send when the object get new Key Up event.
Definition: d4d_base.h:377
D4D Driver main header file.
#define D4D_KEY_SCANCODE_ENTER
This macro is used to specify Key Scan Code ENTER. If not defined, it sets to 0x1C as a default...
Definition: d4d_base.h:300
#define _calc
Definition: d4d_check_box.c:70
D4D_OBJECT_FLAGS flags
runtime object flags
Definition: d4d_object.h:145
D4D_COLOR iconBckg
The checkbox background of icon.
Definition: d4d_scheme.h:543
static void D4D_CheckBoxOnKeyDown(D4D_MESSAGE *pMsg)
#define D4D_OBJECT_DRAWFLAGS_COMPLETE
Draw complete flag.
Definition: d4d_base.h:361
Mouse Left Button Release message - is send in case that mouse left release is detected on this objec...
Definition: d4d_base.h:384
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
D4D_COOR cx
Size in axis X (width)
Definition: d4d_types.h:232
D4D_CHCKBX_ON_CHANGE OnChange
Byte D4D_COOR
Type definition of eGUI coordination variables.
Definition: d4d_types.h:219
#define D4D_CHECKBOX_STATUS_CHECKED_MASK
D4D_POINT position
Position on the screen/object.
Definition: d4d_object.h:169
const D4D_BMP * pBmpChecked
#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
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
Line type thick.
Definition: d4d_types.h:294
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
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
D4D_OBJECT_PTR D4D_GetFocusedObject(const D4D_SCREEN *pScreen)
The function returns pointer to object that is focused in given screen.
Definition: d4d_screen.c:266
D4D_MSGID nMsgId
Type of message.
Definition: d4d_base.h:404
const D4D_OBJECT_SYS_FUNCTION d4d_checkBoxSysFunc
Definition: d4d_check_box.c:53
D4D_SIZE size
Size of the object.
Definition: d4d_object.h:170
void D4D_RRect(D4D_POINT *ppt, D4D_SIZE *psz, D4D_LINETYPE ltype, D4D_COLOR color, D4D_COOR radius)
Function draw rectangle on the screen with round corners.
static void D4D_CheckBoxOnDraw(D4D_MESSAGE *pMsg)
D4D_KEY_SCANCODE key
There will be stored only code of key without release / press information - is valid with D4D_MSG_KEY...
Definition: d4d_base.h:409
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
#define D4D_ALIGN_H_CENTER_MASK
The horizontal center aligment option mask (for texts and also bitmaps).
Definition: d4d_base.h:225
D4D_STRING * D4D_CheckBoxGetTextBuffer(D4D_OBJECT *pThis)
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
D4D_POINT position
Screen coordination on physical screen (standard screen has {0,0})
Definition: d4d_screen.h:175
const D4D_BMP * pBmpUnChecked
#define D4D_OBJECT_F_FASTTOUCH
Object has enabled fast touch screen capability. This option supports only a some objects (button...
Definition: d4d_object.h:76
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
static void D4D_CheckBoxKillFocus(D4D_MESSAGE *pMsg)
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_FillRRect(D4D_POINT *ppt, D4D_SIZE *psz, D4D_COLOR color, D4D_COOR radius)
Function draw filled rectangle on the screen with round corners.
D4D_SIZE D4D_GetBmpSize(const D4D_BMP *pBmp)
Function gets information about bitmap size.
Definition: d4d_bmp.c:418
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
static void D4D_CheckBoxValue2Coor(D4D_OBJECT *pThis)
Definition: d4d_check_box.c:74
D4D_BOOL D4D_CheckBoxGetValue(D4D_OBJECT_PTR pThis)
Function Gets the the check box value.
#define D4D_CHECKBOX_F_ICON_RECTANGLE
Enable the check box icon rectangle.
Definition: d4d_check_box.h:87
Key Down message - is send when the object get new Key Down event.
Definition: d4d_base.h:378
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
struct D4D_SCREEN_S * pScreen
Pointer to screen who is receiver of this message.
Definition: d4d_base.h:403
Byte D4D_CHECKBOX_STATUS
D4D_COOR x
Coordination in axis X.
Definition: d4d_types.h:225
Kill Focus message - is send when the object is losing focus.
Definition: d4d_base.h:374
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