Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WM_Redraw.c Source File

WM_Redraw.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        : WM_Redraw.c
00041 Purpose     : Demonstrates the redrawing mechanism of the window manager
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 
00049 ----------------------------------------------------------------------
00050 */
00051 
00052 #include "GUI.h"
00053 #include "WM.h"
00054 
00055 /*********************************************************************
00056 *
00057 *       Defines
00058 *
00059 **********************************************************************
00060 */
00061 //
00062 // Recommended memory to run the sample with adequate performance
00063 //
00064 #define RECOMMENDED_MEMORY (1024L * 5)
00065 
00066 /*******************************************************************
00067 *
00068 *       static code
00069 *
00070 ********************************************************************
00071 */
00072 /*******************************************************************
00073 *
00074 *       _cbBkWindow
00075 */
00076 static void _cbBkWindow(WM_MESSAGE* pMsg) {
00077   switch (pMsg->MsgId) {
00078   case WM_PAINT:
00079     GUI_ClearRect(0, 50, 319, 239);
00080   default:
00081     WM_DefaultProc(pMsg);
00082   }
00083 }
00084 
00085 /*******************************************************************
00086 *
00087 *       _cbWindow
00088 */
00089 static void _cbWindow(WM_MESSAGE* pMsg) {
00090   GUI_RECT Rect;
00091 
00092   switch (pMsg->MsgId) {
00093   case WM_PAINT:
00094     WM_GetInsideRect(&Rect);
00095     GUI_SetBkColor(GUI_RED);
00096     GUI_SetColor(GUI_YELLOW);
00097     GUI_ClearRectEx(&Rect);
00098     GUI_DrawRectEx(&Rect);
00099     GUI_SetColor(GUI_BLACK);
00100     GUI_SetFont(&GUI_Font8x16);
00101     GUI_DispStringHCenterAt("Foreground window", 75, 40);
00102     break;
00103   default:
00104     WM_DefaultProc(pMsg);
00105   }
00106 }
00107 
00108 /*******************************************************************
00109 *
00110 *       _MoveWindow
00111 */
00112 static void _MoveWindow(const char* pText) {
00113   WM_HWIN hWnd;
00114   int     i;
00115 
00116   //
00117   // Create foreground window
00118   //
00119   hWnd = WM_CreateWindow(10, 50, 150, 100, WM_CF_SHOW, _cbWindow, 0);
00120   GUI_Delay(500);
00121   //
00122   // Move foreground window
00123   //
00124   for (i = 0; i < 40; i++) {
00125     WM_MoveWindow(hWnd, 2, 2);
00126     GUI_Delay(10);
00127   }
00128   //
00129   // Show text before deleting window if we have one
00130   //
00131   if (pText) {
00132     GUI_DispStringAt(pText, 5, 50);
00133     GUI_Delay(2500);
00134   }
00135   //
00136   // Delete foreground window
00137   //
00138   WM_DeleteWindow(hWnd);
00139   WM_Invalidate(WM_HBKWIN);
00140   GUI_Exec();
00141 }
00142 
00143 /*******************************************************************
00144 *
00145 *       _DemoRedraw
00146 */
00147 static void _DemoRedraw(void) {
00148   WM_CALLBACK * _cbOldBk;
00149 
00150   GUI_SetBkColor(GUI_BLACK);
00151   GUI_Clear();
00152   GUI_SetColor(GUI_WHITE);
00153   GUI_SetFont(&GUI_Font24_ASCII);
00154   GUI_DispStringHCenterAt("WM_Redraw - Sample", 160, 5);
00155   GUI_SetFont(&GUI_Font8x16);
00156   while(1) {
00157     //
00158     // Move a window over background
00159     //
00160     _MoveWindow("Background has not been redrawn");
00161     //
00162     // Clear background
00163     //
00164     GUI_ClearRect(0, 50, 319, 239);
00165     GUI_Delay(1000);
00166     //
00167     // Set callback for background window
00168     //
00169     _cbOldBk = WM_SetCallback(WM_HBKWIN, _cbBkWindow);
00170     //
00171     // Move a window over background
00172     //
00173     _MoveWindow("Background has been redrawn");
00174     //
00175     // Delete callback for Background window
00176     //
00177     WM_SetCallback(WM_HBKWIN, _cbOldBk);
00178   }
00179 }
00180 
00181 /*********************************************************************
00182 *
00183 *       Public code
00184 *
00185 **********************************************************************
00186 */
00187 /*********************************************************************
00188 *
00189 *       MainTask
00190 */
00191 void MainTask(void) {
00192   GUI_Init();
00193   //
00194   // Check if recommended memory for the sample is available
00195   //
00196   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00197     GUI_ErrorOut("Not enough memory available."); 
00198     return;
00199   }
00200   _DemoRedraw();
00201 }
00202 
00203 /*************************** End of file ****************************/