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

« Back to documentation index

Show/hide line numbers WIDGET_Header.c Source File

WIDGET_Header.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_Header.c
00041 Purpose     : Demonstrates the use of header widgets
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - (x)
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ---------------------------END-OF-HEADER------------------------------
00049 */
00050 #include <stddef.h>
00051 #include <string.h>
00052 #include "GUI.h"
00053 #include "HEADER.h"
00054 #include "FRAMEWIN.h"
00055 
00056 /*********************************************************************
00057 *
00058 *       Defines
00059 *
00060 **********************************************************************
00061 */
00062 #define MSG_CHANGE_MAIN_TEXT (WM_USER + 0)
00063 #define MSG_CHANGE_INFO_TEXT (WM_USER + 1)
00064 
00065 //
00066 // Recommended memory to run the sample with adequate performance
00067 //
00068 #define RECOMMENDED_MEMORY (1024L * 10)
00069 
00070 /*********************************************************************
00071 *
00072 *       Static data
00073 *
00074 **********************************************************************
00075 */
00076 static HEADER_Handle _hHeader;
00077 static char _acMainText[100];
00078 static char _acInfoText[100];
00079 
00080 /*********************************************************************
00081 *
00082 *       Static code
00083 *
00084 **********************************************************************
00085 */
00086 /*******************************************************************
00087 *
00088 *       _ChangeMainText
00089 *
00090 *  Sends a message to the background window and invalidate it, so
00091 *  the callback of the background window display the new text.
00092 */
00093 static void _ChangeMainText(char* pStr) {
00094   WM_MESSAGE Message;
00095 
00096   Message.MsgId  = MSG_CHANGE_MAIN_TEXT;
00097   Message.Data.p = pStr;
00098   WM_SendMessage(WM_HBKWIN, &Message);
00099   WM_InvalidateWindow(WM_HBKWIN);
00100 }
00101 
00102 /*******************************************************************
00103 *
00104 *       _ChangeInfoText
00105 *
00106 *  Sends a message to the background window and invalidate it, so
00107 *  the callback of the background window display the new text.
00108 */
00109 static void _ChangeInfoText(char* pStr) {
00110   WM_MESSAGE Message;
00111 
00112   Message.MsgId  = MSG_CHANGE_INFO_TEXT;
00113   Message.Data.p = pStr;
00114   WM_SendMessage(WM_HBKWIN, &Message);
00115   WM_InvalidateWindow(WM_HBKWIN);
00116 }
00117 
00118 /*******************************************************************
00119 *
00120 *       _cbBkWindow
00121 */
00122 static void _cbBkWindow(WM_MESSAGE* pMsg) {
00123   switch (pMsg->MsgId) {
00124     case MSG_CHANGE_MAIN_TEXT:
00125       strcpy(_acMainText, (char const *)pMsg->Data.p);
00126       WM_InvalidateWindow(pMsg->hWin);
00127       break;
00128     case MSG_CHANGE_INFO_TEXT:
00129       strcpy(_acInfoText, (char const *)pMsg->Data.p);
00130       WM_InvalidateWindow(pMsg->hWin);
00131       break;
00132     case WM_PAINT:
00133       GUI_SetBkColor(GUI_BLACK);
00134       GUI_Clear();
00135       GUI_SetColor(GUI_WHITE);
00136       GUI_SetFont(&GUI_Font24_ASCII);
00137       GUI_DispStringHCenterAt("HEADER Widget - Sample", 160, 5);
00138       GUI_SetFont(&GUI_Font8x16);
00139       GUI_DispStringAt(_acMainText, 5, 40);
00140       GUI_SetFont(&GUI_Font8x8);
00141       GUI_DispStringAt(_acInfoText, 5, 60);
00142       break;
00143     default:
00144       WM_DefaultProc(pMsg);
00145   }
00146 }
00147 
00148 /*********************************************************************
00149 *
00150 *       _OnPaint
00151 */
00152 static void _OnPaint(void) {
00153   GUI_RECT Rect;
00154 
00155   GUI_SetBkColor(GUI_GRAY);
00156   GUI_Clear();
00157   WM_GetClientRect(&Rect);
00158   Rect.x1 = HEADER_GetItemWidth(_hHeader, 0);
00159   GUI_SetColor(GUI_RED);
00160   GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
00161   Rect.x0 = Rect.x1;
00162   Rect.x1 += HEADER_GetItemWidth(_hHeader, 1);
00163   GUI_SetColor(GUI_GREEN);
00164   GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
00165   Rect.x0 = Rect.x1;
00166   Rect.x1 += HEADER_GetItemWidth(_hHeader, 2);
00167   GUI_SetColor(GUI_BLUE);
00168   GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
00169 }
00170 
00171 /*********************************************************************
00172 *
00173 *       cbWindow
00174 */
00175 static void _cbWindow(WM_MESSAGE * pMsg) {
00176   switch (pMsg->MsgId) {
00177     case WM_PAINT:
00178       _OnPaint();
00179       break;
00180   }
00181   WM_DefaultProc(pMsg);
00182 }
00183 
00184 /*********************************************************************
00185 *
00186 *       _Demo
00187 */
00188 static void _Demo(void) {
00189   int Key;
00190   int Cnt;
00191   char acInfoText[] = "-- sec to play with header control";
00192 
00193   Key = 0;
00194   Cnt = 10;
00195   _ChangeInfoText("HEADER_AddItem");
00196   HEADER_AddItem(_hHeader, 100, "Red"  , GUI_TA_VCENTER | GUI_TA_HCENTER);
00197   HEADER_AddItem(_hHeader,   0, "Green", GUI_TA_VCENTER | GUI_TA_HCENTER);
00198   HEADER_AddItem(_hHeader,   0, ":-)"  , GUI_TA_VCENTER | GUI_TA_HCENTER);
00199   GUI_Delay(750);
00200   _ChangeInfoText("HEADER_SetItemWidth");
00201   HEADER_SetItemWidth(_hHeader, 1, 60);
00202   GUI_Delay(750);
00203   _ChangeInfoText("HEADER_SetItemText");
00204   HEADER_SetItemWidth(_hHeader, 2, 100);
00205   HEADER_SetItemText(_hHeader, 2, "Blue");
00206   GUI_Delay(750);
00207   _ChangeInfoText("HEADER_SetFont");
00208   HEADER_SetFont(_hHeader, &GUI_Font8x8);
00209   GUI_Delay(750);
00210   _ChangeInfoText("HEADER_SetHeight");
00211   HEADER_SetHeight(_hHeader, 50);
00212   GUI_Delay(750);
00213   _ChangeInfoText("HEADER_SetTextColor");
00214   HEADER_SetTextColor(_hHeader, GUI_MAKE_COLOR(0x00cc00));
00215   GUI_Delay(750);
00216   _ChangeInfoText("HEADER_SetBkColor");
00217   HEADER_SetBkColor(_hHeader, GUI_DARKGRAY);
00218   GUI_Delay(750);
00219   _ChangeInfoText("HEADER_SetTextAlign");
00220   HEADER_SetTextAlign(_hHeader, 0, GUI_TA_HCENTER);
00221   while (!Key && (Cnt > 0)) {
00222     acInfoText[0] = '0' + (Cnt / 10);
00223     acInfoText[1] = '0' + (Cnt-- % 10);
00224     _ChangeInfoText(acInfoText);
00225     GUI_Delay(1000);
00226     Key = GUI_GetKey();
00227   }
00228 }
00229 
00230 /*********************************************************************
00231 *
00232 *       _DemoHeaderFrameWin
00233 */
00234 static void _DemoHeaderFrameWin(void) {
00235   FRAMEWIN_Handle hFrameWin;
00236 
00237   _ChangeMainText("HEADER control inside a FRAMEWIN");
00238   hFrameWin = FRAMEWIN_Create("Title", _cbWindow, WM_CF_SHOW, 10, 80, 300, 140);
00239   FRAMEWIN_SetActive(hFrameWin, 1);
00240   _hHeader = HEADER_CreateAttached(WM_GetClientWindow(hFrameWin), 1234, 0);
00241   _Demo();
00242   WM_DeleteWindow(hFrameWin);
00243 }
00244 
00245 /*********************************************************************
00246 *
00247 *       _DemoHeaderWin
00248 */
00249 static void _DemoHeaderWin(void) {
00250   WM_HWIN hWin;
00251 
00252   _ChangeMainText("HEADER control inside a window");
00253   hWin = WM_CreateWindow(10, 80, 300, 140, WM_CF_SHOW, _cbWindow, 0);
00254   _hHeader = HEADER_CreateAttached(hWin, 1234, 0);
00255   _Demo();
00256   WM_DeleteWindow(hWin);
00257 }
00258 
00259 /*********************************************************************
00260 *
00261 *       _DemoHeader
00262 */
00263 static void _DemoHeader(void) {
00264   _ChangeMainText("HEADER control without parent");
00265   _hHeader = HEADER_Create(10, 80, 300, 0, 0, 1234, WM_CF_SHOW, 0);
00266   _Demo();
00267   WM_DeleteWindow(_hHeader);
00268 }
00269 
00270 /*********************************************************************
00271 *
00272 *       Public code
00273 *
00274 **********************************************************************
00275 */
00276 /*********************************************************************
00277 *
00278 *       MainTask
00279 */
00280 void MainTask(void) {
00281   GUI_Init();
00282   //
00283   // Check if recommended memory for the sample is available
00284   //
00285   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00286     GUI_ErrorOut("Not enough memory available."); 
00287     return;
00288   }
00289   WM_EnableMemdev(WM_HBKWIN);
00290   WM_SetCreateFlags(WM_CF_MEMDEV);
00291   WM_SetCallback(WM_HBKWIN, _cbBkWindow);
00292   GUI_CURSOR_Show();
00293   while(1) {
00294     _DemoHeaderFrameWin();
00295     _DemoHeaderWin();
00296     _DemoHeader();
00297   }
00298 }
00299 
00300 /*************************** End of file ****************************/