Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WIDGET_SchemeSmall.c
00001 /********************************************************************* 00002 * SEGGER Microcontroller GmbH * 00003 * Solutions for real time microcontroller applications * 00004 ********************************************************************** 00005 * * 00006 * (c) 1996 - 2018 SEGGER Microcontroller GmbH * 00007 * * 00008 * Internet: www.segger.com Support: support@segger.com * 00009 * * 00010 ********************************************************************** 00011 00012 ** emWin V5.48 - Graphical user interface for embedded applications ** 00013 All Intellectual Property rights in the Software belongs to SEGGER. 00014 emWin is protected by international copyright laws. Knowledge of the 00015 source code may not be used to write a similar product. This file may 00016 only be used in accordance with the following terms: 00017 00018 The software has been licensed to Cypress Semiconductor Corporation, 00019 whose registered office is situated at 198 Champion Ct. San Jose, CA 00020 95134 USA solely for the purposes of creating libraries for Cypress 00021 PSoC3 and PSoC5 processor-based devices, sublicensed and distributed 00022 under the terms and conditions of the Cypress End User License 00023 Agreement. 00024 Full source code is available at: www.segger.com 00025 00026 We appreciate your understanding and fairness. 00027 ---------------------------------------------------------------------- 00028 Licensing information 00029 Licensor: SEGGER Microcontroller Systems LLC 00030 Licensed to: Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA 00031 Licensed SEGGER software: emWin 00032 License number: GUI-00319 00033 License model: Services and License Agreement, signed June 10th, 2009 00034 Licensed platform: Any Cypress platform (Initial targets are: PSoC3, PSoC5) 00035 ---------------------------------------------------------------------- 00036 Support and Update Agreement (SUA) 00037 SUA period: 2009-06-12 - 2022-07-27 00038 Contact to extend SUA: sales@segger.com 00039 ---------------------------------------------------------------------- 00040 File : WIDGET_SchemeSmall.c 00041 Purpose : Example demonstrating the use of widget effects 00042 Requirements: WindowManager - (x) 00043 MemoryDevices - (x) 00044 AntiAliasing - ( ) 00045 VNC-Server - ( ) 00046 PNG-Library - ( ) 00047 TrueTypeFonts - ( ) 00048 ---------------------------------------------------------------------- 00049 */ 00050 00051 #include <stdlib.h> 00052 #include <string.h> 00053 #include <stdio.h> 00054 00055 #include "GUI.h" 00056 #include "DIALOG.h" 00057 00058 #if !defined(WIDGET_USE_SCHEME_SMALL) 00059 #error Wrong scheme selected! 00060 #endif 00061 00062 /********************************************************************* 00063 * 00064 * Defines 00065 * 00066 ********************************************************************** 00067 */ 00068 #define NUM_WIDGETS GUI_COUNTOF(_aID) 00069 #define ID_MENU (GUI_ID_USER + 0) 00070 #define ID_MENU_FILE_NEW (GUI_ID_USER + 1) 00071 #define ID_MENU_FILE_OPEN (GUI_ID_USER + 2) 00072 #define ID_MENU_FILE_CLOSE (GUI_ID_USER + 3) 00073 #define ID_MENU_FILE_EXIT (GUI_ID_USER + 4) 00074 #define ID_MENU_FILE_RECENT (GUI_ID_USER + 5) 00075 #define ID_MENU_RECENT_0 (GUI_ID_USER + 6) 00076 #define ID_MENU_RECENT_1 (GUI_ID_USER + 7) 00077 #define ID_MENU_RECENT_2 (GUI_ID_USER + 8) 00078 #define ID_MENU_RECENT_3 (GUI_ID_USER + 9) 00079 #define ID_MENU_EDIT_UNDO (GUI_ID_USER + 10) 00080 #define ID_MENU_EDIT_REDO (GUI_ID_USER + 11) 00081 #define ID_MENU_EDIT_COPY (GUI_ID_USER + 12) 00082 #define ID_MENU_EDIT_PASTE (GUI_ID_USER + 13) 00083 #define ID_MENU_EDIT_DELETE (GUI_ID_USER + 14) 00084 #define ID_MENU_HELP_ABOUT (GUI_ID_USER + 15) 00085 00086 // 00087 // Recommended memory to run the sample with adequate performance 00088 // 00089 #define RECOMMENDED_MEMORY (1024L * 60) 00090 00091 /********************************************************************* 00092 * 00093 * Static data 00094 * 00095 ********************************************************************** 00096 */ 00097 // 00098 // Makes it easier to access the array _ahWin 00099 // 00100 enum { 00101 BUTTON0, EDIT0, LISTBOX0, PROGBAR0, 00102 LISTVIEW0, MULTIEDIT0, DROPDOWN0, SCROLLBAR0, 00103 SCROLLBAR1, SCROLLBAR2, SLIDER0, SLIDER1, 00104 SLIDER2, GRAPH0, MULTIPAGE0 00105 }; 00106 00107 // 00108 // Dialog resource of main dialog box 00109 // 00110 static const GUI_WIDGET_CREATE_INFO _aDlgWidgets[] = { 00111 { WINDOW_CreateIndirect, "", 0, 0, 0, 690, 435, 0}, 00112 { TEXT_CreateIndirect, "Progress bar", GUI_ID_TEXT0, 10, 35, 120, 25, TEXT_CF_HCENTER}, 00113 { PROGBAR_CreateIndirect, NULL, GUI_ID_PROGBAR0, 10, 60, 120, 25 }, 00114 { TEXT_CreateIndirect, "Button", GUI_ID_TEXT0, 10, 90, 120, 25, TEXT_CF_HCENTER}, 00115 { BUTTON_CreateIndirect, "Button", GUI_ID_BUTTON0, 10, 115, 120, 25 }, 00116 { TEXT_CreateIndirect, "Dropdown", GUI_ID_TEXT0, 10, 145, 120, 25, TEXT_CF_HCENTER}, 00117 { DROPDOWN_CreateIndirect, NULL, GUI_ID_DROPDOWN0, 10, 170, 120, 85, DROPDOWN_CF_AUTOSCROLLBAR}, 00118 { TEXT_CreateIndirect, "Edit", GUI_ID_TEXT0, 150, 35, 120, 25, TEXT_CF_HCENTER}, 00119 { EDIT_CreateIndirect, NULL, GUI_ID_EDIT0, 150, 60, 120, 25 }, 00120 { TEXT_CreateIndirect, "Listbox", GUI_ID_TEXT0, 150, 90, 120, 25, TEXT_CF_HCENTER}, 00121 { LISTBOX_CreateIndirect, "", GUI_ID_LISTBOX0, 150, 115, 120, 165, 0, 0 }, 00122 { TEXT_CreateIndirect, "Listview", GUI_ID_TEXT0, 290, 35, 150, 25, TEXT_CF_HCENTER}, 00123 { LISTVIEW_CreateIndirect, NULL, GUI_ID_LISTVIEW0, 290, 60, 150, 135, 0 }, 00124 { TEXT_CreateIndirect, "Multiedit", GUI_ID_TEXT0, 290, 200, 150, 25, TEXT_CF_HCENTER}, 00125 { MULTIEDIT_CreateIndirect, "", GUI_ID_MULTIEDIT0, 290, 225, 150, 60, 0, 0 }, 00126 { TEXT_CreateIndirect, "Scrollbars", GUI_ID_TEXT0, 460, 35, 100, 25, TEXT_CF_HCENTER}, 00127 { SCROLLBAR_CreateIndirect, NULL, GUI_ID_SCROLLBAR1, 460, 60, 20, 200, SCROLLBAR_CF_VERTICAL }, 00128 { SCROLLBAR_CreateIndirect, NULL, GUI_ID_SCROLLBAR2, 490, 60, 70, 200, SCROLLBAR_CF_VERTICAL }, 00129 { SCROLLBAR_CreateIndirect, NULL, GUI_ID_SCROLLBAR0, 460, 270, 100, 15, 0 }, 00130 { TEXT_CreateIndirect, "Sliders", GUI_ID_TEXT0, 580, 35, 100, 25, TEXT_CF_HCENTER}, 00131 { SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER1, 580, 60, 20, 200, SLIDER_CF_VERTICAL }, 00132 { SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER2, 610, 60, 70, 200, SLIDER_CF_VERTICAL }, 00133 { SLIDER_CreateIndirect, NULL, GUI_ID_SLIDER0, 580, 270, 100, 15, 0 }, 00134 { TEXT_CreateIndirect, "Graph", GUI_ID_TEXT0, 210, 300, 175, 25, TEXT_CF_HCENTER}, 00135 { GRAPH_CreateIndirect, 0, GUI_ID_GRAPH0, 210, 325, 175, 100 }, 00136 { TEXT_CreateIndirect, "Multipage", GUI_ID_TEXT0, 400, 300, 220, 25, TEXT_CF_HCENTER}, 00137 { MULTIPAGE_CreateIndirect, "Multipage", GUI_ID_MULTIPAGE0, 400, 325, 220, 100 }, 00138 }; 00139 00140 // 00141 // Dialog resource of options dialog box 00142 // 00143 static const GUI_WIDGET_CREATE_INFO _aDlgOptions[] = { 00144 { FRAMEWIN_CreateIndirect, "Effect", 0, 10, 325, 185, 120, 0, 0 }, 00145 { CHECKBOX_CreateIndirect, NULL, GUI_ID_CHECK0, 0, 2, 90, 0, 0, 0 }, 00146 { RADIO_CreateIndirect, NULL, GUI_ID_RADIO0, 80, 2, 95, 100, 0, 0x1e03 }, 00147 }; 00148 00149 // 00150 // Dialog resource of first multipage window 00151 // 00152 static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] = { 00153 { WINDOW_CreateIndirect, "Dialog 1", 0, 0, 0, 260, 100, 0 }, 00154 { TEXT_CreateIndirect, "Dialog 1", 0, 5, 5, 80, 25, TEXT_CF_LEFT }, 00155 { BUTTON_CreateIndirect, "Button", GUI_ID_BUTTON0, 5, 30, 80, 25, 0 }, 00156 }; 00157 00158 // 00159 // Dialog resource of second multipage window 00160 // 00161 static const GUI_WIDGET_CREATE_INFO _aDialogCreate2[] = { 00162 { WINDOW_CreateIndirect, "Dialog 2", 0, 0, 0, 260, 100, 0 }, 00163 { TEXT_CreateIndirect, "Dialog 2", 0, 5, 5, 80, 25, TEXT_CF_LEFT }, 00164 { SLIDER_CreateIndirect, "", GUI_ID_SLIDER0, 5, 30, 200, 40, 0 }, 00165 }; 00166 00167 // 00168 // Array of widget ID's 00169 // 00170 static int _aID[] = { 00171 GUI_ID_BUTTON0, GUI_ID_EDIT0, GUI_ID_LISTBOX0, GUI_ID_PROGBAR0, 00172 GUI_ID_LISTVIEW0, GUI_ID_MULTIEDIT0, GUI_ID_DROPDOWN0, GUI_ID_SCROLLBAR0, 00173 GUI_ID_SCROLLBAR1, GUI_ID_SCROLLBAR2, GUI_ID_SLIDER0, GUI_ID_SLIDER1, 00174 GUI_ID_SLIDER2, GUI_ID_GRAPH0, GUI_ID_MULTIPAGE0 00175 }; 00176 00177 // 00178 // Array of widget handles 00179 // 00180 static WM_HWIN _ahWin[GUI_COUNTOF(_aID)]; 00181 00182 // 00183 // Array of available effects 00184 // 00185 static const WIDGET_EFFECT * _apEffect[] = { 00186 &WIDGET_Effect_3D, 00187 &WIDGET_Effect_Simple, 00188 &WIDGET_Effect_None 00189 }; 00190 00191 // 00192 // Array of strings used to label the frame window 00193 // 00194 static const char * _apEffects[] = { 00195 "Widget effect: 3D", 00196 "Widget effect: Simple", 00197 "Widget effect: None" 00198 }; 00199 00200 // 00201 // Used for graph widget 00202 // 00203 static I16 _aValue[3]; // Array of values to be added 00204 static GRAPH_DATA_Handle _ahData[3]; // Array of handles for the GRAPH_DATA objects 00205 static GUI_COLOR _aColor[] = { GUI_RED, GUI_GREEN, GUI_LIGHTBLUE }; // Array of colors for the GRAPH_DATA objects 00206 static WM_HWIN _hDlg; 00207 static WM_HWIN _hFrameWin; 00208 static int _AutoMode = 1; 00209 00210 /********************************************************************* 00211 * 00212 * Static code 00213 * 00214 ********************************************************************** 00215 */ 00216 /********************************************************************* 00217 * 00218 * _AddValues 00219 * 00220 * Function description 00221 * This routine calculates new random values in dependence of the 00222 * previous added values and adds them to the GRAPH_DATA objects. 00223 */ 00224 static void _AddValues(int MaxValue) { 00225 int Add; 00226 int Vz; 00227 int i; 00228 00229 for (i = 0; i < (int)GUI_COUNTOF(_aValue); i++) { 00230 Add = rand() % (2 + i * i); 00231 Vz = ((rand() % 2) * 2) - 1; 00232 _aValue[i] += Add * Vz; 00233 if (_aValue[i] > MaxValue) { 00234 _aValue[i] = MaxValue; 00235 } else if (_aValue[i] < 0) { 00236 _aValue[i] = 0; 00237 } 00238 GRAPH_DATA_YT_AddValue(_ahData[i], _aValue[i]); 00239 } 00240 } 00241 00242 /********************************************************************* 00243 * 00244 * _SetWidgetEffect 00245 * 00246 * Function description 00247 * Sets the effect for the given widget and recursive for its child windows. 00248 */ 00249 static void _SetWidgetEffect(WM_HWIN hWin, const WIDGET_EFFECT * pEffect) { 00250 WM_HWIN hChild; 00251 00252 if (hWin) { 00253 WIDGET_SetEffect(hWin, pEffect); 00254 // 00255 // Iterate over the child windows 00256 // 00257 hChild = WM_GetFirstChild(hWin); 00258 while (hChild) { 00259 _SetWidgetEffect(hChild, pEffect); 00260 hChild = WM_GetNextSibling(hChild); 00261 } 00262 } 00263 } 00264 00265 /********************************************************************* 00266 * 00267 * _SetEffect 00268 */ 00269 static void _SetEffect(int Index) { 00270 const WIDGET_EFFECT * pEffect; 00271 unsigned i; 00272 00273 pEffect = _apEffect[Index]; 00274 WIDGET_SetDefaultEffect(pEffect); 00275 FRAMEWIN_SetText(_hFrameWin, _apEffects[Index]); 00276 // 00277 // Iterate over all dialog widgets 00278 // 00279 for (i = 0; i < NUM_WIDGETS; i++) { 00280 _SetWidgetEffect(_ahWin[i], _apEffect[Index]); 00281 } 00282 } 00283 00284 /********************************************************************* 00285 * 00286 * _AddMenuItem 00287 */ 00288 static void _AddMenuItem(MENU_Handle hMenu, MENU_Handle hSubmenu, const char* pText, U16 Id, U16 Flags) { 00289 MENU_ITEM_DATA Item; 00290 00291 Item.pText = pText; 00292 Item.hSubmenu = hSubmenu; 00293 Item.Flags = Flags; 00294 Item.Id = Id; 00295 MENU_AddItem(hMenu, &Item); 00296 } 00297 00298 /********************************************************************* 00299 * 00300 * _CreateMenu 00301 */ 00302 static WM_HWIN _CreateMenu(WM_HWIN hParent) { 00303 MENU_Handle hMenu; 00304 MENU_Handle hMenuFile; 00305 MENU_Handle hMenuEdit; 00306 MENU_Handle hMenuHelp; 00307 MENU_Handle hMenuRecent; 00308 00309 // 00310 // Create main menu 00311 // 00312 hMenu = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_HORIZONTAL, ID_MENU); 00313 // 00314 // Create sub menus 00315 // 00316 hMenuFile = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00317 hMenuEdit = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00318 hMenuHelp = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00319 hMenuRecent = MENU_CreateEx(0, 0, 0, 0, WM_UNATTACHED, 0, MENU_CF_VERTICAL, 0); 00320 // 00321 // Add menu items to menu 'Recent' 00322 // 00323 _AddMenuItem(hMenuRecent, 0, "File 0", ID_MENU_RECENT_0, 0); 00324 _AddMenuItem(hMenuRecent, 0, "File 1", ID_MENU_RECENT_1, 0); 00325 _AddMenuItem(hMenuRecent, 0, "File 2", ID_MENU_RECENT_2, 0); 00326 _AddMenuItem(hMenuRecent, 0, "File 3", ID_MENU_RECENT_3, 0); 00327 // 00328 // Add menu items to menu 'File' 00329 // 00330 _AddMenuItem(hMenuFile, 0, "New", ID_MENU_FILE_NEW, 0); 00331 _AddMenuItem(hMenuFile, 0, "Open", ID_MENU_FILE_OPEN, 0); 00332 _AddMenuItem(hMenuFile, 0, "Close", ID_MENU_FILE_CLOSE, 0); 00333 _AddMenuItem(hMenuFile, 0, 0, 0, MENU_IF_SEPARATOR); 00334 _AddMenuItem(hMenuFile, hMenuRecent, "Files...", ID_MENU_FILE_RECENT, 0); 00335 _AddMenuItem(hMenuFile, 0, 0, 0, MENU_IF_SEPARATOR); 00336 _AddMenuItem(hMenuFile, 0, "Exit", ID_MENU_FILE_EXIT, 0); 00337 // 00338 // Add menu items to menu 'Edit' 00339 // 00340 _AddMenuItem(hMenuEdit, 0, "Undo", ID_MENU_EDIT_UNDO, 0); 00341 _AddMenuItem(hMenuEdit, 0, "Redo", ID_MENU_EDIT_REDO, 0); 00342 _AddMenuItem(hMenuEdit, 0, 0, 0, MENU_IF_SEPARATOR); 00343 _AddMenuItem(hMenuEdit, 0, "Copy", ID_MENU_EDIT_COPY, 0); 00344 _AddMenuItem(hMenuEdit, 0, "Paste", ID_MENU_EDIT_PASTE, 0); 00345 _AddMenuItem(hMenuEdit, 0, "Delete", ID_MENU_EDIT_DELETE, 0); 00346 // 00347 // Add menu items to menu 'Help' 00348 // 00349 _AddMenuItem(hMenuHelp, 0, "About", ID_MENU_HELP_ABOUT, 0); 00350 // 00351 // Add menu items to main menu 00352 // 00353 _AddMenuItem(hMenu, hMenuFile, "File", 0, 0); 00354 _AddMenuItem(hMenu, hMenuEdit, "Edit", 0, 0); 00355 _AddMenuItem(hMenu, hMenuHelp, "Help", 0, 0); 00356 // 00357 // Attach menu to parent window 00358 // 00359 MENU_Attach(hMenu, hParent, 0, 0, WM_GetWindowSizeX(hParent), 0, 0); 00360 return hMenu; 00361 } 00362 00363 /********************************************************************* 00364 * 00365 * _cbBkWindow 00366 */ 00367 static void _cbBkWindow(WM_MESSAGE * pMsg) { 00368 switch (pMsg->MsgId) { 00369 case WM_PAINT: 00370 GUI_SetBkColor(GUI_BLUE); 00371 GUI_Clear(); 00372 GUI_SetColor(GUI_WHITE); 00373 GUI_SetFont(&GUI_Font24_ASCII); 00374 GUI_DispStringHCenterAt("WIDGET_Effect - Sample", 160, 5); 00375 break; 00376 default: 00377 WM_DefaultProc(pMsg); 00378 } 00379 } 00380 00381 /********************************************************************* 00382 * 00383 * _cbDialogPage 00384 * 00385 * Function description 00386 * Dialog routine for multi page windows 00387 */ 00388 static void _cbDialogPage(WM_MESSAGE * pMsg) { 00389 WM_DefaultProc(pMsg); 00390 } 00391 00392 /********************************************************************* 00393 * 00394 * _cbCallbackWidgets 00395 * 00396 * Function description 00397 * Initializes the widgets of the main dialog box 00398 */ 00399 static void _cbCallbackWidgets(WM_MESSAGE * pMsg) { 00400 GRAPH_SCALE_Handle hScaleH; 00401 GRAPH_SCALE_Handle hScaleV; 00402 unsigned i; 00403 WM_HWIN hDlg; 00404 WM_HWIN hMultipageDialog; 00405 char acBuffer[10]; 00406 int Len; 00407 int j; 00408 00409 hDlg = pMsg->hWin; 00410 switch (pMsg->MsgId) { 00411 case WM_INIT_DIALOG: 00412 // 00413 // Get handles of widgets 00414 // 00415 for (i = 0; i < NUM_WIDGETS; i++) { 00416 _ahWin[i] = WM_GetDialogItem(hDlg, _aID[i]); 00417 } 00418 // 00419 // Init dropdown widget 00420 // 00421 for (i = 0; i < 8; i++) { 00422 sprintf(acBuffer, "Item x"); 00423 Len = strlen(acBuffer); 00424 acBuffer[Len - 1] = '1' + i; 00425 DROPDOWN_AddString(_ahWin[DROPDOWN0], acBuffer); 00426 } 00427 // 00428 // Init edit widget 00429 // 00430 EDIT_SetText(_ahWin[EDIT0], "Edit"); 00431 // 00432 // Init listbox widget 00433 // 00434 LISTBOX_SetAutoScrollV(_ahWin[LISTBOX0], 1); 00435 for (i = 0; i < 4; i++) { 00436 sprintf(acBuffer, "Item x"); 00437 Len = strlen(acBuffer); 00438 acBuffer[Len - 1] = '1' + i; 00439 LISTBOX_AddString(_ahWin[LISTBOX0], acBuffer); 00440 } 00441 // 00442 // Init listview widget 00443 // 00444 for (i = 0; i < 2; i++) { 00445 sprintf(acBuffer, "Col. x"); 00446 Len = strlen(acBuffer); 00447 acBuffer[Len - 1] = '1' + i; 00448 LISTVIEW_AddColumn(_ahWin[LISTVIEW0], 60, acBuffer, GUI_TA_CENTER); 00449 } 00450 for (i = 0; i < 9; i++) { 00451 LISTVIEW_AddRow(_ahWin[LISTVIEW0], NULL); 00452 for (j = 0; j < (int)LISTVIEW_GetNumColumns(_ahWin[LISTVIEW0]); j++) { 00453 sprintf(acBuffer, "Rx/Cx"); 00454 acBuffer[1] = '1' + i; 00455 acBuffer[4] = '1' + j; 00456 LISTVIEW_SetItemText(_ahWin[LISTVIEW0], j, i, acBuffer); 00457 } 00458 } 00459 LISTVIEW_SetGridVis(_ahWin[LISTVIEW0], 1); 00460 SCROLLBAR_CreateAttached(_ahWin[LISTVIEW0], SCROLLBAR_CF_VERTICAL); 00461 // 00462 // Init multiedit widget 00463 // 00464 MULTIEDIT_SetText(_ahWin[MULTIEDIT0], "This text could be modified by the MULTIEDIT widget"); 00465 MULTIEDIT_SetWrapWord(_ahWin[MULTIEDIT0]); 00466 MULTIEDIT_SetAutoScrollV(_ahWin[MULTIEDIT0], 1); 00467 // 00468 // Init progbar widget 00469 // 00470 WIDGET_SetEffect(_ahWin[PROGBAR0], &WIDGET_Effect_3D); 00471 // 00472 // Init graph widget 00473 // 00474 for (i = 0; i < GUI_COUNTOF(_aColor); i++) { 00475 _aValue[i] = rand() % 95; 00476 _ahData[i] = GRAPH_DATA_YT_Create(_aColor[i], 500, 0, 0); 00477 GRAPH_AttachData(_ahWin[GRAPH0], _ahData[i]); 00478 } 00479 GRAPH_SetGridDistY(_ahWin[GRAPH0], 25); 00480 GRAPH_SetGridVis(_ahWin[GRAPH0], 1); 00481 GRAPH_SetGridFixedX(_ahWin[GRAPH0], 1); 00482 GRAPH_SetBorder(_ahWin[GRAPH0], 20, 4, 5, 4); 00483 // 00484 // Create and add vertical scale of graph widget 00485 // 00486 hScaleV = GRAPH_SCALE_Create(18, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25); 00487 GRAPH_SCALE_SetTextColor(hScaleV, GUI_RED); 00488 GRAPH_AttachScale(_ahWin[GRAPH0], hScaleV); 00489 // 00490 // Create and add horizontal scale of graph widget 00491 // 00492 hScaleH = GRAPH_SCALE_Create(46, GUI_TA_HCENTER | GUI_TA_VCENTER, GRAPH_SCALE_CF_HORIZONTAL, 50); 00493 GRAPH_SCALE_SetTextColor(hScaleH, GUI_DARKGREEN); 00494 GRAPH_AttachScale(_ahWin[GRAPH0], hScaleH); 00495 // 00496 // Init multipage widget 00497 // 00498 hMultipageDialog = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), _cbDialogPage, WM_UNATTACHED, 0, 0); 00499 MULTIPAGE_AddPage(_ahWin[MULTIPAGE0], hMultipageDialog, "Page 1"); 00500 hMultipageDialog = GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), _cbDialogPage, WM_UNATTACHED, 0, 0); 00501 MULTIPAGE_AddPage(_ahWin[MULTIPAGE0], hMultipageDialog, "Page 2"); 00502 // 00503 // Create and attach menu 00504 // 00505 _CreateMenu(hDlg); 00506 break; 00507 default: 00508 WM_DefaultProc(pMsg); 00509 } 00510 } 00511 00512 /********************************************************************* 00513 * 00514 * _cbCallbackFramewin 00515 * 00516 * Function description 00517 * Handles the scroll messages of the scrollbar 00518 */ 00519 static void _cbCallbackFramewin(WM_MESSAGE * pMsg) { 00520 WM_SCROLL_STATE ScrollState; 00521 WM_HWIN hDlg; 00522 int xPos; 00523 int yPos; 00524 00525 hDlg = pMsg->hWin; 00526 switch (pMsg->MsgId) { 00527 case WM_NOTIFY_PARENT: 00528 if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) { 00529 if (pMsg->hWinSrc == WM_GetScrollbarH(hDlg)) { 00530 WM_GetScrollState(pMsg->hWinSrc, &ScrollState); 00531 xPos = WM_GetWindowOrgX(WM_GetParent(_hDlg)) - ScrollState.v; 00532 yPos = WM_GetWindowOrgY(_hDlg); 00533 WM_MoveTo(_hDlg, xPos, yPos); 00534 } 00535 } 00536 break; 00537 default: 00538 WM_DefaultProc(pMsg); 00539 } 00540 } 00541 00542 /********************************************************************* 00543 * 00544 * _cbCallbackOptions 00545 * 00546 * Function description 00547 * Callback of the options dialog box, sets the widget effects 00548 */ 00549 static void _cbCallbackOptions(WM_MESSAGE * pMsg) { 00550 WM_HWIN hDlg; 00551 WM_HWIN hItem; 00552 00553 hDlg = pMsg->hWin; 00554 switch (pMsg->MsgId) { 00555 case WM_INIT_DIALOG: 00556 // 00557 // Init check box 00558 // 00559 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0); 00560 CHECKBOX_Check(hItem); 00561 CHECKBOX_SetText(hItem, "Auto"); 00562 // 00563 // Init radio button 00564 // 00565 hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0); 00566 RADIO_SetText(hItem, "3D", 0); 00567 RADIO_SetText(hItem, "Simple", 1); 00568 RADIO_SetText(hItem, "None", 2); 00569 break; 00570 case WM_NOTIFY_PARENT: 00571 if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) { 00572 hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0); 00573 if (pMsg->hWinSrc == hItem) { 00574 _SetEffect(RADIO_GetValue(hItem)); 00575 } 00576 } else if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) { 00577 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0); 00578 if (pMsg->hWinSrc == hItem) { 00579 _AutoMode = CHECKBOX_IsChecked(hItem); 00580 } 00581 } 00582 break; 00583 default: 00584 WM_DefaultProc(pMsg); 00585 } 00586 } 00587 00588 /********************************************************************* 00589 * 00590 * Public code 00591 * 00592 ********************************************************************** 00593 */ 00594 /********************************************************************* 00595 * 00596 * MainTask 00597 */ 00598 void MainTask(void) { 00599 WM_SCROLL_STATE ScrollState; 00600 GUI_RECT RectDlg; 00601 GUI_RECT RectClient; 00602 unsigned IndexEffect; 00603 WM_HWIN hDlgOptions; 00604 WM_HWIN hScrollbar; 00605 WM_HWIN hScroll; 00606 WM_HWIN hWin; 00607 char acBuffer[100]; 00608 int Cnt; 00609 int ButtonState; 00610 int DropdownState; 00611 int ProgbarValue; 00612 int ProgbarInc; 00613 int SliderValue; 00614 int SliderInc; 00615 int ScrollbarValue; 00616 int ScrollbarInc; 00617 int ListViewInc; 00618 int ListBoxInc; 00619 int MultiEditInc; 00620 int Index; 00621 int Inc; 00622 int Len; 00623 int Sel; 00624 int Vz; 00625 int j; 00626 00627 Cnt = 0; 00628 IndexEffect = 0; 00629 ButtonState = 0; 00630 DropdownState = 0; 00631 ProgbarValue = 0; 00632 ProgbarInc = 1; 00633 SliderValue = 0; 00634 SliderInc = 1; 00635 ScrollbarValue = 0; 00636 ScrollbarInc = 1; 00637 ListViewInc = 1; 00638 ListBoxInc = 1; 00639 MultiEditInc = 1; 00640 Vz = 1; 00641 GUI_Init(); 00642 // 00643 // Check if recommended memory for the sample is available 00644 // 00645 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 00646 GUI_ErrorOut("Not enough memory available."); 00647 return; 00648 } 00649 GUI_CURSOR_Show(); 00650 WM_SetCallback(WM_HBKWIN, _cbBkWindow); 00651 WM_SetCreateFlags(WM_CF_MEMDEV); // Use memory devices on all windows to avoid flicker 00652 WM_EnableMemdev(WM_HBKWIN); // Enable use of memory devices for desktop windows 00653 // 00654 // Create framewindow and set its properties 00655 // 00656 _hFrameWin = FRAMEWIN_CreateEx(0, 0, 640, 480, 0, WM_CF_SHOW, 0, 0, "", _cbCallbackFramewin); 00657 FRAMEWIN_SetMoveable(_hFrameWin, 1); 00658 FRAMEWIN_SetText(_hFrameWin, _apEffects[0]); 00659 FRAMEWIN_SetFont(_hFrameWin, &GUI_Font13B_ASCII); 00660 // 00661 // Create main dialog window as child from framewindows client window 00662 // 00663 _hDlg = GUI_CreateDialogBox(_aDlgWidgets, GUI_COUNTOF(_aDlgWidgets), _cbCallbackWidgets, WM_GetClientWindow(_hFrameWin), 0, 0); 00664 // 00665 // Attach scrollbar to framewindows client window and set its properties 00666 // 00667 hScrollbar = SCROLLBAR_CreateAttached(WM_GetClientWindow(_hFrameWin), 0); 00668 WM_GetWindowRectEx(_hDlg, &RectDlg); 00669 WM_GetClientRectEx(WM_GetClientWindow(_hFrameWin), &RectClient); 00670 SCROLLBAR_SetNumItems(hScrollbar, RectDlg.x1); 00671 SCROLLBAR_SetPageSize(hScrollbar, RectClient.x1); 00672 // 00673 // Create options dialog with 'stay on top' and 'moveable' attribute 00674 // 00675 hDlgOptions = GUI_CreateDialogBox(_aDlgOptions, GUI_COUNTOF(_aDlgOptions), _cbCallbackOptions, WM_HBKWIN, 0, 0); 00676 FRAMEWIN_SetMoveable(hDlgOptions, 1); 00677 WM_SetStayOnTop(hDlgOptions, 1); 00678 // 00679 // Main loop for modifying the widgets 00680 // 00681 while (1) { 00682 if (_AutoMode) { 00683 Cnt++; 00684 // 00685 // Modify progbar 00686 // 00687 if ((Cnt % 2) == 0) { 00688 ProgbarValue += ProgbarInc; 00689 if ((ProgbarValue == 110) || (ProgbarValue == -10)) { 00690 ProgbarInc *= -1; 00691 } 00692 PROGBAR_SetValue(_ahWin[PROGBAR0], ProgbarValue); 00693 } 00694 // 00695 // Modify slider 00696 // 00697 if ((Cnt % 2) == 0) { 00698 SliderValue += SliderInc; 00699 if ((SliderValue == 100) || (SliderValue == 0)) { 00700 SliderInc *= -1; 00701 } 00702 for (j = 0; j < 3; j++) { 00703 SLIDER_SetValue(_ahWin[SLIDER0 + j], SliderValue); 00704 } 00705 } 00706 // 00707 // Modify scrollbar 00708 // 00709 if ((Cnt % 3) == 0) { 00710 ScrollbarValue += ScrollbarInc; 00711 if ((ScrollbarValue == 90) || (ScrollbarValue == 0)) { 00712 ScrollbarInc *= -1; 00713 } 00714 for (j = 0; j < 3; j++) { 00715 SCROLLBAR_SetValue(_ahWin[SCROLLBAR0 + j], ScrollbarValue); 00716 } 00717 } 00718 // 00719 // Modify multipage 00720 // 00721 if ((Cnt % 120) == 0) { 00722 MULTIPAGE_SelectPage(_ahWin[MULTIPAGE0], MULTIPAGE_GetSelection(_ahWin[MULTIPAGE0]) ^ 1); 00723 } 00724 // 00725 // Modify dropdown 00726 // 00727 if ((Cnt % 120) == 0) { 00728 DropdownState ^= 1; 00729 if (DropdownState) { 00730 DROPDOWN_Expand(_ahWin[DROPDOWN0]); 00731 } else { 00732 DROPDOWN_Collapse(_ahWin[DROPDOWN0]); 00733 } 00734 } 00735 // 00736 // Modify button 00737 // 00738 if ((Cnt % 40) == 0) { 00739 ButtonState ^= 1; 00740 BUTTON_SetPressed(_ahWin[BUTTON0], ButtonState); 00741 } 00742 // 00743 // Modify listbox 00744 // 00745 if ((Cnt % 30) == 0) { 00746 Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]); 00747 if (Sel < 0) { 00748 Sel = 0; 00749 } 00750 LISTBOX_SetSel(_ahWin[LISTBOX0], Sel + ListBoxInc); 00751 Sel = LISTBOX_GetSel(_ahWin[LISTBOX0]); 00752 if ((Sel == (int)LISTBOX_GetNumItems(_ahWin[LISTBOX0]) - 1) || (Sel == 0)) { 00753 ListBoxInc *= -1; 00754 } 00755 } 00756 // 00757 // Modify listview 00758 // 00759 if ((Cnt % 50) == 0) { 00760 Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]); 00761 if (Sel < 0) { 00762 Sel = 0; 00763 } 00764 LISTVIEW_SetSel(_ahWin[LISTVIEW0], Sel + ListViewInc); 00765 Sel = LISTVIEW_GetSel(_ahWin[LISTVIEW0]); 00766 if ((Sel == (int)LISTVIEW_GetNumRows(_ahWin[LISTVIEW0]) - 1) || (Sel == 0)) { 00767 ListViewInc *= -1; 00768 } 00769 } 00770 // 00771 // Modify multiedit 00772 // 00773 if ((Cnt % 5) == 0) { 00774 MULTIEDIT_SetCursorOffset(_ahWin[MULTIEDIT0], MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]) + MultiEditInc); 00775 MULTIEDIT_GetText(_ahWin[MULTIEDIT0], acBuffer, sizeof(acBuffer)); 00776 Sel = MULTIEDIT_GetCursorCharPos(_ahWin[MULTIEDIT0]); 00777 Len = strlen(acBuffer); 00778 if ((Sel == (Len - 1)) || (Sel == 0)) { 00779 MultiEditInc *= -1; 00780 } 00781 if (!DropdownState) { 00782 WM_SetFocus(_ahWin[MULTIEDIT0]); 00783 } 00784 } 00785 // 00786 // Modify graph 00787 // 00788 _AddValues(95); 00789 // 00790 // Move window 00791 // 00792 if ((Cnt % 1200) == 0) { 00793 hScroll = WM_GetScrollbarH(WM_GetClientWindow(_hFrameWin)); 00794 WM_GetScrollState(hScroll, &ScrollState); 00795 Inc = (ScrollState.NumItems - ScrollState.PageSize) / 2; 00796 ScrollState.v += Inc * Vz; 00797 if ((ScrollState.v >= Inc * 2) || (ScrollState.v <= 0)) { 00798 Vz *= -1; 00799 } 00800 SCROLLBAR_SetValue(hScroll, ScrollState.v); 00801 } 00802 // 00803 // Change effect 00804 // 00805 if ((Cnt % 400) == 0) { 00806 IndexEffect++; 00807 Index = IndexEffect % GUI_COUNTOF(_apEffect); 00808 _SetEffect(Index); 00809 hWin = WM_GetDialogItem(hDlgOptions, GUI_ID_RADIO0); 00810 RADIO_SetValue(hWin, Index); 00811 } 00812 } 00813 // 00814 // Wait a while 00815 // 00816 GUI_Delay(10); 00817 } 00818 } 00819 00820 /*************************** End of file ****************************/
Generated on Thu Jul 14 2022 12:58:43 by
