GUIDEMO.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /*********************************************************************
  2. * Portions COPYRIGHT 2016 STMicroelectronics *
  3. * Portions SEGGER Microcontroller GmbH & Co. KG *
  4. * Solutions for real time microcontroller applications *
  5. **********************************************************************
  6. * *
  7. * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
  8. * *
  9. * Internet: www.segger.com Support: support@segger.com *
  10. * *
  11. **********************************************************************
  12. ** emWin V5.28 - Graphical user interface for embedded applications **
  13. All Intellectual Property rights in the Software belongs to SEGGER.
  14. emWin is protected by international copyright laws. Knowledge of the
  15. source code may not be used to write a similar product. This file may
  16. only be used in accordance with the following terms:
  17. The software has been licensed to STMicroelectronics International
  18. N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
  19. les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
  20. purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
  21. troller products commercialized by Licensee only, sublicensed and dis_
  22. tributed under the terms and conditions of the End User License Agree_
  23. ment supplied by STMicroelectronics International N.V.
  24. Full source code is available at: www.segger.com
  25. We appreciate your understanding and fairness.
  26. ----------------------------------------------------------------------
  27. File : GUIDEMO.c
  28. Purpose : Several GUIDEMO routines
  29. ----------------------------------------------------------------------
  30. */
  31. /**
  32. ******************************************************************************
  33. * @file GUIDEMO.c
  34. * @author MCD Application Team
  35. * @brief Several GUIDEMO routines
  36. ******************************************************************************
  37. * @attention
  38. *
  39. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
  40. * All rights reserved.</center></h2>
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted, provided that the following conditions are met:
  44. *
  45. * 1. Redistribution of source code must retain the above copyright notice,
  46. * this list of conditions and the following disclaimer.
  47. * 2. Redistributions in binary form must reproduce the above copyright notice,
  48. * this list of conditions and the following disclaimer in the documentation
  49. * and/or other materials provided with the distribution.
  50. * 3. Neither the name of STMicroelectronics nor the names of other
  51. * contributors to this software may be used to endorse or promote products
  52. * derived from this software without specific written permission.
  53. * 4. This software, including modifications and/or derivative works of this
  54. * software, must execute solely and exclusively on microcontroller or
  55. * microprocessor devices manufactured by or for STMicroelectronics.
  56. * 5. Redistribution and use of this software other than as permitted under
  57. * this license is void and will automatically terminate your rights under
  58. * this license.
  59. *
  60. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  61. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  62. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  63. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  64. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  65. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  66. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  67. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  68. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  69. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  70. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  71. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  72. *
  73. ******************************************************************************
  74. */
  75. #include "GUIDEMO.h"
  76. /*********************************************************************
  77. *
  78. * Dialog resources
  79. *
  80. **********************************************************************
  81. */
  82. static const GUI_WIDGET_CREATE_INFO _aFrameWinControl[] = {
  83. { FRAMEWIN_CreateIndirect, "Control", 0, 0, 0, CONTROL_SIZE_X, CONTROL_SIZE_Y, 0, 0 },
  84. { BUTTON_CreateIndirect, "Halt", GUI_ID_HALT, 2, 24, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0 },
  85. { BUTTON_CreateIndirect, "Next", GUI_ID_NEXT, 36, 24, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0 },
  86. { PROGBAR_CreateIndirect, 0, GUI_ID_PROGBAR0, 2, 11, PROGBAR_SIZE_X, PROGBAR_SIZE_Y, WM_CF_HIDE, 0 },
  87. { TEXT_CreateIndirect, 0, GUI_ID_TEXT0, 2, 2, TEXT_SIZE_X, TEXT_SIZE_Y, 0, 0 }
  88. };
  89. static const GUI_WIDGET_CREATE_INFO _aFrameWinInfo[] = {
  90. { FRAMEWIN_CreateIndirect, "STemWin Demo", 0, 0, 0, 0, 0, 0, 0 },
  91. { TEXT_CreateIndirect, "", GUI_ID_TEXT0, 3, 3, 0, 0, 0, 0 }
  92. };
  93. /*********************************************************************
  94. *
  95. * Static variables
  96. *
  97. **********************************************************************
  98. */
  99. static GUIDEMO_CONFIG _GUIDemoConfig;
  100. static WM_HWIN _hDialogControl;
  101. static WM_HWIN _hDialogInfo;
  102. static void (* _pfDrawBk)(int DrawLogo);
  103. static int _iDemo;
  104. static int _iDemoMinor;
  105. static int _HaltTime;
  106. static int _HaltTimeStart;
  107. static int _Halt;
  108. static int _Next;
  109. static int _Pressed;
  110. static U8 _DrawLogo;
  111. /*********************************************************************
  112. *
  113. * Static functions
  114. *
  115. **********************************************************************
  116. */
  117. /*********************************************************************
  118. *
  119. * _ClearHalt
  120. *
  121. * This function is called if the next button is pressed after
  122. * the demo was halted
  123. */
  124. static void _ClearHalt(void) {
  125. _Halt = 0;
  126. _HaltTime = 0;
  127. _HaltTimeStart = 0;
  128. }
  129. /*********************************************************************
  130. *
  131. * _DrawBkSimple
  132. */
  133. static void _DrawBkSimple(int DrawLogo) {
  134. GUI_SetBkColor(BK_COLOR_1);
  135. GUI_Clear();
  136. if (DrawLogo) {
  137. GUI_DrawBitmap(&bmSTLogo70x35, 5, 5);
  138. }
  139. }
  140. #if GUIDEMO_USE_AUTO_BK
  141. /*********************************************************************
  142. *
  143. * _DrawBk
  144. */
  145. static void _DrawBk(int DrawLogo) {
  146. int xSize;
  147. int ySize;
  148. xSize = LCD_GetXSize();
  149. ySize = LCD_GetYSize();
  150. GUI_DrawGradientV(0, 0, xSize, ySize, BK_COLOR_0, BK_COLOR_1);
  151. if (DrawLogo) {
  152. GUI_DrawBitmap(&bmSTLogo70x35, 5, 5);
  153. }
  154. }
  155. /*********************************************************************
  156. *
  157. * _DrawBkCircle
  158. */
  159. static void _DrawBkCircle(int DrawLogo) {
  160. static GUI_MEMDEV_Handle hMemStretch;
  161. GUI_MEMDEV_Handle hMemGradient;
  162. GUI_MEMDEV_Handle hMemCircle;
  163. GUI_MEMDEV_Handle hMemOld;
  164. int CircleWidth;
  165. int ySizeV;
  166. int xSize;
  167. int ySize;
  168. int i;
  169. U32 * pData;
  170. xSize = LCD_GetXSize();
  171. ySize = LCD_GetYSize();
  172. ySizeV = LCD_GetVYSize();
  173. if (ySizeV > ySize) {
  174. GUI_SetBkColor(BK_COLOR_1);
  175. GUI_ClearRect(0, 0, xSize, ySizeV);
  176. }
  177. if (hMemStretch == 0) {
  178. CircleWidth = (CIRCLE_RADIUS << 1) + 1;
  179. hMemCircle = GUI_MEMDEV_CreateFixed(0, 0, CircleWidth, CircleWidth, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
  180. hMemStretch = GUI_MEMDEV_CreateEx (0, 0, xSize, ySize, GUI_MEMDEV_NOTRANS);
  181. hMemGradient = GUI_MEMDEV_CreateFixed(0, 0, 1, CIRCLE_RADIUS, GUI_MEMDEV_NOTRANS, GUI_MEMDEV_APILIST_32, GUI_COLOR_CONV_8888);
  182. //
  183. // Initialize background
  184. //
  185. hMemOld = GUI_MEMDEV_Select(hMemCircle);
  186. GUI_SetBkColor(BK_COLOR_1);
  187. GUI_Clear();
  188. //
  189. // Create Gradient
  190. //
  191. GUI_MEMDEV_Select(hMemGradient);
  192. GUI_DrawGradientV(0, 0, 0, CIRCLE_RADIUS, BK_COLOR_0, BK_COLOR_1);
  193. //
  194. // Get color and draw circles
  195. //
  196. pData = (U32 *)GUI_MEMDEV_GetDataPtr(hMemGradient);
  197. GUI_MEMDEV_Select(hMemCircle);
  198. for (i = 0; i < CIRCLE_RADIUS; i++, pData++) {
  199. GUI_SetColor(*pData);
  200. GUI_DrawCircle(CIRCLE_RADIUS, CIRCLE_RADIUS, i);
  201. }
  202. //
  203. // Stretch and display
  204. //
  205. GUI_MEMDEV_Select(hMemStretch);
  206. GUI_MEMDEV_DrawPerspectiveX(hMemCircle, 0, 0, ySize, ySize, xSize, 0);
  207. GUI_MEMDEV_Delete(hMemCircle);
  208. GUI_MEMDEV_Delete(hMemGradient);
  209. GUI_MEMDEV_Select(hMemOld);
  210. }
  211. GUI_MEMDEV_Write(hMemStretch);
  212. if (DrawLogo) {
  213. GUI_DrawBitmap(&bmSTLogo70x35, LOGO_DIST_BORDER, LOGO_DIST_BORDER);
  214. }
  215. }
  216. #endif
  217. /*********************************************************************
  218. *
  219. * _HideProgress
  220. */
  221. static void _HideProgress(void) {
  222. PROGBAR_Handle hProg;
  223. hProg = WM_GetDialogItem(_hDialogControl, GUI_ID_PROGBAR0);
  224. WM_HideWindow(hProg);
  225. }
  226. /*********************************************************************
  227. *
  228. * _ShowProgress
  229. */
  230. static void _ShowProgress(void) {
  231. PROGBAR_Handle hProg;
  232. hProg = WM_GetDialogItem(_hDialogControl, GUI_ID_PROGBAR0);
  233. WM_ShowWindow(hProg);
  234. }
  235. /*********************************************************************
  236. *
  237. * _cbBk
  238. */
  239. static void _cbBk(WM_MESSAGE * pMsg) {
  240. WM_KEY_INFO * pInfo;
  241. switch (pMsg->MsgId) {
  242. case WM_PAINT:
  243. _pfDrawBk(_DrawLogo);
  244. break;
  245. case WM_SET_FOCUS:
  246. pMsg->Data.v = 0;
  247. break;
  248. case WM_KEY:
  249. pInfo = (WM_KEY_INFO *)pMsg->Data.p;
  250. if (pInfo->PressedCnt) {
  251. switch (pInfo->Key) {
  252. case 'n':
  253. _Next = 1;
  254. break;
  255. }
  256. }
  257. break;
  258. default:
  259. WM_DefaultProc(pMsg);
  260. break;
  261. }
  262. }
  263. /*********************************************************************
  264. *
  265. * _cbEffect
  266. */
  267. static int _cbEffect(int TimeRem, void * pVoid) {
  268. GUI_PID_STATE State;
  269. int Pressed;
  270. GUI_USE_PARA(TimeRem);
  271. Pressed = *((int *)pVoid);
  272. GUI_Exec();
  273. GUI_PID_GetState(&State);
  274. if (State.Pressed) {
  275. *((int *)pVoid) = 1;
  276. return 0;
  277. } else {
  278. if ((State.Pressed == 0) && (Pressed == 1)) {
  279. *((int *)pVoid) = 0;
  280. _Next = 1;
  281. return 1;
  282. }
  283. _Next = GUIDEMO_CheckCancel();
  284. return _Next;
  285. }
  286. }
  287. /*********************************************************************
  288. *
  289. * _cbFrameWinControl
  290. */
  291. static void _cbFrameWinControl(WM_MESSAGE * pMsg) {
  292. WM_HWIN hItem;
  293. int xSize;
  294. int ySize;
  295. int NCode;
  296. int Id;
  297. switch (pMsg->MsgId) {
  298. case WM_KEY:
  299. WM_SendMessage(WM_HBKWIN, pMsg);
  300. break;
  301. case WM_INIT_DIALOG:
  302. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_PROGBAR0);
  303. PROGBAR_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
  304. PROGBAR_SetFont(hItem, &GUI_FontD6x8);
  305. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_HALT);
  306. BUTTON_SetFocussable(hItem, 0);
  307. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_NEXT);
  308. BUTTON_SetFocussable(hItem, 0);
  309. hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT0);
  310. TEXT_SetText(hItem, "Intro");
  311. TEXT_SetFont(hItem, &GUI_Font8_ASCII);
  312. break;
  313. case WM_PAINT:
  314. xSize = WM_GetWindowSizeX(pMsg->hWin);
  315. ySize = WM_GetWindowSizeY(pMsg->hWin);
  316. GUI_DrawGradientV(0, 0, xSize - 1, ySize - 1, 0xFFFFFF, 0xDCCEC0);
  317. break;
  318. case WM_NOTIFY_PARENT:
  319. Id = WM_GetId(pMsg->hWinSrc);
  320. NCode = pMsg->Data.v;
  321. switch (NCode) {
  322. case WM_NOTIFICATION_CLICKED:
  323. switch (Id) {
  324. case GUI_ID_HALT:
  325. if (_Halt) {
  326. _Halt = 0;
  327. _HaltTime = GUI_GetTime() - _HaltTimeStart;
  328. WM_MakeModal(0);
  329. } else {
  330. _Halt = 1;
  331. _HaltTimeStart = GUI_GetTime() - _HaltTime;
  332. WM_MakeModal(pMsg->hWin);
  333. }
  334. break;
  335. case GUI_ID_NEXT:
  336. _Next = 1; // Will be set to 0 by GUIDEMO_GetNextState()
  337. _ClearHalt(); // Clear _Halt, so the next sample demonstrates immediately
  338. break;
  339. }
  340. break;
  341. }
  342. break;
  343. default:
  344. WM_DefaultProc(pMsg);
  345. }
  346. }
  347. /*********************************************************************
  348. *
  349. * _cbFrameWinInfo
  350. */
  351. static void _cbFrameWinInfo(WM_MESSAGE * pMsg) {
  352. int xSize;
  353. int ySize;
  354. switch (pMsg->MsgId) {
  355. case WM_KEY:
  356. WM_SendMessage(WM_HBKWIN, pMsg);
  357. break;
  358. case WM_CREATE:
  359. xSize = LCD_GetXSize();
  360. WM_SetWindowPos(pMsg->hWin, xSize >> 1, 0, xSize >> 1, INFO_SIZE_Y);
  361. break;
  362. case WM_PAINT:
  363. xSize = WM_GetWindowSizeX(pMsg->hWin);
  364. ySize = WM_GetWindowSizeY(pMsg->hWin);
  365. GUI_DrawGradientV(0, 0, xSize - 1, ySize - 1, 0xFFFFFF, 0xDCCEC0);
  366. break;
  367. default:
  368. WM_DefaultProc(pMsg);
  369. }
  370. }
  371. /*********************************************************************
  372. *
  373. * _FRAMEWIN_DrawSkinFlex
  374. */
  375. static int _FRAMEWIN_DrawSkinFlex(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
  376. switch (pDrawItemInfo->Cmd) {
  377. case WIDGET_ITEM_CREATE:
  378. FRAMEWIN_SetTextAlign(pDrawItemInfo->hWin, GUI_TA_HCENTER | GUI_TA_VCENTER);
  379. FRAMEWIN_SetTextColor(pDrawItemInfo->hWin, GUI_BLACK);
  380. break;
  381. default:
  382. return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  383. }
  384. return 0;
  385. }
  386. /*********************************************************************
  387. *
  388. * _Main
  389. */
  390. static void _Main(void) {
  391. int xSize;
  392. int ySize;
  393. WM_SelectWindow(WM_HBKWIN);
  394. GUI_Clear();
  395. #if (GUI_SUPPORT_CURSOR | GUI_SUPPORT_TOUCH)
  396. // GUI_CURSOR_Show();
  397. #endif
  398. //
  399. // Create and configure Control and Information window
  400. //
  401. xSize = LCD_GetXSize();
  402. ySize = LCD_GetYSize();
  403. _hDialogControl = GUI_CreateDialogBox(_aFrameWinControl, GUI_COUNTOF(_aFrameWinControl), &_cbFrameWinControl, WM_HBKWIN, xSize - CONTROL_SIZE_X, ySize - CONTROL_SIZE_Y);
  404. _hDialogInfo = GUI_CreateDialogBox(_aFrameWinInfo, GUI_COUNTOF(_aFrameWinInfo), &_cbFrameWinInfo, WM_HBKWIN, (xSize >> 1) - 1, 0);
  405. WM_HideWindow(_hDialogInfo);
  406. //
  407. // Show Intro
  408. //
  409. WM_InvalidateWindow(_hDialogControl);
  410. WM_DisableMemdev(WM_HBKWIN);
  411. GUI_Exec();
  412. WM_EnableMemdev(WM_HBKWIN);
  413. GUI_SetBkColor(GUI_RED);
  414. GUI_Clear();
  415. GUI_SetBkColor(GUI_GREEN);
  416. GUI_Clear();
  417. GUI_SetBkColor(GUI_BLUE);
  418. GUI_Clear();
  419. GUIDEMO_Intro();
  420. //
  421. // Run the demos
  422. //
  423. for (_iDemo = 0; _GUIDemoConfig.apFunc[_iDemo]; _iDemo++) {
  424. _ClearHalt();
  425. GUIDEMO_UpdateControlText();
  426. (*_GUIDemoConfig.apFunc[_iDemo])();
  427. _iDemoMinor = 0;
  428. _Pressed = 0;
  429. }
  430. _iDemo = 0;
  431. //
  432. // Cleanup
  433. //
  434. WM_DeleteWindow(_hDialogControl);
  435. WM_DeleteWindow(_hDialogInfo);
  436. #if (GUI_SUPPORT_CURSOR | GUI_SUPPORT_TOUCH)
  437. GUI_CURSOR_Hide();
  438. #endif
  439. }
  440. /*********************************************************************
  441. *
  442. * Public functions
  443. *
  444. **********************************************************************
  445. */
  446. /*********************************************************************
  447. *
  448. * GUIDEMO_SetDrawLogo
  449. */
  450. void GUIDEMO_SetDrawLogo(U8 OnOff) {
  451. _DrawLogo = OnOff ? 1 : 0;
  452. }
  453. /*********************************************************************
  454. *
  455. * GUIDEMO_AddIntToString
  456. */
  457. void GUIDEMO_AddIntToString(char * pText, unsigned int Number) {
  458. int TextLen;
  459. int LenNum;
  460. int i;
  461. TextLen = 0;
  462. while (*(pText + TextLen)) {
  463. TextLen++;
  464. }
  465. i = 1;
  466. LenNum = 1;
  467. while ((Number / i) >= 10) {
  468. i *= 10;
  469. LenNum++;
  470. }
  471. *(pText + TextLen + LenNum) = '\0';
  472. while (LenNum) {
  473. *(pText + TextLen + LenNum - 1) = '0' + Number % 10;
  474. Number /= 10;
  475. LenNum--;
  476. }
  477. }
  478. /*********************************************************************
  479. *
  480. * GUIDEMO_AddStringToString
  481. */
  482. void GUIDEMO_AddStringToString(char * pText, const char * acAdd) {
  483. int i;
  484. int j;
  485. i = 0;
  486. j = 0;
  487. while (*(pText + i)) {
  488. i++;
  489. }
  490. while (*(acAdd + j)) {
  491. *(pText + i) = *(acAdd + j);
  492. i++;
  493. j++;
  494. }
  495. *(pText + i) = '\0';
  496. }
  497. /*********************************************************************
  498. *
  499. * GUIDEMO_CheckCancel
  500. */
  501. int GUIDEMO_CheckCancel(void) {
  502. //
  503. // Do not return until the button is released
  504. //
  505. while (_Halt == 1) {
  506. GUI_Delay(10);
  507. }
  508. //
  509. // Check Next Button
  510. //
  511. if (_Next == 1) {
  512. _Next = 0;
  513. return 1;
  514. }
  515. return 0;
  516. }
  517. /*********************************************************************
  518. *
  519. * GUIDEMO_ClearText
  520. *
  521. */
  522. void GUIDEMO_ClearText(char * pText) {
  523. *pText = 0;
  524. }
  525. /*********************************************************************
  526. *
  527. * GUIDEMO_Delay
  528. *
  529. * This function has to be called if the current step of the sample
  530. * is the last one and consists of a single frame
  531. */
  532. void GUIDEMO_Delay(int TimeDelay) {
  533. PROGBAR_Handle hProg;
  534. int NextState;
  535. U32 TimeStart;
  536. U32 TimeDiff;
  537. hProg = WM_GetDialogItem(_hDialogControl, GUI_ID_PROGBAR0);
  538. if (TimeDelay > SHOW_PROGBAR_AT) {
  539. _ShowProgress();
  540. }
  541. PROGBAR_SetValue(hProg, 0);
  542. PROGBAR_SetMinMax(hProg, 0, TimeDelay);
  543. TimeStart = GUI_GetTime();
  544. do {
  545. TimeDiff = GUIDEMO_GetTime() - TimeStart;
  546. if (TimeDelay > SHOW_PROGBAR_AT) {
  547. PROGBAR_SetValue(hProg, TimeDiff);
  548. }
  549. GUI_Delay(5);
  550. NextState = GUIDEMO_CheckCancel();
  551. } while (TimeDiff < (U32)TimeDelay && !NextState);
  552. if (TimeDelay > SHOW_PROGBAR_AT) {
  553. _HideProgress();
  554. }
  555. GUI_Exec();
  556. }
  557. /*********************************************************************
  558. *
  559. * GUIDEMO_DrawBk
  560. */
  561. void GUIDEMO_DrawBk(int DrawLogo) {
  562. _pfDrawBk(DrawLogo);
  563. }
  564. /*********************************************************************
  565. *
  566. * GUIDEMO_GetConfFlag
  567. */
  568. U16 GUIDEMO_GetConfFlag(U16 Flag) {
  569. return (_GUIDemoConfig.Flags & Flag) ? 1 : 0;
  570. }
  571. /*********************************************************************
  572. *
  573. * GUIDEMO_GetTime
  574. */
  575. int GUIDEMO_GetTime(void) {
  576. return _Halt ? _HaltTimeStart : GUI_GetTime() - _HaltTime;
  577. }
  578. /*********************************************************************
  579. *
  580. * GUIDEMO_HideControlWin
  581. */
  582. void GUIDEMO_HideControlWin(void) {
  583. WM_HideWindow(_hDialogControl);
  584. WM_ValidateWindow(WM_HBKWIN);
  585. }
  586. /*********************************************************************
  587. *
  588. * GUIDEMO_HideInfoWin
  589. */
  590. void GUIDEMO_HideInfoWin(void) {
  591. WM_HideWindow(_hDialogInfo);
  592. WM_ValidateWindow(WM_HBKWIN);
  593. }
  594. /*********************************************************************
  595. *
  596. * GUIDEMO_NotifyStartNext
  597. *
  598. * Use this function if the next step of the current sample will be
  599. * shown immediately
  600. */
  601. void GUIDEMO_NotifyStartNext(void) {
  602. _iDemoMinor++;
  603. _ClearHalt();
  604. GUIDEMO_UpdateControlText();
  605. }
  606. /*********************************************************************
  607. *
  608. * GUIDEMO_ShowControlWin
  609. */
  610. void GUIDEMO_ShowControlWin(void) {
  611. WM_ShowWindow(_hDialogControl);
  612. GUI_Exec();
  613. }
  614. /*********************************************************************
  615. *
  616. * GUIDEMO_ShowInfo
  617. */
  618. void GUIDEMO_ShowInfo(const char * acInfo) {
  619. TEXT_Handle hText;
  620. if (WM_IsVisible(_hDialogInfo)) {
  621. hText = WM_GetDialogItem(_hDialogInfo, GUI_ID_TEXT0);
  622. TEXT_SetText(hText, acInfo);
  623. }
  624. }
  625. /*********************************************************************
  626. *
  627. * GUIDEMO_ShowInfoWin
  628. */
  629. void GUIDEMO_ShowInfoWin(void) {
  630. WM_ShowWindow(_hDialogInfo);
  631. }
  632. /*********************************************************************
  633. *
  634. * GUIDEMO_ShowIntro
  635. *
  636. * Function description
  637. * Shows the GUIDEMO introduction screen which display the title of
  638. * the sample and a short description.
  639. */
  640. void GUIDEMO_ShowIntro(const char * acTitle, const char * acDescription) {
  641. int FontDistY;
  642. int TimeWait;
  643. int xCenter;
  644. int yCenter;
  645. int xSize;
  646. int ySize;
  647. int i;
  648. xSize = LCD_GetXSize();
  649. ySize = LCD_GetYSize();
  650. xCenter = xSize >> 1;
  651. yCenter = ySize >> 1;
  652. GUIDEMO_HideInfoWin();
  653. GUIDEMO_ShowControlWin();
  654. GUI_Exec();
  655. GUIDEMO_DrawBk(1);
  656. GUI_SetColor(GUI_WHITE);
  657. //
  658. // Title
  659. //
  660. GUI_SetTextMode(GUI_TM_TRANS);
  661. GUI_SetFont(&GUI_FontRounded22);
  662. GUI_DispStringHCenterAt(acTitle, xCenter, 60);
  663. //
  664. // Description
  665. //
  666. GUI_SetFont(&GUI_Font16_ASCII);
  667. FontDistY = GUI_GetFontDistY();
  668. GUI_DispStringHCenterAt(acDescription, xCenter, yCenter - FontDistY + 10);
  669. //
  670. // Determine time to wait
  671. //
  672. i = 0;
  673. while (acDescription[i]) {
  674. i++;
  675. }
  676. TimeWait = i * CHAR_READING_TIME;
  677. GUIDEMO_Wait(TimeWait);
  678. }
  679. /*********************************************************************
  680. *
  681. * GUIDEMO_UpdateControlText
  682. */
  683. void GUIDEMO_UpdateControlText(void) {
  684. TEXT_Handle hText;
  685. char acText[20] = { 0 };
  686. hText = WM_GetDialogItem(_hDialogControl, GUI_ID_TEXT0);
  687. GUIDEMO_AddStringToString(acText, "Demo ");
  688. GUIDEMO_AddIntToString (acText, _iDemo + 1);
  689. GUIDEMO_AddStringToString(acText, ".");
  690. GUIDEMO_AddIntToString (acText, _iDemoMinor);
  691. GUIDEMO_AddStringToString(acText, "/");
  692. GUIDEMO_AddIntToString (acText, _GUIDemoConfig.NumDemos - 1);
  693. TEXT_SetText (hText, acText);
  694. }
  695. /*********************************************************************
  696. *
  697. * GUIDEMO_Wait
  698. *
  699. * This function has to be called if the current step is a static
  700. * frame and another step will follow
  701. */
  702. void GUIDEMO_Wait(int TimeWait) {
  703. GUIDEMO_Delay(TimeWait);
  704. GUIDEMO_NotifyStartNext();
  705. }
  706. /*********************************************************************
  707. *
  708. * GUIDEMO_Main
  709. */
  710. void GUIDEMO_Main(void) {
  711. FRAMEWIN_SKINFLEX_PROPS Framewin_Props;
  712. #if GUIDEMO_USE_AUTO_BK
  713. int NumFreeBytes;
  714. int BitsPerPixel;
  715. #endif
  716. GUI_MEMDEV_SetAnimationCallback(_cbEffect, (void *)&_Pressed);
  717. WM_SetCallback(WM_HBKWIN, _cbBk);
  718. BUTTON_SetReactOnLevel();
  719. FRAMEWIN_GetSkinFlexProps(&Framewin_Props, FRAMEWIN_SKINFLEX_PI_ACTIVE);
  720. Framewin_Props.Radius = 0;
  721. FRAMEWIN_SetSkinFlexProps(&Framewin_Props, FRAMEWIN_SKINFLEX_PI_ACTIVE);
  722. FRAMEWIN_GetSkinFlexProps(&Framewin_Props, FRAMEWIN_SKINFLEX_PI_INACTIVE);
  723. Framewin_Props.Radius = 0;
  724. FRAMEWIN_SetSkinFlexProps(&Framewin_Props, FRAMEWIN_SKINFLEX_PI_INACTIVE);
  725. FRAMEWIN_SetDefaultSkin (_FRAMEWIN_DrawSkinFlex);
  726. PROGBAR_SetDefaultSkin (PROGBAR_SKIN_FLEX);
  727. BUTTON_SetDefaultSkin (BUTTON_SKIN_FLEX);
  728. SCROLLBAR_SetDefaultSkin (SCROLLBAR_SKIN_FLEX);
  729. SLIDER_SetDefaultSkin (SLIDER_SKIN_FLEX);
  730. HEADER_SetDefaultSkin (HEADER_SKIN_FLEX);
  731. GUI_SetTextMode (GUI_TM_TRANS);
  732. GUIDEMO_Config(&_GUIDemoConfig);
  733. #if GUIDEMO_USE_VNC
  734. if (GUIDEMO_GetConfFlag(GUIDEMO_CF_USE_VNC)) {
  735. _GUIDemoConfig.pGUI_VNC_X_StartServer(0, 0);
  736. }
  737. #endif
  738. #if GUIDEMO_USE_AUTO_BK
  739. //
  740. // Determine if HW has enough memory to draw the gradient circle as background
  741. //
  742. BitsPerPixel = LCD_GetBitsPerPixel();
  743. if ((BitsPerPixel >= 16) && GUIDEMO_GetConfFlag(GUIDEMO_CF_USE_AUTO_BK)) {
  744. NumFreeBytes = GUI_ALLOC_GetNumFreeBytes();
  745. if (NumFreeBytes > NUMBYTES_NEEDED) {
  746. _pfDrawBk = _DrawBkCircle;
  747. } else {
  748. _pfDrawBk = _DrawBk;
  749. }
  750. } else
  751. #endif
  752. {
  753. _pfDrawBk = _DrawBkSimple;
  754. }
  755. GUIDEMO_SetDrawLogo(1);
  756. while (1) {
  757. _Main();
  758. }
  759. }
  760. /*************************** End of file ****************************/