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

« Back to documentation index

Show/hide line numbers WIDGET_NumPad.c Source File

WIDGET_NumPad.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_NumPad.c
00041 Purpose     : Shows how to use a numpad as input device on a touch screen
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ---------------------------END-OF-HEADER------------------------------
00049 */
00050 
00051 #include "DIALOG.h"
00052 
00053 /*********************************************************************
00054 *
00055 *       Defines
00056 *
00057 **********************************************************************
00058 */
00059 //
00060 // Recommended memory to run the sample with adequate performance
00061 //
00062 #define RECOMMENDED_MEMORY (1024L * 10)
00063 
00064 /*********************************************************************
00065 *
00066 *       Static data
00067 *
00068 **********************************************************************
00069 */
00070 //
00071 // Bitmap data for arrow keys
00072 //
00073 static GUI_CONST_STORAGE GUI_COLOR _aColorsArrow[] = {
00074   GUI_MAKE_COLOR(0xFFFFFF), GUI_MAKE_COLOR(0x000000)
00075 };
00076 
00077 static GUI_CONST_STORAGE GUI_LOGPALETTE _PalArrow = {
00078   2,    /* number of entries */
00079   1,    /* No transparency */
00080   &_aColorsArrow[0]
00081 };
00082 
00083 static GUI_CONST_STORAGE unsigned char _acArrowRight[] = {
00084   ____XX__, ________,
00085   ____XXXX, ________,
00086   XXXXXXXX, XX______,
00087   ____XXXX, ________,
00088   ____XX__, ________
00089 };
00090 
00091 static GUI_CONST_STORAGE unsigned char _acArrowLeft[] = {
00092   ____XX__, ________,
00093   __XXXX__, ________,
00094   XXXXXXXX, XX______,
00095   __XXXX__, ________,
00096   ____XX__, ________
00097 };
00098 
00099 static GUI_CONST_STORAGE GUI_BITMAP _bmArrowRight = {
00100   10,            /* XSize */
00101   5,             /* YSize */
00102   2,             /* BytesPerLine */
00103   1,             /* BitsPerPixel */
00104   _acArrowRight, /* Pointer to picture data (indices) */
00105   &_PalArrow     /* Pointer to palette */
00106 };
00107 
00108 static GUI_CONST_STORAGE GUI_BITMAP _bmArrowLeft = {
00109   10,            /* XSize */
00110   5,             /* YSize */
00111   2,             /* BytesPerLine */
00112   1,             /* BitsPerPixel */
00113   _acArrowLeft,  /* Pointer to picture data (indices) */
00114   &_PalArrow     /* Pointer to palette */
00115 };
00116 //
00117 // Array of keys
00118 //
00119 static int _aKey[] = {GUI_KEY_DELETE, GUI_KEY_TAB, GUI_KEY_LEFT, GUI_KEY_RIGHT};
00120 
00121 //
00122 // Dialog resource of numpad
00123 //
00124 static const GUI_WIDGET_CREATE_INFO _aDialogNumPad[] = {
00125 //
00126 //  Function                 Text      Id                 Px   Py   Dx   Dy
00127 //
00128   { WINDOW_CreateIndirect,   0,        0,                225, 110,  95, 130},
00129   { BUTTON_CreateIndirect,   "7",      GUI_ID_USER +  7,   5,   5,  25,  20},
00130   { BUTTON_CreateIndirect,   "8",      GUI_ID_USER +  8,  35,   5,  25,  20},
00131   { BUTTON_CreateIndirect,   "9",      GUI_ID_USER +  9,  65,   5,  25,  20},
00132   { BUTTON_CreateIndirect,   "4",      GUI_ID_USER +  4,   5,  30,  25,  20},
00133   { BUTTON_CreateIndirect,   "5",      GUI_ID_USER +  5,  35,  30,  25,  20},
00134   { BUTTON_CreateIndirect,   "6",      GUI_ID_USER +  6,  65,  30,  25,  20},
00135   { BUTTON_CreateIndirect,   "1",      GUI_ID_USER +  1,   5,  55,  25,  20},
00136   { BUTTON_CreateIndirect,   "2",      GUI_ID_USER +  2,  35,  55,  25,  20},
00137   { BUTTON_CreateIndirect,   "3",      GUI_ID_USER +  3,  65,  55,  25,  20},
00138   { BUTTON_CreateIndirect,   "0",      GUI_ID_USER +  0,   5,  80,  25,  20},
00139   { BUTTON_CreateIndirect,   ".",      GUI_ID_USER + 10,  35,  80,  25,  20},
00140   { BUTTON_CreateIndirect,   "Del",    GUI_ID_USER + 11,  65,  80,  25,  20},
00141   { BUTTON_CreateIndirect,   "Tab",    GUI_ID_USER + 12,   5, 105,  25,  20},
00142   { BUTTON_CreateIndirect,   0,        GUI_ID_USER + 13,  35, 105,  25,  20},
00143   { BUTTON_CreateIndirect,   0,        GUI_ID_USER + 14,  65, 105,  25,  20},
00144 };
00145 
00146 //
00147 // Dialog resource of user dialog
00148 //
00149 static const GUI_WIDGET_CREATE_INFO _aDialogUser[] = {
00150 //
00151 //  Function                 Text      Id                 Px   Py   Dx   Dy
00152 //
00153   { FRAMEWIN_CreateIndirect, "Dialog", 0,                 40,  90, 140, 115, FRAMEWIN_CF_MOVEABLE},
00154   { EDIT_CreateIndirect,     0,        GUI_ID_EDIT0,      10,  10, 110,  20, 0, 12},
00155   { EDIT_CreateIndirect,     0,        GUI_ID_EDIT1,      10,  40, 110,  20, 0, 12},
00156   { BUTTON_CreateIndirect,   "Ok",     GUI_ID_OK,         10,  70,  50,  20 },
00157   { BUTTON_CreateIndirect,   "Cancel", GUI_ID_CANCEL,     70,  70,  50,  20 },
00158 };
00159 
00160 //
00161 // Title of sample
00162 //
00163 static char _aTitle[] = {"WIDGET_NumPad"};
00164 
00165 //
00166 // Explanation of sample
00167 //
00168 static char * _apExplain[] = {
00169   "This sample shows how to use a numpad as input",
00170   "device. This can be useful if no keyboard",
00171   "is available and the user should edit numeric",
00172   "values or text on a touch screen.",
00173 };
00174 
00175 /*********************************************************************
00176 *
00177 *       Static code
00178 *
00179 **********************************************************************
00180 */
00181 /*********************************************************************
00182 *
00183 *       _cbDialogNumPad
00184 *
00185 * Function description
00186 *   Callback function of the numpad.
00187 */
00188 static void _cbDialogNumPad(WM_MESSAGE * pMsg) {
00189   GUI_RECT r;
00190   unsigned i; 
00191   int      NCode;
00192   unsigned Id;
00193   int      Pressed;
00194   WM_HWIN  hDlg;
00195   WM_HWIN  hItem;
00196   
00197   Pressed = 0;
00198   hDlg = pMsg->hWin;
00199   switch (pMsg->MsgId) {
00200   case WM_PAINT:
00201     WM_GetClientRect(&r);
00202     GUI_SetColor(GUI_MAKE_COLOR(0x000000));
00203     GUI_DrawRect(r.x0, r.y0, r.x1, r.y1);          /* Draw rectangle around it */
00204     /* Draw the bright sides */
00205     GUI_SetColor(GUI_MAKE_COLOR(0xffffff));
00206     GUI_DrawHLine(r.y0 + 1, r.x0 + 1, r.x1 - 2);   /* Draw top line */
00207     GUI_DrawVLine(r.x0 + 1, r.y0 + 1, r.y1 - 2);
00208     /* Draw the dark sides */
00209     GUI_SetColor(GUI_MAKE_COLOR(0x555555));
00210     GUI_DrawHLine(r.y1-1, r.x0 + 1, r.x1 - 1);
00211     GUI_DrawVLine(r.x1-1, r.y0 + 1, r.y1 - 2);
00212     break;
00213   case WM_INIT_DIALOG:
00214     for (i = 0; i < GUI_COUNTOF(_aDialogNumPad) - 1; i++) {
00215       hItem = WM_GetDialogItem(hDlg, GUI_ID_USER + i);
00216       BUTTON_SetFocussable(hItem, 0);                       /* Set all buttons non focussable */
00217       switch (i) {
00218       case 13:
00219         BUTTON_SetBitmapEx(hItem, 0, &_bmArrowLeft, 7, 7);  /* Set bitmap for arrow left button (unpressed) */
00220         BUTTON_SetBitmapEx(hItem, 1, &_bmArrowLeft, 7, 7);  /* Set bitmap for arrow left button (pressed) */
00221         break;
00222       case 14:
00223         BUTTON_SetBitmapEx(hItem, 0, &_bmArrowRight, 7, 7); /* Set bitmap for arrow right button (unpressed) */
00224         BUTTON_SetBitmapEx(hItem, 1, &_bmArrowRight, 7, 7); /* Set bitmap for arrow right button (pressed) */
00225         break;
00226       }
00227     }
00228     WM_GetDialogItem(hDlg, GUI_ID_USER + 12);
00229     break;
00230   case WM_NOTIFY_PARENT:
00231     Id    = WM_GetId(pMsg->hWinSrc);      /* Id of widget */
00232     NCode = pMsg->Data.v;                 /* Notification code */
00233     switch (NCode) {
00234     case WM_NOTIFICATION_CLICKED:
00235       Pressed = 1;
00236     case WM_NOTIFICATION_RELEASED:
00237       if ((Id >= GUI_ID_USER) && (Id <= (GUI_ID_USER + GUI_COUNTOF(_aDialogNumPad) - 1))) {
00238         int Key;
00239         if (Id < GUI_ID_USER + 11) {
00240           char acBuffer[10];
00241           BUTTON_GetText(pMsg->hWinSrc, acBuffer, sizeof(acBuffer)); /* Get the text of the button */
00242           Key = acBuffer[0];
00243         } else {
00244           Key = _aKey[Id - GUI_ID_USER - 11];                        /* Get the text from the array */
00245         }
00246         GUI_SendKeyMsg(Key, Pressed);                                /* Send a key message to the focussed window */
00247       }
00248       break;
00249     }
00250   default:
00251     WM_DefaultProc(pMsg);
00252   }
00253 }
00254 
00255 /*********************************************************************
00256 *
00257 *       _cbDialogUser
00258 *
00259 * Purpose:
00260 *   Callback function of the user dialog.
00261 */
00262 static void _cbDialogUser(WM_MESSAGE * pMsg) {
00263   int      i; 
00264   int      NCode;
00265   int      Id;
00266   WM_HWIN  hDlg;
00267   WM_HWIN  hItem;
00268 
00269   hDlg = pMsg->hWin;
00270   switch (pMsg->MsgId) {
00271   case WM_INIT_DIALOG:
00272     for (i = 0; i < 2; i++) {
00273       hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT0 + i);  /* Get the handle of the edit widget */
00274       EDIT_SetText(hItem, "12345678");                   /* Set text */
00275     }
00276     break;
00277   case WM_NOTIFY_PARENT:
00278     Id    = WM_GetId(pMsg->hWinSrc);      /* Id of widget */
00279     NCode = pMsg->Data.v;                 /* Notification code */
00280     switch (NCode) {
00281       case WM_NOTIFICATION_RELEASED:      /* React only if released */
00282         if (Id == GUI_ID_OK) {            /* OK Button */
00283           GUI_EndDialog(hDlg, 0);
00284         }
00285         if (Id == GUI_ID_CANCEL) {        /* Cancel Button */
00286           GUI_EndDialog(hDlg, 1);
00287         }
00288         break;
00289     }
00290     break;
00291   default:
00292     WM_DefaultProc(pMsg);
00293   }
00294 }
00295 
00296 /*********************************************************************
00297 *
00298 *       _cbDesktop
00299 *
00300 * Function description
00301 *   This routine handles the drawing of the desktop window.
00302 */
00303 static void _cbDesktop(WM_MESSAGE * pMsg) {
00304   unsigned i;
00305 
00306   switch (pMsg->MsgId) {
00307   case WM_PAINT:
00308     GUI_SetBkColor(GUI_RED);
00309     GUI_Clear();
00310     GUI_SetFont(&GUI_Font24_ASCII);
00311     GUI_DispStringHCenterAt(_aTitle, 160, 5);
00312     GUI_DispNextLine();
00313     GUI_SetFont(GUI_DEFAULT_FONT);
00314     GUI_DispNextLine();
00315     for (i = 0; i < GUI_COUNTOF(_apExplain); i++) {
00316       GUI_DispStringHCenterAt(_apExplain[i], 160, GUI_GetDispPosY());
00317       GUI_DispNextLine();
00318     }
00319     break;
00320   }
00321 }
00322 
00323 /*********************************************************************
00324 *
00325 *       Exported code
00326 *
00327 **********************************************************************
00328 */
00329 /*********************************************************************
00330 *
00331 *       MainTask
00332 */
00333 void MainTask(void) {
00334   WM_HWIN hNumPad;
00335 
00336   GUI_Init();
00337   //
00338   // Check if recommended memory for the sample is available
00339   //
00340   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00341     GUI_ErrorOut("Not enough memory available."); 
00342     return;
00343   }
00344   WM_SetCallback(WM_HBKWIN, _cbDesktop);
00345   hNumPad = GUI_CreateDialogBox(_aDialogNumPad, 
00346                                 GUI_COUNTOF(_aDialogNumPad), 
00347                                 _cbDialogNumPad, WM_HBKWIN, 0, 0); /* Create the numpad dialog */
00348   WM_SetStayOnTop(hNumPad, 1);
00349   while (1) {
00350     GUI_ExecDialogBox(_aDialogUser, 
00351                       GUI_COUNTOF(_aDialogUser), 
00352                       _cbDialogUser, WM_HBKWIN, 0, 0);             /* Execute the user dialog */
00353     GUI_Delay(1000);
00354   }
00355 }
00356 
00357 /*************************** End of file ****************************/
00358