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

« Back to documentation index

Show/hide line numbers WIDGET_ScrollbarMove.c Source File

WIDGET_ScrollbarMove.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        : SCROLLBAR_Move.c
00041 Purpose     : Example demonstrating scrollbar as child of a window
00042 Requirements: WindowManager - (x)
00043               MemoryDevices - ( )
00044               AntiAliasing  - ( )
00045               VNC-Server    - ( )
00046               PNG-Library   - ( )
00047               TrueTypeFonts - ( )
00048 ----------------------------------------------------------------------
00049 */
00050 
00051 #include "GUI.h"
00052 #include "SCROLLBAR.h"
00053 #include "EDIT.h"
00054 
00055 /*********************************************************************
00056 *
00057 *       Defines
00058 *
00059 **********************************************************************
00060 */
00061 #define EDIT_MAX_X 10
00062 #define EDIT_MAX_Y 3
00063 
00064 #define EDIT_ITEM_SIZEX 47
00065 
00066 //
00067 // Recommended memory to run the sample with adequate performance
00068 //
00069 #define RECOMMENDED_MEMORY (1024L * 20)
00070 
00071 /*********************************************************************
00072 *
00073 *       Static variables
00074 *
00075 **********************************************************************
00076 */
00077 static EDIT_Handle _aahEdit[EDIT_MAX_Y][EDIT_MAX_X];
00078 static int         _x;
00079 
00080 /*********************************************************************
00081 *
00082 *       Static code
00083 *
00084 **********************************************************************
00085 */
00086 /*********************************************************************
00087 *
00088 *       _cbWindow
00089 *
00090 * Function description
00091 *   The callback moves the edit-fiels when a notification message was send.
00092 */
00093 static void _cbWindow(WM_MESSAGE * pMsg) {
00094   WM_SCROLL_STATE ScrollState;
00095   int             x;
00096   int             y;
00097 
00098   switch (pMsg->MsgId) {
00099   case WM_NOTIFY_PARENT:
00100     if (pMsg->Data.v == WM_NOTIFICATION_VALUE_CHANGED) {
00101       if (WM_GetId(pMsg->hWinSrc) == GUI_ID_HSCROLL) {
00102         WM_GetScrollState(pMsg->hWinSrc, &ScrollState);
00103         if (_x != ScrollState.v) {
00104           for (y = 0; y < EDIT_MAX_Y; y++) {
00105             for (x = 0; x < EDIT_MAX_X; x++) {
00106               WM_MoveWindow(_aahEdit[y][x], _x - ScrollState.v, 0);
00107             }
00108           }
00109           _x = ScrollState.v;
00110         }
00111       }
00112     }
00113     break;
00114   case WM_PAINT:
00115     GUI_SetBkColor(GUI_BLACK);
00116     GUI_Clear();
00117     break;
00118   default:
00119     WM_DefaultProc(pMsg);
00120   }
00121 }
00122 
00123 /*********************************************************************
00124 *
00125 *       _DemoScrollbarMove
00126 *
00127 * Function description
00128 *   This function creates the window and his child objects. Then it
00129 *   runs into a idle-loop, so that the window manager can handle the
00130 *   objects.
00131 */
00132 static void _DemoScrollbarMove(void) {
00133   SCROLLBAR_Handle hScroll;
00134   WM_HWIN          hWindow;
00135   int              x;
00136   int              y;
00137 
00138   //
00139   // Clear display and display headline
00140   //
00141   GUI_SetBkColor(GUI_BLUE);
00142   GUI_Clear();
00143   GUI_SetColor(GUI_WHITE);
00144   GUI_SetFont(&GUI_Font24_ASCII);
00145   GUI_SetTextAlign(GUI_TA_HCENTER);
00146   GUI_DispStringAt("SCROLLBAR_Move - Sample", 160, 5);
00147   GUI_SetTextAlign(GUI_TA_LEFT);
00148   GUI_SetColor(GUI_MAKE_COLOR(0xFFFFFF));
00149   GUI_SetFont(&GUI_Font8x16);
00150   //
00151   // Create the window
00152   //
00153   hWindow = WM_CreateWindow(50, 90, 220, 79, WM_CF_SHOW, _cbWindow, 0);
00154   //
00155   // Create the scrollbar
00156   //
00157   hScroll = SCROLLBAR_CreateAttached(hWindow, 0);
00158   SCROLLBAR_SetNumItems(hScroll, EDIT_ITEM_SIZEX * EDIT_MAX_X);
00159   SCROLLBAR_SetPageSize(hScroll, 220);
00160   //
00161   // Create the edit-fields
00162   //
00163   for (y = 0; y < EDIT_MAX_Y; y++) {
00164     for (x = 0; x < EDIT_MAX_X; x++) {
00165       _aahEdit[y][x] = EDIT_CreateAsChild(x * EDIT_ITEM_SIZEX, y * 22, EDIT_ITEM_SIZEX, 22, hWindow, 13, WM_CF_SHOW, 5);
00166       EDIT_SetTextAlign(_aahEdit[y][x], GUI_TA_RIGHT | GUI_TA_VCENTER);
00167       EDIT_SetFont(_aahEdit[y][x], &GUI_Font8x16);
00168       EDIT_SetDecMode(_aahEdit[y][x], ((y * EDIT_MAX_X) + x) * 100, -99999, +99999, 2, 0);
00169     }
00170   }
00171 }
00172 
00173 /*********************************************************************
00174 *
00175 *       Public code
00176 *
00177 **********************************************************************
00178 */
00179 /*********************************************************************
00180 *
00181 *       MainTask
00182 */
00183 void MainTask(void) {
00184   GUI_Init();
00185   //
00186   // Check if recommended memory for the sample is available
00187   //
00188   if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
00189     GUI_ErrorOut("Not enough memory available."); 
00190     return;
00191   }
00192   _DemoScrollbarMove();
00193   while(1) {
00194     GUI_Delay(20);
00195   }
00196 }
00197 
00198 /*************************** End of file ****************************/