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

« Back to documentation index

Show/hide line numbers WM_LateClipping.c Source File

WM_LateClipping.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_LateClipping.c
00041 Purpose     : Demonstrates early and late clipping
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 #include "FRAMEWIN.h"
00055 #include "BUTTON.h"
00056 
00057 /*********************************************************************
00058 *
00059 *       Defines
00060 *
00061 **********************************************************************
00062 */
00063 //
00064 // Recommended memory to run the sample with adequate performance
00065 //
00066 #define RECOMMENDED_MEMORY (1024L * 5)
00067 
00068 /*********************************************************************
00069 *
00070 *       Static data
00071 *
00072 **********************************************************************
00073 */
00074 static WM_HWIN _hWin1;
00075 static WM_HWIN _hWin2;
00076 static WM_HWIN _hBut1;
00077 static WM_HWIN _hBut2;
00078 static int     _PaintCount1;
00079 static int     _PaintCount2;
00080 
00081 static GUI_COLOR _aColors[] = {
00082 #if (GUI_USE_ARGB == 1)
00083   0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFFA000A0, 0xFF00FFFF
00084 #else
00085   0x0000FF, 0x00FF00, 0xFF0000, 0x00FFFF, 0xA000A0, 0xFFFF00
00086 #endif
00087 };
00088 
00089 /*********************************************************************
00090 *
00091 *       Static code
00092 *
00093 **********************************************************************
00094 */
00095 /*********************************************************************
00096 *
00097 *       _cbBkWin
00098 */
00099 static void _cbBkWin(WM_MESSAGE* pMsg) {
00100   switch(pMsg->MsgId) {
00101   case WM_PAINT:
00102     GUI_SetBkColor(GUI_BLACK);
00103     GUI_Clear();
00104     GUI_SetColor(GUI_MAKE_COLOR(0x0060FF));
00105     GUI_DispStringAt("PaintCount (Early):", 0, 0);
00106     GUI_DispDecAt(_PaintCount1, 120, 0, 5);
00107     GUI_SetColor(GUI_MAKE_COLOR(0x00FFC0));
00108     GUI_DispStringAt("PaintCount (Late):", 0, 12);
00109     GUI_DispDecAt(_PaintCount2, 120, 12, 5);
00110     break;
00111   case WM_NOTIFY_PARENT:
00112     if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
00113       if (pMsg->hWinSrc == _hBut1) {
00114         WM_InvalidateWindow(_hWin1);
00115         WM_InvalidateWindow(_hWin2);
00116       } else if (pMsg->hWinSrc == _hBut2) {
00117         _PaintCount1 = 0;
00118         _PaintCount2 = 0;
00119         WM_InvalidateWindow(pMsg->hWin);
00120       }
00121     }
00122     break;
00123   default:
00124     WM_DefaultProc(pMsg);
00125   }
00126 }
00127 
00128 /*********************************************************************
00129 *
00130 *       _cbTop
00131 */
00132 static void _cbTop(WM_MESSAGE* pMsg) {
00133   switch(pMsg->MsgId) {
00134   case WM_PAINT:
00135     GUI_SetBkColor(GUI_MAGENTA);
00136     GUI_Clear();
00137     break;
00138   default:
00139     WM_DefaultProc(pMsg);
00140   }
00141 }
00142 
00143 /*********************************************************************
00144 *
00145 *       _cbFrameWin1
00146 */
00147 static void _cbFrameWin1(WM_MESSAGE* pMsg) {
00148   switch(pMsg->MsgId) {
00149   case WM_PAINT:
00150     GUI_SetBkColor(_aColors[_PaintCount1 % 6]);
00151     GUI_Clear();
00152     GUI_SetColor(GUI_MAKE_COLOR(0x0060FF));
00153     GUI_FillCircle(25, 25, 15);
00154     GUI_SetColor(GUI_BLACK);
00155     GUI_DrawCircle(25, 25, 15);
00156     _PaintCount1++;
00157     WM_InvalidateWindow(WM_HBKWIN);
00158     break;
00159   default:
00160     WM_DefaultProc(pMsg);
00161   }
00162 }
00163 
00164 /*********************************************************************
00165 *
00166 *       _cbFrameWin2
00167 */
00168 static void _cbFrameWin2(WM_MESSAGE* pMsg) {
00169   switch(pMsg->MsgId) {
00170   case WM_PAINT:
00171     GUI_SetBkColor(_aColors[_PaintCount2 % 6]);
00172     GUI_Clear();
00173     GUI_SetColor(GUI_MAKE_COLOR(0x00FFC0));
00174     GUI_FillCircle(25, 25, 15);
00175     GUI_SetColor(GUI_BLACK);
00176     GUI_DrawCircle(25, 25, 15);
00177     _PaintCount2++;
00178     WM_InvalidateWindow(WM_HBKWIN);
00179     break;
00180   default:
00181     WM_DefaultProc(pMsg);
00182   }
00183 }
00184 
00185 /*********************************************************************
00186 *
00187 *       _ShowDemo
00188 */
00189 static void _ShowDemo(void) {
00190   WM_HWIN hWin0;
00191   WM_HWIN hWin1;
00192   WM_HWIN hWin2;
00193   WM_HWIN hFrame1;
00194   WM_HWIN hFrame2;
00195   WM_HWIN hClient1;
00196   WM_HWIN hClient2;
00197 
00198   WM_SetCallback(WM_HBKWIN, _cbBkWin);
00199   hFrame1  = FRAMEWIN_CreateEx( 10, 30, 140, 140, 0, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "Early Clipping", _cbFrameWin1);
00200   hFrame2  = FRAMEWIN_CreateEx(170, 30, 140, 140, 0, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, 0, "Late Clipping", _cbFrameWin2);
00201   hClient1 = WM_GetClientWindow(hFrame1);
00202   hClient2 = WM_GetClientWindow(hFrame2);
00203   _hWin1   = WM_CreateWindowAsChild(0, 0, WM_GetWindowSizeX(hClient1), WM_GetWindowSizeY(hClient1), hClient1, WM_CF_SHOW, _cbFrameWin1, 0);
00204   _hWin2   = WM_CreateWindowAsChild(0, 0, WM_GetWindowSizeX(hClient2), WM_GetWindowSizeY(hClient2), hClient2, WM_CF_SHOW | WM_CF_LATE_CLIP, _cbFrameWin2, 0);
00205   _hBut1   = BUTTON_CreateEx( 10, 210, 140, 20, 0, WM_CF_SHOW, 0, 1);
00206   _hBut2   = BUTTON_CreateEx(170, 210, 140, 20, 0, WM_CF_SHOW, 0, 2);
00207   hWin0    = FRAMEWIN_CreateEx( 60,  80, 40, 40, 0, WM_CF_SHOW | WM_CF_STAYONTOP, FRAMEWIN_CF_MOVEABLE, 0, "Top 0", _cbTop);
00208   hWin1    = FRAMEWIN_CreateEx(220,  80, 40, 40, 0, WM_CF_SHOW | WM_CF_STAYONTOP, FRAMEWIN_CF_MOVEABLE, 0, "Top 1", _cbTop);
00209   hWin2    = FRAMEWIN_CreateEx(140, 170, 40, 40, 0, WM_CF_SHOW | WM_CF_STAYONTOP, FRAMEWIN_CF_MOVEABLE, 0, "Top 2", _cbTop);
00210   FRAMEWIN_SetResizeable(hWin0, 1);
00211   FRAMEWIN_SetResizeable(hWin1, 1);
00212   FRAMEWIN_SetResizeable(hWin2, 1);
00213   BUTTON_SetText(_hBut1, "Invalidate");
00214   BUTTON_SetText(_hBut2, "Reset counters");
00215   while(1) {
00216     GUI_Delay(50);
00217   }
00218 }
00219 
00220 /*********************************************************************
00221 *
00222 *       Public code
00223 *
00224 **********************************************************************
00225 */
00226 /*********************************************************************
00227 *
00228 *       MainTask
00229 */
00230 void MainTask(void) {
00231   GUI_Init();
00232   //
00233   // Check if recommended memory for the sample is available
00234   //
00235   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00236     GUI_ErrorOut("Not enough memory available."); 
00237     return;
00238   }
00239   while(1) {
00240     _ShowDemo();
00241   }
00242 }
00243 
00244 /*************************** End of file ****************************/