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

« Back to documentation index

Show/hide line numbers MOTION_MovingWindow.c Source File

MOTION_MovingWindow.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        : MOTION_MovingWindow.c
00041 Purpose     : Shows how to use simple motion support
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - (x)
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 
00051 //
00052 // Recommended memory to run the sample with adequate performance
00053 //
00054 #define RECOMMENDED_MEMORY (1024L * 20)
00055 
00056 /*********************************************************************
00057 *
00058 *       Includes
00059 *
00060 **********************************************************************
00061 */
00062 #include "WM.h"
00063 
00064 /*********************************************************************
00065 *
00066 *       Types
00067 *
00068 **********************************************************************
00069 */
00070 typedef struct {
00071   int Axis;
00072   int Speed;
00073 } PARA;
00074 
00075 /*********************************************************************
00076 *
00077 *       Static data
00078 *
00079 **********************************************************************
00080 */
00081 static const PARA _aPara[] = {
00082   { GUI_COORD_X, +100 },
00083   { GUI_COORD_Y, +100 },
00084   { GUI_COORD_X, -100 },
00085   { GUI_COORD_Y, -100 },
00086 };
00087 
00088 /*********************************************************************
00089 *
00090 *       Static code
00091 *
00092 **********************************************************************
00093 */
00094 /*********************************************************************
00095 *
00096 *       _cbWin0
00097 */
00098 static void _cbWin0(WM_MESSAGE * pMsg) {
00099   int xSize, ySize;
00100 
00101   switch (pMsg->MsgId) {
00102   case WM_PAINT:
00103     xSize = LCD_GetXSize();
00104     ySize = LCD_GetYSize();
00105     GUI_DrawGradientV(0, 0, xSize, ySize, GUI_BLUE, GUI_BLACK);
00106     GUI_SetColor(GUI_WHITE);
00107     GUI_SetFont(&GUI_Font24_ASCII);
00108     GUI_SetTextMode(GUI_TM_TRANS);
00109     GUI_DispStringHCenterAt("WM_Motion - Sample", 160, 5);
00110     break;
00111   default:
00112     WM_DefaultProc(pMsg);
00113     break;
00114   }
00115 }
00116 
00117 /*********************************************************************
00118 *
00119 *       _cbWin1
00120 */
00121 static void _cbWin1(WM_MESSAGE * pMsg) {
00122   int xSize, ySize;
00123 
00124   switch (pMsg->MsgId) {
00125   case WM_PAINT:
00126     xSize = WM_GetWindowSizeX(pMsg->hWin);
00127     ySize = WM_GetWindowSizeY(pMsg->hWin);
00128     GUI_DrawGradientV(0, 0, xSize, ySize, GUI_DARKGREEN, GUI_DARKRED);
00129     GUI_SetTextMode(GUI_TM_TRANS);
00130     GUI_DispStringHCenterAt("I am a window", xSize >> 1, 5);
00131     GUI_DispStringHCenterAt("Try to catch me", xSize >> 1, 15);
00132     GUI_DispStringAt("xPos: ", 20, 30);
00133     GUI_DispDec(WM_GetWindowOrgX(pMsg->hWin), 3);
00134     GUI_DispStringAt("yPos: ", 20, 40);
00135     GUI_DispDec(WM_GetWindowOrgY(pMsg->hWin), 3);
00136     GUI_SetColor(GUI_GRAY);
00137     GUI_DrawRect(0, 0, xSize - 1, ySize - 1);
00138     break;
00139   default:
00140     WM_DefaultProc(pMsg);
00141     break;
00142   }
00143 }
00144 
00145 /*********************************************************************
00146 *
00147 *       Public code
00148 *
00149 **********************************************************************
00150 */
00151 /*********************************************************************
00152 *
00153 *       MainTask
00154 */
00155 void MainTask(void) {
00156   WM_HWIN  hWin0;
00157   WM_HWIN  hWin1;
00158   int      xSize, ySize;
00159   unsigned i;
00160 
00161   WM_SetCreateFlags(WM_CF_MEMDEV);
00162   GUI_Init();
00163   //
00164   // Check if recommended memory for the sample is available
00165   //
00166   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00167     GUI_ErrorOut("Not enough memory available."); 
00168     return;
00169   }
00170   WM_MOTION_Enable(1);
00171   xSize = LCD_GetXSize();
00172   ySize = LCD_GetYSize();
00173   hWin0 = WM_CreateWindowAsChild(0, 0, xSize, ySize, WM_HBKWIN, WM_CF_SHOW, _cbWin0, 0);
00174   hWin1 = WM_CreateWindowAsChild(10, 30, 120, 60, hWin0, WM_CF_SHOW | WM_CF_MOTION_X | WM_CF_MOTION_Y, _cbWin1, 0);
00175   while (1) {
00176     for (i = 0; i < GUI_COUNTOF(_aPara); i++) {
00177       WM_MOTION_SetSpeed(hWin1, _aPara[i].Axis, _aPara[i].Speed);
00178       GUI_Delay(1000);
00179       WM_MOTION_SetDeceleration(hWin1, _aPara[i].Axis, 100);
00180       GUI_Delay(1000);
00181     }
00182   }
00183 }
00184 
00185 /*************************** End of file ****************************/