Home
AN03002_Custom_Widget_Type
Contents
1. Table 2 2 MYWIDG Return value 0 on success 1 on error ET SetUserData parameter list AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 16 CHAPTER 2 Creating a custom widget type 2 5 Widget specific default properties Default values should be defined for every property which is not explicitly set by the user at creation According to the MYWIDGET Obj structure the default values might be defined as shown below const MYWIDGET_Obj MYWIDGET_Default 0 U8 Pressed GUI DARKBLUE GUI LIGHTBLUE GUI GRAY j GUI COLOR aBkColor 3 GUI WHITE GUI DARKGRAY GUI LIGHTGRAY j GUI COLOR aTextColor 3 GUI ORANGE GUI COLOR FocusColor NULL const char pText 0 int NumExtraBytes js These values are used when the widget is created The function MYWIDGET Create changes as follows MYWIDGET Handle MYWIDGET Create int x0 int y0 int xSize int ySize WM HWIN hWinParent U32 Style WM CALLBACK pfCallback int NumExtraBytes MYWIDGET Handle hWin MYWIDGET Obj MyWidget hWin WM CreateWindowAsChild x0 y0 xSize ySize hWinParent Style pfCallback sizeof MYWIDGET Obj NumExtraBytes MyWidget MYWIDGET Default MyWidget NumExtraBytes NumExtraBytes WM SetUserData hWin amp MyWidget sizeof MYWIDGET Obj return hWin ANO03002 Custom Widget Type Creation Guide
2. Chapter 3 Example implementation This chapter shows an example application which includes the complete source code which was explained in the previous chapter as well as the usage of a custom user callback function and user data Additionally a BUTTON widget is used to make the change of the focus recognizable AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 22 CHAPTER 3 Example implementation 3 1 Sample description The following sample shows the internal implementation of the custom widget type which actually is a button and also shows an end user application which uses a cus tom callback function to display the text which was previously stored as widget user data 3 2 Internal source code include lt string h gt Definition of NULL include lt stdlib h gt malloc and free include GUI h include WM h include BUTTON h f kk kk ck kk kc ec ke he REE RR RR EERE EKER ER EKER EER ERE RRR EKER EERE RRA RRA RR RR ko ko kk k k k Color indices define MYWIDGET CI UNPRESSED 0 define MYWIDGET CI PRESSED 1 define MYWIDGET CI DISABLED 2 f 5k kk kk ck kc tec ke he ke e ERE RRA ERRE e e kkk kkk kkk RR RRR k k RR kkk RRA RR ARA RARA k kk k k Typedef 7 typedef WM_HMEM MYWIDGET_Handle f 5k kk kk kc ERK KER REE EEE ERE e ke RRR EKER ER EERE RAR RA RR RR RARA RR RAR RARE RAR MYWIDGET Obj a typedef struct
3. Extrabytes GUI_Init hMyWidget MYWIDGET_Create 10 10 100 50 WM_HBKWIN WM_CF_SHOW NULL _cbMyWidget strlen acExtraBytes MYWIDGET_SetUserData hMyWidget acExtraBytes strlen acExtraBytes BUTTON_Create 10 100 100 50 0 WM_CF_SHOW while 1 GUI_Delay 100 AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 26 CHAPTER 3 Example implementation ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 27 Index Symbols cbMyWidget eee 25 C Callback function NN 17 Callback mechanism ssee 18 Color indices eene 22 Creating the window 12 Custom widget type esee 11 D Default properties eene 16 E emWin user Manual een 9 ENG Ser i s crece t RR E 13 End user application sses 25 Example implementation 21 G GUI PID STATE eeeeneHeemns 19 I Internal source code sseess 22 Introduction ss 9 M Main Task issu sex ex xx n EY 25 Mandatory properties sss 17 MYWIDGET Callback e 18 23 MYWIDGET CI DISABLED 13 18 MYWIDGET CI PRESSED 13 18 MYWIDGET CI UNPRESSED 13 18 MYWIDGET Create 12 13 25 MYWIDGET Default a 16
4. WM SetFocus hWin WM InvalidateWindow hWin else MyWidget Pressed 0 WM SetUserData hWin amp MyWidget sizeof MYWIDGET Obj WM InvalidateWindow hWin break default WM_DefaultProc pMsg The additional code retrieves the PID state which is sent along with the wM TOUCH message and sets the user data accordingly After updating the widget specific data the widget is invalidated in order to receive a new WM_PAINT message When running this code clicking the widget will cause the color to change Neverthe less the focus rectangle is not drawn although the function wM SetFocus is called when the widget receives a pressed PID state The reason for this behavior is that the widget never accepts the focus To do so the callback function needs to react to the wM SET FOCUS message as shown below ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 20 I void MYWIDGI MYWIDGET ET Callback WM MESSAGE Handle hWin GUI_PID_STATE pState MYWIDGET Obj MyWidget WinRect GUI RECT ColorIndex pMsg E du int hWin pMsg gt hWin WM GetWindowRectEx hWin amp WinRect GUI MoveRect amp WinRect WinRect x0 WM GetUserData hWin amp MyWidget switch pMsg MsgId case WM PAINT if WM IsEnabled hWin if MyWidget Pressed ColorIndex MYWIDGET CI PRESSED els
5. 22 MYWIDGET GetUserData 14 24 MYWIDGET Handle eeeneennnne 12 MYWIDGET Obj eem 13 22 MYWIDGET SetUserData 15 24 ANO03002 Custom Widget Type Creation Guide N NumExtraBytes 13 O OVERVIEW SEENEN 10 R Requirements 2 eere 10 12 S Sample description 22 Syntax conventions used 5 T Typedef EE 22 typedef exe eve Rex e Pe n ql 12 Ww Widget handle 12 Widget specific callback function 18 Widget specific data sues 13 WM CreateWindowAsChild 12 WM GetUserData enn 13 WMHGSEIMEM ee es ouv Eng e Ree ovs 12 WM PAINT adds 18 WMSET FOCUS es deed EE 18 WM SetUserData enn 13 WM TOUCH ees dE REENEN 18 WWW Segger com aers irie ran Henne 9 2013 SEGGER Microcontroller GmbH amp Co KG 28 Index ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG
6. xSize ySize hWinParent Style pfCallback sizeof MYWIDGET Obj NumExtraBytes return hWin Warning The end user must not use the function WM_GetUserData or WM_SetUserData with a widget of a custom type as it is imple mented using this guide since he would either overwrite widget spe cific data or not retrieve the data he actually expects Therefor custom functions for these purposes have to be implemented as shown in the following AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 14 CHAPTER 2 Creating a custom widget type MYWIDGET_GetUserData Function description Copies the given number of bytes of user data to the destination buffer Implementation int MYWIDGET_GetUserData MYWIDGET_Handle hWin void pDest int SizeOfBuffer MYWIDGET Obj MyWidget int U8 if S ret WM_Ge pExtr if pl NumBytes pExtraBytes izeOfBuffer lt 0 urn 0 tUserData hWin amp MyWidget sizeof MYWIDGET_Obj aBytes U8 malloc sizeof MYWIDGET_Obj MyWidget NumExtraBytes ExtraBytes WM_GetUserData hWin pExtraBytes if sizeof MYWIDGET_Obj MyWidget NumExtraBytes SizeOfBuffer gt MyWidget NumExtraBytes NumBytes MyWidget NumExtraBytes je lse NumBytes SizeOfBuffer GUI MEMCPY pDest pExtraBytes sizeof MYWIDGET_Obj NumBytes free pExtraBytes return NumBy
7. 2013 SEGGER Microcontroller GmbH amp Co KG 17 2 6 Setting mandatory properties Assuming it is mandatory or at least usual for a button to display a text on top the function MYWIDGET_Create can be changed as follows MYWIDGET_Handle MYWIDGET Create int x0 int y0 int xSize int ySize WM_HWIN hWinParent U32 Style const char pText WM_CALLBACK pfCallback int NumExtraBytes MYWIDGET_Handle hWin MYWIDGET_Obj MyWidget hWin WM_CreateWindowAsChild x0 y0 xSize ySize hWinParent Style pfCallback sizeof MYWIDGET_Obj NumExtraBytes MYWIDGET Default NumExtraBytes MyWidget MyWidget NumExtraBytes if pText MyWidget pText pText WM SetUserData hWin amp MyWidget sizeof MYWIDGET_Obj return hWin MyWidget pText is set to pText after the default values were applied 2 7 Setting the callback function The last and most important part of implementing the Create function is setting the window to use the widget specific callback function Since the opportunity for the end user to implement a custom callback function has to be preserved it should be checked if a pointer to a custom callback function was passed MYWIDGET Handle MYWIDGET Create int x0 int y0 int xSize int ySize WM HWIN hWinParent U32 Style const char pText WM CALLBACK pfCallback int NumExtraBytes MYWIDGET Handle hWin MYWIDGET Obj MyWidget WM CALLBA
8. U8 Pressed GUI_COLOR aBkColor 3 GUI_COLOR aTextColor 3 GUI_COLOR FocusColor const char pText int NumExtraBytes 1 MYWIDGET Obj FERRERA kc tec RARE RAR RR EERE EER e RARA KERR ERE RRR HERE RR kkk k kk k kk k k RR k k k k k k k MYWIDGET Default const MYWIDGET Obj MYWIDGET Default 0 GUI DARKBLUE GUI LIGHTBLUE GUI GRAY GUI WHITE GUI DARKGRAY GUI LIGHTGRAY GUI ORANGE NULL 0 ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 23 FERRERA AR EE kkk kk kk kkk EEE e ke e kkk kkk kkk ARE UE KR RR RARA EERE RARA RR kk kkk kk X MYWIDGET Callback T void MYWIDGET Callback WM MESSAGE pMsg MYWIDGET Handle hWin GUI_PID_STATE pState MYWIDGET_Obj MyWidget GUI_RECT WinRect int ColorIndex hWin pMsg gt hWin WM_GetWindowRectEx hWin amp WinRect GUI_MoveRect amp WinRect WinRect x0 WinRect y0 WM GetUserData hWin amp MyWidget sizeof MYWIDGET_Obj switch pMsg MsgId case WM_PAINT if WM IsEnabled hWin if MyWidget Pressed ColorIndex MYWIDGET CI PRESSED else ColorIndex MYWIDGI Lj EE T CI UNPRESSI El D else ColorIndex MYWIDGET_CI_DISABLED GUI_SetColor MyWidget aBkColor ColorIndex GUI FillRectEx amp WinRect if WM HasFocus hWin GUI SetColor MyWidget FocusColor GUI DrawRectEx amp WinRect j G
9. fetched first void MYWIDGET Callback WM MESSAGE pMsg MYWIDGET Handle hWin MYWIDGET Obj MyWidget GUI RECT WinRect Ant ColorIndex hWin pMsg gt hWin if Get the window coordinates and widget specific data di WM GetWindowRectEx hWin amp WinRect GUI MoveRect amp WinRect WinRect x0 WinRect y0 WM GetUserData hWin amp MyWidget sizeof MYWIDGET Obj switch pMsg gt MsgId case WM PAINT Zeg Determine the color according to the current state if WM IsEnabled hWin if MyWidget Pressed ColorIndex MYWIDGET_CI_PRESSED else ColorIndex MYWIDGET_CI_UNPRESSED else ColorIndex MYWIDGET_CI_DISABLED Draw the background L GUI_SetColor MyWidget aBkColor ColorIndex GUI FillRectEx amp WinRect Draw the focus rectangle LE if WM_HasFocus hWin GUI_SetColor MyWidget FocusColor GUI DrawRectEx amp WinRect if Display the text hit GUI_SetColor MyWidget aTextColor ColorIndex GUI_SetTextMode GUI_TM_TRANS GUI_DispStringInRect MyWidget pText amp WinRect GUI_TA_HCENTER GUI_TA_VCENTER break default WM DefaultProc pMsg ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 19 At this point the code can be run and the widget can be recognized as a rectangle on the screen Since this is going to be a button one may expect a change
10. CK pfUsed if pfCallback pfUsed pfCallback else pfUsed MYWIDGET Callback hWin WM_CreateWindowAsChild x0 y0 xSize ySize hWinParent Style pfUsed sizeof MYWIDGET_Obj NumExtraBytes MyWidget MYWIDGET_Default MyWidget NumExtraBytes NumExtraBytes if pText MyWidget pText pText WM SetUserData hWin amp MyWidget sizeof MYWIDGET_Obj return hWin AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 18 CHAPTER 2 Creating a custom widget type 2 8 Widget specific callback function The callback function makes the user recognize the type of the widget It is responsi ble for drawing the widget as well as for reacting on other events like keyboard or touch events Since this guide deals with an example implementation for a custom button widget it is sufficient to deal with the message WM PAINT WM TOUCH and WM SET FOCUS A complete reference of messages as well as a detailed description on how the Win dow Manager s callback mechanism works can be found in the emWin user manual in chapter 15 The Window Manager The first step is using the starting point void MYWIDGET Callback WM MESSAGE pMsg switch pMsg MsgId default WM DefaultProc pMsg In order to have a visual impact on the widget a reaction to the wM PAINT message is implemented Since the colors to use are stored in the user data they have to be
11. IN hWinParent U32 Style const char pText WM CALLBACK pfCallback int NumExtraBytes MYWIDGET Handle hWin MYWIDGET_Obj MyWidget WM_CALLBACK pfUsed if pfCallback pfUsed pfCallback else pfUsed MYWIDGET_Callback MyWidget MyWidget NumExtraBytes if pText MyWidget pText pText MYWIDGET Default NumExtraBytes hWin WM_CreateWindowAsChild x0 y0 xSize ySize hWinParent Style pfUsed sizeof MYWIDGET_Obj NumExtraBytes WM SetUserData hWin amp MyWidget sizeof MYWIDGET_Obj return hWin 3 3 End user application RRR kk kk EKER kkk kkk kkk kkk RR RARE RAR k k k k kkk k k RR kkk k EER ER RAR k k k k k k k k k k cbMyWidget void cbMyWidget WM MESSAGE pMsg GUI_RECT WinRect char acText 20 0 switch pMsg gt MsgId case WM_PAINT MYWIDGET_Callback pMsg MYWIDGET_GetUserData pMsg gt hWin acText sizeof acText GUI_SetColor GUI_WHITE GUI_SetTextMode GUI_TM_TRANS WM_GetWindowRectEx pMsg gt hWin amp WinRect GUI MoveRect amp WinRect WinRect x0 WinRect y0 GUI DispStringInRect acText amp WinRect GUI TA HCENTER GUI TA VCENTER break default MYWIDGET Callback pMsg f kk ke kk kk RE RRA RARA RARA RAR kkk kkk kkk kkk kkk ck ck RARA RRA kkk kk kkk kk kkk k kkk MainTask St void MainTask void MYWIDGET_Handle hMyWidget char acExtraBytes
12. It assumes you have a working knowledge of the C language Knowledge of assembly program ming is not required Typographic conventions for syntax This manual uses the following typographic conventions Style Used for Body Body text opus Text that you enter at the command prompt or that appears on the display that is system functions file or pathnames Parameter Parameters in API functions Sample Sample code in program examples Change Changed sample code in program examples Sample comment Comments in program examples Reference to chapters sections tables and figures or other docu Reference ments GUIElement Buttons dialog boxes menu names menu commands Emphasis Very important sections Table 1 1 Typographic conventions ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG SEGGER Microcontroller GmbH amp Co KG develops and distributes software development tools and ANSI C software components middleware for embedded sys tems in several industries such as telecom medical b technology consumer electronics automotive industry SEGG ER and industrial automation SEGGER s intention is to cut software development time for embedded applications by offering compact flexible and easy to use middleware allowing developers to concentrate on their application Our most popular products are emWin a universal graphic software pa
13. UI SetColor MyWidget aTextColor ColorIndex GUI_SetTextMode GUI_TM_TRANS GUI DispStringInRect MyWidget pText amp WinRect GUI TA HCENTER GUI_TA_VCENTER break case WM TOUCH if pMsg Data p pState GUI PID STATE pMsg Data p if MyWidget Pressed pState gt Pressed MyWidget Pressed pState gt Pressed WM SetUserData hWin amp MyWidget sizeof MYWIDGET Obj if MyWidget Pressed WM SetFocus hWin WM InvalidateWindow hWin else MyWidget Pressed 0 WM SetUserData hWin amp MyWidget sizeof MYWIDGET Obj WM InvalidateWindow hWin j break case WM SET FOCUS if pMsg Data v pMsg gt Data v 0 WM_InvalidateWindow hWin break default WM_DefaultProc pMsg AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 24 CHAPTER 3 Example implementation fk kk kk kc ck ke EKER e ke ke REE RR ERE RARE RAR RARA RR RR kkk kkk kkk kkk kkk k ck RR kk kkk kk B MYWIDGET GetUserData m int MYWIDGET GetUserData MYWIDGET Handle hWin void pDest int SizeOfBuffer MYWIDGET Obj MyWidget int NumBytes U8 pExtraBytes if SizeOfBuffer lt 0 return 0 WM GetUserData hWin amp MyWidget sizeof MYWIDGET_Obj pExtraBytes U8 malloc sizeof MYWIDGET_Obj MyWidget NumExtraBytes pExtraBytes WM_GetUserData hWin pExtraBytes sizeof MYWIDGET_Obj MyWidget NumExtraBytes
14. ckage for embed ded applications and embOS a small yet efficient real time kernel emWin written entirely in ANSI C can easily be used on any CPU and most any display It is comple mented by the available PC tools Bitmap Converter Font Converter Simulator and Viewer embOS supports most 8 16 32 bit CPUs Its small memory footprint makes it suitable for single chip applications Apart from its main focus on software tools SEGGER develops and produces programming tools for flash micro controllers as well as J Link a JTAG emulator to assist in develop ment debugging and production which has rapidly become the industry standard for debug access to ARM cores Corporate Office United States Office http www segger com http www segger us com EMBEDDED SOFTWARE SEGGER TOOLS Middleware emWin Flasher Graphics software and GUI Flash programmer emWin is designed to provide an effi Flash Programming tool primarily for micro con cient processor and display control trollers ler independent graphical user interface GUI for any application that J Link operates with a graphical display JTAG emulator for ARM cores USB driven JTAG interface for ARM cores embOS Real Time Operating System J Trace EX embOS is an RTOS designed to offer JTAG emulator with trace LM the benefits of a complete multitasking USB driven JTAG interface for ARM cores with system for hard real time applications Trace memory supporting th
15. e CHAPTER 2 ColorIndex MYWIDGET CI UNPRESS else ColorIndex MYWIDGET CI DISABLED j Creating a custom widget type WinRect y0 sizeof MYWIDGET Obj GUI SetColor MyWidget aBkColor ColorIndex GUI FillRectEx amp WinRect if WM HasFocus hWin GUI SetColor MyWidget FocusColor GUI DrawRectEx amp WinRect GUI_SetColor MyWidget aTextColor ColorIndex GUI_SetTextMode GUI_TM_TRANS GUI_DispStringInRect MyWidget pText amp WinRect GUI_TA_HCENTER GUI_TA_VCENTER break case WM_TOUCH pState GUI_PID_STATE pMsg gt Data p if MyWidget Pressed pState gt Pressed MyWidget Pressed pState gt Pressed WM_SetUserData hWin amp MyWidget if MyWidget Pressed WM_SetFocus hWin WM_InvalidateWindow hWin break case WM_SET_FOCUS if pMsg gt Data v pMsg gt Data v 05 WM InvalidateWindow hWin break default WM DefaultProc pMsg pMsg gt Data v sizeof MYWIDGET_Obj 1 means that the widget receives the focus In order to let the Win dow Manager know that the focus was accepted the value has to be set to 0 Oth erwise the focus is not received Once the widget gains or loses the focus it should be invalidated so the appearance changes accordingly if it is intended to do so ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 21
16. e ARM ETM Embed with minimal resources ded Trace Macrocell embOS IP J Link J Trace Related Software TCP IP stack Add on software to be used with SEGGER s indus embOS IP a high performance TCP IP try standard JTAG emulator this includes flash stack that has been optimized for programming software and flash breakpoints speed versatility and a small memory footprint emFile ous Device drivers e g for NAND and NOR flashes SD MMC and Compact Flash cards are available USB Stack USB device host stack A USB stack designed to work on any embedded system with a USB control ler Bulk communication and most stan dard device classes are supported File system emFile is an embedded file system with FS FAT12 FAT16 and FAT32 support Vari b AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG Table of Contents 1 MEHTFOGEIOUOF ER 9 1 1 Requirements cuneate A sex tese eres taxat d ed eb CA waitin A 10 1 2 OVA WN iia tee MBA UN DG i Ee I RIP MEN NX I RE PR NEVER 10 2 Creating a custom widget Ivpe nemen nnne 11 2 1 e UE le En EE 12 2 2 Creating the WIN O Wovvinarinn dc Ed cc mena tu e ENNEN dee ee uen 12 2 3 Widget handle uiia etre eerte e ener veces n n ec ne en e a n ee cr a 12 2 4 Widget Specific data EE 13 2 5 Widget specific default properties ss 16 2 6 Setting mandatory properties cnn narran meme nnn nnn 17 2 7 Setting the callback function esee
17. e een hern kn e n E el a Se 17 2 8 Widget specific callback function 18 3 Example Implementar iia 21 3 1 Sample descriptio M A rennes 22 3 2 Internal So rce Code meea IA RUM o a S 22 3 3 End user application cise dd id 25 AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG Chapter 1 Introduction This document is intended to give a short and simple description on how to imple ment a custom emWin widget This guide deals with an example implementation of a button The used functions are explained by their meaning as it is necessary to understand the context A complete function reference can be found in the according chapter in the emWin user manual which can be downloaded at www segger com AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 10 CHAPTER 1 Introduction 1 1 Requirements In order to be able to use this document it is required to have a licensed copy of emWin This guide is written for emWin V5 20 but might be used for later versions as well Knowledge of the used emWin functions is not required since cross refer ences to the according function descriptions in the emWin user manual are included 1 2 Overview The actual task when implementing a custom widget is to provide the end user with the following e Create function which
18. emWin Window Manager Widgets Custom Widget Type Creation Guide Document ANO3002 Revision 0 Date September 6 2013 gt SEGGER A product of SEGGER Microcontroller GmbH amp Co KG www segger com Disclaimer Specifications written in this document are believed to be accurate but are not guar anteed to be entirely free of error The information in this manual is subject to change for functional or performance improvements without notice Please make sure your manual is the latest edition While the information herein is assumed to be accurate SEGGER Microcontroller GmbH amp Co KG SEGGER assumes no responsibil ity for any errors or omissions SEGGER makes and you receive no warranties or con ditions express implied statutory or in any communication with you SEGGER specifically disclaims any implied warranty of merchantability or fitness for a particu lar purpose Copyright notice You may not extract portions of this manual or modify the PDF file in any way without the prior written permission of SEGGER The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license 2013 SEGGER Microcontroller GmbH amp Co KG Hilden Germany Trademarks Names mentioned in this manual may be trademarks of their respective companies Brand and product names are trademarks or registered trademarks of their respec tive holders Con
19. if SizeOfBuffer gt MyWidget NumExtraBytes NumBytes MyWidget NumExtraBytes else NumBytes SizeOfBuffer Fh F GUI MEMCPY pDest pExtraBytes sizeof MYWIDGET_Obj NumBytes free pExtraBytes return NumBytes return 0 f kk kk ERE RR ERE KERR ERE RRE RRA RARA kkk kkk RRA RARA RR RR RRA AR ERR kkk kkk kkk k B MYWIDGET SetUserData gw int MYWIDGET SetUserData MYWIDGET Handle hWin void pSrc int SizeOfBuffer MYWIDGET Obj MyWidget int NumBytes U8 pExtraBytes if SizeOfBuffer lt 0 return 1 WM GetUserData hWin amp MyWidget sizeof MYWIDGET_Ob3 pExtraBytes U8 malloc sizeof MYWIDGET_Obj MyWidget NumExtraBytes if pExtraBytes WM_GetUserData hWin pExtraBytes sizeof MYWIDGET_Obj MyWidget NumExtraBytes if SizeOfBuffer gt MyWidget NumExtraBytes NumBytes MyWidget NumExtraBytes else NumBytes SizeOfBuffer GUI_MEMCPY pExtraBytes sizeof MYWIDGET_Obj pSrc NumBytes WM_SetUserData hWin pExtraBytes sizeof MYWIDGET_Obj MyWidget NumExtraBytes free pExtraBytes return 0 return 1 ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 25 FERRERA RARE RARE RR EEK EEE kk kkk kkk kkk kkk kkk kkk kkk kk kkk kkk kkk RR kk k k k kk MYWIDGET Create T MYWIDGET Handle MYWIDGET Create int x0 int y0 int xSize int ySize WM HW
20. returns a handle to the created widget and allows setting callback function e Set and Get functions to request and set widget specific properties e Callback function to process messages which were sent to the custom widget In the following chapters the custom function are prefixed MYWIDGET_ These func tion are the ones which are meant to be used by the end user ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG Chapter 2 Creating a custom widget type This chapter describes how to implement a custom type of widget This includes a function to create the widget a function to handle messages and functions to set and get widget specific properties AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 12 2 1 CHAPTER 2 Creating a custom widget type Requirements Since widgets are actually windows with enhanced functionality it is required to cre ate a window which is able to store additional data Depending on the actual type of widget to implement it might be good practice to add further parameters to the pro totype of the Create function in order to force the user to set up the widget in a certain way right from creation If a button widget has to be implemented and one might say that it is necessary to define a text which should be displayed on the button a pointer to a string might be added to the prototype 2 2 Creating the
21. ruct U8 Pressed GUI_COLOR aBkColor 3 GUI_COLOR aTextColor 3 GUI_COLOR FocusColor const char pText int NumExtraBytes MYWIDGET Obj The background and text colors were declared as arrays so the state of the widget can be distinguished by its visual appearance In later sections the following defines are used to access the color arrays according to the current state of the widget define MYWIDGET CI UNPRESSED define MYWIDGET CI PRESSED define MYWIDGET CI DISABLED Nro The included variables of the MywIDGET_Obj structure can be defined as it is required by the actual type of widget to implement The only variable which is required in every case is a variable to store the number of bytes which is defined by the end user at creation In this case it is called NumExtraBytes For the type of button widget which is implemented in this guide the contained variables are used to store the state the state specific colors and a pointer to a string This structure is going to be stored as user data Nevertheless the opportunity for the end user to attach data to the widget has to be preserved The function MYWIDGET_Create changes as follows MYWIDGET_Handle MYWIDGET_Create int x0 int y0 int xSize int ySize WM_HWIN hWinParent U32 Style WM_CALLBACK pfCallback int NumExtraBytes MYWIDGET_Handle hWin hWin WM_CreateWindowAsChild x0 y0
22. tact address SEGGER Microcontroller GmbH amp Co KG In den Weiden 11 D 40721 Hilden Germany Tel 49 2103 2878 0 Fax 49 2103 2878 28 E mail support segger com Internet http www segger com ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG Manual versions This manual describes the current software version If any error occurs inform us and we will try to assist you as soon as possible Contact us for further information on topics or routines not yet specified Print date September 6 2013 Revision Date By Description 0 130326 AS Initial version AN03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG About this document Assumptions This document assumes that you already have a solid knowledge of the following e The software tools used for building your application assembler linker C com piler e The C programming language e The target processor e DOS command line If you feel that your knowledge of C is not sufficient we recommend The C Program ming Language by Kernighan and Richie ISBN 0 13 1103628 which describes the standard in C programming and in newer editions also covers the ANSI C standard How to use this manual This manual explains all the functions and macros that the product offers
23. tes return 0 Parameter Description hWin Handle to the Widget pDest Pointer to the destination buffer SizeOfBuffer Size of the destination buffer Table 2 1 MYWIDGET GetUserData parameter list Return Numbe value r of copied bytes ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG MYWIDGET_SetU serData Function description 15 Sets the given number of bytes of the source buffer as user data Implementation int MYWIDGET_SetUserData MYWIDG MYWIDGET_Obj int U8 MyWidget NumBytes pExtraBytes if SizeOfBuffer 0 return 1 WM_GetUserData pExtraBytes if pExtraBytes WM_GetUserData hWin pExtraBytes if SizeOfBuffer gt MyWidget Num NumBytes else NumBytes GUI_MEMCPY pl ET Handle bin void pSrc int SizeOfBuffer hWin amp MyWidget sizeof MYWIDGET_Obj U8 malloc sizeof MYWIDGET Obj MyWidget NumExtraBytes sizeof MYWIDGET_Obj MyWidget NumExtraBytes MyWidget NumExtraBytes SizeOfBuffer ExtraBytes ExtraBytes sizeof MYWIDGET_Obj pSrc NumBytes WM_SetUserData hWin pExtraBytes sizeof MYWIDGET_Obj MyWidget NumExtraBytes free pExtraBytes return 0 return 1 Parameter Description hWin Handle to the Widget pSrc Pointer to the source buffer SizeOfBuffer Size ofthe source buffer
24. when it is clicked but nothing happens The reason is that the variable MyWidget Pressed is never changed so the widget is drawn the same way regardless the pressed state In order to update the state it is required to react to the message WM TOUCH void MYWIDGET Callback WM MESSAGE pMsg MYWIDGET Handle hWin GUI_PID_STATE pState MYWIDGET_Obj MyWidget GUI_RECT WinRect int ColorIndex hWin pMsg gt hWin WM_GetWindowRectEx hWin amp WinRect GUI MoveRect amp WinRect WinRect x0 WinRect y0 WM GetUserData hWin amp MyWidget sizeof MYWIDGET Obj switch pMsg MsgId case WM PAINT if WM IsEnabled hWin if MyWidget Pressed ColorIndex MYWIDGET CI PRESSED else ColorIndex MYWIDGI LE pu T CI UNPRESSI El D else ColorIndex MYWIDGET CI DISABLED GUI_SetColor MyWidget aBkColor ColorIndex GUI FillRectEx amp WinRect if WM HasFocus hWin GUI SetColor MyWidget FocusColor GUI DrawRectEx amp WinRect GUI_SetColor MyWidget aTextColor ColorIndex GUI_SetTextMode GUI_TM_TRANS GUI_DispStringInRect MyWidget pText amp WinRect GUI TA HCENTER GUI_TA_VCENTER break case WM_TOUCH if pMsg gt Data p pState GUI_PID_STATE pMsg gt Data p if MyWidget Pressed pState gt Pressed MyWidget Pressed pState gt Pressed WM SetUserData hWin amp MyWidget sizeof MYWIDGET_Obj if MyWidget Pressed
25. window The first and basic step is creating a simple window This can be done using the func tion WM_CreateWindowAsChild The prototype of this function can be copied and used for the custom create function MYWIDGET_Create WM HWIN MYWIDGET Create int x0 int y0 int xSize int ySize WM HWIN hWinParent U32 Style WM CALLBACK pfCallback int NumExtraBytes WM HWIN hWin hWin WM CreateWindowAsChild x0 y0 xSize ySize hWinParent Style pfCallback NumExtraBytes return hWin The parameters of the function MYWIDGET_Create are passed to the function WM_CreateWindowAsChild without any changes A detailed description of the func tion can be found in chapter 15 7 The Window Manager gt WM API in the emWin user manual 2 3 Widget handle To allow the end user to easily distinguish between widget types a specific type of handle can be defined typedef WM_HMEM MYWIDGET_Handle The prototype of the create function changes accordingly MYWIDGET Handle MYWIDGET Create int x0 int y0 int xSize int ySize WM HWIN hWinParent U32 Style WM CALLBACK pfCallback int NumExtraBytes ANO03002 Custom Widget Type Creation Guide 2013 SEGGER Microcontroller GmbH amp Co KG 2 4 Widget specific data To be able to implement widget specific functionality widget specific data has to be stored simple data structure should be sufficient as shown by the example below typedef st
Download Pdf Manuals
Related Search
AN03002_Custom_Widget_Type
Related Contents
JVC UX-L30 User's Manual Janvier 2012 - Groupe Jung Pololu - Pololu AVR Library Command Reference Imagem em PDF - Acervo User Manual Samsung HT-Z320 User Manual KOHLER K-7394-CP Installation Guide VT 200 Copyright © All rights reserved.
Failed to retrieve file