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

« Back to documentation index

Show/hide line numbers WIDGET_FrameWin.c Source File

WIDGET_FrameWin.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_FrameWin.c
00041 Purpose     : Example demonstrating the use of a FRAMEWIN widget
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 #include <stddef.h>
00051 #include <string.h>
00052 #include "GUI.h"
00053 #include "FRAMEWIN.h"
00054 
00055 /*********************************************************************
00056 *
00057 *       Defines
00058 *
00059 **********************************************************************
00060 */
00061 #define SPEED   1200
00062 
00063 #define MSG_CHANGE_MAIN_TEXT (WM_USER + 0)
00064 
00065 //
00066 // Recommended memory to run the sample with adequate performance
00067 //
00068 #define RECOMMENDED_MEMORY (1024L * 30)
00069 
00070 /*********************************************************************
00071 *
00072 *       Static data
00073 *
00074 **********************************************************************
00075 */
00076 static FRAMEWIN_Handle  _hFrame;
00077 static WM_CALLBACK*     _pcbOldFrame;
00078 static char             _acMainText[100];
00079 static int              _LockClose = 1;
00080 
00081 /*******************************************************************
00082 *
00083 *       Static code
00084 *
00085 ********************************************************************
00086 */
00087 /*******************************************************************
00088 *
00089 *       _ChangeMainText
00090 *
00091 *  Sends a message to the background window and invalidate it, so
00092 *  the callback of the background window display the new text.
00093 */
00094 static void _ChangeMainText(char* pStr, int Delay) {
00095   WM_MESSAGE Message;
00096   Message.MsgId  = MSG_CHANGE_MAIN_TEXT;
00097   Message.Data.p = pStr;
00098   GUI_Delay(Delay);
00099   WM_SendMessage(WM_HBKWIN, &Message);
00100   WM_InvalidateWindow(WM_HBKWIN);
00101   GUI_Delay(Delay/3);
00102 }
00103 
00104 /*******************************************************************
00105 *
00106 *       _cbChild
00107 */
00108 static void _cbChild(WM_MESSAGE * pMsg) {
00109   WM_HWIN hWin = (FRAMEWIN_Handle)(pMsg->hWin);
00110   switch (pMsg->MsgId) {
00111   case WM_PAINT:
00112     //
00113     // Handle the paint message
00114     //
00115     GUI_SetBkColor(GUI_WHITE);
00116     GUI_SetColor(GUI_BLACK);
00117     GUI_SetFont(&GUI_FontComic24B_ASCII);
00118     GUI_SetTextAlign(GUI_TA_HCENTER | GUI_TA_VCENTER);
00119     GUI_Clear();
00120     GUI_DispStringHCenterAt("Client window", 
00121                             WM_GetWindowSizeX(hWin) / 2, 
00122                             WM_GetWindowSizeY(hWin) / 2);
00123     break;
00124   default:
00125     WM_DefaultProc(pMsg);
00126   }
00127 }
00128 
00129 /*******************************************************************
00130 *
00131 *       _cbFrame
00132 */
00133 static void _cbFrame(WM_MESSAGE * pMsg) {
00134   switch (pMsg->MsgId) {
00135   case WM_NOTIFY_PARENT:
00136     if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
00137       int Id = WM_GetId(pMsg->hWinSrc);      // Id of widget
00138       if (Id == GUI_ID_CLOSE) {
00139         if (_LockClose) {
00140           return;
00141         }
00142         _hFrame = 0;
00143       }
00144     }
00145     break;
00146   }
00147   if (_pcbOldFrame) {
00148     (*_pcbOldFrame)(pMsg);
00149   }
00150 }
00151 
00152 /*******************************************************************
00153 *
00154 *       _cbBkWindow
00155 *
00156 * Function description
00157 *   This callback is necessary to redraw the background when
00158 *   frame window is moved
00159 */
00160 static void _cbBkWindow(WM_MESSAGE * pMsg) {
00161   switch (pMsg->MsgId) {
00162     case MSG_CHANGE_MAIN_TEXT:
00163       strcpy(_acMainText, (char const *)pMsg->Data.p);
00164       WM_InvalidateWindow(pMsg->hWin);
00165       break;
00166     case WM_PAINT:
00167       GUI_SetBkColor(GUI_BLACK);
00168       GUI_Clear();
00169       GUI_SetColor(GUI_WHITE);
00170       GUI_SetFont(&GUI_Font24_ASCII);
00171       GUI_DispStringHCenterAt("WIDGET_FrameWin - Sample", 160, 5);
00172       GUI_SetFont(&GUI_Font8x16);
00173       GUI_DispStringHCenterAt(_acMainText, 160, 40);
00174       GUI_SetFont(&GUI_Font6x8);
00175       GUI_DispStringHCenterAt("The function FRAMEWIN_Create creates both the\n"
00176                               "frame window and the client window.", 160, 190);
00177       break;
00178     default:
00179       WM_DefaultProc(pMsg);
00180   }
00181 }
00182 
00183 /*******************************************************************
00184 *
00185 *       _DemoFramewin
00186 *
00187 * Function description
00188 *   Creates the frame window and sets the callback for frame, child
00189 *   and background window
00190 */
00191 static void _DemoFramewin(void) {
00192   int i;
00193   char acInfoText[] = "-- sec to play with window";
00194   WM_HWIN hChild;
00195 
00196  
00197   WM_SetCallback(WM_HBKWIN, _cbBkWindow);
00198   //
00199   // Create and configure frame window
00200   //
00201   _ChangeMainText("FRAMEWIN_Create", SPEED);
00202   _hFrame = FRAMEWIN_Create("Frame window", 0, WM_CF_SHOW, 50, 75, 220, 100);
00203   _pcbOldFrame = WM_SetCallback(_hFrame, _cbFrame);
00204   hChild = WM_GetClientWindow(_hFrame);
00205   WM_SetCallback(hChild, _cbChild);
00206   FRAMEWIN_SetMoveable(_hFrame, 1);
00207   //
00208   // Create buttons
00209   //
00210   FRAMEWIN_AddCloseButton(_hFrame, FRAMEWIN_BUTTON_LEFT, 0);
00211   FRAMEWIN_AddMaxButton(_hFrame, FRAMEWIN_BUTTON_RIGHT, 0);
00212   FRAMEWIN_AddMinButton(_hFrame, FRAMEWIN_BUTTON_RIGHT, 2);
00213   //
00214   // Modify frame window attributes
00215   //
00216   _ChangeMainText("FRAMEWIN_SetActive", SPEED);
00217   FRAMEWIN_SetActive(_hFrame, 1);
00218   _ChangeMainText("FRAMEWIN_SetFont", SPEED);
00219   FRAMEWIN_SetFont(_hFrame, &GUI_Font16B_ASCII);
00220   FRAMEWIN_SetTitleHeight(_hFrame, 20);
00221   _ChangeMainText("FRAMEWIN_SetTextColor", SPEED);
00222   FRAMEWIN_SetTextColor(_hFrame, GUI_YELLOW);
00223   _ChangeMainText("FRAMEWIN_SetTextAlign", SPEED);
00224   FRAMEWIN_SetTextAlign(_hFrame, GUI_TA_HCENTER);
00225   _ChangeMainText("FRAMEWIN_Minimize", SPEED);
00226   FRAMEWIN_Minimize(_hFrame);
00227   _ChangeMainText("FRAMEWIN_Maximize", SPEED);
00228   FRAMEWIN_Maximize(_hFrame);
00229   _ChangeMainText("FRAMEWIN_Restore", SPEED);
00230   FRAMEWIN_Restore(_hFrame);
00231   _ChangeMainText("FRAMEWIN_SetTitleVis", SPEED);
00232   for (i = 0; i < 5; i++) {
00233     FRAMEWIN_SetTitleVis(_hFrame, 0);
00234     GUI_Delay(200);
00235     FRAMEWIN_SetTitleVis(_hFrame, 1);
00236     GUI_Delay(200);
00237   }
00238   //
00239   // Time to play with frame window
00240   //
00241   _LockClose = 0;
00242   for (i = 250; (i > 0) && _hFrame; i--) {
00243     acInfoText[0] = '0' + ((i + 9) / 100);
00244     acInfoText[1] = '0' + (((i + 9) / 10) % 10);
00245     _ChangeMainText(acInfoText, 0);
00246     GUI_Delay(100);
00247   }
00248   if (_hFrame) {
00249     _ChangeMainText("WM_Delete", SPEED);
00250     WM_DeleteWindow(_hFrame);
00251   } else {
00252     _ChangeMainText("", 50);
00253   }
00254 }
00255 
00256 /*********************************************************************
00257 *
00258 *       Public code
00259 *
00260 **********************************************************************
00261 */
00262 /*********************************************************************
00263 *
00264 *       MainTask
00265 */
00266 void MainTask(void) {
00267   GUI_Init();
00268   //
00269   // Check if recommended memory for the sample is available
00270   //
00271   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00272     GUI_ErrorOut("Not enough memory available."); 
00273     return;
00274   }
00275   WM_EnableMemdev(WM_HBKWIN);
00276   while(1) {
00277     _DemoFramewin();
00278   }
00279 }
00280 
00281 /*************************** End of file ****************************/
00282