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_GraphYT.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_GraphYT.c 00041 Purpose : Demonstrates the use of the GRAPH widget 00042 Requirements: WindowManager - (x) 00043 MemoryDevices - ( ) 00044 AntiAliasing - ( ) 00045 VNC-Server - ( ) 00046 PNG-Library - ( ) 00047 TrueTypeFonts - ( ) 00048 ---------------------------------------------------------------------- 00049 */ 00050 #include <stdlib.h> 00051 #include <string.h> 00052 00053 #include "DIALOG.h" 00054 #include "GRAPH.h" 00055 00056 /********************************************************************* 00057 * 00058 * Defines 00059 * 00060 ********************************************************************** 00061 */ 00062 #define MAX_VALUE 180 00063 00064 // 00065 // Recommended memory to run the sample with adequate performance 00066 // 00067 #define RECOMMENDED_MEMORY (1024L * 30) 00068 00069 /********************************************************************* 00070 * 00071 * Static data 00072 * 00073 ********************************************************************** 00074 */ 00075 static GRAPH_DATA_Handle _ahData[3]; // Array of handles for the GRAPH_DATA objects 00076 static GRAPH_SCALE_Handle _hScaleV; // Handle of vertical scale 00077 static GRAPH_SCALE_Handle _hScaleH; // Handle of horizontal scale 00078 00079 static I16 _aValue[3]; 00080 static int _Stop = 0; 00081 00082 static GUI_COLOR _aColor[] = {GUI_RED, GUI_GREEN, GUI_LIGHTBLUE}; // Array of colors for the GRAPH_DATA objects 00083 00084 // 00085 // Dialog ressource 00086 // 00087 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { 00088 { FRAMEWIN_CreateIndirect, "Graph widget demo", 0 , 0, 0, 320, 240, FRAMEWIN_CF_MOVEABLE }, 00089 { GRAPH_CreateIndirect, 0, GUI_ID_GRAPH0 , 5, 5, 265, 170 }, 00090 { TEXT_CreateIndirect, "Spacing X:", 0 , 10, 180, 50, 20 }, 00091 { TEXT_CreateIndirect, "Spacing Y:", 0 , 10, 200, 50, 20 }, 00092 { SLIDER_CreateIndirect, 0, GUI_ID_SLIDER0 , 60, 180, 60, 16 }, 00093 { SLIDER_CreateIndirect, 0, GUI_ID_SLIDER1 , 60, 200, 60, 16 }, 00094 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK0 , 130, 180, 50, 0 }, 00095 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK1 , 130, 200, 50, 0 }, 00096 { TEXT_CreateIndirect, "Border", 0 , 275, 5, 35, 15 }, 00097 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK2 , 275, 20, 35, 0 }, 00098 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK3 , 275, 40, 35, 0 }, 00099 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK4 , 275, 60, 35, 0 }, 00100 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK5 , 275, 80, 35, 0 }, 00101 { TEXT_CreateIndirect, "Effect", 0 , 275, 100, 35, 15 }, 00102 { RADIO_CreateIndirect, 0, GUI_ID_RADIO0 , 270, 115, 35, 0, 0, 3 }, 00103 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK6 , 180, 180, 50, 0 }, 00104 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK7 , 180, 200, 50, 0 }, 00105 { BUTTON_CreateIndirect, "Full Screen", GUI_ID_BUTTON0 , 240, 180, 65, 18 }, 00106 { CHECKBOX_CreateIndirect, 0, GUI_ID_CHECK8 , 240, 200, 70, 0 }, 00107 }; 00108 00109 /********************************************************************* 00110 * 00111 * Static code 00112 * 00113 ********************************************************************** 00114 */ 00115 /********************************************************************* 00116 * 00117 * _AddValues 00118 * 00119 * Function description 00120 * This routine calculates new random values in dependence of the previous added values 00121 * and adds them to the GRAPH_DATA objects 00122 */ 00123 static void _AddValues(void) { 00124 unsigned i; 00125 00126 for (i = 0; i < GUI_COUNTOF(_aColor); i++) { 00127 int Add = ((unsigned)rand()) % (2 + i * i); 00128 int Vz = (((unsigned)(rand()) % 2) << 1) - 1; 00129 _aValue[i] += Add * Vz; 00130 if (_aValue[i] > MAX_VALUE) { 00131 _aValue[i] = MAX_VALUE; 00132 } else if (_aValue[i] < 0) { 00133 _aValue[i] = 0; 00134 } 00135 GRAPH_DATA_YT_AddValue(_ahData[i], _aValue[i]); 00136 } 00137 } 00138 00139 /********************************************************************* 00140 * 00141 * _UserDraw 00142 * 00143 * Function description 00144 * This routine is called by the GRAPH object before anything is drawn 00145 * and after the last drawing operation. 00146 */ 00147 static void _UserDraw(WM_HWIN hWin, int Stage) { 00148 if (Stage == GRAPH_DRAW_LAST) { 00149 char acText[] = "Temperature"; 00150 GUI_RECT Rect; 00151 GUI_RECT RectInvalid; 00152 int FontSizeY; 00153 00154 GUI_SetFont(&GUI_Font13_ASCII); 00155 FontSizeY = GUI_GetFontSizeY(); 00156 WM_GetInsideRect(&Rect); 00157 WM_GetInvalidRect(hWin, &RectInvalid); 00158 Rect.x1 = Rect.x0 + FontSizeY; 00159 GUI_SetColor(GUI_YELLOW); 00160 GUI_DispStringInRectEx(acText, &Rect, GUI_TA_HCENTER, strlen(acText), GUI_ROTATE_CCW); 00161 } 00162 } 00163 00164 /********************************************************************* 00165 * 00166 * _ForEach 00167 * 00168 * Function description 00169 * This routine hides/shows all windows except the button, graph and scroll bar widgets 00170 */ 00171 static void _ForEach(WM_HWIN hWin, void * pData) { 00172 int Id; 00173 int FullScreenMode; 00174 00175 FullScreenMode = *(int *)pData; 00176 Id = WM_GetId(hWin); 00177 if ((Id == GUI_ID_GRAPH0) || (Id == GUI_ID_BUTTON0) || (Id == GUI_ID_VSCROLL) || (Id == GUI_ID_HSCROLL)) { 00178 return; 00179 } 00180 if (FullScreenMode) { 00181 WM_HideWindow(hWin); 00182 } else { 00183 WM_ShowWindow(hWin); 00184 } 00185 } 00186 00187 /********************************************************************* 00188 * 00189 * _ToggleFullScreenMode 00190 * 00191 * Function description 00192 * This routine switches between full screen mode and normal mode by hiding or showing the 00193 * widgets of the dialog, enlarging/shrinking the graph widget and modifying some other 00194 * attributes of the dialog widgets. 00195 */ 00196 static void _ToggleFullScreenMode(WM_HWIN hDlg) { 00197 static int FullScreenMode; 00198 static GUI_RECT Rect; 00199 static unsigned ScalePos; 00200 WM_HWIN hGraph; 00201 WM_HWIN hButton; 00202 WM_HWIN hClient; 00203 GUI_RECT RectInside; 00204 int xPos, yPos; 00205 00206 hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00207 hButton = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0); 00208 FullScreenMode ^= 1; 00209 if (FullScreenMode) { 00210 // 00211 // Enter the full screen mode 00212 // 00213 hClient = WM_GetClientWindow(hDlg); 00214 BUTTON_SetText(hButton, "Back"); 00215 WM_MoveWindow(hButton, 0, 11); 00216 FRAMEWIN_SetTitleVis(hDlg, 0); 00217 WM_GetInsideRectEx(hClient, &RectInside); 00218 WM_GetWindowRectEx(hGraph, &Rect); 00219 WM_ForEachDesc(hClient, _ForEach, &FullScreenMode); // Hide all descendants 00220 xPos = WM_GetWindowOrgX(hClient); 00221 yPos = WM_GetWindowOrgY(hClient); 00222 WM_SetWindowPos(hGraph, xPos, yPos, RectInside.x1, RectInside.y1); 00223 ScalePos = GRAPH_SCALE_SetPos(_hScaleH, RectInside.y1 - 20); 00224 } else { 00225 // 00226 // Return to normal mode 00227 // 00228 BUTTON_SetText(hButton, "Full Screen"); 00229 WM_MoveWindow(hButton, 0, -11); 00230 WM_ForEachDesc(WM_GetClientWindow(hDlg), _ForEach, &FullScreenMode); // Show all descendants 00231 WM_SetWindowPos(hGraph, Rect.x0, Rect.y0, Rect.x1 - Rect.x0 + 1, Rect.y1 - Rect.y0 + 1); 00232 FRAMEWIN_SetTitleVis(hDlg, 1); 00233 GRAPH_SCALE_SetPos(_hScaleH, ScalePos); 00234 } 00235 } 00236 00237 /********************************************************************* 00238 * 00239 * _cbCallback 00240 * 00241 * Function description 00242 * Callback function of the dialog 00243 */ 00244 static void _cbCallback(WM_MESSAGE * pMsg) { 00245 unsigned i; 00246 int NCode; 00247 int Id; 00248 int Value; 00249 WM_HWIN hDlg; 00250 WM_HWIN hItem; 00251 00252 hDlg = pMsg->hWin; 00253 switch (pMsg->MsgId) { 00254 case WM_INIT_DIALOG: 00255 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00256 // 00257 // Add graphs 00258 // 00259 for (i = 0; i < GUI_COUNTOF(_aColor); i++) { 00260 _aValue[i] = rand() % 180; 00261 _ahData[i] = GRAPH_DATA_YT_Create(_aColor[i], 500, 0, 0); 00262 GRAPH_AttachData(hItem, _ahData[i]); 00263 } 00264 // 00265 // Set graph attributes 00266 // 00267 GRAPH_SetGridDistY(hItem, 25); 00268 GRAPH_SetGridVis(hItem, 1); 00269 GRAPH_SetGridFixedX(hItem, 1); 00270 GRAPH_SetUserDraw(hItem, _UserDraw); 00271 // 00272 // Create and add vertical scale 00273 // 00274 _hScaleV = GRAPH_SCALE_Create( 35, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25); 00275 GRAPH_SCALE_SetTextColor(_hScaleV, GUI_YELLOW); 00276 GRAPH_AttachScale(hItem, _hScaleV); 00277 // 00278 // Create and add horizontal scale 00279 // 00280 _hScaleH = GRAPH_SCALE_Create(155, GUI_TA_HCENTER, GRAPH_SCALE_CF_HORIZONTAL, 50); 00281 GRAPH_SCALE_SetTextColor(_hScaleH, GUI_DARKGREEN); 00282 GRAPH_AttachScale(hItem, _hScaleH); 00283 // 00284 // Init check boxes 00285 // 00286 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK2); 00287 CHECKBOX_SetText(hItem, "L"); 00288 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK3); 00289 CHECKBOX_SetText(hItem, "T"); 00290 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK4); 00291 CHECKBOX_SetText(hItem, "R"); 00292 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK5); 00293 CHECKBOX_SetText(hItem, "B"); 00294 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK0); 00295 CHECKBOX_SetText(hItem, "Stop"); 00296 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK1); 00297 CHECKBOX_SetText(hItem, "Grid"); 00298 CHECKBOX_SetState(hItem, 1); 00299 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK6); 00300 CHECKBOX_SetText(hItem, "HScroll"); 00301 CHECKBOX_SetState(hItem, 1); 00302 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK7); 00303 CHECKBOX_SetText(hItem, "VScroll"); 00304 hItem = WM_GetDialogItem(hDlg, GUI_ID_CHECK8); 00305 CHECKBOX_SetText(hItem, "MirrorX"); 00306 // 00307 // Init slider widgets 00308 // 00309 hItem = WM_GetDialogItem(hDlg, GUI_ID_SLIDER0); 00310 SLIDER_SetRange(hItem, 0, 10); 00311 SLIDER_SetValue(hItem, 5); 00312 SLIDER_SetNumTicks(hItem, 6); 00313 hItem = WM_GetDialogItem(hDlg, GUI_ID_SLIDER1); 00314 SLIDER_SetRange(hItem, 0, 20); 00315 SLIDER_SetValue(hItem, 5); 00316 SLIDER_SetNumTicks(hItem, 6); 00317 // 00318 // Init radio widget 00319 // 00320 hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0); 00321 RADIO_SetText(hItem, "3D", 0); 00322 RADIO_SetText(hItem, "flat", 1); 00323 RADIO_SetText(hItem, "-", 2); 00324 // 00325 // Init button widget 00326 // 00327 hItem = WM_GetDialogItem(hDlg, GUI_ID_BUTTON0); 00328 WM_SetStayOnTop(hItem, 1); 00329 break; 00330 case WM_NOTIFY_PARENT: 00331 Id = WM_GetId(pMsg->hWinSrc); // Id of widget 00332 NCode = pMsg->Data.v; // Notification code 00333 switch (NCode) { 00334 case WM_NOTIFICATION_CLICKED: 00335 switch (Id) { 00336 case GUI_ID_BUTTON0: 00337 _ToggleFullScreenMode(hDlg); 00338 break; 00339 } 00340 break; 00341 case WM_NOTIFICATION_VALUE_CHANGED: 00342 switch (Id) { 00343 case GUI_ID_CHECK0: 00344 // 00345 // Toggle stop mode 00346 // 00347 _Stop ^= 1; 00348 break; 00349 case GUI_ID_CHECK1: 00350 // 00351 // Toggle grid 00352 // 00353 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00354 GRAPH_SetGridVis(hItem, CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK1))); 00355 break; 00356 case GUI_ID_CHECK2: 00357 case GUI_ID_CHECK3: 00358 case GUI_ID_CHECK4: 00359 case GUI_ID_CHECK5: 00360 // 00361 // Toggle border 00362 // 00363 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00364 GRAPH_SetBorder(hItem, 00365 CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK2)) * 40, 00366 CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK3)) * 5, 00367 CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK4)) * 5, 00368 CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK5)) * 5); 00369 break; 00370 case GUI_ID_SLIDER0: 00371 // 00372 // Set horizontal grid spacing 00373 // 00374 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00375 Value = SLIDER_GetValue(pMsg->hWinSrc) * 10; 00376 GRAPH_SetGridDistX(hItem, Value); 00377 GRAPH_SCALE_SetTickDist(_hScaleH, Value); 00378 break; 00379 case GUI_ID_SLIDER1: 00380 // 00381 // Set vertical grid spacing 00382 // 00383 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00384 Value = SLIDER_GetValue(pMsg->hWinSrc) * 5; 00385 GRAPH_SetGridDistY(hItem, Value); 00386 GRAPH_SCALE_SetTickDist(_hScaleV, Value); 00387 break; 00388 case GUI_ID_RADIO0: 00389 // 00390 // Set the widget effect 00391 // 00392 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00393 switch (RADIO_GetValue(pMsg->hWinSrc)) { 00394 case 0: 00395 WIDGET_SetEffect(hItem, &WIDGET_Effect_3D); 00396 break; 00397 case 1: 00398 WIDGET_SetEffect(hItem, &WIDGET_Effect_Simple); 00399 break; 00400 case 2: 00401 WIDGET_SetEffect(hItem, &WIDGET_Effect_None); 00402 break; 00403 } 00404 break; 00405 case GUI_ID_CHECK6: 00406 // 00407 // Toggle horizontal scroll bar 00408 // 00409 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00410 if (CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK6))) { 00411 GRAPH_SetVSizeX(hItem, 500); 00412 } else { 00413 GRAPH_SetVSizeX(hItem, 0); 00414 } 00415 break; 00416 case GUI_ID_CHECK7: 00417 // 00418 // Toggle vertical scroll bar 00419 // 00420 hItem = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00421 if (CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK7))) { 00422 GRAPH_SetVSizeY(hItem, 300); 00423 } else { 00424 GRAPH_SetVSizeY(hItem, 0); 00425 } 00426 break; 00427 case GUI_ID_CHECK8: 00428 // 00429 // Toggle alignment 00430 // 00431 WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00432 for (i = 0; i < GUI_COUNTOF(_aColor); i++) { 00433 if (CHECKBOX_IsChecked(WM_GetDialogItem(hDlg, GUI_ID_CHECK8))) { 00434 GRAPH_DATA_YT_SetAlign(_ahData[i], GRAPH_ALIGN_LEFT); 00435 GRAPH_DATA_YT_MirrorX (_ahData[i], 1); 00436 } else { 00437 GRAPH_DATA_YT_SetAlign(_ahData[i], GRAPH_ALIGN_RIGHT); 00438 GRAPH_DATA_YT_MirrorX (_ahData[i], 0); 00439 } 00440 } 00441 break; 00442 } 00443 break; 00444 } 00445 break; 00446 default: 00447 WM_DefaultProc(pMsg); 00448 } 00449 } 00450 00451 /********************************************************************* 00452 * 00453 * Public code 00454 * 00455 ********************************************************************** 00456 */ 00457 /********************************************************************* 00458 * 00459 * MainTask 00460 */ 00461 void MainTask(void) { 00462 WM_HWIN hDlg; 00463 WM_HWIN hGraph; 00464 00465 hGraph = 0; 00466 GUI_Init(); 00467 // 00468 // Check if recommended memory for the sample is available 00469 // 00470 if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) { 00471 GUI_ErrorOut("Not enough memory available."); 00472 return; 00473 } 00474 GUI_CURSOR_Show(); 00475 WM_SetDesktopColor(GUI_BLACK); 00476 #if GUI_SUPPORT_MEMDEV 00477 WM_SetCreateFlags(WM_CF_MEMDEV); 00478 #endif 00479 hDlg = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbCallback, 0, 0, 0); 00480 while (1) { 00481 #ifdef WIN32 00482 GUI_Delay(10); 00483 #endif 00484 if (!_Stop) { 00485 if (!hGraph) { 00486 hGraph = WM_GetDialogItem(hDlg, GUI_ID_GRAPH0); 00487 } 00488 _AddValues(); 00489 } 00490 GUI_Exec(); 00491 } 00492 } 00493 00494 /*************************** End of file ****************************/ 00495
Generated on Thu Jul 14 2022 12:58:43 by
