eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_menu.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_MenuOnMessage(D4D_MESSAGE* pMsg);
52 
53 static void D4D_MenuOnInit(D4D_MESSAGE* pMsg);
55 
57 {
58  D4D_DEFSTR("Menu"),
60  NULL,
62 };
63 
64 // temporary structure for menu temporary value calculation
65 typedef struct
66 {
67  D4D_POINT position;
68  D4D_GEOMETRY contentGeom;
69  D4D_COOR titleBar_y;
70  D4D_SIZE maxIcon;
71  D4D_MENU_INDEX posCnt;
72  D4D_COOR textOff;
73  D4D_TCHAR index_txt[8];
74  Byte index_txt_len;
75  D4D_MENU_INDEX itemsCnt;
76 } D4D_MENU_TMP_VAL;
77 
78 #define _calc (*((D4D_MENU_TMP_VAL*)d4d_scratchPad))
79 
80 
81 
82 
83 /*******************************************************
84 *
85 * MENU Helper computing routines
86 *
87 *******************************************************/
88 
90 {
91  Byte tmpB;
92  D4D_SIZE tmpSize = {0, 0};
93  D4D_MENU_INDEX itemsCnt = D4D_GetItemsCount(pMenu);
94 
95 
96  // compute max width of used Icons
97  for(tmpB = 0; tmpB < itemsCnt; tmpB++)
98  {
99  if(pMenu->pItems[tmpB].pIcon != NULL)
100  {
101  if(D4D_GetBmpWidth(pMenu->pItems[tmpB].pIcon) > tmpSize.cx)
102  tmpSize.cx = D4D_GetBmpWidth(pMenu->pItems[tmpB].pIcon);
103 
104  if(D4D_GetBmpHeight(pMenu->pItems[tmpB].pIcon) > tmpSize.cy)
105  tmpSize.cy = D4D_GetBmpHeight(pMenu->pItems[tmpB].pIcon);
106  }
107  }
108  return tmpSize;
109 }
110 
112 {
113  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
114 
115  D4D_COOR bar_height = 0;
116 
117  if(pMenu->title_text.pText != NULL)
118  bar_height = D4D_GetFontHeight(pMenu->title_text.fontId);
119 
120  if(pThis->initFlags & D4D_MENU_F_INDEX)
121  if(D4D_GetFontHeight(pMenu->indexFontId) > bar_height)
122  bar_height = D4D_GetFontHeight(pMenu->indexFontId);
123 
124  if(pMenu->pIcon != NULL)
125  if(D4D_GetBmpHeight(pMenu->pIcon) > bar_height)
126  bar_height = D4D_GetBmpHeight(pMenu->pIcon);
127 
128  if(bar_height)
129  {
130  bar_height += 3;
131 
132  #if D4D_ROUND_CORNER_ENABLE == D4D_TRUE
133  bar_height += pThis->radius / 2;
134  #endif
135  }
136 
137  return bar_height;
138 }
139 
140 
142 {
143  D4D_MENU_INDEX i = 0;
144 
145  while(pMenu->pItems[i].pIcon || pMenu->pItems[i].text.pText)
146  {
147  i++;
148  }
149 
150  return i;
151 
152 }
153 
154 static void D4D_MenuValue2Coor(D4D_OBJECT* pThis)
155 {
156  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
157  _calc.position = D4D_GetClientToScreenPoint(pThis, &pThis->position);
158 
159  D4D_ComputeGeometry(&(_calc.contentGeom), pThis);
160 
161  _calc.titleBar_y = D4D_GetTitleBarHeight(pThis);
162  _calc.maxIcon = D4D_GetIconsMaxSize(pMenu);
163  _calc.textOff = pMenu->textOff;
164  _calc.itemsCnt = D4D_GetItemsCount(pMenu);
165 
166 
167  // Get the position count
168 
169  if(!pMenu->posCnt)
170  {
171  if(_calc.maxIcon.cy > (D4D_GetFontHeight(pMenu->itemsFontId)))
172  _calc.posCnt = (D4D_MENU_INDEX)((_calc.contentGeom.sz.cy - D4D_GetTitleBarHeight(pThis)) / (_calc.maxIcon.cy + 3));
173  else
174  _calc.posCnt = (D4D_MENU_INDEX)((_calc.contentGeom.sz.cy - D4D_GetTitleBarHeight(pThis)) / (D4D_GetFontHeight(pMenu->itemsFontId) + 3));
175  }
176  // if count of items position or text offsets are not declared , then use automatic values
177  if(!_calc.textOff)
178  {
179  if(_calc.posCnt > 1)
180  _calc.textOff = (D4D_COOR)( (pThis->size.cy - _calc.titleBar_y) / (_calc.posCnt));
181  else
182  _calc.textOff = (D4D_COOR)((pThis->size.cy - _calc.titleBar_y) / 2);
183  }
184 
185  if(pThis->initFlags & D4D_MENU_F_INDEX)
186  {
187 
188  // Draw index counter
189  _calc.index_txt_len = D4D_SprintDecU8((Byte)(pMenu->pData->ix + 1), _calc.index_txt, (D4D_TCHAR) 0);
190  _calc.index_txt[_calc.index_txt_len++] = '/';
191  _calc.index_txt_len += D4D_SprintDecU8((Byte)_calc.itemsCnt, &_calc.index_txt[_calc.index_txt_len], (D4D_TCHAR) 0);
192  _calc.index_txt[_calc.index_txt_len] = 0;
193 
194  }
195 
196 
197 }
198 
199 /*******************************************************
200 *
201 * MENU Drawing routine
202 *
203 *******************************************************/
204 
205 static void D4D_MenuOnDraw(D4D_MESSAGE* pMsg)
206 {
207  D4D_OBJECT* pThis = pMsg->pObject;
208  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
209  D4D_OBJECT_DRAWFLAGS draw = pMsg->prm.draw;
210  D4D_COLOR clrT, clrB;
211  D4D_POINT tmp_point;
212  D4D_SIZE tmp_size;
213  D4D_STRING tmp_txtbuff;
214  D4D_STR_PROPERTIES tmp_str_prty;
215  Byte tmpB;
216 
217  tmp_txtbuff.str_properties = &tmp_str_prty;
218  tmp_txtbuff.printOff = 0;
219  // Get background simple color
220  clrT = D4D_ObjectGetForeFillColor(pThis);
221  clrB = D4D_ObjectGetBckgFillColor(pThis);
222 
223  #ifdef D4D_DEBUG
224  // sanity check
226  #endif
227 
228  // Compute all tempoarary values
229  D4D_MenuValue2Coor(pThis);
230 
231  // draw just a color rectangle instead of bitmap
233  {
234  D4D_FillRRect(&_calc.position, &pThis->size, clrB, pThis->radius);
235 
236  if(pMenu->pIcon != NULL)
237  {
238  tmp_point.x = (D4D_COOR)(_calc.contentGeom.pnt.x + 2);
239  tmp_point.y = (D4D_COOR)(_calc.contentGeom.pnt.y + ((_calc.titleBar_y - D4D_GetBmpHeight(pMenu->pIcon)) / 2));
240 
241  D4D_DrawRBmp(&tmp_point, pMenu->pIcon, (D4D_BOOL)!D4D_IsEnabled(pThis), pThis->radius);
242  }
243 
244  if(pMenu->title_text.pText)
245  {
246  tmp_point.x = (D4D_COOR)(_calc.contentGeom.pnt.x + 4);
247 
248  #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
249  tmp_point.x += (D4D_COOR)(pThis->radius/2);
250  #endif
251 
252  if(pMenu->pIcon != NULL)
253  tmp_point.x += D4D_GetBmpHeight(pMenu->pIcon);
254 
255  tmp_point.y = _calc.contentGeom.pnt.y;
256 
257  tmp_size.cx = D4D_GetTextWidth(pMenu->title_text.fontId, pMenu->title_text.pText);
258  tmp_size.cy = D4D_GetFontHeight(pMenu->title_text.fontId);
259 
260  D4D_DrawTextRect(&tmp_point, &tmp_size, &pMenu->title_text, clrT, clrB);
261  }
262 
263  if(_calc.titleBar_y)
264  {
265  D4D_MoveToXY(_calc.contentGeom.pnt.x,\
266  (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y));
267 
268  D4D_LineToXY((D4D_COOR)(_calc.contentGeom.pnt.x + _calc.contentGeom.sz.cx - 1),\
269  (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y), D4D_LINE_THIN, clrT);
270  }
271  }
272 
273  // Draw the frame
274  if(draw & (D4D_OBJECT_DRAWFLAGS_COMPLETE | D4D_OBJECT_DRAWFLAGS_STATE))
275  D4D_DrawFrame(pThis, clrT, clrB);
276 
277  if(pThis->initFlags & D4D_MENU_F_INDEX)
278  {
279  // Draw index counter
280  tmp_txtbuff.printLen = (D4D_INDEX)((_calc.itemsCnt < 10)? 3:5);
281  tmp_size.cx = (D4D_COOR)(tmp_txtbuff.printLen * D4D_GetFontWidth(pMenu->indexFontId) + 2);
282  tmp_size.cy = (D4D_COOR)(_calc.titleBar_y - 2);
283  tmp_point.x = (D4D_COOR)(_calc.contentGeom.pnt.x + _calc.contentGeom.sz.cx - tmp_size.cx - 2);
284  tmp_point.y = (D4D_COOR)(_calc.contentGeom.pnt.y);
285 
286  #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
287  tmp_size.cy -= (D4D_COOR)(pThis->radius / 2);
288  tmp_point.x -= (D4D_COOR)(pThis->radius / 2);
289  tmp_point.y += (D4D_COOR)(pThis->radius / 2);
290  #endif
291 
292  tmp_txtbuff.pText = _calc.index_txt;
293  tmp_txtbuff.fontId = pMenu->indexFontId;
296  D4D_DrawTextRect(&tmp_point, &tmp_size, &tmp_txtbuff, clrT, clrB);
297  }
298 
299  for(tmpB = 0; (tmpB < _calc.posCnt) && (tmpB + pMenu->pData->page_ix < _calc.itemsCnt); tmpB++)
300  {
301  if(((pMenu->pData->ix - pMenu->pData->page_ix) != tmpB) || (!D4D_IsEnabled(pThis)))
302  {
303  clrT = D4D_ObjectGetForeFillColor(pThis);
304  clrB = D4D_ObjectGetBckgFillColor(pThis);
305  }
306  else
307  {
308  D4D_CLR_SCHEME *pScheme_tmp = D4D_ObjectGetScheme(pThis);
309  clrT = pScheme_tmp->foreFocus;
310  clrB = pScheme_tmp->bckgFocus;
311  }
312 
313  // Draw menu item text
314  if(pMenu->pItems[tmpB + pMenu->pData->page_ix].text.pText != NULL)
315  {
316  tmp_point.x = (D4D_COOR)(_calc.contentGeom.pnt.x + _calc.maxIcon.cx + 4);
317  tmp_point.y = (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y + 1 + (tmpB * _calc.textOff));
318 
319  tmp_size.cx = (D4D_COOR)(_calc.contentGeom.sz.cx - (_calc.maxIcon.cx + 6 + ((D4D_GET_MENU_SCROLL_BAR_HOR(pThis)->pData->flags & D4D_OBJECT_F_VISIBLE)? D4D_MENU_SCRLBR_WIDTH:0)));
320  #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
321  tmp_point.x += (D4D_COOR)(pThis->radius / 2);
322  tmp_size.cx -= (D4D_COOR)(pThis->radius / 1);
323  #endif
324  tmp_size.cy = D4D_GetFontHeight(pMenu->itemsFontId); // to invoke autosize capability in axis Y
325 
326  tmp_txtbuff.pText = pMenu->pItems[tmpB + pMenu->pData->page_ix].text.pText;
327  tmp_txtbuff.fontId = pMenu->itemsFontId;
328  tmp_txtbuff.buffSize = 0;
329  tmp_txtbuff.printLen = D4D_GetTextLength(tmp_txtbuff.pText);
332 
333 
334  D4D_DrawTextRect(&tmp_point, &tmp_size, &tmp_txtbuff, clrT, clrB);
335  }
336 
337  // Draw menu item icon
338  if(_calc.maxIcon.cx)
339  {
340  tmp_point.x = (D4D_COOR)(_calc.contentGeom.pnt.x + 3);
341 
342  if(_calc.maxIcon.cy < _calc.textOff)
343  tmp_point.y = (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y + 3 + (tmpB * _calc.textOff) + ((D4D_GetFontHeight(pMenu->itemsFontId) - _calc.maxIcon.cy) / 2));
344  else
345  tmp_point.y = (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y + 3 + (tmpB * _calc.textOff));
346 
347  if(pMenu->pItems[tmpB + pMenu->pData->page_ix].pIcon != NULL)
348  D4D_DrawRBmp(&tmp_point, pMenu->pItems[tmpB + pMenu->pData->page_ix].pIcon, (D4D_BOOL)!D4D_IsEnabled(pThis), pThis->radius);
349  else
350  D4D_FillRRect(&tmp_point, &_calc.maxIcon, D4D_ObjectGetBckgFillColor(pThis), pThis->radius);
351  }
352  }
353 }
354 
355 /*******************************************************
356 *
357 * MENU object focus next item routine
358 *
359 *******************************************************/
361 {
362  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
363 
364  // Compute all tempoarary values
365  D4D_MenuValue2Coor(pThis);
366  pMenu->pData->ix++;
367 
368  if(_calc.itemsCnt >= _calc.posCnt)
369  {
370  if(pMenu->pData->ix >= _calc.itemsCnt)
371  {
372  pMenu->pData->ix = 0;
373  pMenu->pData->page_ix = 0;
374  }else if(pMenu->pData->ix - pMenu->pData->page_ix > (_calc.posCnt - 1))
375  {
376  pMenu->pData->page_ix++;
377  }
379  } else
380  {
381  if(pMenu->pData->ix >= _calc.itemsCnt)
382  {
383  pMenu->pData->ix = 0;
384  }
385 
386  }
387 }
388 
389 /*******************************************************
390 *
391 * MENU object focus previous item routine
392 *
393 *******************************************************/
395 {
396  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
397 
398  // Compute all tempoarary values
399  D4D_MenuValue2Coor(pThis);
400 
401  pMenu->pData->ix--;
402 
403  if(_calc.itemsCnt >= _calc.posCnt)
404  {
405  if(pMenu->pData->ix < 0)
406  {
407  pMenu->pData->ix = (D4D_MENU_INDEX)(_calc.itemsCnt - 1);
408  pMenu->pData->page_ix = (D4D_MENU_INDEX)(_calc.itemsCnt - _calc.posCnt);
409 
410  }else if(pMenu->pData->ix - pMenu->pData->page_ix < 0)
411  {
412  pMenu->pData->page_ix--;
413  }
414 
416  } else
417  {
418  if(pMenu->pData->ix < 0)
419  {
420  pMenu->pData->ix = (D4D_MENU_INDEX)(_calc.itemsCnt - 1);
421  }
422  }
423 }
424 
425 
426 /*******************************************************
427 *
428 * MENU key handling routine
429 *
430 *******************************************************/
431 
432 static void D4D_MenuOnKeyDown(D4D_MESSAGE* pMsg)
433 {
434  if(D4D_GetCapturedObject() == pMsg->pObject)
435  {
436  if(pMsg->prm.key == D4D_KEY_SCANCODE_DOWN)
437  {
440 
441  } else if(pMsg->prm.key == D4D_KEY_SCANCODE_UP)
442  {
445  }
446  }
447 }
448 
449 /*******************************************************
450 *
451 * MENU key handling routine
452 *
453 *******************************************************/
454 
455 static void D4D_MenuOnKeyUp(D4D_MESSAGE* pMsg)
456 {
457  D4D_MENU* pMenu = D4D_GET_MENU(pMsg->pObject);
458 
459  if(pMsg->prm.key == D4D_KEY_SCANCODE_ENTER)
460  {
461  if(D4D_GetCapturedObject() != pMsg->pObject)
462  {
463  D4D_CaptureKeys(pMsg->pObject);
464  }else
465  {
466  if(pMenu->OnClicked)
467  pMenu->OnClicked(pMsg->pObject, pMenu->pData->ix);
468 
470  }
471  }
472 
473  if(pMsg->prm.key == D4D_KEY_SCANCODE_ESC)
474  {
476  }
477 }
478 
479 /*******************************************************
480 *
481 * MENU touch screen handling routine
482 *
483 *******************************************************/
484 #if defined(D4D_LLD_TCH) || defined(D4D_LLD_MOUSE)
485 static void D4D_MenuOnTouch(D4D_MESSAGE* pMsg, D4D_POINT* pPoint)
486 {
487  D4D_OBJECT* pThis = pMsg->pObject;
488  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
489 
490  if(pThis->pData->flags & D4D_OBJECT_F_TABSTOP)
491  {
492  if((D4D_GetFocusedObject(pMsg->pScreen) == pThis) || (pThis->pData->flags & D4D_OBJECT_F_FASTTOUCH))
493  {
494  D4D_FocusSet(pMsg->pScreen, pThis);
495 
496  D4D_MenuValue2Coor(pThis);
497 
498  if(pPoint->x < (pThis->position.x + pThis->size.cx - ((D4D_GET_MENU_SCROLL_BAR_HOR(pThis)->pData->flags & D4D_OBJECT_F_VISIBLE)? D4D_MENU_SCRLBR_WIDTH:0)))
499  {
500  // Select Menu Item
501  D4D_COOR tmp_y;
502  Byte tmpB;
503  D4D_MENU_INDEX tmpItemsCnt = D4D_GetItemsCount(pMenu);
504 
505  tmp_y = (D4D_COOR)(pPoint->y - pThis->position.y);
506 
507  if(tmp_y <= _calc.titleBar_y)
508  return;
509 
510  tmp_y -= _calc.titleBar_y;
511 
512  // now is in tmp_y offset of y from title bar
513 
514  // Check the list
515  for(tmpB = pMenu->pData->page_ix; tmpB < _calc.itemsCnt; tmpB++)
516  {
517  // Check end if list
518  if((tmpB - pMenu->pData->page_ix) >= _calc.posCnt)
519  break;
520 
521  if(tmp_y < _calc.textOff)
522  {
523  // founded touched line
524  if(pMenu->pData->ix != tmpB)
525  {
526  // Touched line is not focused
527  pMenu->pData->ix = (D4D_MENU_INDEX)tmpB;
528 
529  }else
530  {
531  if(pMenu->OnClicked)
532  pMenu->OnClicked(pThis, pMenu->pData->ix);
533  }
534  break;
535  }
536  tmp_y -= _calc.textOff;
537  }
539  }
540  }else
541  {
542  D4D_FocusSet(pMsg->pScreen, pThis);
543  }
544  }
545 }
546 #endif
547 
549 {
550  // Try to check if the Menu needs scroll Bar
551  D4D_MenuValue2Coor(pObject);
552 
553  // Switch off possible scroll bar in refresh case
554  D4D_GET_MENU_SCROLL_BAR_HOR(pObject)->pData->flags &= ~D4D_OBJECT_F_VISIBLE;
555 
556  if((_calc.posCnt < _calc.itemsCnt) || (pObject->initFlags & D4D_MENU_F_SIDEBAR))
557  {
558  D4D_OBJECT* pScrlBr;
559  pScrlBr = D4D_GET_MENU_SCROLL_BAR_HOR(pObject);
560 
561  pScrlBr->pData->flags |= D4D_OBJECT_F_VISIBLE;
562 
563  // Init child objects coordinations
564  pScrlBr->position.x = (D4D_COOR)(_calc.contentGeom.pnt.x + _calc.contentGeom.sz.cx - D4D_MENU_SCRLBR_WIDTH);
565  pScrlBr->position.y = (D4D_COOR)(_calc.contentGeom.pnt.y + _calc.titleBar_y + 1);
566 
567  pScrlBr->position = D4D_GetScreenToClientPoint( pScrlBr, &pScrlBr->position);
568 
569  pScrlBr->size.cx = D4D_MENU_SCRLBR_WIDTH;
570  pScrlBr->size.cy = (D4D_COOR)(_calc.contentGeom.sz.cy - _calc.titleBar_y - 1);
571 
572  pScrlBr->radius = D4D_LimitU(pObject->radius, 0, D4D_MENU_SCRLBR_WIDTH / 2);
573 
574  if(_calc.itemsCnt < _calc.posCnt)
575  D4D_ScrlBrSetRange(pScrlBr, 0, _calc.posCnt);
576  else
577  D4D_ScrlBrSetRange(pScrlBr, 0, _calc.itemsCnt);
578 
579  D4D_ScrlBrSetStep(pScrlBr, _calc.posCnt, D4D_MENU_SCRLBR_STEP);
580  D4D_ScrlBrSetPosition(pScrlBr, 0);
581  return D4D_TRUE;
582  }
583  return D4D_FALSE;
584 }
585 
586 static void D4D_MenuOnInit(D4D_MESSAGE* pMsg)
587 {
588  // init screen pointer of child objects
589  D4D_GET_MENU_SCROLL_BAR_HOR(pMsg->pObject)->pData->pScreen = pMsg->pObject->pData->pScreen;
590 
591  (void)D4D_MenuScrollBarSetup(pMsg->pObject);
592 
593  // set flag to redraw screen
595 }
596 
597 void D4D_MenuScrollBarsFeedBack(D4D_OBJECT* pThis, D4D_INDEX old_position, D4D_INDEX new_position)
598 {
599  D4D_MENU* pMenu = D4D_GET_MENU(D4D_GetParentObject(pThis));
600 
601  D4D_UNUSED(old_position);
602  pMenu->pData->page_ix = (D4D_MENU_INDEX)new_position;
603 
605 }
606 
607 /******************************************************************************
608 * Begin of D4D_MENU public functions
609 */
614 /**************************************************************************/
621 {
622  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
623 
624  if(pThis == NULL)
625  return 0;
626 
627  return pMenu->pData->ix;
628 
629 }
630 
631 /**************************************************************************/
639 {
640  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
641 
642  if(pThis == NULL)
643  return;
644 
645  if(ix > D4D_GetItemsCount(pMenu))
646  ix = D4D_GetItemsCount(pMenu);
647 
648  pMenu->pData->ix = ix;
649  pMenu->pData->page_ix = ix;
650 
652 
653 }
654 
655 /**************************************************************************/
662 {
663  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
664 
665  return D4D_GetItemsCount(pMenu);
666 }
667 
668 /**************************************************************************/
676 {
677  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
678  D4D_MENU_INDEX i_max = D4D_GetItemsCount(pMenu);
679  D4D_MENU_INDEX i;
680 
681  for(i=0;i< i_max;i++)
682  {
683  if(pMenu->pItems[i].pUser == pUser)
684  return i;
685  }
686 
687  return -1;
688 }
689 
690 /**************************************************************************/
697 {
698  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
699  return pMenu->pItems[pMenu->pData->ix].pUser;
700 }
701 
702 /**************************************************************************/
709 {
710  D4D_MENU* pMenu = D4D_GET_MENU(pThis);
711  return (D4D_STRING*)&(pMenu->pItems[pMenu->pData->ix].text);
712 }
713 
714 /******************************************************************************
715 * End of public functions */
717 /******************************************************************************/
718 
719 /**************************************************************/
729 /*******************************************************
730 *
731 * The MENU message handler
732 *
733 *******************************************************/
734 
736 {
737  #if defined(D4D_LLD_TCH) || defined(D4D_LLD_MOUSE)
738  D4D_POINT touchClickPoint;
739  #endif
740  switch(pMsg->nMsgId)
741  {
742  case D4D_MSG_DRAW:
743  D4D_MenuOnDraw(pMsg);
744  break;
745 
746  case D4D_MSG_KEYDOWN:
747  D4D_MenuOnKeyDown(pMsg);
748  break;
749 
750  case D4D_MSG_KEYUP:
751  D4D_MenuOnKeyUp(pMsg);
752  break;
753 
754 #ifdef D4D_LLD_MOUSE
756  touchClickPoint = D4D_GetMouseCoordinates(pMsg->pObject);
757  D4D_MenuOnTouch(pMsg, &touchClickPoint);
758  break;
759 
762  break;
763 
766  break;
767 
768 #endif
769 
770 #ifdef D4D_LLD_TCH
771  case D4D_MSG_TOUCHED:
772  case D4D_MSG_TOUCH_AUTO:
773  touchClickPoint = D4D_GetTouchScreenCoordinates(pMsg->pObject);
774  D4D_MenuOnTouch(pMsg, &touchClickPoint);
775  break;
776 #endif
777  case D4D_MSG_ONINIT:
779 
780  D4D_MenuOnInit(pMsg);
781  break;
782 
783  default:
784  // call the default behavior of all objects
785  D4D_ObjOnMessage(pMsg);
786  }
787 }
788 
789 /**************************************************************/
795 {
796  return &(D4D_GET_MENU(pThis)->title_text);
797 }
D4D_INDEX buffSize
size of text buffer array
Definition: d4d_string.h:103
D4D_WCHAR D4D_TCHAR
Type definition of eGUI character (it depends on UNICODE setting if this is D4D_CHAR or D4D_WCHAR)...
Definition: d4d_types.h:284
static void D4D_MenuFocusNextItem(D4D_OBJECT *pThis)
Definition: d4d_menu.c:360
D4D_OBJECT * D4D_GetParentObject(D4D_OBJECT *pObject)
Definition: d4d_object.c:498
#define D4D_KEY_SCANCODE_ESC
This macro is used to specify Key Scan Code ESC. If not defined, it sets to 0x01 as a default...
Definition: d4d_base.h:305
D4D_COLOR D4D_ObjectGetBckgFillColor(D4D_OBJECT *pObj)
Function return object current fill background color.
Definition: d4d_scheme.c:225
D4D_MENU_INDEX D4D_MenuGetItemCount(D4D_OBJECT_PTR pThis)
Function gets the count of menu items.
Definition: d4d_menu.c:661
#define D4D_KEY_SCANCODE_UP
This macro is used to specify Key Scan Code UP. If not defined, it sets to 0x51 as a default...
Definition: d4d_base.h:280
D4D_TEXT_PROPERTIES text_properties
Text properties structure.
Definition: d4d_string.h:96
D4D_MENU_INDEX ix
Definition: d4d_menu.h:171
D4D_INDEX printLen
Length of string that should be used (printed).
Definition: d4d_string.h:106
D4D_MENU_INDEX D4D_MenuGetIndex(D4D_OBJECT *pThis)
Function returns the current selected item index.
Definition: d4d_menu.c:620
struct D4D_SCREEN_S * pScreen
pointer to object screen owner - it is placed in RAM bacause one object could be used in multiply scr...
Definition: d4d_object.h:146
Type definition of eGUI point structure.
Definition: d4d_types.h:223
D4D_STRING text
Definition: d4d_menu.h:164
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
Mouse Whell Move Down message - is send in case that mouse whell move down is detected on this object...
Definition: d4d_base.h:390
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
#define D4D_GET_MENU_SCROLL_BAR_HOR(pObj)
Definition: d4d_menu.h:197
The string type. This structure contains all properties about string in eGUI.
Definition: d4d_string.h:100
D4D_COLOR D4D_ObjectGetForeFillColor(D4D_OBJECT *pObj)
Function return object current fill fore color.
Definition: d4d_scheme.c:208
#define D4D_DrawRBmp(ppt, pBmp, greyScale, radius)
Definition: d4d.h:192
D4D_OBJECT_INITFLAGS initFlags
The initializations object flags.
Definition: d4d_object.h:178
#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.
void D4D_ScrlBrSetPosition(D4D_OBJECT_PTR pObj, D4D_INDEX position)
The function sets the scroll bar position.
static D4D_COOR D4D_GetTitleBarHeight(D4D_OBJECT *pThis)
Definition: d4d_menu.c:111
#define D4D_MENU_IX_TXT_PRTY_DEFAULT
This is menu init index text properties. If not defined, it sets to (D4D_ALIGN_H_CENTER_MASK | D4D_AL...
Definition: d4d_menu.h:118
D4D_FONT fontId
index of used font
Definition: d4d_string.h:104
static void D4D_MenuFocusPreviousItem(D4D_OBJECT *pThis)
Definition: d4d_menu.c:394
#define D4D_MENU_IX_FNT_PRTY_DEFAULT
This is menu init index font properties. If not defined, it sets to ( 0 ) as a default.
Definition: d4d_menu.h:112
D4D_POINT D4D_GetTouchScreenCoordinates(D4D_OBJECT *pObject)
void D4D_MoveToXY(D4D_COOR x, D4D_COOR y)
Function move logic cursor to new position.
static D4D_MENU_INDEX D4D_GetItemsCount(D4D_MENU *pMenu)
Definition: d4d_menu.c:141
#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.
#define D4D_MENU_ITEM_FNT_PRTY_DEFAULT
This is menu init items font properties. If not defined, it sets to ( 0 ) as a default.
Definition: d4d_menu.h:124
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
void D4D_MenuOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_menu.c:735
Key Up message - is send when the object get new Key Up event.
Definition: d4d_base.h:377
D4D Driver main header file.
static void D4D_MenuOnInit(D4D_MESSAGE *pMsg)
Definition: d4d_menu.c:586
#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
D4D_OBJECT_FLAGS flags
runtime object flags
Definition: d4d_object.h:145
static void D4D_MenuOnDraw(D4D_MESSAGE *pMsg)
Definition: d4d_menu.c:205
The string properties type. This structure contains as Font as Text properties.
Definition: d4d_string.h:93
D4D_COOR D4D_GetBmpHeight(const D4D_BMP *pBmp)
Function gets information about bitmap height.
Definition: d4d_bmp.c:481
Auto Touched message - is send when the object is still keep touch by touch screen driver ...
Definition: d4d_base.h:380
#define D4D_GetMouseCoordinates(pObject)
Definition: d4d_mouse.h:226
#define D4D_OBJECT_DRAWFLAGS_COMPLETE
Draw complete flag.
Definition: d4d_base.h:361
void D4D_ScrlBrSetRange(D4D_OBJECT_PTR pObj, D4D_INDEX minimum, D4D_INDEX maximum)
The function sets the range of scroll bar scale.
#define D4D_SCRATCHPAD_SIZE
Call back function raised by any new input event (touch, mouse, keys).
Definition: d4d_base.h:579
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.
void * pUser
Definition: d4d_menu.h:166
#define D4D_KEY_SCANCODE_DOWN
This macro is used to specify Key Scan Code DOWN. If not defined, it sets to 0x50 as a default...
Definition: d4d_base.h:285
#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
#define D4D_MENU_SCRLBR_STEP
This is menu embedded scroll bar change step If not defined, it sets to 1 step as a default...
Definition: d4d_menu.h:94
D4D_COOR cx
Size in axis X (width)
Definition: d4d_types.h:232
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
D4D_MENU_ON_CLICK OnClicked
Definition: d4d_menu.h:185
D4D_STRING * D4D_MenuGetItemText(D4D_OBJECT_PTR pThis)
Function gets the selected item text.
Definition: d4d_menu.c:708
#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 _calc
Definition: d4d_menu.c:78
void D4D_ScrlBrSetStep(D4D_OBJECT_PTR pObj, D4D_INDEX page, D4D_INDEX step)
The function sets the step and page of scroll bar scale.
unsigned char Byte
Type definition of Byte (unsigned 8-bit).
Definition: d4d_types.h:151
void D4D_ObjOnMessage(D4D_MESSAGE *pMsg)
Definition: d4d_object.c:443
#define D4D_GET_MENU(pObj)
Definition: d4d_menu.h:195
void D4D_MenuSetIndex(D4D_OBJECT *pThis, D4D_MENU_INDEX ix)
Function select new item by index.
Definition: d4d_menu.c:638
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
D4D_INDEX D4D_GetTextLength(D4D_TCHAR *pText)
The function returns lenght of text.
Definition: d4d_string.c:329
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
#define D4D_ASSERT(cond)
Definition: d4d_base.h:583
#define D4D_MENU_SCRLBR_WIDTH
This is menu embedded scroll bar width If not defined, it sets to 20 pixels as a default.
Definition: d4d_menu.h:88
D4D_CLR_SCHEME * D4D_ObjectGetScheme(D4D_OBJECT *pObj)
Function return the pointer to current use object scheme of object.
Definition: d4d_scheme.c:109
void D4D_MenuScrollBarsFeedBack(D4D_OBJECT *pThis, D4D_INDEX old_position, D4D_INDEX new_position)
Definition: d4d_menu.c:597
D4D_TCHAR * pText
pointer to text array
Definition: d4d_string.h:102
D4D_STR_PROPERTIES * str_properties
pointer to string properties
Definition: d4d_string.h:105
D4D_COOR y
Coordination in axis Y.
Definition: d4d_types.h:226
D4D_COLOR bckgFocus
The object background color in focused state.
Definition: d4d_scheme.h:583
#define D4D_OBJECT_F_NOTINIT
Definition: d4d_object.h:113
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_STRING title_text
Definition: d4d_menu.h:177
D4D_MSGID nMsgId
Type of message.
Definition: d4d_base.h:404
D4D_SIZE size
Size of the object.
Definition: d4d_object.h:170
D4D_MENU_INDEX page_ix
Definition: d4d_menu.h:172
static D4D_SIZE D4D_GetIconsMaxSize(D4D_MENU *pMenu)
Definition: d4d_menu.c:89
void * D4D_MenuGetItemUserData(D4D_OBJECT_PTR pThis)
Function gets the selected item user data.
Definition: d4d_menu.c:696
const D4D_MENU_ITEM * pItems
Definition: d4d_menu.h:184
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
LWord D4D_INDEX
Type definition of eGUI general index variables.
Definition: d4d_types.h:206
The object main structure type definition.
Definition: d4d_object.h:167
void D4D_CaptureKeys(D4D_OBJECT_PTR pObj)
Function switch on capturing the keys to objects.
Definition: d4d_object.c:190
Draw message - is send when the object should be redrawed.
Definition: d4d_base.h:371
#define D4D_MENU_ITEM_TXT_PRTY_DEFAULT
This is menu init items text properties. If not defined, it sets to (D4D_ALIGN_H_LEFT_MASK | D4D_ALIG...
Definition: d4d_menu.h:130
D4D_COOR D4D_GetBmpWidth(const D4D_BMP *pBmp)
Function gets information about bitmap width.
Definition: d4d_bmp.c:450
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
#define D4D_MENU_F_INDEX
Enable show of index of items in header.
Definition: d4d_menu.h:69
The object system function needed for each object - this is part of D4D_OBJECT main structure...
Definition: d4d_object.h:134
sByte D4D_MENU_INDEX
This is menu item index variable type.
Definition: d4d_menu.h:143
#define D4D_OBJECT_F_VISIBLE
Object after initialization is visible on the screen.
Definition: d4d_object.h:72
#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
D4D_MENU_INDEX posCnt
Definition: d4d_menu.h:180
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
#define D4D_UNUSED(x)
Macro used just for notify compiler that the input parameter is not used.
Definition: d4d_base.h:504
Byte D4D_SprintDecU8(Byte val, D4D_TCHAR *pText, D4D_TCHAR fill)
The function convert decimal unsigned 8 bit number to string.
Definition: d4d_string.c:262
Type definition of eGUI size structure.
Definition: d4d_types.h:230
D4D_FONT_SIZE D4D_GetFontWidth(D4D_FONT ix)
Definition: d4d_font.c:398
D4D_COOR D4D_GetTextWidth(D4D_FONT ix, D4D_TCHAR *pText)
The function returns width of text in pixels.
Definition: d4d_string.c:357
static void D4D_MenuValue2Coor(D4D_OBJECT *pThis)
Definition: d4d_menu.c:154
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_MENU_INDEX D4D_MenuFindUserDataItem(D4D_OBJECT_PTR pThis, void *pUser)
Function finds the index of items with specified user data.
Definition: d4d_menu.c:675
Type definition of eGUI geometry structure.
Definition: d4d_types.h:237
Line type thin.
Definition: d4d_types.h:293
D4D_MENU_DATA * pData
Definition: d4d_menu.h:183
D4D_FONT itemsFontId
Definition: d4d_menu.h:179
const D4D_BMP * pIcon
Definition: d4d_menu.h:182
const D4D_OBJECT_SYS_FUNCTION d4d_menuSysFunc
Definition: d4d_menu.c:56
#define D4D_LimitU
Definition: d4d_math.h:105
static void D4D_MenuOnKeyUp(D4D_MESSAGE *pMsg)
Definition: d4d_menu.c:455
void D4D_InvalidateObject(D4D_OBJECT_PTR pObject, D4D_BOOL bComplete)
Function invalidate object to redraw on screen.
Definition: d4d_object.c:71
static D4D_BOOL D4D_MenuScrollBarSetup(D4D_OBJECT *pObject)
Definition: d4d_menu.c:548
D4D_COOR textOff
Definition: d4d_menu.h:181
static void D4D_MenuOnKeyDown(D4D_MESSAGE *pMsg)
Definition: d4d_menu.c:432
D4D_STRING * D4D_MenuGetTextBuffer(D4D_OBJECT *pThis)
Definition: d4d_menu.c:794
Key Down message - is send when the object get new Key Down event.
Definition: d4d_base.h:378
void D4D_LineToXY(D4D_COOR x, D4D_COOR y, D4D_LINETYPE ltype, D4D_COLOR color)
Function draw line on the screen.
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
const D4D_BMP * pIcon
Definition: d4d_menu.h:165
struct D4D_SCREEN_S * pScreen
Pointer to screen who is receiver of this message.
Definition: d4d_base.h:403
D4D_FONT_PROPERTIES font_properties
Font properties structure.
Definition: d4d_string.h:95
D4D_FONT_SIZE D4D_GetFontHeight(D4D_FONT ix)
Definition: d4d_font.c:381
Mouse Whell Move Up message - is send in case that mouse whell move up is detected on this object...
Definition: d4d_base.h:389
D4D_FONT indexFontId
Definition: d4d_menu.h:178
D4D_INDEX printOff
Offset of string that should be used (printed).
Definition: d4d_string.h:107
D4D_COLOR foreFocus
The object fore color in focused state.
Definition: d4d_scheme.h:587
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.
#define D4D_MENU_F_SIDEBAR
Forca always show of side bar scroll bar.
Definition: d4d_menu.h:70
D4D_BOOL D4D_IsEnabled(D4D_OBJECT *pObject)
Function find out if the object is enabled or not.
Definition: d4d_object.c:303
D4D_POINT D4D_GetScreenToClientPoint(D4D_OBJECT *pObject, D4D_POINT *nScreenPoint)
The function convert global screen point on the screen to the client point.
Definition: d4d_screen.c:586
D4D_OBJECT * D4D_GetCapturedObject(void)
Function returns the current keys capturing object pointer.
Definition: d4d_object.c:241