emWin Graphic Library with Graphical User Interface User & Reference Guide Document: UM03001 Software version: V5.20 Document revision: 2 Date: March 8, 2013 A product of SEGGER Microcontroller GmbH & Co. KG www.segger.com 2 CHAPTER Disclaimer Specifications written in this document are believed to be accurate, but are not guaranteed 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 & Co. KG (SEGGER) assumes no responsibility for any errors or omissions. SEGGER makes and you receive no warranties or conditions, express, implied, statutory or in any communication with you. SEGGER specifically disclaims any implied warranty of merchantability or fitness for a particular 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. (c) 1997 - 2013 SEGGER Microcontroller GmbH & 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 respective holders. Contact address SEGGER Microcontroller GmbH & 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 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: March 8, 2013 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 3 Software Rev. Date By Description 5.20 2 130308 AS Chapter 28 'Language Support' - New function GUI_LANG_GetTextBuffered() added. - New function GUI_LANG_GetTextBufferedEx() added. 5.20 1 130305 AS Chapter 19 'Skinning' - New function CHECKBOX_GetSkinFlexButtonSize() added. - New function CHECKBOX_SetSkinFlexButtonSize() added. JE Chapter 25 'Sprites' - New function GUI_SPRITE_CreateHidden() added. - New function GUI_SPRITE_CreateHiddenEx() added. Chapter 29 'Display Drivers' GUIDRV_FlexColor: - Support for Himax HX8340 added to 66712. - New module 66772 added wit support for: Hitachi HD66772, Samsung S6D0117, Sitronix ST7712, Himax HX8301, Ilitek ILI9220 and ILI9221 GUIDRV_SLin: - Support for Epson S1D13305 added. Chapter 30 'VNC-Server' - New function GUI_VNC_SetLockFrame() added. Chapter 32 'Timing and execution' - New function GUI_Error() added. Chapter 34 'Configuration' - New function GUI_SetOnErrorFunc() added. Chapter 25 'Sprites' - New function GUI_SPRITE_CreateHidden() added. - New function GUI_SPRITE_CreateHiddenEx() added. Chapter 29 'Display Drivers' GUIDRV_FlexColor: - Support for Himax HX8340 added to 66712. - New module 66772 added wit support for: Hitachi HD66772, Samsung S6D0117, Sitronix ST7712, Himax HX8301, Ilitek ILI9220 and ILI9221 GUIDRV_SLin: - Support for Epson S1D13305 added. Chapter 30 'VNC-Server' - New function GUI_VNC_SetLockFrame() added. Chapter 32 'Timing and execution' - New function GUI_Error() added. Chapter 34 'Configuration' - New function GUI_SetOnErrorFunc() added. 5.20 0 130218 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 4 CHAPTER Software Rev. Date By Description 5.18 0 120917 JE AS Chapter 8 'Displaying bitmap files' - New function GUI_BMP_SerializeExBpp() added. Chapter 9 'Bitmap Converter' - New functions added to create animated sprites and cursors out of animated GIF files. Chapter 13 'Memory Devices' - New function GUI_MEMDEV_SerializeBMP() added. Chapter 15 'The Window Manager (WM)' New function WM_SetCaptureMove() added. New function WM_Screen2hWin() added. New function WM_Screen2hWinEx() added. Chapter 16 'Window Objects (Widgets)' - New functions added: TEXT_GetText() LISTVIEW_SetWrapMode() Chapter 27 'Antialiasing' - New function GUI_AA_SetDrawMode() added. Chapter 28 'Foreign Language Support' - New feature "Text- and language resource files" added. Chapter 29 'Display drivers' GUIDRV_FlexColor: - Function GUIDRV_FlexColor_SetInterface66709_B16() replaced by the function GUIDRV_FlexColor_SetReadFunc66709_B16(). - Function GUIDRV_FlexColor_SetInterface66720_B16() replaced by the function GUIDRV_FlexColor_SetReadFunc66720_B16(). - New module 66702 added: Solomon SSD1284, SSD1289, SSD1298 - New module 66715 added: Himax HX8352B - Recommended calling sequence for configuration functions added. GUIDRV_S1D13781: - Additional information about initialized registers added. 5.16 2 120809 AS Chapter 16 'Window Objects (Widgets)' - New function SPINBOX_SetRange() added. Various corrections. AS Chapter 15 'The Window Manager (WM)' Descriptions of the following functions reworked: - WM_GetScrollPosH() - WM_GetScrollPosV() - WM_SetScrollPosH() - WM_SetScrollPosV() Preface, About and Chapter 1 'Intro' reworked. JE AS Chapter 12 'Colors' - New color conversion routine added to support 1bpp at different color depths. Chapter 13 'Memory Devices' - New function GUI_MEMDEV_RotateHQT() added. 5.16 5.16 1 0 120628 120605 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 5 Software Rev. 5.16 0 Date 120605 By JE AS Description Chapter 15 'The Window Manager (WM)' - Support for ToolTips added. - New functions added: WM_TOOLTIP_AddTool() WM_TOOLTIP_Create() WM_TOOLTIP_Delete() WM_TOOLTIP_SetDefaultFont() WM_TOOLTIP_SetDefaultColor() WM_TOOLTIP_SetDefaultPeriod() Chapter 16 'Window Objects (Widgets)' - New functions added: BUTTON_SetReactOnTouch() DROPDOWN_SetUpMode() ICONVIEW_EnableStreamAuto() - Changed function SPINBOX_SetButtonSize(): New option SPINBOX_EDGE_CENTER. Chapter 17 'Dialogs' - CHOOSECOLOR dialog and functions added: CHOOSECOLOR_Create() CHOOSECOLOR_GetSel() CHOOSECOLOR_SetSel() CHOOSECOLOR_SetDefaultColor() CHOOSECOLOR_SetDefaultSpace() CHOOSECOLOR_SetDefaultBorder() CHOOSECOLOR_SetDefaultButtonSize() - CHOOSEFILE dialog and functions added: CHOOSEFILE_Create() CHOOSEFILE_EnableToolTips() CHOOSEFILE_SetButtonText() CHOOSEFILE_SetDefaultButtonText() CHOOSEFILE_SetToolTips() CHOOSEFILE_SetTopMode() Chapter 23 'Pointer Input Devices' - New function GUI_PID_IsPressed() added. Chapter 24 'Keyboard Input' - New function GUI_GetKeyState() added. Chapter 28 'Foreign Language Support' - New function GUI_LANG_GetNumItems() added. - New function GUI_LANG_GetText() added. - New function GUI_LANG_GetTextEx() added. - New function GUI_LANG_LoadCSV() added. - New function GUI_LANG_LoadCSVEx() added. - New function GUI_LANG_LoadText() added. - New function GUI_LANG_LoadTextEx() added. - New function GUI_LANG_SetLang() added. - New function GUI_LANG_SetMaxNumLang() added. - New function GUI_LANG_SetSep() added. Chapter 29 'Display drivers' - New display controller supported by GUIDRV_SPage: GUIDRV_SPage_Set1510: Epson S1D15605, S1D15606, S1D15607, S1D15608, S1D15705, S1D15710, S1D15714 Integrated Solutions Technology IST3020 New Japan Radio Company NJU6676 Novatek NT7502, NT7534, NT7538, NT75451 Samsung S6B0719, S6B0713, S6B0724, S6B1713 Sino Wealth SH1101A Sitronix ST7522, ST7565, ST7567 Solomon SSD1303, SSD1805, SSD1815, SSD1821 Sunplus SPLC501C UltraChip UC1608, UC1701, UC1601, UC1606 GUIDRV_SPage_Set1512: Epson S1D15E05, S1D15E06, S1D15719, S1D15721 GUIDRV_SPage_SetST7591: Sitronix ST7591 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 6 CHAPTER Software Rev. 5.16 5.14 0 3 Date 120605 120202 By Description JE AS Chapter 29 'Display drivers' - New display controllers supported by GUIDRV_FlexColor: 66708: Ilitek ILI9335 66709: Ilitek ILI9338, ILI9340, ILI9341, ILI9342 66719: Samsung S6E63D6 - New function LCD_SetMaxNumColors() added. - Support for 1bpp added to GUIDRV_SPage. - Function GUIDRV_SPage_SetS1D15() obsolete Replaced by GUIDRV_SPage_Set1512 - New variants GUIDRV_Lin added: GUIDRV_LIN_OX_8 GUIDRV_LIN_OXY_8 - New driver GUIDRV_S1D13781 added. New chapter 'Touch drivers' (30) added. - New driver GUITDRV_ADS7846 added. AS Chapter 29 'Display drivers' - New display controller supported by GUIDRV_FlexColor: 66709: Ilitek ILI9340 - New display controllers supported by GUIDRV_SPage: Epson S1D15605, S1D15606, S1D15607, S1D15608, S1D15705, S1D15710, S1D15714 Integrated Solutions Technology IST3020 New Japan Radio Company NJU6676 Novatek NT7502, NT7534, NT7538, NT75451 Samsung S6B0719, S6B0713, S6B0724, S6B1713 Sino Wealth SH1101A Sitronix ST7522, ST7565, ST7567 Solomon SSD1805, SSD1303, SSD1815 UltraChip UC1608, UC1701, UC1601, UC1606 Sunplus SPLC501C - New function GUIDRV_SPage_Set1510 added. - New function GUIDRV_SPage_Set1512 added. 5.14 2 120201 AS Chapter 8 'Displaying bitmaps files' - Improved description of how the 'GetData'-function is used by emWin. Chapter 29 'Display drivers' - GUIDRV_SPage now supports 1bpp. - New display controllers supported by GUIDRV_SPage: Epson S1D15E05, S1D15E06, S1D15719, S1D15721 Sitronix ST7591 - New function GUIDRV_SPage_SetST7591 added. 5.14 1 120124 AS Chapter 16 'Window Objects (Widgets)' - New function EDIT_GetTextColor(). - New function SPINBOX_GetEditHandle(). JE AS Chapter 3 'Simulation' - New function SIM_GUI_Enable() added. Chapter 7 '2D Graphic Library' - New functions added: GUI_DrawStreamedBitmapAuto() GUI_DrawStreamedBitmapExAuto() GUI_DrawStreamedBitmap24Ex() GUI_DrawStreamedBitmap555Ex() GUI_DrawStreamedBitmap565Ex() GUI_DrawStreamedBitmapM555Ex() GUI_DrawStreamedBitmapM565Ex() Chapter 11 'Font Converter' - Functions to size, shift and move characters added. Chapter 12 'Colors' - Sub chapter 'Gamma correction' added. 5.14 0 120111 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 7 Software Rev. 5.14 5.12 5.12 0 1 0 Date 120111 111021 110621 By Description JE AS Chapter 15 'The Window Manager (WM)' - Change of the WM_MOVE message to transmit position changes. - New functions added: WM_MOTION_Enable() WM_MOTION_SetMovement() WM_MOTION_SetDeceleration() WM_MOTION_SetDefaultPeriod() WM_MOTION_SetMotion() WM_MOTION_SetMoveable() WM_MOTION_SetSpeed() Chapter 16 'Window Objects (Widgets)' - New widget "SPINBOX" added. - New widget "IMAGE" added. - Return values added to the following functions: BUTTON_SetText() TEXT_SetText() - New function DROPDOWN_GetItemText() added. - New function EDIT_GetBkColor() added. - New function EDIT_SetBkColor() added. - New function EDIT_SetFocussable() added. - New function EDIT_GetFont() added. - New function GUI_EditFloat() added. - Listing of widget IDs added. Chapter 25 'Sprites' - New function GUI_SPRITE_CreateAnim() added. - New function GUI_SPRITE_CreateExAnim() added. Chapter 26 'Cursors' - New function GUI_CURSOR_SelectAnim() added. Chapter 29 'Display drivers' - New display controllers supported by GUIDRV_FlexColor: 66708: FocalTech FT1509 66709: Renesas R61526 66709: Ilitek ILI9342 66712: Himax HX8347 66712: Himax HX8352 - New display controllers supported by GUIDRV_CompactColor_16: 66708: FocalTech FT1509 66709: Renesas R61526 66709: Ilitek ILI9342 AS Font Converter documentation added as chapter 11. - New function GUIDRV_FlexColor_SetFunc66712() added. - New function GUIDRV_FlexColor_SetInterface66712B16() added. - New display controller supported by GUIDRV_07X1: 741: Novatek NT7508 - New display controller supported by GUIDRV_Page1bpp: 1510: Solomon SSD1821 - GUIDRV_Lin 'Using the Lin driver in systems with cache memory' changed. AS JE Chapter 16 'Window Objects (Widgets)' - New function LISTVIEW_SetHeaderHeight() added. - New function ICONVIEW_AddStreamedBitmapItem() added. - New function ICONVIEW_GetItemText() added. - New function ICONVIEW_GetItemUserData() added. - New function ICONVIEW_GetNumItems() added. - New function ICONVIEW_InsertBitmapItem() added. - New function ICONVIEW_InsertStreamedBitmapItem() added. - New function ICONVIEW_SetBitmapItem() added. - New function ICONVIEW_SetFrame() added. - New function ICONVIEW_SetItemText() added. - New function ICONVIEW_SetItemUserData() added. - New function ICONVIEW_SetSpace() added. - New function ICONVIEW_SetStreamedBitmapItem() added. - New function ICONVIEW_SetTextAlign() added. - New function TEXT_GetNumLines() added. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 8 CHAPTER Software Rev. Date By Description 5.12 0 110621 AS JE Chapter 29 'Display Drivers' - New display drivers added: GUIDRV_Dist GUIDRV_SPage - New display controller supported by GUIDRV_CompactColor_16: 66709: Solomon SSD1961 - LCD_SetDevFunc(): LCD_DEVFUNC_COPYRECT added. - GUIDRV_Lin: Support for LCD_DEVFUNC_COPYRECT added. 5.10 1 110531 AS JE Chapter 29 'Display Drivers - New display driver: GUIDRV_FlexColor AS JE Chapter 13 'Memory Devices' - Default for GUI_USE_MEMDEV_1BPP_FOR_SCREEN set to 1. - New function GUI_MEMDEV_MarkDirty() added. New Chapter 18 'GUIBuilder' added. Chapter 29 'Display Drivers' - New display controllers supported by GUIDRV_CompactColor_16: 66708: Ilitek ILI9328 66709: Sitronix ST7715 66772: Ilitek ILI9221 - New function GUIDRV_BitPlains_Config() added. AS JE Chapter 9 '2D Graphic Library' - New function GUI_CreateBitmapFromStreamRLEAlpha() added. - New function GUI_CreateBitmapFromStreamRLE32() added. - Function GUI_CreateBitmapFromStream() supports additional formats. Chapter 12 'Bitmap Converter' - New format 'Alpha channel, compressed' added. - New format 'True color with alpha channel, compressed' added. - New function 'Image/Convert Into/Best Palette + transparency' added. Chapter 14 'Memory Devices' - New functions GUI_MEMDEV_SetAnimationCallback() added. - New functions GUI_MEMDEV_ShiftInWindow() added. - New functions GUI_MEMDEV_ShiftOutWindow() added. Chapter 15 'Execution Model' - New function GUI_SetSignalEventFunc() added. - New function GUI_SetWaitEventFunc() added. - New function GUI_SetWaitEventTimedFunc() added. - Definitions of configuration macros changed. Chapter 16 'Window Manager' - New function WM_MULTIBUF_Enable() added. - New messages WM_PRE_PAINT and WM_POST_PAINT added. Chapter 17 'Widgets' - LISTVIEW_SetUserData() renamed in LISTVIEW_SetUserDataRow(). - LISTVIEW_GetUserData() renamed in LISTVIEW_GetUserDataRow(). - New function _SetUserData() added for all widgets. - New function _GetUserData() added for all widgets. - New function _CreateUser() added for all widgets. - New function BUTTON_GetTextAlign() added. - New function BUTTON_SetReactOnLevel() added. - New function ICONVIEW_CreateIndirect() added. - New function ICONVIEW_DeleteItem() added. - New function LISTWHEEL_CreateIndirect() added. - New function SCROLLBAR_SetThumbSizeMin() added. - New function SCROLLBAR_GetThumbSizeMin() added. - New function TREEVIEW_ITEM_CollapseAll() added. - New function TREEVIEW_ITEM_ExpandAll() added. 5.10 5.08 0 0 110329 110112 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 9 Software Rev. 5.08 5.06 5.04 0 0 2 Date 110112 100907 100526 By Description AS JE Chapter 19 'Skinning' - New configuration macro WIDGET_USE_FLEX_SKIN added. - New message WIDGET_ITEM_GET_RADIUS added to frame window skin. Chapter 20 'Multiple buffering'. - New function GUI_MULTIBUF_Begin() added. - New function GUI_MULTIBUF_End() added. - New function GUI_MULTIBUF_Config() added. Chapter 28 'Foreign Language Support' - New function GUI_UC_EnableBIDI() added. JE Chapter 9 'Fonts': - New function GUI_SetDefaultFont() added. Chapter 12 'Memory Devices': - New function GUI_MEMDEV_FadeDevices() added. Chapter 15 'Widgets': - New functions added: BUTTON_SetReactOnLevel() GRAPH_DATA_XY_SetOwnerDraw() LISTVIEW_SetItemBitmap() LISTWHEEL_SetPos() SCROLLBAR_GetNumItems() SCROLLBAR_GetPageSize() New chapter 17 'Skinning': - Skinning for the most common widgets added. Chapter 26 'Display Driver': - New function GUI_SetOrientation() added. - New OXY-orientations for 16, 24 and 32 bpp added to GUIDRV_Lin. AS Chapter 'Widgets': - New function GRAPH_DATA_XY_SetOwnerDraw() added. - New function LISTVIEW_SetItemBitmap() added. Chapter 'Fonts': - New function GUI_SetDefaultFont() added. Chapter '2-D Graphic Library': - New function GUI_GetPixelIndex() added. Chapter 'Execution Model': GUITASK_SetMaxTask() - GUIDRV_CompactColor_16: Support for the following display controllers added: Himax HX8353 LGDP4551 Orisetech SPFD54124C Renesas R61505 Sitronix ST7735, ST7787 Solomon SSD1284, SSD2119 - Added driver macros to each driver which uses them. 5.04 1 100505 AS New Drivers 'GUIDRV_S1D15G00' and 'GUIDRV_SLin' added. Various corrections Chapter '2-D Graphic Library': - New function GUI_DrawGradientRoundedV() - New function GUI_DrawGradientRoundedH() - New function GUI_DrawRoundedFrame() Chapter 'Memory Devices': - New function GUI_MEMDEV_MoveInWindow() - New function GUI_MEMDEV_MoveOutWindow() - New function GUI_MEMDEV_FadeInWindow() - New function GUI_MEMDEV_FadeOutWindow() Chapter 'Simulation' - New function SIM_GUI_SetCallback() - New function SIM_GUI_ShowDevice() 5.04 0 100104 JE Chapter 5 'Displaying Text': - New function GUI_DispStringInRectWrap() added. - New function GUI_WrapGetNumLines() added. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 10 CHAPTER Software Rev. Date By Description 5.04 0 100104 JE Chapter 7 '2-D Graphic Library': - New function GUI_EnableAlpha() added. - New function GUI_RestoreUserAlpha() added. - New function GUI_SetUserAlpha() added. - New function GUI_CreateBitmapFromStream() added. - New function GUI_DrawStreamedBitmapEx() added. - New function GUI_GetStreamedBitmapInfo() added. - New function GUI_GetStreamedBitmapInfoEx() added. - New function GUI_SetStreamedBitmapHook() added. - New function GUI_CreateBitmapFromStreamIDX() added. - New function GUI_CreateBitmapFromStreamRLE4() added. - New function GUI_CreateBitmapFromStreamRLE8() added. - New function GUI_CreateBitmapFromStream565() added. - New function GUI_CreateBitmapFromStreamM565() added. - New function GUI_CreateBitmapFromStream555() added. - New function GUI_CreateBitmapFromStreamM555() added. - New function GUI_CreateBitmapFromStreamRLE16() added. - New function GUI_CreateBitmapFromStreamRLEM16() added. - New function GUI_CreateBitmapFromStream24() added. - New function GUI_CreateBitmapFromStreamAlpha() added. Chapter 9 'Fonts': - New font F20F_ASCII (framed) added. - New fonts F6x8_ASCII and F6x8_1 added. - New fonts F8x8_ASCII and F8x8_1 added. - New fonts F8x16_ASCII and F8x16_1 added. - Support for new font formats extended AA2 and extended AA4 added. Chapter 12 'Memory Devices': - Considerations for multiple layers/displays added. Chapter 14 'Window Manager': - WM_DeleteWindow() now also deletes any associated timer. Chapter 15 'Widgets': - New function WINDOW_SetBkColor() added. Chapter 19 'Pointer Input Devices': - PID buffer added. - Explanation of touch calibration revised. Chapter 20 'Keyboard': - Keyboard buffer added. Chapter 25 'Display Driver': - New driver GUIDRV_BitPlains added. - New driver GUIDRV_SLin added. - New driver GUIDRV_SSD1926 added. - Driver GUIDRV_1611 added. - Driver GUIDRV_6331 added. - Driver GUIDRV_7529 added. - Driver GUIDRV_Page1bpp added. - GUIDRV_CompactColor_16: Support for the following display controllers added: Himax HX8340, HX8352 Solomon SSD1298, SSD1355, SSD1963 Epson S1D19122 Orisetech SPFD5414D Ilitek ILI9320, ILI9326 Chapter 26 'VNC Server': - New function GUI_VNC_EnableKeyboardInput() - New function GUI_VNC_GetNumConnections() - New function GUI_VNC_SetPassword() - New function GUI_VNC_SetProgName() - New function GUI_VNC_SetSize() - New function GUI_VNC_RingBell() 5.00 1 090409 JE Chapter 3 'Simulator': - Completely revised. Chapter 8 'Displaying bitmap files' - PNG support added. 5.00 0 090326 JE Software has been completely revised. For the version history of earlier versions, refer to older documents. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 11 About this document Assumptions This document assumes that you already have a solid knowledge of the following: * * * * The software tools used for building your application (assembler, linker, C compiler) The C programming language The target processor DOS command line If you feel that your knowledge of C is not sufficient, we recommend The C Programming 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. It assumes you have a working knowledge of the C language. Knowledge of assembly programming is not required. Typographic conventions for syntax This manual uses the following typographic conventions: Style Used for Body Body text. Keyword 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 Example code in program examples. Sample comment Comments in program examples. New Example Example code that has been added to an existing program example. Reference Reference to chapters, sections, tables and figures or other documents. GUIElement Buttons, dialog boxes, menu names, menu commands. Warning Important cautions or reminders. Emphasis Very important sections. Table 0.1: Typographic conventions UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 12 SEGGER Microcontroller GmbH & Co. KG develops and distributes software development tools and ANSI C software components (middleware) for embedded systems in several industries such as telecom, medical technology, consumer electronics, automotive industry 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 package for embedded 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 complemented 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 development, debugging and production, which has rapidly become the industry standard for debug access to ARM cores. Corporate Office: http://www.segger.com EMBEDDED SOFTWARE (Middleware) emWin Graphics software and GUI emWin is designed to provide an efficient, processor- and display controller-independent graphical user interface (GUI) for any application that operates with a graphical display. embOS Real Time Operating System embOS is an RTOS designed to offer the benefits of a complete multitasking system for hard real time applications with minimal resources. embOS/IP TCP/IP stack embOS/IP a high-performance TCP/IP stack that has been optimized for speed, versatility and a small memory footprint. United States Office: http://www.segger-us.com SEGGER TOOLS Flasher Flash programmer Flash Programming tool primarily for micro controllers. J-Link JTAG emulator for ARM cores USB driven JTAG interface for ARM cores. J-Trace JTAG emulator with trace USB driven JTAG interface for ARM cores with Trace memory. supporting the ARM ETM (Embedded Trace Macrocell). J-Link / J-Trace Related Software Add-on software to be used with SEGGER's industry standard JTAG emulator, this includes flash programming software and flash breakpoints. emFile File system emFile is an embedded file system with FAT12, FAT16 and FAT32 support. Various Device drivers, e.g. for NAND and NOR flashes, SD/MMC and CompactFlash cards, are available. USB-Stack USB device/host stack A USB stack designed to work on any embedded system with a USB controller. Bulk communication and most standard device classes are supported. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 13 Table of Contents 1 Introduction to emWin ....................................................................................................29 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.5 1.6 1.7 1.8 Purpose of this document ......................................................................... 29 Requirements.......................................................................................... 29 Target system (hardware) ........................................................................ 29 Development environment (compiler)......................................................... 30 Features................................................................................................. 30 Examples and demos ............................................................................... 31 Starter kits ............................................................................................. 31 Screen and coordinates ............................................................................ 32 How to connect the display to the micro controller ....................................... 32 Data types.............................................................................................. 33 2 Getting Started...............................................................................................................35 2.1 2.1.1 2.1.2 2.2 2.3 2.3.1 2.4 2.5 2.6 2.7 2.8 Recommended project structure ................................................................ 36 Subdirectories ......................................................................................... 36 Include directories ................................................................................... 36 Adding emWin to the target program ......................................................... 37 Creating a library..................................................................................... 37 Adapting the library batch files to a different system .................................... 38 C files to include in the project .................................................................. 39 Configuring emWin .................................................................................. 40 Initializing emWin .................................................................................... 40 Using emWin with target hardware ............................................................ 41 The "Hello world" example program ........................................................... 42 3 Simulation ......................................................................................................................43 3.1 3.1.1 3.1.1.1 3.1.1.2 3.1.1.3 3.1.1.4 3.1.2 3.1.2.1 3.1.2.2 3.1.2.3 3.1.3 3.1.3.1 3.1.3.2 3.1.3.3 3.2 3.2.1 3.2.2 3.2.3 3.3 3.4 3.4.1 3.5 3.5.1 3.5.2 Using the simulation ................................................................................ 44 Using the simulation with the trial version of emWin..................................... 44 Directory structure................................................................................... 44 Visual C++ workspace.............................................................................. 44 Compiling the demo program .................................................................... 45 Compiling the examples ........................................................................... 45 Using the simulation with the emWin source................................................ 46 Directory structure................................................................................... 46 Visual C++ workspace.............................................................................. 46 Compiling the application.......................................................................... 47 Advanced features of the simulation........................................................... 47 Pause and Resume .................................................................................. 47 View system info ..................................................................................... 47 Copy to clipboard .................................................................................... 47 Device simulation .................................................................................... 48 Generated frame view .............................................................................. 49 Custom bitmap view ................................................................................ 49 Window view........................................................................................... 50 Device simulation API............................................................................... 51 Hardkey simulation .................................................................................. 56 Hardkey simulation API ............................................................................ 57 Integrating the emWin simulation into an existing simulation......................... 60 Directory structure................................................................................... 60 Using the simulation library....................................................................... 60 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 14 3.5.2.1 3.5.2.2 3.5.3 3.5.3.1 3.5.3.2 3.5.4 Modifying WinMain .................................................................................. 60 Example application................................................................................. 61 Integration into the embOS Simulation....................................................... 62 WinMain................................................................................................. 62 Target program (main) ............................................................................ 64 GUI simulation API .................................................................................. 65 4 Viewer ............................................................................................................................69 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 Using the viewer ..................................................................................... 70 Using the simulation and the viewer .......................................................... 70 Using the viewer with virtual pages ........................................................... 71 Always on top ......................................................................................... 71 Open further windows of the display output ................................................ 71 Zooming ................................................................................................ 71 Copy the output to the clipboard ............................................................... 72 Using the viewer with multiple displays ...................................................... 73 Using the viewer with multiple layers ......................................................... 73 5 Displaying Text ..............................................................................................................75 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 Basic routines ......................................................................................... 76 Text API................................................................................................. 77 Routines to display text............................................................................ 78 Selecting text drawing modes ................................................................... 85 Selecting text alignment........................................................................... 87 Setting the current text position ................................................................ 89 Retrieving the current text position............................................................ 90 Routines to clear a window or parts of it..................................................... 90 6 Displaying Values ..........................................................................................................91 6.1 6.2 6.3 6.4 6.5 6.6 Value API ............................................................................................... 92 Displaying decimal values......................................................................... 93 Displaying floating point values ................................................................. 97 Displaying binary values..........................................................................100 Displaying hexadecimal values .................................................................101 Version of emWin ...................................................................................102 7 2-D Graphic Library......................................................................................................103 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 7.10 7.11 7.12 7.13 7.14 7.15 7.16 7.17 Graphic API ...........................................................................................104 Drawing modes......................................................................................107 Query current client rectangle ..................................................................108 Pen size ................................................................................................109 Basic drawing routines ............................................................................110 Alpha blending.......................................................................................116 Drawing bitmaps ....................................................................................119 Drawing streamed bitmaps ......................................................................122 Drawing lines.........................................................................................129 Drawing polygons...................................................................................133 Drawing circles ......................................................................................138 Drawing ellipses.....................................................................................139 Drawing arcs .........................................................................................140 Drawing graphs .....................................................................................142 Drawing pie charts .................................................................................143 Saving and restoring the GUI-context .......................................................144 Clipping ................................................................................................145 8 Displaying bitmap files .................................................................................................147 8.1 8.1.1 8.1.2 BMP file support .....................................................................................148 Supported formats .................................................................................148 BMP file API...........................................................................................148 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 15 8.2 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.3.4 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.5 JPEG file support ................................................................................... 155 Supported JPEG compression methods ..................................................... 155 Converting a JPEG file to C source............................................................ 155 Displaying JPEG files .............................................................................. 155 Memory usage ...................................................................................... 156 Progressive JPEG files ............................................................................ 156 JPEG file API ......................................................................................... 156 GIF file support ..................................................................................... 161 Converting a GIF file to C source ............................................................. 161 Displaying GIF files ................................................................................ 161 Memory usage ...................................................................................... 161 GIF file API ........................................................................................... 162 PNG file support .................................................................................... 170 Converting a PNG file to C source ............................................................ 170 Displaying PNG files ............................................................................... 170 Memory usage ...................................................................................... 170 PNG file API .......................................................................................... 170 Getting data with the ...Ex() functions ...................................................... 174 9 Bitmap Converter .........................................................................................................177 9.1 9.2 9.2.1 9.2.2 9.2.3 9.3 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.5.6 9.6 9.7 9.8 9.9 9.9.1 9.9.2 9.10 What it does ......................................................................................... 178 Loading a bitmap................................................................................... 179 Supported input file formats.................................................................... 179 Loading from a file................................................................................. 179 Using the clipboard ................................................................................ 179 Color conversion.................................................................................... 180 Using a custom palette ........................................................................... 181 Saving a palette file ............................................................................... 181 Palette file format .................................................................................. 181 Palette files for fixed palette modes.......................................................... 181 Converting a bitmap .............................................................................. 182 Generating C files from bitmaps............................................................... 182 Supported bitmap formats ...................................................................... 182 Palette information ................................................................................ 182 Transparency ........................................................................................ 183 Alpha blending ...................................................................................... 183 Selecting the best format........................................................................ 184 Saving the file ....................................................................................... 185 Generating C stream files ....................................................................... 186 Compressed bitmaps.............................................................................. 187 Creating animated sprites / cursors.......................................................... 187 Command line usage.............................................................................. 190 Format for commands ............................................................................ 190 Valid command line options..................................................................... 190 Example of a converted bitmap ............................................................... 192 10 Fonts ..........................................................................................................................195 10.1 10.2 10.3 10.3.1 10.3.2 10.3.3 10.3.4 10.3.5 10.4 10.5 10.6 10.7 10.8 Introduction.......................................................................................... 196 Font types ............................................................................................ 196 Font formats ......................................................................................... 198 C file format ......................................................................................... 198 System Independent Font (SIF) format..................................................... 198 External Bitmap Font (XBF) format .......................................................... 199 iType font engine support ....................................................................... 200 TrueType Font (TTF) format .................................................................... 201 Converting a TTF file to C source ............................................................. 202 Declaring custom fonts ........................................................................... 202 Selecting a font ..................................................................................... 202 Font API ............................................................................................... 203 C file related font functions ..................................................................... 204 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 16 10.9 10.10 10.11 10.12 10.13 10.13.1 10.13.2 10.13.3 10.14 10.14.1 10.15 10.15.1 10.15.2 10.15.3 10.15.4 10.15.4.1 10.15.4.2 10.15.4.3 10.15.5 10.15.5.1 10.15.5.2 10.15.5.3 10.15.6 10.15.6.1 10.15.6.2 10.15.6.3 10.15.7 10.15.7.1 10.15.7.2 10.15.7.3 10.15.8 10.15.8.1 10.15.8.2 10.15.8.3 'SIF' file related font functions..................................................................205 'TTF' file related font functions .................................................................207 'XBF' file related font functions.................................................................210 Common font-related functions ................................................................212 Character sets .......................................................................................216 ASCII ...................................................................................................216 ISO 8859-1 Western Latin character set ....................................................216 Unicode ................................................................................................218 Font Converter.......................................................................................219 Adding fonts ..........................................................................................219 Standard fonts.......................................................................................220 Font identifier naming convention.............................................................220 Font file naming convention .....................................................................221 Measurement, ROM-size and character set of fonts .....................................221 Proportional fonts...................................................................................222 Overview ..............................................................................................222 Measurement, ROM size and used files ......................................................222 Characters ............................................................................................224 Proportional fonts, framed .......................................................................230 Overview ..............................................................................................230 Measurement, ROM size and used files ......................................................230 Characters ............................................................................................230 Monospaced fonts ..................................................................................231 Overview ..............................................................................................231 Measurement, ROM size and used files ......................................................232 Characters ............................................................................................233 Digit fonts (proportional).........................................................................238 Overview ..............................................................................................238 Measurement, ROM size and used files ......................................................238 Characters ............................................................................................238 Digit fonts (monospaced) ........................................................................240 Overview ..............................................................................................240 Measurement, ROM size and used files ......................................................240 Characters ............................................................................................240 11 Font Converter ...........................................................................................................243 11.1 11.2 11.2.1 11.2.2 11.2.2.1 11.2.2.2 11.2.2.3 11.2.3 11.2.3.1 11.2.3.2 11.2.3.3 11.2.4 11.2.4.1 11.2.4.2 11.2.4.3 11.2.4.4 11.2.4.5 11.2.4.6 11.3 11.3.1 11.3.1.1 11.3.1.2 11.3.1.3 11.3.2 11.3.3 Requirements ........................................................................................244 Using the Font Converter.........................................................................245 Creating an emWin font file from a Windows font .......................................245 Font generation options dialog .................................................................247 Type of font to generate..........................................................................247 Encoding...............................................................................................248 Antialiasing ...........................................................................................248 Font Dialog............................................................................................248 Font, Font Style, and Size .......................................................................249 Script ...................................................................................................249 Unit of Size ...........................................................................................249 User Interface........................................................................................249 Selecting the current character ................................................................249 Toggling character status ........................................................................249 Selecting pixels......................................................................................250 Modifying character bits ..........................................................................250 Operations ............................................................................................250 Modifying the viewing mode ....................................................................251 Options.................................................................................................251 Saving the font ......................................................................................252 Creating a C file .....................................................................................252 Creating a System Independent Font (SIF) ................................................253 Creating an External Binary Font (XBF) .....................................................253 Modifying an existing C font file................................................................254 Merging fonts with existing C font files ......................................................255 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 17 11.4 11.4.1 11.4.2 11.4.3 11.5 11.5.1 11.5.2 11.6 11.6.1 11.6.2 11.7 11.7.1 11.8 11.9 11.10 Pattern files .......................................................................................... 256 Creating pattern files using Notepad......................................................... 256 Creating pattern files using the Font Converter .......................................... 256 Enabling characters using a pattern file .................................................... 256 Supported output modes ........................................................................ 256 Standard mode ..................................................................................... 257 Antialiased modes.................................................................................. 257 Command line options............................................................................ 258 Table of commands................................................................................ 258 Execution examples ............................................................................... 259 Font Examples ...................................................................................... 260 Resulting C code, standard mode ............................................................. 260 Resulting C code, 2 bpp antialiased mode ................................................. 261 Resulting C code, 4 bpp antialiased mode ................................................. 262 Resulting C code, extended mode ............................................................ 263 12 Colors.........................................................................................................................265 12.1 12.2 12.3 12.4 12.5 12.6 12.7 12.8 12.8.1 12.8.2 Predefined colors ................................................................................... 266 The color bar test routine ....................................................................... 266 Fixed palette modes............................................................................... 267 Detailed fixed palette mode description .................................................... 268 Application defined color conversion ......................................................... 279 Custom palette mode ............................................................................. 280 Gamma correction ................................................................................. 280 Color API .............................................................................................. 281 Basic color functions .............................................................................. 282 Index & color conversion ........................................................................ 284 13 Memory Devices ........................................................................................................287 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 13.10 13.10.1 13.11 13.12 13.13 13.14 13.15 13.16 13.17 Using Memory Devices: an illustration ...................................................... 288 Supported color depth (bpp) ................................................................... 288 Memory Devices and the Window Manager ................................................ 289 Memory Devices and multiple layers......................................................... 289 Memory requirements ............................................................................ 289 Performance ......................................................................................... 290 Basic functions ...................................................................................... 291 In order to be able to use Memory Devices................................................ 291 Multi layer / multi display configurations ................................................... 291 Configuration options ............................................................................. 291 GUI_USE_MEMDEV_1BPP_FOR_SCREEN ................................................... 291 Memory device API ................................................................................ 292 Basic functions ...................................................................................... 293 Banding Memory Device ......................................................................... 307 Auto device object ................................................................................. 308 Measurement device object..................................................................... 311 Animation functions ............................................................................... 313 Animation functions (Window Manager required)........................................ 314 14 Execution Model: Single Task / Multitask ..................................................................319 14.1 14.2 14.2.1 14.2.2 14.2.3 14.2.4 14.2.5 14.2.6 14.3 14.3.1 14.3.2 Supported execution models ................................................................... 320 Single task system (superloop)................................................................ 320 Description ........................................................................................... 320 Superloop example (without emWin) ........................................................ 320 Advantages........................................................................................... 320 Disadvantages ...................................................................................... 320 Using emWin......................................................................................... 320 Superloop example (with emWin) ............................................................ 321 Multitask system: one task calling emWin ................................................. 321 Description ........................................................................................... 321 Advantages........................................................................................... 321 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 18 14.3.3 14.3.4 14.4 14.4.1 14.4.2 14.4.3 14.4.4 14.4.5 14.4.6 14.5 14.6 14.7 14.7.1 Disadvantages .......................................................................................321 Using emWin .........................................................................................321 Multitask system: multiple tasks calling emWin ..........................................322 Description............................................................................................322 Advantages ...........................................................................................322 Disadvantages .......................................................................................322 Using emWin .........................................................................................322 Recommendations ..................................................................................322 Example ...............................................................................................322 Configuration functions for multitasking support .........................................323 Configuration macros for multitasking support ...........................................325 Kernel interface API................................................................................326 Examples ..............................................................................................329 15 The Window Manager (WM) ......................................................................................331 15.1 15.2 15.2.1 15.2.2 15.2.3 15.2.4 15.2.5 15.2.6 15.2.7 15.2.8 15.2.9 15.2.10 15.3 15.3.1 15.3.2 15.3.2.1 15.3.2.2 15.3.3 15.3.3.1 15.4 15.4.1 15.4.2 15.4.2.1 15.4.2.2 15.5 15.5.1 15.5.2 15.5.3 15.5.4 15.5.5 15.5.6 15.6 15.7 15.7.1 15.8 15.9 15.10 15.11 15.12 15.13 15.14 Description of terms ...............................................................................332 Callback mechanism, invalidation, rendering and keyboard input ..................333 Rendering without callbacks.....................................................................333 Rendering using callbacks .......................................................................334 Overwriting callback functions..................................................................334 Background window redrawing and callback...............................................335 Invalidation ...........................................................................................336 Rendering of transparent windows ............................................................336 Automatic use of memory devices ............................................................336 Automatic use of multiple frame buffers ....................................................336 Automatic use of display driver cache .......................................................337 Keyboard input ......................................................................................337 Motion support.......................................................................................337 Enabling motion support of the WM ..........................................................337 Basic motion support for a window ...........................................................337 Using creation flags ................................................................................337 Using API function ..................................................................................337 Advanced motion support ........................................................................338 WM_MOTION message and WM_MOTION_INFO..........................................338 ToolTips ................................................................................................339 How they work.......................................................................................339 Creating ToolTips ...................................................................................339 Creating ToolTips for dialog items.............................................................339 Creating ToolTips for simple windows........................................................340 Messages ..............................................................................................340 Message structure ..................................................................................340 List of messages ....................................................................................341 System-defined messages .......................................................................342 Pointer input device (PID) messages .........................................................346 System-defined notification codes ............................................................350 Application-defined messages ..................................................................350 Configuration options..............................................................................351 WM API.................................................................................................352 Using the WM API functions .....................................................................354 WM API: Basic functions..........................................................................355 WM API: Motion support..........................................................................385 WM API: ToolTip related functions ............................................................389 WM API: Memory device support (optional) ...............................................392 WM API: Timer related functions ..............................................................393 WM API: Widget related functions.............................................................395 Example ...............................................................................................399 16 Window Objects (Widgets).........................................................................................401 16.1 16.1.1 Some basics ..........................................................................................402 Available widgets ...................................................................................402 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 19 16.1.2 16.1.3 16.2 16.3 16.4 16.4.1 16.4.2 16.4.3 16.5 16.5.1 16.5.2 16.5.3 16.5.4 16.5.5 16.5.6 16.6 16.6.1 16.6.2 16.6.3 16.6.4 16.6.5 16.6.6 16.7 16.7.1 16.7.2 16.7.3 16.7.4 16.7.5 16.7.6 16.8 16.8.1 16.8.2 16.8.3 16.8.4 16.8.5 16.8.6 16.9 16.9.1 16.9.2 16.9.3 16.9.4 16.9.5 16.10 16.10.1 16.10.2 16.10.3 16.10.4 16.10.4.1 16.10.4.2 16.10.5 16.10.5.1 16.10.5.2 16.10.6 16.10.7 16.10.8 16.10.8.1 16.10.8.2 16.10.8.3 16.10.8.4 16.10.9 16.11 Understanding the redrawing mechanism.................................................. 403 How to use widgets................................................................................ 403 Configuration options ............................................................................. 405 Widget IDs ........................................................................................... 406 General widget API ................................................................................ 406 WM routines used for widgets.................................................................. 406 Common routines .................................................................................. 406 User drawn widgets ............................................................................... 410 BUTTON: Button widget.......................................................................... 412 Configuration options ............................................................................. 412 Predefined IDs ...................................................................................... 413 Notification codes .................................................................................. 413 Keyboard reaction ................................................................................. 413 BUTTON API ......................................................................................... 413 Examples ............................................................................................. 426 CHECKBOX: Checkbox widget ................................................................. 428 Configuration options ............................................................................. 428 Predefined IDs ...................................................................................... 429 Notification codes .................................................................................. 429 Keyboard reaction ................................................................................. 429 CHECKBOX API...................................................................................... 429 Example ............................................................................................... 443 DROPDOWN: Dropdown widget ............................................................... 444 Configuration options ............................................................................. 444 Predefined IDs ...................................................................................... 445 Notification codes .................................................................................. 445 Keyboard reaction ................................................................................. 445 DROPDOWN API .................................................................................... 445 Example ............................................................................................... 458 EDIT: Edit widget .................................................................................. 459 Configuration options ............................................................................. 459 Predefined IDs ...................................................................................... 459 Notification codes .................................................................................. 459 Keyboard reaction ................................................................................. 460 EDIT API .............................................................................................. 460 Examples ............................................................................................. 477 FRAMEWIN: Frame window widget ........................................................... 478 Structure of the frame window ................................................................ 479 Configuration options ............................................................................. 480 Keyboard reaction ................................................................................. 480 FRAMEWIN API...................................................................................... 480 Example ............................................................................................... 501 GRAPH: Graph widget ............................................................................ 502 Structure of the graph widget.................................................................. 502 Creating and deleting a graph widget ....................................................... 503 Drawing process .................................................................................... 503 Supported types of curves ...................................................................... 503 GRAPH_DATA_XY .................................................................................. 504 GRAPH_DATA_YT................................................................................... 504 Configuration options ............................................................................. 504 Graph widget ........................................................................................ 504 Scale object .......................................................................................... 504 Predefined IDs ...................................................................................... 504 Keyboard reaction ................................................................................. 504 GRAPH API ........................................................................................... 504 Common routines .................................................................................. 506 GRAPH_DATA_YT related routines............................................................ 514 GRAPH_DATA_XY related routines............................................................ 518 Scale related routines ............................................................................ 522 Examples ............................................................................................. 527 HEADER: Header widget ......................................................................... 528 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 20 16.11.1 16.11.2 16.11.3 16.11.4 16.11.5 16.12 16.12.1 16.12.2 16.12.3 16.12.4 16.12.5 16.12.6 16.13 16.13.1 16.13.2 16.13.3 16.14 16.14.1 16.14.2 16.14.3 16.14.4 16.14.5 16.14.6 16.15 16.15.1 16.15.2 16.15.3 16.15.4 16.15.5 16.15.6 16.16 16.16.1 16.16.2 16.16.3 16.16.4 16.16.5 16.17 16.17.1 16.17.2 16.17.3 16.17.4 16.17.5 16.17.6 16.18 16.18.1 16.18.2 16.18.3 16.18.4 16.18.5 16.18.6 16.19 16.19.1 16.19.2 16.19.3 16.19.4 16.19.5 16.19.6 16.20 16.20.1 16.20.2 16.20.3 Configuration options..............................................................................529 Notification codes...................................................................................529 Keyboard reaction ..................................................................................529 HEADER API ..........................................................................................529 Example ...............................................................................................541 ICONVIEW: Icon view widget ...................................................................542 Configuration options..............................................................................542 Predefined IDs .......................................................................................543 Notification codes...................................................................................543 Keyboard reaction ..................................................................................543 ICONVIEW API .......................................................................................543 Example ...............................................................................................555 IMAGE: Image widget .............................................................................556 Configuration options..............................................................................556 Predefined IDs .......................................................................................556 IMAGE API ............................................................................................556 LISTBOX: List box widget ........................................................................559 Configuration options..............................................................................559 Predefined IDs .......................................................................................559 Notification codes...................................................................................559 Keyboard reaction ..................................................................................560 LISTBOX API .........................................................................................560 Examples ..............................................................................................576 LISTVIEW: Listview widget ......................................................................577 Configuration options..............................................................................578 Predefined IDs .......................................................................................578 Notification codes...................................................................................578 Keyboard reaction ..................................................................................579 LISTVIEW API ........................................................................................579 Example ...............................................................................................601 LISTWHEEL: Listwheel widget ..................................................................602 Configuration options..............................................................................602 Predefined IDs .......................................................................................602 Notification codes...................................................................................602 Keyboard reaction ..................................................................................603 LISTWHEEL API......................................................................................603 MENU: Menu widget ...............................................................................616 Menu messages .....................................................................................617 Data structures ......................................................................................618 Configuration options..............................................................................618 Keyboard reaction ..................................................................................619 MENU API .............................................................................................619 Example ...............................................................................................633 MULTIEDIT: Multi line text widget.............................................................634 Configuration options..............................................................................634 Predefined IDs .......................................................................................635 Notification codes...................................................................................635 Keyboard reaction ..................................................................................635 MULTIEDIT API ......................................................................................635 Example ...............................................................................................645 MULTIPAGE: Multiple page widget ............................................................646 Configuration options..............................................................................647 Predefined IDs .......................................................................................647 Notification codes...................................................................................647 Keyboard reaction ..................................................................................647 MULTIPAGE API .....................................................................................647 Example ...............................................................................................659 PROGBAR: Progress bar widget ................................................................660 Configuration options..............................................................................660 Predefined IDs .......................................................................................660 Keyboard reaction ..................................................................................660 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 21 16.20.4 16.20.5 16.21 16.21.1 16.21.2 16.21.3 16.21.4 16.21.5 16.21.6 16.22 16.22.1 16.22.2 16.22.3 16.22.4 16.22.5 16.22.6 16.23 16.23.1 16.23.2 16.23.3 16.23.4 16.23.5 16.23.6 16.24 16.24.1 16.24.2 16.24.3 16.24.4 16.24.5 16.24.6 16.25 16.25.1 16.25.2 16.25.3 16.25.4 16.25.5 16.26 16.26.1 16.26.2 16.26.3 16.26.4 16.26.5 16.26.6 16.26.6.1 16.26.6.2 16.26.7 16.27 16.27.1 16.27.2 16.27.3 PROGBAR API ....................................................................................... 660 Examples ............................................................................................. 665 RADIO: Radio button widget ................................................................... 666 Configuration options ............................................................................. 666 Predefined IDs ...................................................................................... 667 Notification codes .................................................................................. 667 Keyboard reaction ................................................................................. 667 RADIO API............................................................................................ 667 Examples ............................................................................................. 677 SCROLLBAR: Scroll bar widget................................................................. 678 Configuration options ............................................................................. 678 Predefined IDs ...................................................................................... 678 Notification codes .................................................................................. 678 Keyboard reaction ................................................................................. 678 SCROLLBAR API .................................................................................... 679 Example ............................................................................................... 686 SLIDER: Slider widget ............................................................................ 688 Configuration options ............................................................................. 688 Predefined IDs ...................................................................................... 688 Notification codes .................................................................................. 688 Keyboard reaction ................................................................................. 688 SLIDER API........................................................................................... 689 Example ............................................................................................... 694 SPINBOX: Spinning box widget................................................................ 695 Configuration options ............................................................................. 696 Predefined IDs ...................................................................................... 697 Notification codes .................................................................................. 697 Keyboard reaction ................................................................................. 697 SPINBOX API ........................................................................................ 697 Example ............................................................................................... 704 TEXT: Text widget ................................................................................. 705 Configuration options ............................................................................. 705 Predefined IDs ...................................................................................... 705 Keyboard reaction ................................................................................. 705 TEXT API .............................................................................................. 705 Examples ............................................................................................. 711 TREEVIEW: Treeview widget ................................................................... 712 Description of terms............................................................................... 713 Configuration options ............................................................................. 714 Predefined IDs ...................................................................................... 714 Notification codes .................................................................................. 714 Keyboard reaction ................................................................................. 715 TREEVIEW API ...................................................................................... 715 Common routines .................................................................................. 716 Item related routines ............................................................................. 728 Example ............................................................................................... 733 WINDOW: Window widget....................................................................... 735 Configuration options ............................................................................. 735 Keyboard reaction ................................................................................. 735 WINDOW API ........................................................................................ 735 17 Dialogs .......................................................................................................................737 17.1 17.2 17.2.1 17.2.2 17.2.2.1 17.2.2.2 17.3 17.4 17.4.1 Dialog basics......................................................................................... 738 Creating a dialog ................................................................................... 739 Resource table ...................................................................................... 739 Dialog procedure ................................................................................... 739 Initializing the dialog.............................................................................. 740 Defining dialog behavior ......................................................................... 741 Dialog API ............................................................................................ 743 Common dialogs.................................................................................... 745 CALENDAR............................................................................................ 745 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 22 17.4.1.1 17.4.1.2 17.4.1.3 17.4.2 17.4.2.1 17.4.2.2 17.4.2.3 17.4.3 17.4.3.1 17.4.3.2 17.4.3.3 17.4.3.4 17.4.4 17.4.4.1 17.4.4.2 17.4.4.3 Notification codes...................................................................................745 Keyboard reaction ..................................................................................745 CALENDAR API.......................................................................................746 CHOOSECOLOR......................................................................................751 Notification codes...................................................................................751 Keyboard reaction ..................................................................................751 CHOOSECOLOR API ................................................................................751 CHOOSEFILE .........................................................................................756 Configuration options..............................................................................756 Keyboard reaction ..................................................................................756 File- and path names ..............................................................................756 CHOOSEFILE API....................................................................................756 MESSAGEBOX........................................................................................763 Configuration options..............................................................................763 Keyboard reaction ..................................................................................763 MESSAGEBOX API ..................................................................................763 18 GUIBuilder .................................................................................................................765 18.1 18.2 18.3 18.3.1 18.3.2 18.3.3 18.3.4 18.3.5 18.3.6 18.4 18.5 18.6 18.7 Introduction ..........................................................................................766 Getting started ......................................................................................767 Creating a dialog....................................................................................768 Selecting a parent widget ........................................................................768 Resizing and positioning in the editor ........................................................768 Modifying the widget properties................................................................768 Adding additional functions to a widget .....................................................768 Deleting a widget property ......................................................................769 Deleting a widget ...................................................................................769 Saving the current dialog(s) ....................................................................770 Output of the GUIBuilder.........................................................................771 Modifying the C files ...............................................................................773 How to use the C files .............................................................................773 19 Skinning .....................................................................................................................775 19.1 19.2 19.3 19.4 19.4.1 19.4.2 19.5 19.6 19.6.1 19.6.2 19.6.3 19.7 19.8 19.8.1 19.8.2 19.8.3 19.8.4 19.9 19.9.1 19.9.2 19.9.3 19.9.4 19.10 19.10.1 19.10.2 19.10.3 19.10.4 What is a 'skin'?.....................................................................................776 From using API functions to skinning ........................................................776 Skinnable widgets ..................................................................................777 Using a skin ..........................................................................................777 Runtime configuration.............................................................................778 Compile time configuration ......................................................................778 Simple changes to the look of the 'Flex' skin ..............................................778 Major changes to the look of the 'Flex' skin................................................779 The skinning callback mechanism .............................................................779 Changing the look of the default skin ........................................................779 List of commands ...................................................................................780 General skinning API ..............................................................................782 BUTTON_SKIN_FLEX...............................................................................785 Configuration structure ...........................................................................785 Configuration options..............................................................................785 Skinning API..........................................................................................786 List of commands ...................................................................................787 CHECKBOX_SKIN_FLEX...........................................................................788 Configuration structure ...........................................................................788 Configuration options..............................................................................788 Skinning API..........................................................................................789 List of commands ...................................................................................791 DROPDOWN_SKIN_FLEX .........................................................................793 Configuration structure ...........................................................................793 Configuration options..............................................................................794 Skinning API..........................................................................................794 List of commands ...................................................................................795 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 23 19.11 19.11.1 19.11.2 19.11.3 19.11.4 19.12 19.12.1 19.12.2 19.12.3 19.12.4 19.13 19.13.1 19.13.2 19.13.3 19.13.4 19.14 19.14.1 19.14.2 19.14.3 19.14.4 19.15 19.15.1 19.15.2 19.15.3 19.15.4 19.16 19.16.1 19.16.2 19.16.3 19.16.4 19.17 19.17.1 19.17.2 19.17.3 19.17.4 FRAMEWIN_SKIN_FLEX .......................................................................... 796 Configuration structure........................................................................... 796 Configuration options ............................................................................. 797 Skinning API ......................................................................................... 797 List of commands .................................................................................. 798 HEADER_SKIN_FLEX .............................................................................. 801 Configuration structure........................................................................... 801 Configuration options ............................................................................. 801 Skinning API ......................................................................................... 802 List of commands .................................................................................. 802 PROGBAR_SKIN_FLEX ............................................................................ 804 Configuration structure........................................................................... 804 Configuration options ............................................................................. 804 Skinning API ......................................................................................... 805 List of commands .................................................................................. 805 RADIO_SKIN_FLEX ................................................................................ 808 Configuration structure........................................................................... 808 Configuration options ............................................................................. 809 Skinning API ......................................................................................... 809 List of commands .................................................................................. 810 SCROLLBAR_SKIN_FLEX ......................................................................... 812 Configuration structure........................................................................... 812 Configuration options ............................................................................. 813 Skinning API ......................................................................................... 813 List of commands .................................................................................. 814 SLIDER_SKIN_FLEX ............................................................................... 817 Configuration structure........................................................................... 817 Configuration options ............................................................................. 818 Skinning API ......................................................................................... 818 List of commands .................................................................................. 819 SPINBOX_SKIN_FLEX............................................................................. 821 Configuration structure........................................................................... 821 Configuration options ............................................................................. 822 Skinning API ......................................................................................... 822 List of commands .................................................................................. 823 20 Multiple buffering........................................................................................................825 20.1 20.1.1 20.1.2 20.2 20.3 20.4 20.4.1 20.4.2 20.5 20.6 How it works......................................................................................... 826 Double buffering.................................................................................... 826 Triple buffering...................................................................................... 826 Requirements........................................................................................ 827 Limitations............................................................................................ 827 Configuration ........................................................................................ 827 LCD_X_Config() .................................................................................... 827 LCD_X_DisplayDriver()........................................................................... 828 Automatic use of multiple buffers with the WM .......................................... 829 Multiple buffer API ................................................................................. 830 21 Virtual screens / Virtual pages ...................................................................................835 21.1 21.2 21.3 21.4 21.4.1 21.4.2 21.4.3 21.5 Introduction.......................................................................................... 836 Requirements........................................................................................ 836 Configuration ........................................................................................ 837 Examples ............................................................................................ 837 Basic example ....................................................................................... 837 Real time example using the Window Manager........................................... 839 Dialog example using the Window Manager ............................................... 840 Virtual screen API .................................................................................. 842 22 Multi layer / multi display support...............................................................................843 22.1 Introduction.......................................................................................... 844 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 24 22.1.1 22.1.2 22.1.2.1 22.2 22.2.1 22.2.2 22.2.3 22.2.4 22.3 22.3.1 22.3.2 22.3.3 22.4 22.5 22.6 Selecting a layer for drawing operations ....................................................844 Selecting a layer for a window .................................................................844 Moving a window from one layer to an other ..............................................845 Using multi layer support ........................................................................847 Transparency.........................................................................................847 Alpha blending.......................................................................................848 Hardware cursors ...................................................................................849 Multi layer example ................................................................................849 Using multi display support......................................................................849 Enabling multi display support .................................................................849 Run-time screen rotation.........................................................................850 Multi display example .............................................................................850 Configuring multi layer support ................................................................850 Configuring multi display support .............................................................851 Multi layer API .......................................................................................851 23 Pointer Input Devices.................................................................................................855 23.1 23.2 23.3 23.3.1 23.3.2 23.3.2.1 23.3.2.2 23.4 23.4.1 23.4.2 23.4.2.1 23.4.2.2 23.4.2.3 23.4.2.4 23.4.2.5 23.5 Description............................................................................................856 Pointer input device API ..........................................................................856 Mouse driver .........................................................................................858 Generic mouse API .................................................................................858 PS2 mouse driver ...................................................................................859 Using the PS2 mouse driver.....................................................................859 PS2 mouse driver API .............................................................................859 Touch screen driver ................................................................................860 Generic touch screen API ........................................................................860 The analog touch screen driver ................................................................861 Setting up the analog touch screen...........................................................862 Runtime calibration ................................................................................864 Hardware routines..................................................................................864 Driver API for analog touch screens ..........................................................866 Configuring the analog touch-screen driver ................................................867 Joystick input example............................................................................868 24 Keyboard Input...........................................................................................................869 24.1 24.1.1 24.1.2 Description............................................................................................870 Driver layer API .....................................................................................871 Application layer API...............................................................................872 25 Sprites........................................................................................................................875 25.1 25.2 Introduction ..........................................................................................876 Sprite API .............................................................................................876 26 Cursors ......................................................................................................................883 26.1 26.2 Available cursors ....................................................................................884 Cursor API ............................................................................................885 27 Antialiasing.................................................................................................................889 27.1 27.1.1 27.1.2 27.1.3 27.2 27.3 27.4 27.5 Introduction ..........................................................................................890 Quality of antialiasing .............................................................................890 Antialiased Fonts....................................................................................890 High-resolution coordinates .....................................................................891 Antialiasing API......................................................................................892 Control functions....................................................................................892 Drawing functions ..................................................................................893 Examples ..............................................................................................897 28 Language Support .....................................................................................................903 28.1 Unicode ................................................................................................904 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 25 28.1.1 28.1.2 28.1.3 28.1.3.1 28.1.4 28.1.4.1 28.1.4.2 28.2 28.2.1 28.2.2 28.2.3 28.2.4 28.2.5 28.2.6 28.3 28.3.1 28.3.2 28.3.3 28.3.4 28.3.5 28.3.6 28.3.7 28.4 28.4.1 28.4.2 28.4.3 28.4.4 28.5 28.5.1 UTF-8 encoding ..................................................................................... 904 Unicode characters ................................................................................ 905 UTF-8 strings ........................................................................................ 905 Using U2C.exe to convert UTF-8 text into C code ....................................... 905 Unicode API .......................................................................................... 906 UTF-8 functions ..................................................................................... 906 Double byte functions ............................................................................ 909 Text- and language resource files ............................................................ 910 Unicode support .................................................................................... 910 Loading files from RAM ........................................................................... 910 Loading files from non addressable areas .................................................. 910 Rules for CSV files ................................................................................. 910 Rules for text files ................................................................................. 910 Text- and language resource file API ........................................................ 911 Arabic support....................................................................................... 916 Notation forms ...................................................................................... 916 Ligatures .............................................................................................. 917 Bidirectional text alignment..................................................................... 917 Requirements........................................................................................ 918 How to enable Arabic support .................................................................. 918 Example ............................................................................................... 918 Font files used with Arabic text ................................................................ 918 Thai language support............................................................................ 919 Requirements........................................................................................ 919 How to enable Thai support..................................................................... 919 Example ............................................................................................... 919 Font files used with Thai text................................................................... 919 Shift JIS support ................................................................................... 920 Creating Shift JIS fonts .......................................................................... 920 29 Display drivers ...........................................................................................................921 29.1 29.1.1 29.1.2 29.1.3 29.1.4 29.1.5 29.2 29.2.1 29.2.2 29.2.2.1 29.2.3 29.2.3.1 29.2.4 29.2.4.1 29.2.5 29.2.5.1 29.3 29.3.1 29.3.2 29.3.2.1 29.3.2.2 29.4 29.5 29.5.1 29.5.1.1 29.5.1.2 29.5.2 29.6 29.6.1 29.7 Available display drivers ......................................................................... 922 Driver file naming convention .................................................................. 922 Run-time configurable drivers ................................................................. 923 Compile-time configurable drivers............................................................ 924 Available, but not yet migrated drivers ..................................................... 925 Special purpose drivers .......................................................................... 925 CPU / Display controller interface............................................................. 926 Direct interface ..................................................................................... 926 Indirect interface - Parallel bus ................................................................ 926 Example routines for connection to I/O pins .............................................. 927 Indirect interface - 4 pin SPI ................................................................... 927 Example routines for connection to I/O pins .............................................. 927 Indirect interface - 3 pin SPI ................................................................... 927 Example routines for connection to I/O pins .............................................. 928 Indirect interface - I2C bus ..................................................................... 928 Example routines for connection to I/O pins .............................................. 928 Hardware interface configuration ............................................................. 929 Direct interface ..................................................................................... 929 Indirect interface ................................................................................... 929 Run-time configuration ........................................................................... 929 Compile-time configuration ..................................................................... 931 Non readable displays ............................................................................ 934 Display orientation................................................................................. 934 Driver based configuration of display orientation ........................................ 934 Run-time configuration ........................................................................... 934 Compile-time configuration ..................................................................... 934 Function based configuration of display orientation..................................... 935 Display driver callback function ............................................................... 937 Commands passed to the callback function ............................................... 937 Detailed display driver descriptions .......................................................... 939 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 26 29.7.1 29.7.2 29.7.3 29.7.4 29.7.5 29.7.6 29.7.7 29.7.8 29.7.9 29.7.10 29.7.11 29.7.12 29.7.13 29.7.14 29.7.15 29.7.16 29.7.17 29.7.18 29.7.19 29.7.20 29.8 29.8.1 29.8.2 29.8.2.1 29.8.2.2 29.8.2.3 GUIDRV_BitPlains...................................................................................939 GUIDRV_DCache ....................................................................................942 GUIDRV_Dist .........................................................................................944 GUIDRV_FlexColor..................................................................................946 GUIDRV_IST3088...................................................................................958 GUIDRV_Lin ..........................................................................................960 GUIDRV_S1D13748 ................................................................................964 GUIDRV_S1D13781 ................................................................................967 GUIDRV_S1D15G00 ...............................................................................970 GUIDRV_SLin ........................................................................................973 GUIDRV_SPage......................................................................................977 GUIDRV_SSD1926 .................................................................................983 GUIDRV_CompactColor_16......................................................................986 GUIDRV_Fujitsu_16................................................................................991 GUIDRV_Page1bpp.................................................................................993 GUIDRV_07X1 .......................................................................................996 GUIDRV_1611 .......................................................................................999 GUIDRV_6331 .....................................................................................1002 GUIDRV_7529 .....................................................................................1004 GUIDRV_Template - Template for a new driver ........................................ 1007 LCD layer and display driver API ............................................................1008 Display driver API ................................................................................1008 LCD layer routines................................................................................1009 "Get" group ......................................................................................... 1009 Configuration group.............................................................................. 1012 Cache group ........................................................................................1016 30 VNC Server..............................................................................................................1017 30.1 30.1.1 30.1.2 30.2 30.2.1 30.3 30.3.1 30.3.2 30.3.3 30.4 30.5 30.6 Introduction ........................................................................................1018 Requirements ...................................................................................... 1018 Notes on this implementation ................................................................ 1018 The VNC viewer ................................................................................... 1019 How to use the VNC viewer ................................................................... 1019 emWin VNC server ...............................................................................1020 Starting the emWin VNC server.............................................................. 1020 How the server starts... ........................................................................ 1020 Integration of the VNC server on the target ............................................. 1020 Requirements ...................................................................................... 1020 Configuration options............................................................................ 1021 VNC Server API.................................................................................... 1021 31 Touch drivers ...........................................................................................................1025 31.1 GUITDRV_ADS7846.............................................................................. 1026 32 Timing- and execution-related functions ..................................................................1029 32.1 Timing and execution API ...................................................................... 1030 33 Performance and Resource Usage..........................................................................1033 33.1 33.1.1 33.1.2 33.2 33.2.1 33.2.2 33.3 Performance ........................................................................................1034 Driver benchmark ................................................................................1034 Image drawing performance ..................................................................1035 Memory requirements........................................................................... 1036 Memory requirements of the GUI components.......................................... 1036 Stack requirements .............................................................................. 1037 Memory requirements of example applications .........................................1037 34 Configuration............................................................................................................1039 34.1 34.2 What needs to be configured? ................................................................ 1040 Run-time- and compile-time configuration ...............................................1040 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 27 34.3 34.4 34.4.1 34.4.1.1 34.4.2 34.4.2.1 34.4.3 34.4.3.1 34.4.3.2 34.4.3.3 34.5 34.5.1 34.5.1.1 34.5.1.2 34.5.1.3 34.5.2 34.6 Initialization process of emWin .............................................................. 1040 Run-time configuration ......................................................................... 1041 Customizing GUIConf.c......................................................................... 1041 API functions to be used in GUI_X_Config()............................................. 1041 Customizing LCDConf.c ........................................................................ 1043 API functions to be used in LCD_X_Config() ............................................ 1045 Customizing GUI_X.c ........................................................................... 1045 Timing routines ................................................................................... 1046 Debug routines.................................................................................... 1046 Kernel interface routines....................................................................... 1047 Compile time configuration ................................................................... 1048 Customizing GUIConf.h ........................................................................ 1048 Configuring the available features of emWin ............................................ 1048 Default font and default color configuration ............................................. 1048 Advanced GUI configuration options ....................................................... 1049 Customizing LCDConf.h ........................................................................ 1050 Request available memory .................................................................... 1050 35 Support ....................................................................................................................1051 35.1 35.1.1 35.1.2 35.1.3 35.1.4 35.2 35.3 35.4 35.5 35.6 Problems with tool chain (compiler, linker) .............................................. 1052 Compiler crash .................................................................................... 1052 Compiler warnings ............................................................................... 1052 Compiler errors ................................................................................... 1052 Linker problems .................................................................................. 1053 Problems with hardware/driver .............................................................. 1053 Problems with API functions .................................................................. 1054 Problems with the performance ............................................................. 1054 Contacting support .............................................................................. 1055 FAQ's ................................................................................................. 1056 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 28 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 29 Chapter 1 Introduction to emWin This introduction gives some information about this document. It also gives an overview of what features emWin consists of and what it requires. 1.1 Purpose of this document This guide describes how to install, configure and use the emWin graphical user interface for embedded applications. It also explains the internal structure of the software and all the functions which are offered by emWin and intended for direct use (API, Application Programming Interface). Before actually using emWin, you should read or at least glance through this manual in order to become familiar with the software. The following steps are recommended: * * * * 1.2 Copy the emWin files to your computer. Go through the chapter "Getting Started" on page 35. Use the simulator in order to become more familiar with what the software can do (refer to the chapter "Simulation" on page 43). Expand your program using the rest of the manual for reference. Requirements A target system is not required in order to develop software with emWin; most of the software can be developed using the simulator. However, the final purpose is usually to be able to run the software on a target system. 1.2.1 Target system (hardware) Your target system must: * * * Have a CPU (8/16/32/64 bits) Have a minimum of RAM and ROM Have a full graphic display (any type and any resolution) The RAM needs to be 8-, 16- and 32-bit accessible. Memory requirements vary depending on which parts of the software are used and how efficient your target compiler is. It is therefore not possible to specify precise values, but the following applies to typical systems. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 30 CHAPTER Introduction to emWin Small systems (no Window Manager) * * * RAM: 100 Bytes Stack: 600 Bytes ROM: 10-25 KBytes (depending on the functionality used) Big systems (including Window Manager and widgets) * * * RAM: 2-6 kb (depending on number of windows required) Stack: 1200-1800 bytes (depending on the functionality used) ROM: 30-60 kb (depending on the functionality used) ROM requirements increase according to the number of fonts used in the application. All values are rough estimates and cannot be guaranteed. Detailed information can be found in the chapter "Performance and Resource Usage" on page 1033. 1.2.2 Development environment (compiler) The CPU used is of no importance; only an ANSI-compliant C compiler complying with at least one of the following international standard is required: * * * ISO/IEC/ANSI 9899:1990 (C90) with support for C++ style comments (//) ISO/IEC 9899:1999 (C99) ISO/IEC 14882:1998 (C++) If your compiler has some limitations, let us know and we will inform you if these will be a problem when compiling the software. Any compiler for 16/32/64-bit CPUs or DSPs that we know of can be used; most 8-bit compilers can be used as well. A C++ compiler is not required, but can be used. The application program can therefore also be programmed in C++ if desired. 1.3 Features emWin is designed to provide an efficient, processor- and display controller-independent graphical user interface for any application that operates with a graphical display. It is compatible with single-task and multitask environments, with a proprietary operating system or with any commercial RTOS. emWin is shipped as C source code. It may be adapted to any size physical and virtual display with any display controller and CPU. Its features include the following: General * * * * * * * * * * Any (monochrome, grayscale or color) display with any controller supported (if the right driver is available). May work without display controller on smaller displays. Any interface supported using configuration macros. Display-size configurable. Characters and bitmaps may be written at any point on the display, not just on even-numbered byte addresses. Routines are optimized for both size and speed. Compile time switches allow for different optimizations. For slower display controllers, display can be cached in memory, reducing access to a minimum and resulting in very high speed. Clear structure. Virtual display support; the virtual display can be larger than the actual display. Graphic library * * * * * * Bitmaps of different color depths supported. Bitmap Converter available. Absolutely no floating-point usage. Fast line/point drawing (without floating-point usage). Very fast drawing of circles/polygons. Different drawing modes. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 31 Fonts * * * * * A variety of different fonts are shipped with the basic software: 4*6, 6*8, 6*9, 8*8, 8*9, 8*16, 8*17, 8*18, 24*32, and proportional fonts with pixel-heights of 8, 10, 13, 16. For more information, see chapter 'Fonts'. New fonts can be defined and simply linked in. Only the fonts used by the application are actually linked to the resulting executable, resulting in minimum ROM usage. Fonts are fully scalable, separately in X and Y. Font Converter available; any font available on your host system (that is, Microsoft Windows) can be converted. String/value output routines * * Routines to show values in decimal, binary, hexadecimal, any font. Routines to edit values in decimal, binary, hexadecimal, any font. Window Manager (WM) * * * * Complete window management including clipping. Overwriting of areas outside a window's client area is impossible. Windows can be moved and resized. Callback routines supported (usage optional). WM uses minimum RAM (app. 50 bytes per window). Optional widgets for PC look and feel * Widgets (window objects, also known as controls) are available. They generally operate automatically and are simple to use. Touch-screen & mouse support * For window objects such as the button widget, emWin offers touch-screen and mouse support. PC tools * * * * * 1.4 Simulation library for WIN32-Environments. The source code may be purchased additionally. emWinView. Bitmap Converter. Font Converter. GUIBuilder. Examples and demos To give you a better idea of what emWin can do, we have different demos available as "ready-to-use" simulation executables under Sample\EXE. The source of the sample applications is located in the folder Sample. The folder Sample\GUIDemo contains an application program showing many features of emWin. All examples are also available at www.segger.com. 1.5 Starter kits Complete starter kits including a demo board with a display, a C compiler and an example project are available. For more details, take a look at our website at www.segger.com. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 32 1.6 CHAPTER Introduction to emWin Screen and coordinates The screen consists of many dots that can be controlled individually. These dots are called pixels. Most of the text and drawing functions that emWin offers in its API to the user program can write or draw on any specified pixel. The horizontal scale is called the X-axis, whereas the vertical scale is called the Yaxis. Coordinates are denoted as a pair consisting of an X- and a Y-value (X, Y). The X-coordinate is always first in routines that require X and Y coordinates. The upper left corner of the display (or a window) has per default the coordinates (0,0). Positive X-values are always to the right; positive Y-values are always down. The above graph illustrates the coordinate system and directions of the X- and Y- axes. All coordinates passed to an API function are always specified in pixels. 1.7 How to connect the display to the micro controller emWin handles all access to the display. Virtually any display controller can be supported, independently of how it is accessed. For details, refer to the chapter "Configuration" on page 1039. Also, get in contact with us if your display controller is not supported. We are currently writing drivers for all display controllers available on the market and may already have a proven driver for the display controller that you intend to use. It is usually very simple to write the routines (or macros) used to access the display in your application SEGGER Microcontroller GmbH & Co. KG offers the service of making these customizations for you, if necessary with your target hardware. It does not really matter how the display is connected to the system as long as it is somehow accessible by software, which may be accomplished in a variety of ways. Most of these interfaces are supported by a driver which is supplied in source code form. This driver does not normally require modifications, but is configured for your hardware by making changes in the file LCDConf.h. Details about how to customize a driver to your hardware as necessary are provided in the chapter "Display drivers" on page 921. The most common ways to access the display are described as follows. If you simply want to understand how to use emWin, you may skip this section. Display with memory-mapped display controller: The display controller is connected directly to the data bus of the system, which means the controller can be accessed just like a RAM. This is a very efficient way of accessing the display controller and is most recommended. The display addresses are defined to the segment LCDSEG, and in order to be able to access the display the linker/locator simply needs to be told where to locate this segment. The location must be identical to the access address in physical address space. Drivers are available for this type of interface and for different display controllers. Display with display controller connected to port / buffer For slower display controllers used on fast processors, the use of port-lines may be the only solution. This method of accessing the display has the disadvantage of being somewhat slower than direct bus-interface but, particularly with a cache that minimizes the accesses to the display, the display update is not slowed down significantly. All that needs to be done is to define routines or macros which set or read the hardware ports/buffers that the display is connected to. This type of interface is also supported by different drivers for the different display controllers. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 33 Proprietary solutions: display without display controller The display can also be connected without an display controller. In this case, the display data is usually supplied directly by the controller via a 4- or 8-bit shift register. These proprietary hardware solutions have the advantage of being inexpensive, but the disadvantage of using up much of the available computation time. Depending on the CPU, this can be anything between 20 and almost 100 percent; with slower CPUs, it is really not possible at all. This type of interface does not require a specific display driver because emWin simply places all the display data into the display cache. You yourself must write the hardware-dependent portion that periodically transfers the data in the cache memory to your display. Example code for transferring the video image into the display is available in both C and optimized assembler for M16C and M16C/80. 1.8 Data types Since C does not provide data types of fixed lengths which are identical on all platforms, emWin uses, in most cases, its own data types as shown in the table below: Data type Definition Explanation I8 signed char 8-bit signed value U8 unsigned char 8-bit unsigned value I16 signed short 16-bit signed value U16 unsigned short 16-bit unsigned value I32 signed long 32-bit signed value U32 unsigned long 32-bit unsigned value I16P signed short 16-bit (or more) signed value U16P unsigned short 16-bit (or more) unsigned value For most 16/32-bit controllers, the settings will work fine. However, if you have similar defines in other sections of your program, you might want to change or relocate them. A recommended place is in the file Global.h. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 34 UM03001 User & Reference Guide for emWin V5.20 CHAPTER Introduction to emWin (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 35 Chapter 2 Getting Started The following chapter provides an overview of the basic procedures for setting up and configuring emWin on your target system. It also includes a simple program example. If you find yourself unsure about certain areas, keep in mind that most topics are treated in greater detail in later chapters. You will most likely need to refer to other parts of the manual before you begin more complicated programming. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 36 CHAPTER 2.1 Getting Started Recommended project structure We recommend keeping emWin separate from your application files. It is good practice to keep all the program files (including the header files) together in the GUI subdirectories of your project's root directory. The directory structure should be similar to the one pictured on the right. This practice has the advantage of being very easy to update to newer versions of emWin by simply replacing the GUI\ directories. Your application files can be stored anywhere. Warning: When updating to a newer emWin version: Since files may have been added, moved or deleted, the project directories may need to be updated accordingly. 2.1.1 Subdirectories The following table shows the contents of all GUI subdirectories: Directory Contents Config Configuration files GUI\AntiAlias Antialiasing support * GUI\ConvertMono Color conversion routines used for grayscale displays * GUI\ConvertColor Color conversion routines used for color displays * GUI\Core emWin core files GUI\Font Font files GUI\DisplayDriver Display driver GUI\MemDev Memory device support * GUI\VNC VNC support * GUI\Widget Widget library * GUI\WM Window Manager * (* = optional) 2.1.2 Include directories You should make sure that the include path contains the following directories (the order of inclusion is of no importance): * * * * * Config GUI\Core GUI\DisplayDriver GUI\Widget (if using the widget library) GUI\WM (if using Window Manager) Warning: Always make sure that you have only one version of each file! It is frequently a major problem when updating to a new version of emWin if you have old files included and therefore mix different versions. If you keep emWin in the directories as suggested (and only in these), this type of problem cannot occur. When updating to a newer version, you should be able to keep your configuration files and leave them unchanged. For safety reasons, we recommend backing up (or at least renaming) the GUI\ directories prior to updating. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 37 2.2 Adding emWin to the target program You basically have a choice between including only the source files that you are actually going to use in your project, which will then be compiled and linked, or creating a library and linking the library file. If your tool chain supports "smart" linking (linking in only the modules that are referenced and not those that are not referenced), there is no real need to create a library at all, since only the functions and data structures which are required will be linked. If your tool chain does not support "smart" linking, a library makes sense, because otherwise everything will be linked in and the program size will be excessively large. For some CPUs, we have example projects available to help you get started. 2.3 Creating a library Building a library from the sources is a simple procedure. The Makelib.bat first step is to copy the batch files (located under Sample\Makelib) into your project's root directory. That means the parent directory containing the 'Config' and the 'GUI' folder explained in chapter 2.1. Then, make any necessary changes. Prep.bat There are a total of four batch files which need to be copied, described in the table below. The main file, Makelib.bat, will be the same for all systems and requires no changes. To build a CC.bat library for your target system, you will normally need to make slight modifications to the other three smaller files. Finally, No start the file Makelib.bat to create the library. The batch files assume that your GUI and Config subdirectories are set up as All files recommended. in library? The procedure for creating a library is illustrated in the flow chart to the right. The Makelib.bat file first calls Prep.bat to prepare the environment for the tool chain. Then it calls CC.bat Yes for every file to be included in the library. It does this as many times as necessary. CC.bat adds each object file to a list that lib.bat will be used by lib.bat. When all files to be added to the library have been listed, Makelib.bat then calls lib.bat, which uses a librarian to put the listed object files into the actual library. Of course you are free to create libraries in another way. It is not recommended to create an emWin library including a compile-time configurable display driver. For further information about the configurability of display drivers, please refer to "Available display drivers" on page 922. File Explanation Makelib.bat Main batch file. No modification required. Prep.bat Called by Makelib.bat to prepare environment for the tool chain to be used, CC.bat Called by Makelib.bat for every file to be added to the library; creates a list of these object files which will then be used in the next step by the librarian in the lib.bat file. lib.bat Called by Makelib.bat to put the object files listed by CC.bat into a library. The files as shipped assume that a Microsoft compiler is installed in its default location. If all batch files are copied to the root directory (directly above GUI) and no changes are made at all, a simulation library will be generated for the emWin simulation. In order to create a target library, however, it will be necessary to modify Prep.bat, CC.bat, and lib.bat. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 38 CHAPTER 2.3.1 Getting Started Adapting the library batch files to a different system The following will show how to adapt the files by an example adaptation for a Mitsubishi M32C CPU. Adapting Prep.bat Prep.bat is called at the beginning of Makelib.bat. As described above its job is to set the environment variables for the used tools and the environment variable PATH, so that the batch files can call the tools without specifying an absolute path. Assuming the compiler is installed in the folder C:\MTOOL the file Prep.bat could look as follows: @ECHO OFF SET TOOLPATH=C:\MTOOL REM ****************************************************************** REM Set the variable PATH to be able to call the tools SET PATH=%TOOLPATH%\BIN;%TOOLPATH%\LIB308;%PATH% REM ****************************************************************** REM Set the tool internal used variables SET BIN308=%TOOLPATH%\BIN SET INC308=%TOOLPATH%\INC308 SET LIB308=%TOOLPATH%\LIB308 SET TMP308=%TOOLPATH%\TMP Adapting CC.bat The job of CC.bat is to compile the passed source file and adding the file name of the object file to a link list. When starting MakeLib.bat it creates the following subdirectories relative to its position: Directory Contents Lib This folder should contain the library file after the build process. Temp\Output Should contain all the compiler output and the link list file. Will be deleted after the build process. Temp\Source MakeLib.bat uses this folder to copy all source and header files used for the build process. Will be deleted after the build process. The object file should be created (or moved) to Temp\Output. This makes sure all the output will be deleted after the build process. Also the link list should be located in the output folder. The following shows an example for the Mitsubishi compiler: @ECHO OFF GOTO START REM ****************************************************************** REM Explanation of the used compiler options: -silent : Suppresses the copyright message display at startup -M82 : Generates object code for M32C/80 Series (Remove this switch for M16C80 targets) -c : Creates a relocatable file (extension .r30) and ends processing -I : Specifies the directory containing the file(s) specified in #include -dir : Specifies the destination directory -OS : Maximum optimization of speed followed by ROM size -fFRAM : Changes the default attribute of RAM data to far -fETI : Performs operation after extending char-type data to the int type (Extended according to ANSI standards) :START REM ****************************************************************** REM Compile the passed source file with the Mitsubishi NC308 compiler NC308 -silent -M82 -c -IInc -dir Temp\Output -OS -fFRAM -fETI Temp\Source\%1.c REM ****************************************************************** REM Pause if any problem occurs IF ERRORLEVEL 1 PAUSE REM ****************************************************************** REM Add the file name of the object file to the link list ECHO Temp\Output\%1.R30>>Temp\Output\Lib.dat UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 39 Adapting Lib.bat After all source files have been compiled Lib.bat will be called from MakeLib.bat. The job is to create a library file using the link list created by CC.bat. The destination folder of the library file should be the Lib folder created by MakeLib.bat. The following shows an example for the Mitsubishi librarian: @ECHO OFF GOTO START REM ****************************************************************** REM Explanation of the used options: -C : Creates new library file @ : Specifies command file :START REM ****************************************************************** REM Create the first part of the linker command file ECHO -C Lib\GUI>Temp\Output\PARA.DAT REM ****************************************************************** REM Merge the first part with the link list to the linker command file COPY Temp\Output\PARA.DAT+Temp\Output\Lib.dat Temp\Output\LINK.DAT REM ****************************************************************** REM Call the Mitsubishi librarian LB308 @Temp\Output\LINK.DAT REM ****************************************************************** REM Pause if any problem occurs IF ERRORLEVEL 1 PAUSE 2.4 C files to include in the project Generally speaking, you need to include the core C files of emWin, the display driver, all font files you plan to use and any optional modules you have ordered with emWin: * * * * All C files of the folder Config All C files of the folder GUI\Core The fonts you plan to use (located in GUI\Font) Display driver: All C files of the folder GUI\DisplayDriver. Additional software packages If you plan to use additional, optional modules you must also include their C files: * * * * * * * Gray scale converting functions: all C files located in GUI\ConvertMono Color conversion functions: all C files located in GUI\ConvertColor Antialiasing: all C files located in GUI\AntiAlias Memory Devices: all C files located in GUI\MemDev VNC support: all C files located in GUI\VNC Widget library: all C files located in GUI\Widget Window Manager: all C files located in GUI\WM Target specifics For displays with indirect interface hardware routines must be included. Examples for several kinds of indirect interface routines are available under Samples\LCD_X. RTOS specifics * * If emWin is intended to be used with an RTOS, some RTOS dependent functions need to be implemented. emWin comes with several sample files including implementations for common RTOS packages (called GUI_X_.c), as well as the file GUI_X_Ex.c which just contains place holders of the required functions and might be used to make emWin work with any RTOS. If multitasking is not required (access of the display by one task only) the file GUI_X.c may be used as a starting point for a custom implementation. The sample files can be found in the folder Sample\GUI_X which is contained in the emWin package. Additional information Be sure to include GUI.h in all emWin accessing source files. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 40 2.5 CHAPTER Getting Started Configuring emWin The Config folder should contain all configuration files. The chapter 'Configuration' explains in detail how emWin should be configured. The following types of configuration macros are available: Binary switches "B" Switches can have a value of either 0 or 1, where 0 means deactivated and 1 means activated (actually anything other than 0 would work, but using 1 makes it easier to read a config file). These switches can enable or disable a certain functionality or behavior. Switches are the simplest form of configuration macro. Numerical values "N" Numerical values are used somewhere in the code in place of a numerical constant. Typical examples are in the configuration of the resolution of a display. Selection switches "S" Selection switches are used to select one out of multiple options where only one of those options can be selected. A typical example might be the selection of the type of display controller used, where the number selected denotes which source code (in which display driver) is used to generate object code. Alias "A" A macro which operates like a simple text substitute. An example would be the define U8, in which the preprocessor would replace with unsigned char. Function replacements "F" Macros can basically be treated like regular functions although certain limitations apply, as a macro is still put into the code as simple text replacement. Function replacements are mainly used to add specific functionality to a module (such as the access to a display) which is highly hardware-dependent. This type of macro is always declared using brackets (and optional parameters). 2.6 Initializing emWin The following functions should be used to initialize and 'deinitialize' emWin in order to start the configuration process (see chapter "Configuration" on page 1039) or clear internal data from memory again. Routine GUI_Init() GUI_Exit() Explanation Initializes emWin internal data structures and variables. Clears emWin internal data from memory. GUI_Init() Description Initializes emWin internal data structures and variables. Prototype int GUI_Init(void); Return value 0, if successful; another value if the initialization of the display driver fails. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 41 Additional information Executing this function is mandatory before using any emWin functions. The only exception is setting create flags for windows (see "WM_SetCreateFlags()" on page 378). If the Window Manager is used, the background window is created from within GUI_Init(). So if create flags are set up before GUI_Init() is called, the background window is created according to them. GUI_Exit() Description Clears emWin internal data from memory to make further calls of GUI_Init() possible. Prototype void GUI_Exit(void); Additional information This function should be used if emWin represents a part of the application which is not used continuously and therefore has to be able to be turned on and off again. Please note that after GUI_Exit was called emWin will not work properly until GUI_Init() is called again. 2.7 Using emWin with target hardware The following is just a basic outline of the general steps that should be taken when starting to program with emWin. All steps are explained further in subsequent chapters. Step 1: Configuring emWin The first step is usually to customize emWin. For details about the configuration, refer to the chapter "Configuration" on page 1039". Step 2: Defining access addresses or access routines For memory-mapped display controllers, the access addresses of the display simply need to be defined in the configuration file of the display controller. For port/bufferaccessed display controllers, interface routines must be defined. Examples of the required routines are available under Samples\LCD_X. Step 3: Compiling, linking and testing the example code emWin comes with example code for both single- and multitask environments. Compile, link and test these little example programs until you feel comfortable doing so. Step 4: Modifying the example program Make simple modifications to the example programs. Add additional commands such as displaying text in different sizes on the display, showing lines and so on. Step 5: In multitask applications: adapt to your OS (if necessary) If multiple tasks should be able to access the display simultaneously, the macros GUI_MAXTASK and GUI_OS come into play, as well as the file GUITask.c. For details and example adaptations, refer to the chapter "Configuration" on page 1039". Step 6: Write your own application using emWin By now you should have a clearer understanding of how to use emWin. Think about how to structure the program your application requires and use emWin by calling the appropriate routines. Consult the reference chapters later in this manual, as they discuss the specific emWin functions and configuration macros that are available. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 42 2.8 CHAPTER Getting Started The "Hello world" example program In the following we will show the "Hello world" example program. If you like to see a wide range of emWin based sample applications as well as further simple tutorial applications, please have a look in the Sample folder of your emWin shipment or visit the "emWin Samples" section on www.segger.com. A "Hello world" program has been used as a starting point for C programming since the early days, because it is essentially the smallest program that can be written. An emWin "Hello world" program is shown below and is available as BASIC_HelloWorld.c in the Sample\Tutorial folder shipped with emWin. The whole purpose of the program is to write "Hello world" in the upper left corner of the display. In order to be able to do this, the hardware of the application, the display controller and the GUI must be initialized first. emWin is initialized by a simple call of GUI_Init() in the beginning of the program. In this example, we assume that the hardware of your application is already initialized. The "Hello world" program looks as follows: #include "GUI.h" void MainTask(void) { GUI_Init(); GUI_DispString("Hello world!"); while(1); } Adding functionality to the "Hello world" program Our little program has not been doing too much so far. We can now extend the functionality a bit: after displaying "Hello world", we would like the program to start counting on the display in order to be able to estimate how fast outputs to the display can be made. We can simply add a bit of code to the loop at the end of the main program, which is essentially a call to the function that displays a value in decimal form. The example is available as BASIC_Hello1.c in the Sample folder. #include "GUI.h" void MainTask(void) { int i=0; GUI_Init(); GUI_DispString("Hello world!"); while(1) { GUI_DispDecAt( i++, 20,20,4); if (i > 9999) { i = 0; } } } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 43 Chapter 3 Simulation The PC simulation of emWin allows you to compile the same C source on your Windows PC using a native (typically Microsoft) compiler and create an executable for your own application. Doing so allows the following: * * * Design of the user interface on your PC (no hardware required!). Debugging of the user interface program. Creation of demos of your application, which can be used to discuss the user interface. The resulting executable can be sent easily via e-mail. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 44 CHAPTER 3.1 Simulation Using the simulation The emWin simulation requires Microsoft Visual C++ (version 6.00 or higher) and the integrated development environment (IDE) which comes with it. You will see a simulation of your LCD on your PC screen, which has the same resolution in X and Y and can display the exact same colors as your LCD once it has been properly configured. The entire graphic library API and Window Manager API of the simulation are identical to those on your target system; all functions will behave in the very same way as on the target hardware since the simulation uses the same C source code as the target system. The difference lies only in the lower level of the software: the display driver. Instead of using the actual display driver, the PC simulation uses a simulation driver which writes into a bitmap. The bitmap is then displayed on your screen using a second thread of the simulation. This second thread is invisible to the application; it behaves just as if the LCD routines were writing directly to the display. 3.1.1 Using the simulation with the trial version of emWin The trial version of emWin contains a full library which allows you to evaluate all available features of emWin. It also includes the emWin viewer (used for debugging applications), as well as demo versions of the Font Converter and the Bitmap Converter. Keep in mind that, being a trial version, you will not be able to view the source code of emWin or the simulation, but you will still be able to become familiar with what emWin can do. 3.1.1.1 Directory structure The directory structure of the simulation in the trial version is shown at the right side. The table below explains the contents of the folders: Directory Content Application Source of the demo program. Config Configuration files used to build the library. Note that changes at the header files do not have any effect on the precompiled library! Exe Ready-to-use demo program. GUI Library files and include files needed to use the library. Sample Simulation examples. Simulation Files needed for the simulation. Tool The emWin viewer, a demo version of the Bitmap Converter and a demo version of the Font Converter. 3.1.1.2 Visual C++ workspace The root directory shown above includes the Microsoft Visual C++ workspace (SimulationTrial.dsw) and project file (SimulationTrial.dsp). The workspace allows you to modify an application program and debug it before compiling it on your target system. Double-click the workspace file to open the Microsoft IDE. The directory structure of the Visual C++ workspace will look like the one shown to the right. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 45 3.1.1.3 Compiling the demo program The source files for the demo program are located in the Application directory as a ready-to-go simulation, meaning that you only need to rebuild and start it. Note that to rebuild the executable, you will need to have Microsoft Visual C++ (version 6.00 or later) installed. * * * Step 1: Open the Visual C++ workspace by double-clicking on SimulationTrial.dsw. Step 2: Rebuild the project by choosing Build/Rebuild All from the menu (or by pressing F7). Step 3: Start the simulation by choosing Build/Start Debug/Go from the menu (or by pressing F5). The demo project will begin to run and may be closed at any time by right-clicking on it and selecting Exit. 3.1.1.4 Compiling the examples The Sample directory contains ready-to-go examples that demonstrate different features of emWin and provide examples of some of their typical uses. In order to build any of these executables, their C source must be 'activated' in the project. This is easily done with the following procedure: * * * * * Step 1: Exclude the Application folder from the build process by right-clicking the Application folder of the workspace and selecting 'Settings\General\Exclude from build'. Step 2: Open the Sample folder of the workspace by double-clicking on it. Include the example which should be used by right-clicking on it and deselecting 'Settings\General\Exclude' from build. Step 3: If the example contains its own configuration files (LCDConf.c and/or SIMConf.c) the default configuration files located in the config folder need to be excluded from the build process. Step 4: Rebuild the example by choosing Build/Rebuild All from the menu (or by pressing F7). Step 5: Start the simulation by choosing Build/Start Debug/Go from the menu (or by pressing F5). The result of the example selected above is pictured below: UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 46 CHAPTER 3.1.2 Simulation Using the simulation with the emWin source 3.1.2.1 Directory structure The root directory of the simulation can be anywhere on your PC, for example C:\Work\emWinSim. The directory structure will appear as shown to the right. This structure is very similar to that which we recommend for your target application (see Chapter 3: "Getting Started" for more information). The following table shows the contents of the folders: Directory Content Doc Contains the emWin documentation. Sample Code examples, described later in this documentation. Start All you need to create a new project with emWin. Tool Tools shipped with emWin. A new project can be started by making a copy of the Startfolder. It contains all required files for a new project. Subdirectories containing the emWin sources are in the Start\GUI folder and should contain the exact same files as the directories of the same names which are used for your target (cross) compiler. The files of the GUI subdirectories should not be changed, as this would make updating to a newer version of emWin more difficult. The Start\Config directory contains configuration files which need to be modified in order to reflect your target hardware settings (mainly LCD-size and colors which can be displayed). 3.1.2.2 Visual C++ workspace The root directory shown above includes the Microsoft Visual C++ workspace (Simulation.dsw) and project files (Simulation.dsp). The workspace allows you to modify an application program and debug it before compiling it on your target system. The directory structure of the Visual C++ workspace will appear similar to that shown to the right. Here, the GUI folder is open to display the emWin subdirectories. Note that your GUI directory may not look exactly like the one pictured, depending on which additional features of emWin you have. The folders Core, Font and DisplayDriver are part of the basic emWin package and will always appear in the workspace directory. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 47 3.1.2.3 Compiling the application The simulation contains one or more application C files (located in the Application directory), which can be modified or removed and additional files can be added to the project. You should then rebuild the program within the Visual C++ workspace in order to test/debug it. Once you have reached a point where you are satisfied with the result and want to use the program in your application, you should be able to compile these same files on your target system and get the same result on the target display. The general procedure for using the simulation would be as follows: * * * * * * * 3.1.3 Step 1: Open the Visual C++ workspace by double-clicking on Simulation.dsw. Step 2: Compile the project by choosing Build/Rebuild All from the menu (or by pressing F7). Step 3: Run the simulation by choosing Build/Start Debug/Go from the menu (or by pressing F5). Step 4: Replace the bitmap with your own logo or image. Step 5: Make further modifications to the application program as you wish, by editing the source code or adding/deleting files. Step 6: Compile and run the application program within Visual C++ to test the results. Continue to modify and debug as needed. Step 7: Compile and run the application program on your target system. Advanced features of the simulation Clicking the right mouse button shows a context menu with several advanced functions: 3.1.3.1 Pause and Resume These menu items allows to pause and to resume the application currently running in the simulation. The same can be done by pressing or . Trying to pause an already paused application or trying to resume an already running application causes an error message. 3.1.3.2 View system info This menu item opens a further window with information of the memory currently used by the application. The window continuously shows the current status of memory consumption by showing the free and used bytes and the free and used number of memory blocks. 3.1.3.3 Copy to clipboard This menu item copies the current contents of the display into the clipboard. This makes it easy to use it for documentation purpose with other applications. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 48 CHAPTER 3.2 Simulation Device simulation The device simulation supports 3 views: * * * Generated frame view Custom bitmap view Window view The table below shows the different views: Generated frame view Custom bitmap view Window view The following will explain in detail how each option can be used. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 49 3.2.1 Generated frame view The simulation shows the display inside an automatically generated frame surrounding the display. The frame contains a small button which per default closes the application. This is the default behavior of the simulation for single layer systems. 'Single layer system' means that only the first layer is initialized. 3.2.2 Custom bitmap view The simulation can show the simulated display in a bitmap of your choice, typically your target device. The bitmap can be used to simulate the behavior of the entire target device. In order to simulate the appearance of the device, bitmaps are required. Device bitmap The first bitmap is usually a photo (top view) of the device, and needs to be named Device.bmp. It may be a separate file (in the same directory as the executable), or it may be included as a resource in the application. How to do this is explained later in this chapter. The file should provide an area for the simulated display of the same size in pixels as the physical display resolution. If there are any hardkeys to be simulated the bitmap should also show all of them in unpressed state. Transparent areas need to be colored with exact the same color as defined with the function SIM_GUI_SetTransColor(), typically bright red (0xFF0000). These areas do not have to be rectangular; they can have an arbitrary shape (up to a certain complexity which is limited by your operating system, but is normally sufficient). Bright red is the default color for transparent areas, mainly because it is not usually contained in most bitmaps. To use a bitmap with bright red, the default transparency color may be changed with the function SIM_GUI_SetTransColor(). UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 50 CHAPTER Simulation Hardkey bitmap The second bitmap file is required for defining the hardkeys and must be named Device1.bmp. It contains the buttons in pressed state. The non hardkey area has to be filled with the transparent color. This is only a short description. For more details about how to simulate hardkeys, see "Hardkey simulation" on page 56. Using separate files When starting the simulation, it checks if the directory of the executable contains the bitmap files Device.bmp and Device1.bmp. If these files are available, they are used automatically and the resource bitmaps are ignored. Note that this is only valid with single layer systems. Adding the bitmap to the application resources The resource file of the simulation can be found under System\Simulation\Res\Simulation.rc. It contains the following section: ///////////////////////////////////////////////////////////////////////////// // // Customizable bitmaps // IDB_DEVICE BITMAP DISCARDABLE "Device.bmp" IDB_DEVICE1 BITMAP DISCARDABLE "Device1.bmp" This section can be used to set custom device files. More information can be found in the Win32 documentation. 3.2.3 Window view Default for simulating a multiple layer system is showing each layer in a separate window without using bitmaps or a generated frames. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 51 3.3 Device simulation API All of the device simulation API functions should be called in the setup phase. The calls should be done from within the routine SIM_X_Config(), which is located in the file SIMConf.c in the configuration folder. The example below calls SIM_SetLCDPos() in the setup: #include "LCD_SIM.h" void SIM_X_Config() { SIM_GUI_SetLCDPos(50, 20); // Define the position of the LCD in the bitmap} } The table below lists the available device-simulation-related routines in alphabetical order. Detailed descriptions of the routines follow: Routine Explanation SIM_GUI_ShowDevice() Manages the visibility of the device bitmap. SIM_GUI_SetCallback() Sets a callback function for receiving the handles of the simulation windows. SIM_GUI_SetCompositeColor() Sets the background color of the composite window. (Only used with multi layer systems) SIM_GUI_SetCompositeSize() Sets the size of the composite window. (Only used with multi layer systems) SIM_GUI_SetLCDColorBlack() Set the color to be used as black (color monochrome displays). SIM_GUI_SetLCDColorWhite() Set the color to be used as white (color monochrome displays). SIM_GUI_SetLCDPos() Set the position for the simulated LCD within the target device bitmap. SIM_GUI_SetMag() Set magnification factors for X and/or Y axis. SIM_GUI_SetTransColor() Set the color to be used for transparent areas (default: 0xFF0000). SIM_GUI_UseCustomBitmaps() Tells the simulation to use the custom bitmaps from the application resource file. SIM_GUI_ShowDevice() Description This function can be used to manage the visibility of the surrounding device bitmap of the simulation. Prototype void SIM_GUI_ShowDevice(int OnOff); Parameter OnOff Description 1 for showing the bitmap, 0 for hiding it. Additional information On systems with multiple layers the device bitmap is not shown per default and on single layer systems the bitmap is visible. If a different behavior is required this function can be used to set up the visibility of the device bitmap. SIM_GUI_SetCallback() Description If it is required to simulate more than the display window or hardkeys, you can set a callback function to receive the window handles of the simulation. This opens up the possibility e.g. to add additional controls outside of the display window like leds or sliders. Please note that the emWin functions can not be used there. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 52 CHAPTER Simulation Prototype void SIM_GUI_SetCallback(int (* _pfInfoCallback)(SIM_GUI_INFO * pInfo)); Parameter Description _pfInfoCallback Pointer to the callback function. The function has to expect a pointer to a SIM_GUI_INFO structure as a parameter Content of the SIM_GUI_INFO structure Type HWND Name Description hWndMain Handle to the main window HWND ahWndLCD[16] Array of handles to the display layers HWND ahWndColor[16] Array of handles to the palette layers SIM_GUI_SetCompositeColor() Description When simulating a multiple layer system each layer can be shown in its own window. However, the physical display has only one area. It shows the result of the blended layers. The simulation shows the result in the composite window which can have its own size independent of the layers. Each layer can have its own position and its own size within the composite window. This means that not necessarily the complete area is covered by the layers. For this case (and also for transparency effects) this function sets the default background color of the composite window. Prototype void SIM_GUI_SetCompositeColor(U32 Color); Parameter Color Description Background color to be used. SIM_GUI_SetCompositeSize() Description As described above under SIM_GUI_SetCompositeColor() the size of the composite window is independent of the size of the layers. This function is used to set the size of the composite window. Prototype void SIM_GUI_SetCompositeSize(int xSize, int ySize); Parameter xSize ySize Description Horizontal size in pixels. Vertical size in pixels. Example The following shows a typical use (with a multi layer system): void SIM_X_Config() { SIM_GUI_SetCompositeSize(240, 320); // Set size of composite window SIM_GUI_SetCompositeColor(0x800000); // Define background color of composite window } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 53 SIM_GUI_SetLCDColorBlack(), SIM_GUI_SetLCDColorWhite() Description Set the colors to be used as black or white, respectively, on color monochrome displays. Prototypes int SIM_GUI_SetLCDColorBlack(int DisplayIndex, int Color); int SIM_GUI_SetLCDColorWhite(int DisplayIndex, int Color); Parameter DisplayIndex Color Description Reserved for future use; must be 0. RGB value of the color. Additional information These functions can be used to simulate the true background color of your display. The default color values are black and white, or 0x000000 and 0xFFFFFF. Example using default settings void SIM_X_Config() { SIM_GUI_SetLCDPos(14,84); SIM_GUI_SetLCDColorBlack (0, 0x000000); SIM_GUI_SetLCDColorWhite (0, 0xFFFFFF); (used for colored monochrome displays) // // // // Define in the Define Define the position of the LCD bitmap the color used as black the color used as white // // // // Define in the Define Define the position of the LCD bitmap the color used as black the color used as white } Example using yellow instead of white void SIM_X_Config() { SIM_GUI_SetLCDPos(14,84); SIM_GUI_SetLCDColorBlack (0, 0x000000); SIM_GUI_SetLCDColorWhite (0, 0x00FFFF); (used for colored monochrome displays) } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 54 CHAPTER Simulation SIM_GUI_SetLCDPos() Description Sets the position for the simulated LCD within the target device bitmap. Prototype void SIM_GUI_SetLCDPos(int x, int y); Parameter Description X-position of the upper left corner for the simulated LCD (in pixels). x y Y-position of the upper left corner for the simulated LCD (in pixels). Additional information The X- and Y-positions are relative to the target device bitmap, therefore position (0,0) refers to the upper left corner (origin) of the bitmap and not your actual LCD. Only the origin of the simulated screen needs to be specified; the resolution of your display should already be reflected in the configuration files in the Config directory. The use of this function enables the use of the bitmaps Device.bmp and Device1.bmp. Note that the values need to be >= 0 for enabling the use of the bitmaps. If the use of the device bitmaps should be disabled, omit the call of this function in SIM_X_Init(). SIM_GUI_SetMag() Description Sets magnification factors for X and/or Y axis. Prototype void SIM_GUI_SetMag(int MagX, int MagY); Parameter MagX MagY Description Magnification factor for X axis. Magnification factor for Y axis. Additional information Per default the simulation uses one pixel on the PC for each pixel of the simulated display. The use of this function makes sense for small displays. If using a device bitmap together with a magnification > 1 the device bitmap needs to be adapted to the magnification. The device bitmap is not magnified automatically. SIM_GUI_SetTransColor() Description Sets the color to be used for transparent areas of device or hardkey bitmaps. Prototype I32 SIM_GUI_SetTransColor(I32 Color); Parameter Color Description RGB value of the color in the format 00000000RRRRRRRRGGGGGGGGBBBBBBBB. Additional information The default setting for transparency is bright red (0xFF0000). You would typically only need to change this setting if your bitmap contains the same shade of red. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 55 SIM_GUI_UseCustomBitmaps() Description As described earlier in this chapter it is possible to use device bitmaps from the application resources. This function tells the simulation to use the device- and hardkey bitmaps from the application resources and not to generate the default frame bitmap. Prototype void SIM_GUI_UseCustomBitmaps(void); Additional information The emWin shipment contains per default 2 bitmaps, Device.bmp and Device1.bmp, located in Start\System\Simulation\Res which can be used as a starting point for your own bitmaps. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 56 3.4 CHAPTER Simulation Hardkey simulation The hardkey simulation can only be used in the custom bitmap view. Hardkeys may also be simulated as part of the device, and may be selected with the mouse pointer. The idea is to be able to distinguish whether a key or button on the simulated device is pressed or unpressed. A hardkey is considered "pressed" as long as the mouse button is held down; releasing the mouse button or moving the pointer off of the hardkey "unpresses" the key. A toggle behavior between pressed and unpressed may also be specified with the routine SIM_HARDKEY_SetMode(). In order to simulate hardkeys, you need a second bitmap of the device which is transparent except for the keys themselves (in their pressed state). As described earlier in this chapter, this bitmap can be in a separate file in the directory, or included as a resource in the executable. Hardkeys may be any shape, as long as they are exactly the same size in pixels in both Device.bmp and Device1.bmp. The following example illustrates this: Device bitmap: unpressed hardkey state (Device.bmp) Device hardkey bitmap: pressed hardkey state (Device1.bmp) When a key is "pressed" with the mouse, the corresponding section of the hardkey bitmap (Device1.bmp) will overlay the device bitmap in order to display the key in its pressed state. The keys may be polled periodically to determine if their states (pressed/unpressed) have changed and whether they need to be updated. Alternatively, a callback routine may be set to trigger a particular action to be carried out when the state of a hardkey changes. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 57 3.4.1 Hardkey simulation API The hardkey simulation functions are part of the standard simulation program shipped with emWin. If using a user defined emWin simulation these functions may not be available. The table below lists the available hardkey-simulation-related routines in alphabetical order within their respective categories. Detailed descriptions of the routines follow: Routine Explanation SIM_HARDKEY_GetNum() Return the number of available hardkeys. SIM_HARDKEY_GetState() Return the state of a specified hardkey (0: unpressed, 1: pressed). SIM_HARDKEY_SetCallback() Set a callback routine to be executed when the state of a specified hardkey changes. SIM_HARDKEY_SetMode() Set the behavior for a specified hardkey (default = 0: no toggle). SIM_HARDKEY_SetState() Set the state for a specified hardkey (0: unpressed, 1: pressed). SIM_HARDKEY_GetNum() Description Returns the number of available hardkeys. Prototype int SIM_HARDKEY_GetNum(void); Return value The number of available hardkeys found in the bitmap. Additional information The numbering order for hardkeys is standard reading order (left to right, then top to bottom). The topmost pixel of a hardkey is therefore found first, regardless of its horizontal position. In the bitmap below, for example, the hardkeys are labeled as they would be referenced by the KeyIndex parameter in other functions: It is recommended to call this function in order to verify that a bitmap is properly loaded. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 58 CHAPTER Simulation SIM_HARDKEY_GetState() Description Returns the state of a specified hardkey. Prototype int SIM_HARDKEY_GetState(unsigned int KeyIndex); Parameter KeyIndex Description Index of hardkey (0 = index of first key). Return value State of the specified hardkey: 0: unpressed 1: pressed SIM_HARDKEY_SetCallback() Description Sets a callback routine to be executed when the state of a specified hardkey changes. Prototype SIM_HARDKEY_CB * SIM_HARDKEY_SetCallback(unsigned int KeyIndex, SIM_HARDKEY_CB * pfCallback); Parameter KeyIndex pfCallback Description Index of hardkey (0 = index of first key). Pointer to callback routine. Return value Pointer to the previous callback routine. Additional information Note that multi tasking support has to be enabled if GUI functions need to be called within the callback functions. Without multi tasking support only the GUI functions which are allowed to be called within an interrupt routine should be used. The callback routine must have the following prototype: Prototype typedef void SIM_HARDKEY_CB(int KeyIndex, int State); Parameter KeyIndex State Description Index of hardkey (0 = index of first key). State of the specified hardkey. See table below. Permitted values for parameter State 0 1 Unpressed. Pressed. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 59 SIM_HARDKEY_SetMode() Description Sets the behavior for a specified hardkey. Prototype int SIM_HARDKEY_SetMode(unsigned int KeyIndex, int Mode); Parameter KeyIndex Mode Description Index of hardkey (0 = index of first key). Behavior mode. See table below. Permitted values for parameter Mode 0 1 Normal behavior (default). Toggle behavior. Additional information Normal (default) hardkey behavior means that a key is considered pressed only as long as the mouse button is held down on it. When the mouse is released or moved off of the hardkey, the key is considered unpressed. With toggle behavior, each click of the mouse toggles the state of a hardkey to pressed or unpressed. That means if you click the mouse on a hardkey and it becomes pressed, it will remain pressed until you click the mouse on it again. SIM_HARDKEY_SetState() Description Sets the state for a specified hardkey. Prototype int SIM_HARDKEY_SetState(unsigned int KeyIndex, int State); Parameter KeyIndex State Description Index of hardkey (0 = index of first key). State of the specified hardkey. See table below. Permitted values for parameter State 0 1 Unpressed. Pressed. Additional information This function is only usable when SIM_HARDKEY_SetMode() is set to 1 (toggle mode). UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 60 CHAPTER Simulation 3.5 Integrating the emWin simulation into an existing simulation In order to integrate the emWin simulation into an existing simulation, the source code of the simulation is not required. The source code of the simulation is not normally shipped with emWin. It is a separate (optional) software item and is not included in the emWin basic package. Normally the source code of the emWin simulation is not needed but available as an optional software item. As described earlier in this chapter the basic package and the trial version contains a simulation library. The API functions of this library can be used if for example the emWin simulation should be added to an existing hardware or real time kernel (RTOS) simulation. To add the emWin simulation to an existing simulation (written in C or C++, using the Win32 API), only a few lines of code need to be added. 3.5.1 Directory structure The subfolder Simulation of the System folder contains the emWin simulation. The directory structure is shown on the right. The table below explains the contents of the subfolders: Directory Content Simulation Simulation source and header files to be used with and without the simulation source code. The folder also contains a ready to use simulation library. Res Resource files. SIM_GUI GUI simulation source code (optional). WinMain Contains the WinMain routine. 3.5.2 Using the simulation library The following steps will show how to use the simulation library to integrate the emWin simulation into an existing simulation: * * * * Step 1: Add the simulation library GUISim.lib to the project. Step 2: Add all GUI files to the project as described in the chapter 2.1.1, "Subdirectories". Step 3: Add the include directories to the project as described in the chapter 2.1.2, "Include Directories". Step 4: Modify WinMain. 3.5.2.1 Modifying WinMain Every windows Win32 program starts with WinMain() (contrary to a normal C program from the command line, which starts with main(). All that needs to be done is to add a few lines of code to this routine. The following function calls need to be added (normally in the order as it's shown in the following application code example): * * * * * SIM_GUI_Enable SIM_GUI_Init SIM_GUI_CreateLCDWindow CreateThread SIM_GUI_Exit UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 61 3.5.2.2 Example application The following application is available under Sample\WinMain\SampleApp.c and shows how to integrate the emWin simulation into an existing application: #include #include "GUI_SIM_Win32.h" void MainTask(void); /********************************************************************* * * _Thread */ static DWORD __stdcall _Thread(void * Parameter) { MainTask(); return 0; } /********************************************************************* * * _WndProcMain */ static LRESULT CALLBACK _WndProcMain(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { SIM_GUI_HandleKeyEvents(message, wParam); switch (message) { case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } /********************************************************************* * * _RegisterClass */ static void _RegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; memset(&wcex, 0, sizeof(wcex)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.hInstance = hInstance; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)_WndProcMain; wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); wcex.lpszMenuName = 0; wcex.lpszClassName = "GUIApplication"; RegisterClassEx(&wcex); } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 62 CHAPTER Simulation /********************************************************************* * * WinMain */ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DWORD ThreadID; MSG Msg; HWND hWndMain; // // Register window class // _RegisterClass(hInstance); // // Make sure the driver configuration is done // SIM_GUI_Enable(); // // Create main window // hWndMain = CreateWindow("GUIApplication", "Application window", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VISIBLE, 0, 0, 328, 267, NULL, NULL, hInstance, NULL); // // Initialize the emWin simulation and create an LCD window // SIM_GUI_Init(hInstance, hWndMain, lpCmdLine, "embOS - emWin Simulation"); SIM_GUI_CreateLCDWindow(hWndMain, 0, 0, 320, 240, 0); // // Create a thread which executes the code to be simulated // CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)_Thread, NULL, 0, &ThreadID); // // Main message loop // while (GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } SIM_GUI_Exit(); } 3.5.3 Integration into the embOS Simulation 3.5.3.1 WinMain The following code example shows how to modify the existing WinMain of the embOS simulation in order to integrate the emWin simulation. The red colored lines should be added to WinMain to initialize the emWin simulation, to create a simulation window and to exit the emWin simulation: ... #include "GUI_SIM_Win32.h" ... int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG Msg; HACCEL hAccelTable; HWND hWndMain; BITMAP BmpDevice; DWORD ThreadID; // // Init global data // _StopHyperThreading(); _hInst = hInstance; // // Register main window class // _RegisterClass(); // // Load bitmap // _hBmpDevice = (HBITMAP)LoadImage(_hInst, (LPCTSTR) IDB_DEVICE, IMAGE_BITMAP, 0, 0, 0); _hMenuPopup = LoadMenu(_hInst, (LPCSTR)IDC_CONTEXTMENU); _hMenuPopup = GetSubMenu(_hMenuPopup, 0); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 63 // // Make sure the driver configuration is done // SIM_GUI_Enable(); // // Create main window // GetObject(_hBmpDevice, sizeof(BmpDevice), &BmpDevice); hWndMain = CreateWindowEx(WS_EX_TOPMOST, _sWindowClass, "embOS Simulation", WS_SYSMENU | WS_CLIPCHILDREN | WS_POPUP | WS_VISIBLE, 10, 20, BmpDevice.bmWidth, BmpDevice.bmHeight, NULL, NULL, _hInst, NULL); if (!hWndMain) { return 1; // Error } // // Init emWin simulation and create window // SIM_GUI_Init(hInstance, hWndMain, lpCmdLine, "embOS - emWin Simulation"); SIM_GUI_CreateLCDWindow(hWndMain, 80, 50, 128, 64, 0); // // Show main window // ShowWindow(hWndMain, nCmdShow); // // Load accelerator table // hAccelTable = LoadAccelerators(_hInst, (LPCTSTR)IDC_WINMAIN); // // Application initialization // CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Thread, NULL, 0, &ThreadID); // // Main message loop // if (SIM_Init(hWndMain) == 0) { while (GetMessage(&Msg, NULL, 0, 0)) { if (!TranslateAccelerator(Msg.hwnd, hAccelTable, &Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } } // // Exit emWin simulation // SIM_GUI_Exit(); return 0; } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 64 CHAPTER Simulation 3.5.3.2 Target program (main) The emWin API can be called from one or more target threads. Without RTOS, the WIN32 API function CreateThread is normally used to create a target thread which calls the emWin API; within an RTOS simulation, a target task/thread (Created by the simulated RTOS) is used to call the emWin API. In other words: Use OS_CreateTask to create a task for the user interface. Below a modified embOS start application: #include #include #include #include "RTOS.H" "HW_LED.h" "GUI.h" OS_STACKPTR int Stack0[128], Stack1[128], Stack2[2000]; // Task stacks OS_TASK TCB0, TCB1, TCB2; // Task-control-blocks void Task0(void) { while (1) { HW_LED_Toggle0(); OS_Delay(100); } } void Task1(void) { while (1) { HW_LED_Toggle1(); OS_Delay(500); } } void MainTask(void) { int i; GUI_COLOR aColor[] = {GUI_RED, GUI_YELLOW}; GUI_Init(); while (1) { for (i = 0; i < 2; i++) { GUI_Clear(); GUI_SetColor(aColor[i]); GUI_SetFont(&GUI_FontComic24B_ASCII); GUI_DispStringAt("Hello world!", 1, 1); OS_Delay(200); } } } /********************************************************** * * main */ void main(void) { OS_IncDI(); // Initially disable interrupts OS_InitKern(); // Initialize OS OS_InitHW(); // Initialize Hardware for OS // // You need to create at least one task here! // OS_CREATETASK(&TCB0, "HP Task", Task0, 100, Stack0); OS_CREATETASK(&TCB1, "LP Task", Task1, 50, Stack1); OS_CREATETASK(&TCB2, "GUI Task", MainTask, 80, Stack2); OS_Start(); // Start multitasking } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 65 The following table shows the simulation before and after integrating the emWin simulation: Before 3.5.4 After GUI simulation API The table below lists the available routines for user defined simulation programs in alphabetical order within their respective categories. The functions are only available with the source code of the emWin simulation. Detailed descriptions of the routines follow: Routine SIM_GUI_CreateLCDInfoWindow() SIM_GUI_CreateLCDWindow() SIM_GUI_Enable() SIM_GUI_Exit() SIM_GUI_Init() SIM_GUI_SetLCDWindowHook() Explanation Creates a window which shows the available colors of the given layer with the given size and position. Creates a LCD window with the given size and position. Executes memory and driver configuration. Stops the GUI simulation. Initializes the GUI simulation. Sets a hook function to be called if the LCD window receives a message. SIM_GUI_CreateLCDInfoWindow() Description Creates a window which shows the available colors for the given layer. Prototype HWND SIM_GUI_CreateLCDInfoWindow(HWND hParent, int x, int y, int xSize, int ySize int LayerIndex); Parameter hParent x y Description Handle of the parent window. X position in parent coordinates. Y position in parent coordinates. xSize X size in pixel of the new window. Should be 160 if using a color depth between 1 and 8 or 128 if working in high color mode. ySize Y size in pixel of the new window. Should be 160 if using a color depth between 1 and 8 or 128 if working in high color mode. LayerIndex Index of layer to be shown. Additional information The created color window has no frame, no title bar and no buttons. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 66 CHAPTER Simulation Example SIM_GUI_CreateLCDInfoWindow(hWnd, 0, 0, 160, 160, 0); Screenshot SIM_GUI_CreateLCDWindow() Description Creates a window which simulates a LCD display with the given size at the given position. Prototype HWND SIM_GUI_CreateLCDWindow(HWND hParent, int x, int y, int xSize, int ySize int LayerIndex); Parameter hParent x y xSize ySize LayerIndex Description Handle of the parent window. X position in parent coordinates. Y position in parent coordinates. X size in pixel of the new window. Y size in pixel of the new window. Index of layer to be shown. Additional information All display output to the given layer will be shown in this window. The size of the window should be the same as configured in LCDConf.c. The created simulation window has no frame, no title bar and no buttons. SIM_GUI_Enable() Description The function needs to be called at the beginning of the application to make sure that memory and driver will be configured at first. Prototype void SIM_GUI_Enable(void); SIM_GUI_Exit() Description The function should be called before the simulation returns to the calling process. Prototype void SIM_GUI_Exit(void); SIM_GUI_Init() Description This function initializes the emWin simulation and should be called before any other SIM_GUI... function call. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 67 Prototype int SIM_GUI_Init(HINSTANCE hInst, HWND hWndMain, char * pCmdLine, const char * sAppName); Parameter hInst hWndMain pCmdLine sAppName Description Handle to current instance passed to WinMain . Handle of the simulations main window. Pointer to command line passed to WinMain Pointer to a string that contains the application name. Additional information The parameters hWndMain and sAppName are used if a message box should be displayed. SIM_GUI_SetLCDWindowHook() Description Sets a hook function to be called from the simulation if the LCD window receives a message. Prototype void SIM_GUI_SetLCDWindowHook(SIM_GUI_tfHook * pfHook); Parameter pfHook Description Pointer to hook function. Prototype of hook function int Hook(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam, int * pResult); Parameter hWnd Message wParam lParam pResult Description Handle of LCD window. Message received from the operating system. wParam message parameter passed by the system. lParam message parameter passed by the system. Pointer to an integer which should be used as return code if the message has been processed by the hook function. Return value The hook function should return 0 if the message has been processed. In this case the GUI simulation ignores the message. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 68 UM03001 User & Reference Guide for emWin V5.20 CHAPTER Simulation (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 69 Chapter 4 Viewer If you use the simulation when debugging your application, you cannot see the display output when stepping through the source code. The primary purpose of the viewer is to solve this problem. It shows the contents of the simulated display(s) while debugging in the simulation. The viewer gives you the following additional capabilities: * * * * Multiple windows for each layer Watching the whole virtual layer in one window Magnification of each layer window Composite view if using multiple layers UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 70 CHAPTER 4.1 Viewer Using the viewer The viewer allows you to: * Open multiple windows for any layer/display * Zoom in on any area of a layer/ display * See the contents of the individual layers/displays as well as the composite view in multilayer configurations * See the contents of the virtual screen and the visible display when using the virtual screen support. The screenshot shows the viewer displaying the output of a single layer configuration. The upper left corner shows the simulated display. In the upper right corner is a window, which shows the available colors of the display configuration. At the bottom of the viewer a second display window shows a magnified area of the simulated display. If you start to debug your application, the viewer shows one display window per layer and one color window per layer. In a multi layer configuration, a composite view window will also be visible. 4.1.1 Using the simulation and the viewer If you use the simulation when debugging your application, you cannot see the display output when stepping through the source code. This is due to a limitation of Win32: If one thread (the one being debugged) is halted, all other threads of the process are also halted. This includes the thread which outputs the simulated display on the screen. The emWin viewer solves this problem by showing the display window and the color window of your simulation in a separate process. It is your choice if you want to start the viewer before debugging your application or while you are debugging. Our suggestion: * * * * Step 1: Start the viewer. No display- or color window is shown until the simulation has been started. Step 2: Open the Visual C++ workspace. Step 3: Compile and run the application program. Step 4: Debug the application as described previously. The advantage is that you can now follow all drawing operations step by step in the LCD window. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 71 4.1.2 Using the viewer with virtual pages By default the viewer opens one window per layer which shows the visible part of the video RAM, normally the display. If the configured virtual video RAM is larger than the display, the command View/Virtual Layer/Layer (0...4) can be used to show the whole video RAM in one window. When using the function GUI_SetOrg(), the contents of the visible screen will change, but the virtual layer window remains unchanged: For more information about virtual screens, refer to chapter "Virtual screens / Virtual pages" on page 835. 4.1.3 Always on top Per default the viewer window is always on top. You can change this behavior by selecting Options\Always on top from the menu. 4.1.4 Open further windows of the display output If you want to show a magnified area of the LCD output or the composite view of a multi layer configuration it could be useful to open more than one output window. You can do this by View/Visible Layer/Layer (1...4), View/Virtual Layer/ Layer (1...4) or View/Composite. 4.1.5 Zooming Zooming in or out is easy: Right-click on a layer or composite window opens the Zoom popup menu. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 72 CHAPTER Viewer Choose one of the zoom options: Using the grid If you magnify the LCD output >= 300%, you have the choice between showing the output with or without a grid. It is possible to change the color of the grid. This can be done choosing the Menu point Options/Grid color. Adapting the size of the window If you want to adapt the size of the window to the magnification choose Fit window to size from the first popup menu. 4.1.6 Copy the output to the clipboard Click onto a LCD window or a composite view with the right mouse key and choose Copy to clipboard. Now you can paste the contents of the clipboard for example into the MS Paint application. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 73 4.1.7 Using the viewer with multiple displays If you are working with multiple displays you should set the viewer into 'Multi display mode' by using the command Options/Multi layer/display. When starting the debugger the viewer will open one display window and one color window for each display: 4.1.8 Using the viewer with multiple layers If you are working with multiple layers you should set the viewer into 'Multi layer mode' by using the command Options/Multi layer/display. When starting the debugger the viewer will open one LCD window and one color window for each layer and one composite window for the result. Example The example below shows a screenshot of the viewer with 2 layers. Layer 0 shows color bars with a high color configuration. Layer 1 shows a transparent circle on a white background with colored rectangles. The composite window shows the result which is actually visible on the display UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 74 CHAPTER Viewer Transparency The composite window of the viewer shows all layers; layers with higher index are on top of layers with lower index and can have transparent pixels: Layer 0 Layer 1 No transparency ... Layer n Pixels can be transparent UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 75 Chapter 5 Displaying Text It is very easy to display text with emWin. Knowledge of only a few routines already allows you to write any text, in any available font, at any point on the display. We first provide a short introduction to displaying text, followed by more detailed explanations of the individual routines that are available. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 76 CHAPTER 5.1 Displaying Text Basic routines In order to display text on the LCD, simply call the routine GUI_DispString() with the text you want to display as parameters. For example: GUI_DispString("Hello world!"); The above code will display the text "Hello world" at the current text position. However, as you will see, there are routines to display text in a different font or in a certain position. In addition, it is possible to write not only strings but also decimal, hexadecimal and binary values to the display. Even though the graphic displays are usually byte-oriented, the text can be positioned at any pixel of the display, not only at byte positions. Control characters Control characters are characters with a character code of less than 32. The control characters are defined as part of ASCII. emWin ignores all control characters except for the following: Char. Code ASCII code C Description 10 LF \n Line feed. The current text position is changed to the beginning of the next line. Per default, this is: X = 0. Y + =font-distance in pixels (as delivered by GUI_GetFontDistY() ). 13 CR \r Carriage return. The current text position is changed to the beginning of the current line. Per default, this is: X = 0. Usage of the control character LF can be very convenient in strings. A line feed can be made part of a string so that a string spanning multiple lines can be displayed with a single routine call. Positioning text at a selected position This may be done by using the routine GUI_GotoXY() as shown in the following example: GUI_GotoXY(10,10);// Set text position (in pixels) GUI_DispString("Hello world!");// Show text UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 77 5.2 Text API The table below lists the available text-related routines in alphabetical order within their respective categories. Detailed descriptions of the routines can be found in the sections that follow. Routine Explanation Routines to display text GUI_DispChar() GUI_DispCharAt() GUI_DispChars() GUI_DispNextLine() GUI_DispString() GUI_DispStringAt() GUI_DispStringAtCEOL() GUI_DispStringHCenterAt() GUI_DispStringInRect() GUI_DispStringInRectEx() GUI_DispStringInRectWrap() Displays single character at current position. Displays single character at specified position. Displays character a specified number of times. Moves the cursor to the beginning of the next line. Displays string at current position. Displays string at specified position. Displays string at specified position, then clear to end of line. Displays string centered horizontally at the given position. Displays string in specified rectangle. Displays string in specified rectangle and optionally rotates it. Displays string in specified rectangle with optional wrapping. GUI_DispStringLen() Display string at current position with specified number of characters. GUI_WrapGetNumLines() Get the number of text lines for the given wrap mode. Selecting text drawing modes GUI_GetTextMode() GUI_SetTextMode() GUI_SetTextStyle() Returns the current text mode GUI_GetTextAlign() GUI_SetLBorder() GUI_SetTextAlign() Return current text alignment mode. Sets text drawing mode. Sets the text style to be used. Selecting text alignment Set left border after line feed. Set text alignment mode. Setting the current text position GUI_GotoX() GUI_GotoXY() GUI_GotoY() Set current X-position. Set current (X,Y) position. Set current Y-position. Retrieving the current text position GUI_GetDispPosX() GUI_GetDispPosY() Return current X-position. Return current Y-position. Routines to clear a window or parts of it GUI_Clear() Clear active window (or entire display if background is the active window). GUI_DispCEOL() Clear display from current text position to end of line. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 78 CHAPTER 5.3 Displaying Text Routines to display text GUI_DispChar() Description Displays a single character at the current text position in the current window using the current font. Prototype void GUI_DispChar(U16 c); Parameter Description Character to display. c Additional information This is the basic routine for displaying a single character. All other display routines (GUI_DispCharAt(), GUI_DispString(), etc.) call this routine to output the individual characters. Which characters are available depends on the selected font. If the character is not available in the current font, nothing is displayed. Example Shows a capital A on the display: GUI_DispChar('A'); Related topics GUI_DispChars(), GUI_DispCharAt() GUI_DispCharAt() Description Displays a single character at a specified position in the current window using the current font. Prototype void GUI_DispCharAt(U16 c, I16P x, I16P y); Parameter c x y Description Character to display. X-position to write to in pixels of the client window. Y-position to write to in pixels of the client window. Add information Displays the character with its upper left corner at the specified (X,Y) position. Writes the character using the routine GUI_DispChar(). If the character is not available in the current font, nothing is displayed. Example Shows a capital A on the display in the upper left corner: GUI_DispCharAt('A',0,0); Related topics GUI_DispChar(), GUI_DispChars() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 79 GUI_DispChars() Description Displays a character a specified number of times at the current text position in the current window using the current font. Prototype void GUI_DispChars(U16 c, int Cnt); Parameter Description Character to display. c Cnt Number of repetitions (0 <= Cnt <= 32767). Additional information Writes the character using the routine GUI_DispChar(). If the character is not available in the current font, nothing is displayed. Example Shows the line "******************************" on the display: GUI_DispChars('*', 30); Related topics GUI_DispChar(), GUI_DispCharAt() GUI_DispNextLine() Description Moves the cursor to the beginning of the next line. Prototype void GUI_DispNextLine(void); Related topics GUI_SetLBorder() GUI_DispString() Description Displays the string passed as parameter at the current text position in the current window using the current font. Prototype void GUI_DispString(const char GUI_FAR * s); Parameter s Description String to display. Additional information The string can contain the control character \n. This control character moves the current text position to the beginning of the next line. Example Shows "Hello world" on the display and "Next line" on the next line: GUI_DispString("Hello world"); GUI_DispString("\nNext line"); //Disp text //Disp text Related topics GUI_DispStringAt(), GUI_DispStringAtCEOL(), GUI_DispStringLen() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 80 CHAPTER Displaying Text GUI_DispStringAt() Description Displays the string passed as parameter at a specified position in the current window using the current font. Prototype void GUI_DispStringAt(const char GUI_FAR * s, int x, int y); Parameter s x y Description String to display. X-position to write to in pixels of the client window. Y-position to write to in pixels of the client window. Example Shows "Position 50,20" at position 50,20 on the display: GUI_DispStringAt("Position 50,20", 50, 20); // Disp text Related topics GUI_DispString(), GUI_DispStringAtCEOL(), GUI_DispStringLen(), GUI_DispStringAtCEOL() Description This routine uses the exact same parameters as GUI_DispStringAt(). It does the same thing: displays a given string at a specified position. However, after doing so, it clears the remaining part of the line to the end by calling the routine GUI_DispCEOL(). This routine can be handy if one string is to overwrite another, and the overwriting string is or may be shorter than the previous one. GUI_DispStringHCenterAt() Description Displays the string passed as parameter horizontally centered at a specified position in the current window using the current font. Prototype void GUI_DispStringHCenterAt(const char GUI_FAR * s, int x, int y); Parameter s x y Description String to display. X-position to write to in pixels of the client window. Y-position to write to in pixels of the client window. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 81 GUI_DispStringInRect() Description Displays the string passed as parameter at a specified position within a specified rectangle, in the current window using the current font. Prototype void GUI_DispStringInRect(const char GUI_UNI_PTR * s, GUI_RECT * pRect, int TextAlign); Parameter s pRect TextAlign Description String to display. Rectangle to write to in pixels of the client window. Alignment flags; "OR " combinable. A flag for horizontal and a flag for vertical alignment should be combined. Available flags are: GUI_TA_TOP, GUI_TA_BOTTOM, GUI_TA_VCENTER for vertical alignment. GUI_TA_LEFT, GUI_TA_RIGHT, GUI_TA_HCENTER for horizontal alignment. Example Shows the word "Text" centered horizontally and vertically in the current window: GUI_RECT rClient; GUI_GetClientRect(&rClient); GUI_DispStringInRect("Text", &rClient, GUI_TA_HCENTER | GUI_TA_VCENTER); Additional information If the specified rectangle is too small, the text will be clipped. Related topics GUI_DispString(), GUI_DispStringAtCEOL(), GUI_DispStringLen(), UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 82 CHAPTER Displaying Text GUI_DispStringInRectEx() Description Displays the string passed as parameter at a specified position within a specified rectangle, in the current window using the current font and (optionally) rotates it. Prototype void GUI_DispStringInRectEx(const char * GUI_RECT * int int const GUI_ROTATION * Parameter s pRect TextAlign MaxLen pLCD_Api s, pRect, TextAlign, MaxLen, pLCD_Api); Description String to display. Rectangle to write to in pixels of the client window. Alignment flags; " OR " combinable. A flag for horizontal and a flag for vertical alignment should be combined. Available flags are: GUI_TA_TOP, GUI_TA_BOTTOM, GUI_TA_VCENTER for vertical alignment. GUI_TA_LEFT, GUI_TA_RIGHT, GUI_TA_HCENTER for horizontal alignment. Maximum number of characters to be shown. See table below. Permitted values for parameter pLCD_Api GUI_ROTATE_0 GUI_ROTATE_180 GUI_ROTATE_CCW GUI_ROTATE_CW Does not rotate the text. Shows it from left to right. Rotates the text by 180 degrees. Rotates the text counter clockwise. Rotates the text clockwise. Example Shows the word "Text" centered horizontally and vertically in the given rectangle: GUI_RECT Rect = {10, 10, 40, 80}; char acText[] = "Rotated\ntext"; GUI_SetTextMode(GUI_TM_XOR); GUI_FillRectEx(&Rect); GUI_DispStringInRectEx(acText, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, strlen(acText), GUI_ROTATE_CCW); Screenshot of above example Additional information If the specified rectangle is too small, the text will be clipped. To make the function available the configuration switch GUI_SUPPORT_ROTATION must be activated (default). UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 83 GUI_DispStringInRectWrap() Description Displays a string at a specified position within a specified rectangle, in the current window using the current font and (optionally) wraps the text. Prototype void GUI_DispStringInRectWrap(const char GUI_UNI_PTR * s, GUI_RECT * pRect, int TextAlign, GUI_WRAPMODE WrapMode); Parameter s pRect Description String to display. Rectangle to write to in pixels of the client window. TextAlign Alignment flags; " OR " combinable. A flag for horizontal and a flag for vertical alignment should be combined. Available flags are: GUI_TA_TOP, GUI_TA_BOTTOM, GUI_TA_VCENTER for vertical alignment. GUI_TA_LEFT, GUI_TA_RIGHT, GUI_TA_HCENTER for horizontal alignment. WrapMode See table below. Permitted values for parameter WrapMode GUI_WRAPMODE_NONE GUI_WRAPMODE_WORD GUI_WRAPMODE_CHAR No wrapping will be performed. Text is wrapped word wise. Text is wrapped char wise. Additional information If word wrapping should be performed and the given rectangle is too small for a word char wrapping is executed at this word. Example Shows a text centered horizontally and vertically in the given rectangle with word wrapping: int i; char acText[] = "This example demonstrates text wrapping"; GUI_RECT Rect = {10, 10, 59, 59}; GUI_WRAPMODE aWm[] = {GUI_WRAPMODE_NONE, GUI_WRAPMODE_CHAR, GUI_WRAPMODE_WORD}; GUI_SetTextMode(GUI_TM_TRANS); for (i = 0; i < 3; i++) { GUI_SetColor(GUI_BLUE); GUI_FillRectEx(&Rect); GUI_SetColor(GUI_WHITE); GUI_DispStringInRectWrap(acText, &Rect, GUI_TA_LEFT, aWm[i]); Rect.x0 += 60; Rect.x1 += 60; } Screenshot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 84 CHAPTER Displaying Text GUI_DispStringLen() Description Displays the string passed as parameter with a specified number of characters at the current text position, in the current window using the current font. Prototype void GUI_DispStringLen(const char GUI_FAR * s, int Len); Parameter Description s String to display. Should be a \0 terminated array of 8-bit character. Passing NULL as parameter is permitted. Len Number of characters to display. Additional information If the string has less characters than specified (is shorter), it is padded with spaces. If the string has more characters than specified (is longer), then only the given number of characters is actually displayed. This function is especially useful if text messages can be displayed in different languages (and will naturally differ in length), but only a certain number of characters can be displayed. Related topics GUI_DispString(), GUI_DispStringAt(), GUI_DispStringAtCEOL(), GUI_WrapGetNumLines() Description Returns the number of lines used to show the given text with the given wrap mode. Prototype int GUI_WrapGetNumLines(const char GUI_UNI_PTR * pText, int xSize, GUI_WRAPMODE WrapMode); Parameter pText xSize WrapMode Description String to display. Should be a \0 terminated array of 8-bit character. Passing NULL as parameter is permitted. X-size to be used to draw the text. See table below. Permitted values for parameter WrapMode GUI_WRAPMODE_NONE GUI_WRAPMODE_WORD GUI_WRAPMODE_CHAR No wrapping will be performed. Text is wrapped word wise. Text is wrapped char wise. Additional information Please remember that the number of lines required to draw text depends on the currently selected font. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 85 5.4 Selecting text drawing modes Normally, text is written into the selected window at the current text position using the selected font in normal text. Normal text means that the text overwrites whatever is already displayed where the bits set in the character mask are set on the display. In this mode, active bits are written using the foreground color, while inactive bits are written with the background color. However, in some situations it may be desirable to change this default behavior. emWin offers four flags for this purpose (one default plus three modifiers), which may be combined: Normal text Text can be displayed normally by specifying GUI_TEXTMODE_NORMAL or 0. Reverse text Text can be displayed reverse by specifying GUI_TEXTMODE_REV. What is usually displayed as white on black will be displayed as black on white. Transparent text Text can be displayed transparently by specifying GUI_TEXTMODE_TRANS. Transparent text means that the text is written on top of whatever is already visible on the display. The difference is that whatever was previously on the screen can still be seen, whereas with normal text the background is replaced with the currently selected background color. XOR text Text can be displayed using the XOR mode by specifying GUI_TEXTMODE_XOR. What usually is drawn white (the actual character) is inverted. The effect is identical to that of the default mode (normal text) if the background is black. If the background is white, the output is identical to reverse text. If you use colors, an inverted pixel is calculated as follows: New pixel color = number of colors - actual pixel color - 1. Transparent reversed text Text can be displayed in reverse transparently by specifying GUI_TEXTMODE_TRANS | GUI_TEXTMODE_REV. As with transparent text, it does not overwrite the background, and as with reverse text, the text is displayed in reverse. Additional information Please note that you can also use the abbreviated form: e.g. GUI_TM_NORMAL Example Displays normal, reverse, transparent, XOR, and transparent reversed text: GUI_SetFont(&GUI_Font8x16); GUI_SetBkColor(GUI_BLUE); GUI_Clear(); GUI_SetPenSize(10); GUI_SetColor(GUI_RED); GUI_DrawLine(80, 10, 240, 90); GUI_DrawLine(80, 90, 240, 10); GUI_SetBkColor(GUI_BLACK); GUI_SetColor(GUI_WHITE); GUI_SetTextMode(GUI_TM_NORMAL); GUI_DispStringHCenterAt("GUI_TM_NORMAL" , GUI_SetTextMode(GUI_TM_REV); GUI_DispStringHCenterAt("GUI_TM_REV" , GUI_SetTextMode(GUI_TM_TRANS); GUI_DispStringHCenterAt("GUI_TM_TRANS" , GUI_SetTextMode(GUI_TM_XOR); GUI_DispStringHCenterAt("GUI_TM_XOR" , GUI_SetTextMode(GUI_TM_TRANS | GUI_TM_REV); GUI_DispStringHCenterAt("GUI_TM_TRANS | GUI_TM_REV", UM03001 User & Reference Guide for emWin V5.20 160, 10); 160, 26); 160, 42); 160, 58); 160, 74); (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 86 CHAPTER Displaying Text Screen shot of above example GUI_GetTextMode() Description Returns the currently selected text mode. Prototype int GUI_GetTextMode(void); Return value The currently selected text mode. GUI_SetTextMode() Description Sets the text mode to the parameter specified. Prototype int GUI_SetTextMode(int TextMode); Parameter TextMode Description Text mode to set. May be any combination of the TEXTMODE flags. Permitted values for parameter TextMode (OR-combinable) GUI_TEXTMODE_NORMAL GUI_TEXTMODE_REV GUI_TEXTMODE_TRANS GUI_TEXTMODE_XOR Causes text to be displayed normally. This is the default setting; the value is identical to 0. Causes text to be displayed reverse. Causes text to be displayed transparent. Causes text to invert the background. Return value The previous selected text mode. Example Shows "The value is" at position 0,0 on the display, shows a value in reverse text, then sets the text mode back to normal: int i = 20; GUI_DispStringAt("The value is", 0, 0); GUI_SetTextMode(GUI_TEXTMODE_REV); GUI_DispDec(20, 3); GUI_SetTextMode(GUI_TEXTMODE_NORMAL); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 87 GUI_SetTextStyle() Description Sets the text style to the parameter specified. Prototype char GUI_SetTextStyle(char Style); Parameter Style Description Text style to set. See table below. Permitted values for parameter Style Renders text normal (default). GUI_TS_NORMAL GUI_TS_UNDERLINE GUI_TS_STRIKETHRU GUI_TS_OVERLINE Renders text underlined. Renders text in strike through type. Renders text in overline type. Return value The previous selected text style. 5.5 Selecting text alignment GUI_GetTextAlign() Description Returns the current text alignment mode. Prototype int GUI_GetTextAlign(void); GUI_SetLBorder() Description Sets the left border for line feeds in the current window. Prototype void GUI_SetLBorder(int x) Parameter x Description New left border (in pixels, 0 is left border). UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 88 CHAPTER Displaying Text GUI_SetTextAlign() Description Sets the text alignment mode for the next string output operation in the current window. Prototype int GUI_SetTextAlign(int TextAlign); Parameter TextAlign Description Text alignment mode to set. May be a combination of a horizontal and a vertical alignment flag. Permitted values for parameter TextAlign (horizontal and vertical flags are OR-combinable) Horizontal alignment GUI_TA_LEFT GUI_TA_HCENTER GUI_TA_RIGHT Align X-position left (default). GUI_TA_TOP GUI_TA_VCENTER GUI_TA_BOTTOM Align Y-position with top of characters (default). Center X-position. Align X-position right. Vertical alignment Center Y-position. Align Y-position with bottom pixel line of font. Return value The selected text alignment mode. Additional information Setting the text alignment does not affect GUI_DispChar...()-functions. Text alignment is valid only for the current window. Example Displays the value 1234 with the center of the text at x=100, y=100: GUI_SetTextAlign(GUI_TA_HCENTER | GUI_TA_VCENTER); GUI_DispDecAt(1234,100,100,4); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 89 5.6 Setting the current text position Every task has a current text position. This is the position relative to the origin of the window (usually (0,0)) where the next character will be written if a text output routine is called. Initially, this position is (0,0), which is the upper left corner of the current window. There are 3 functions which can be used to set the current text position. GUI_GotoXY(), GUI_GotoX(), GUI_GotoY() Description Set the current text write position. Prototypes char GUI_GotoXY(int x, int y); char GUI_GotoX(int x); char GUI_GotoY(int y); Parameter x y Description New X-position (in pixels, 0 is left border). New Y-position (in pixels, 0 is top border). Return value Usually 0. If a value != 0 is returned, then the current text position is outside of the window (to the right or below), so a following write operation can be omitted. Additional information GUI_GotoXY() sets both the X- and Y-components of the current text position. GUI_GotoX() sets the X-component of the current text position; the Y-component remains unchanged. GUI_GotoY() sets the Y-component of the current text position; the X-component remains unchanged. Example Shows "(20,20)" at position 20,20 on the display: GUI_GotoXY(20,20) GUI_DispString("The value is"); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 90 5.7 CHAPTER Displaying Text Retrieving the current text position GUI_GetDispPosX() Description Returns the current X-position. Prototype int GUI_GetDispPosX(void); GUI_GetDispPosY() Description Returns the current Y-position. Prototype int GUI_GetDispPosY(void); 5.8 Routines to clear a window or parts of it GUI_Clear() Description Clears the current window. Prototype void GUI_Clear(void); Additional information If no window has been defined, the current window is the entire display. In this case, the entire display is cleared. Example Shows "Hello world" on the display, waits 1 second and then clears the display: GUI_DispStringAt("Hello world", 0, 0); // Disp text GUI_Delay(1000); // Wait 1 second (not part of emWin) GUI_Clear(); // Clear screen GUI_DispCEOL() Description Clears the current window (or the display) from the current text position to the end of the line using the height of the current font. Prototype void GUI_DispCEOL(void); Example Shows "Hello world" on the display, waits 1 second and then displays "Hi" in the same place, replacing the old string: GUI_DispStringAt("Hello world", 0, 0);// Disp text Delay (1000); GUI_DispStringAt("Hi", 0, 0); GUI_DispCEOL(); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 91 Chapter 6 Displaying Values The preceding chapter explained how to show strings on the display. Of course you may use strings and the functions of the standard C library to display values. However, this can sometimes be a difficult task. It is usually much easier (and much more efficient) to call a routine that displays the value in the form that you want. emWin supports different decimal, hexadecimal and binary outputs. The individual routines are explained in this chapter. All functions work without the usage of a floating-point library and are optimized for both speed and size. Of course sprintf may also be used on any system. Using the routines in this chapter can sometimes simplify things and save both ROM space and execution time. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 92 6.1 CHAPTER Displaying Values Value API The table below lists the available value-related routines in alphabetical order within their respective categories. Detailed descriptions of the routines can be found in the sections that follow. Routine Explanation Displaying decimal values GUI_DispDec() Display value in decimal form at current position with specified number of characters. GUI_DispDecAt() Display value in decimal form at specified position with specified number of characters. GUI_DispDecMin() Display value in decimal form at current position with minimum number of characters. GUI_DispDecShift() Display long value in decimal form with decimal point at current position with specified number of characters. GUI_DispDecSpace() Display value in decimal form at current position with specified number of characters, replace leading zeros with spaces. GUI_DispSDec() Display value in decimal form at current position with specified number of characters and sign. GUI_DispSDecShift() Display long value in decimal form with decimal point at current position with specified number of characters and sign. GUI_DispFloat() Display floating-point value with specified number of characters. GUI_DispFloatFix() Display floating-point value with fixed no. of digits to the right of decimal point. GUI_DispFloatMin() Display floating-point value with minimum number of characters. GUI_DispSFloatFix() Display floating-point value with fixed no. of digits to the right of decimal point and sign. GUI_DispSFloatMin() Display floating-point value with minimum number of characters and sign. Displaying floating-point values Displaying binary values GUI_DispBin() GUI_DispBinAt() Display value in binary form at current position. Display value in binary form at specified position. Displaying hexadecimal values GUI_DispHex() GUI_DispHexAt() Display value in hexadecimal form at current position. Display value in hexadecimal form at specified position. Version of emWin GUI_GetVersionString() Return the current version of emWin. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 93 6.2 Displaying decimal values GUI_DispDec() Description Displays a value in decimal form with a specified number of characters at the current text position, in the current window using the current font. Prototype void GUI_DispDec(I32 v, U8 Len); Parameter Description v Value to display. Minimum -2147483648 (= -2^31). Maximum 2147483647 (= 2^31 -1). Len No. of digits to display (max. 10). Additional information Leading zeros are not suppressed (are shown as 0). If the value is negative, a minus sign is shown. Example // Display time as minutes and seconds GUI_DispString("Min:"); GUI_DispDec(Min,2); GUI_DispString(" Sec:"); GUI_DispDec(Sec,2); Related topics GUI_DispSDec(), GUI_DispDecAt(), GUI_DispDecMin(), GUI_DispDecSpace() GUI_DispDecAt() Description Displays a value in decimal form with a specified number of characters at a specified position, in the current window using the current font. Prototype void GUI_DispDecAt(I32 v, I16P x, I16P y, U8 Len); Parameter v x y Len Description Value to display. Minimum -2147483648 (= -2^31). Maximum 2147483647 (= 2^31 -1). X-position to write to in pixels of the client window. Y-position to write to in pixels of the client window. No. of digits to display (max. 10). Additional information Leading zeros are not suppressed. If the value is negative, a minus sign is shown. Example // Update seconds in upper right corner GUI_DispDecAT(Sec, 200, 0, 2); Related topics GUI_DispDec(), GUI_DispSDec(), GUI_DispDecMin(), GUI_DispDecSpace() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 94 CHAPTER Displaying Values GUI_DispDecMin() Description Displays a value in decimal form at the current text position in the current window using the current font. The length of the value does not require to be specified. The minimum length will automatically be used. Prototype void GUI_DispDecMin(I32 v); Parameter Description Value to display. Minimum: -2147483648 (= -2^31); maximum 2147483647 (= 2^31 -1). v Additional information The maximum number of displayed digits is 10. This function should not be used if values have to be aligned but differ in the number of digits. Try one of the functions which require specification of the number of digits to use in this case. Example // Show result GUI_DispString("The result is :"); GUI_DispDecMin(Result); Related topics GUI_DispDec(), GUI_DispDecAt(), GUI_DispSDec(), GUI_DispDecSpace() GUI_DispDecShift() Description Displays a long value in decimal form with a specified number of characters and with decimal point at the current text position, in the current window using the current font. Prototype void GUI_DispDecShift(I32 v, U8 Len, U8 Shift); Parameter v Len Shift Description Value to display. Minimum: -2147483648 (= -2^31); maximum: 2147483647 (= 2^31 -1). No. of digits to display (max. 10). No. of digits to show to right of decimal point. Additional information Watch the maximum number of 9 characters (including sign and decimal point). UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 95 GUI_DispDecSpace() Description Displays a value in decimal form at the current text position in the current window using the current font. Leading zeros are suppressed (replaced by spaces). Prototype void DispDecSpace(I32 v, U8 MaxDigits); Parameter Description v Value to display. Minimum: -2147483648 (= -2^31); maximum: 2147483647 (= 2^31 -1). MaxDigits No. of digits to display, including leading spaces. Maximum no. of digits displayed is 10 (excluding leading spaces). Additional information If values have to be aligned but differ in the number of digits, this function is a good choice. Example // Show result GUI_DispString("The result is :"); GUI_DispDecSpace(Result, 200); Related topics GUI_DispDec(), GUI_DispDecAt(), GUI_DispSDec(), GUI_DispDecMin() GUI_DispSDec() Description Displays a value in decimal form (with sign) with a specified number of characters at the current text position, in the current window using the current font. Prototype void GUI_DispSDec(I32 v, U8 Len); Parameter Description v Value to display. Minimum: -2147483648 (= -2^31); maximum: 2147483647 (= 2^31 -1). Len No. of digits to display (max. 10). Additional information Leading zeros are not suppressed. This function is similar to GUI_DispDec, but a sign is always shown in front of the value, even if the value is positive. Related topics GUI_DispDec(), GUI_DispDecAt(), GUI_DispDecMin(), GUI_DispDecSpace() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 96 CHAPTER Displaying Values GUI_DispSDecShift() Description Displays a long value in decimal form (with sign) with a specified number of characters and with decimal point at the current text position, in the current window using the current font. Prototype void GUI_DispSDecShift(I32 v, U8 Len, U8 Shift); Parameter v Len Shift Description Value to display. Minimum: -2147483648 (= -2^31); maximum: 2147483647 (= 2^31 -1). No. of digits to display (max. 10). No. of digits to show to right of decimal point. Additional information A sign is always shown in front of the value. Watch the maximum number of 9 characters (including sign and decimal point). Example void DemoDec(void) { long l = 12345; GUI_Clear(); GUI_SetFont(&GUI_Font8x8); GUI_DispStringAt("GUI_DispDecShift:\n",0,0); GUI_DispSDecShift(l, 7, 3); GUI_SetFont(&GUI_Font6x8); GUI_DispStringAt("Press any key",0,GUI_VYSIZE-8); WaitKey(); } Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 97 6.3 Displaying floating point values GUI_DispFloat() Description Displays a floating point value with a specified number of characters at the current text position in the current window using the current font. Prototype void GUI_DispFloat(float v, char Len); Parameter Description v Value to display. Minimum 1.2 E-38; maximum 3.4 E38. Len Number of digits to display (max. 10). Additional information Leading zeros are suppressed. The decimal point counts as one character. If the value is negative, a minus sign is shown. Example /* Shows all features for displaying floating point values */ void DemoFloat(void) { float f = 123.45678; GUI_Clear(); GUI_SetFont(&GUI_Font8x8); GUI_DispStringAt("GUI_DispFloat:\n",0,0); GUI_DispFloat (f,9); GUI_GotoX(100); GUI_DispFloat (-f,9); GUI_DispStringAt("GUI_DispFloatFix:\n",0,20); GUI_DispFloatFix (f,9,2); GUI_GotoX(100); GUI_DispFloatFix (-f,9,2); GUI_DispStringAt("GUI_DispSFloatFix:\n",0,40); GUI_DispSFloatFix (f,9,2); GUI_GotoX(100); GUI_DispSFloatFix (-f,9,2); GUI_DispStringAt("GUI_DispFloatMin:\n",0,60); GUI_DispFloatMin (f,3); GUI_GotoX(100); GUI_DispFloatMin (-f,3); GUI_DispStringAt("GUI_DispSFloatMin:\n",0,80); GUI_DispSFloatMin (f,3); GUI_GotoX(100); GUI_DispSFloatMin (-f,3); GUI_SetFont(&GUI_Font6x8); GUI_DispStringAt("Press any key",0,GUI_VYSIZE-8); WaitKey(); } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 98 CHAPTER Displaying Values Screen shot of above example GUI_DispFloatFix() Description Displays a floating-point value with specified number of total characters and a specified number of characters to the right of the decimal point, at the current text position in the current window using the current font. Prototype void GUI_DispFloatFix(float v, char Len, char Decs); Parameter v Len Decs Description Value to display. Minimum 1.2 E-38; maximum 3.4 E38. Number of digits to display (max. 10). Number of digits to show to the right of the decimal point. Additional information Leading zeros are not suppressed. If the value is negative, a minus sign is shown. GUI_DispFloatMin() Description Displays a floating-point value with a minimum number of decimals to the right of the decimal point, at the current text position in the current window using the current font. Prototype void GUI_DispFloatMin(float f, char Fract); Parameter Description v Value to display. Minimum 1.2 E-38; maximum 3.4 E38. Fract Minimum number of characters to display. Additional information Leading zeros are suppressed. If the value is negative, a minus sign is shown. The length does not need to be specified. The minimum length will automatically be used. If values have to be aligned but differ in the number of digits, one of the "...Fix()"functions should be used instead. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 99 GUI_DispSFloatFix() Description Displays a floating-point value (with sign) with a specified number of total characters and a specified number of characters to the right of the decimal point, in the current window using the current font. Prototype void GUI_DispSFloatFix(float v, char Len, char Decs); Parameter v Len Decs Description Value to display. Minimum 1.2 E-38; maximum 3.4 E38. Number of digits to display (max. 10). Number of digits to show to the right of the decimal point. Additional information Leading zeros are not suppressed. A sign is always shown in front of the value. GUI_DispSFloatMin() Description Displays a floating-point value (with sign) with a minimum number of decimals to the right of the decimal point, at the current text position in the current window using the current font. Prototype void GUI_DispSFloatMin(float f, char Fract); Parameter Description v Value to display. Minimum 1.2 E-38; maximum 3.4 E38. Fract Minimum number of digits to display. Additional information Leading zeros are suppressed. A sign is always shown in front of the value. The length does not need to be specified. The minimum length will automatically be used. If values have to be aligned but differ in the number of digits, one of the "...Fix()"functions should be used instead. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 100 6.4 CHAPTER Displaying Values Displaying binary values GUI_DispBin() Description Displays a value in binary form at the current text position in the current window using the current font. Prototype void GUI_DispBin(U32 v, U8 Len); Parameter v Len Description Value to display, 32-bit. No. of digits to display (including leading zeros). Additional information As with decimal and hexadecimal values, the least significant bit is rightmost. Example // // Show binary value 7, result: 000111 // U32 Input = 0x7; GUI_DispBin(Input, 6); Related topics GUI_DispBinAt() GUI_DispBinAt() Description Displays a value in binary form at a specified position in the current window using the current font. Prototype void GUI_DispBinAt(U32 v, I16P x, I16P y, U8 Len); Parameter v x y Len Description Value to display, 16-bit. X-position to write to in pixels of the client window. Y-position to write to in pixels of the client window. No. of digits to display (including leading zeroes). Additional information As with decimal and hexadecimal values, the least significant bit is rightmost. Example // // Show binary input status // GUI_DispBinAt(Input, 0,0, 8); Related topics GUI_DispBin(), GUI_DispHex() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 101 6.5 Displaying hexadecimal values GUI_DispHex() Description Displays a value in hexadecimal form at the current text position in the current window using the current font. Prototype void GUI_DispHex(U32 v, U8 Len); Parameter v Len Description Value to display, 16-bit. No. of digits to display. Additional information As with decimal and binary values, the least significant bit is rightmost. Example /* Show value of AD-converter */ GUI_DispHex(Input, 4); Related topics GUI_DispDec(), GUI_DispBin(), GUI_DispHexAt() GUI_DispHexAt() Description Displays a value in hexadecimal form at a specified position in the current window using the current font. Prototype void GUI_DispHexAt(U32 v, I16P x, I16P y, U8 Len); Parameter v x y Len Description Value to display, 16-bit. X-position to write to in pixels of the client window. Y-position to write to in pixels of the client window. No. of digits to display. Additional information As with decimal and binary values, the least significant bit is rightmost. Example // // Show value of AD-converter at specified position // GUI_DispHexAt(Input, 0, 0, 4); Related topics GUI_DispDec(), GUI_DispBin(), GUI_DispHex() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 102 6.6 CHAPTER Displaying Values Version of emWin GUI_GetVersionString() Description Returns a string containing the current version of emWin. Prototype const char * GUI_GetVersionString(void); Example // // Displays the current version at the current cursor position // GUI_DispString(GUI_GetVersionString()); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 103 Chapter 7 2-D Graphic Library emWin contains a complete 2-D graphic library which should be sufficient for most applications. The routines supplied with emWin can be used with or without clipping (refer to the chapter "The Window Manager (WM)" on page 331) and are based on fast and efficient algorithms. Currently, only the GUI_DrawArc() function requires floating-point calculations. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 104 7.1 CHAPTER 2-D Graphic Library Graphic API The table below lists the available graphic-related routines in alphabetical order within their respective categories. Detailed descriptions can be found in the sections that follow. Routine Description Returns the color index of a given position. GUI_GetPixelIndex() Drawing modes Returns the current drawing mode. GUI_GetDrawMode() GUI_SetDrawMode() Sets the drawing mode. Pen size Returns the current pen size in pixels. GUI_GetPenSize() GUI_SetPenSize() Sets the pen size in pixels. Query current client rectangle Returns the current available drawing area. GUI_GetClientRect() Basic drawing routines GUI_ClearRect() Fills a rectangular area with the background color. GUI_CopyRect() Copies a rectangle area on the display GUI_DrawGradientH() Draws a rectangle filled with a horizontal color gradient. GUI_DrawGradientV() Draws a rectangle filled with a vertical color gradient. GUI_DrawGradientRoundedH() Draws a rectangle with rounded corners filled with a horizontal color gradient. GUI_DrawGradientRoundedV() Draws a rectangle with rounded corners filled with a vertical color gradient. Draws a single pixel. GUI_DrawPixel() GUI_DrawPoint() GUI_DrawRect() GUI_DrawRectEx() GUI_DrawRoundedFrame() GUI_DrawRoundedRect() GUI_FillRect() GUI_FillRectEx() GUI_FillRoundedRect() GUI_InvertRect() Draws a point. Draws a rectangle. Draws a rectangle. Draws a frame with rounded corners. Draws a rectangle with rounded corners. Draws a filled rectangle. Draws a filled rectangle. Draws a filled rectangle with rounded corners. Invert a rectangular area. Alpha blending GUI_EnableAlpha() Enables/disables automatic alpha blending GUI_RestoreUserAlpha() Restores the previous state of user alpha blending GUI_SetAlpha() Sets the current alpha blending value. (Obsolete) GUI_SetUserAlpha() Sets an additional value which is used to calculate the actual alpha blending value to be used. Drawing bitmaps Draws a bitmap. GUI_DrawBitmap() GUI_DrawBitmapEx() Draws a scaled bitmap. Draws a bitmap with alpha blending information on a system with hardware alpha blending support. GUI_DrawBitmapHWAlpha() Draws a magnified bitmap. GUI_DrawBitmapMag() Drawing streamed bitmaps GUI_CreateBitmapFromStream() Creates a bitmap from a given stream of any type. GUI_CreateBitmapFromStreamIDX() Creates a bitmap from an index based bitmap stream. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 105 Routine Description Creates a bitmap from an RLE4 bitmap stream. GUI_CreateBitmapFromStreamRLE4() GUI_CreateBitmapFromStreamRLE8() Creates a bitmap from an RLE8 bitmap stream. GUI_CreateBitmapFromStream565() Creates a bitmap from a 16bpp (565) bitmap stream. GUI_CreateBitmapFromStreamM565() Creates a bitmap from a 16bpp (M565) bitmap stream with red and blue swapped. GUI_CreateBitmapFromStream555() Creates a bitmap from a 16bpp (555) bitmap stream. GUI_CreateBitmapFromStreamM555() Creates a bitmap from a 16bpp (M555) bitmap stream with red and blue swapped. GUI_CreateBitmapFromStreamRLE16() Creates a bitmap from an RLE16 (565) bitmap stream. GUI_CreateBitmapFromStreamRLEM16() Creates a bitmap from an RLEM16 (M565) bitmap stream with red and blue swapped. Creates a bitmap from a 24 bit bitmap stream. GUI_CreateBitmapFromStream24() GUI_CreateBitmapFromStreamAlpha() Creates a bitmap from a 32 bit bitmap stream. GUI_CreateBitmapFromStreamRLEAlpha() Creates a bitmap from an RLE compressed 8 bit alpha bitmap stream. GUI_CreateBitmapFromStreamRLE32() Creates a bitmap from an RLE32 bitmap stream. GUI_DrawStreamedBitmap() Draws a bitmap from an indexed based bitmap stream (1 - 8bpp). GUI_DrawStreamedBitmapAuto() Draws a bitmap from a bitmap stream of any supported format. GUI_DrawStreamedBitmapEx() Draws a bitmap from an indexed based bitmap stream (1 - 8bpp) without loading the complete image. GUI_DrawStreamedBitmapExAuto() Draws a bitmap from a bitmap stream of any supported format without loading the complete image. GUI_DrawStreamedBitmap555Ex() Draws a bitmap from a 16bpp (555) bitmap stream without loading the complete image. GUI_DrawStreamedBitmapM555Ex() Draws a bitmap from a 16bpp (M555) bitmap stream without loading the complete image. GUI_DrawStreamedBitmap565Ex() Draws a bitmap from a 16bpp (565) bitmap stream without loading the complete image. GUI_DrawStreamedBitmapM565Ex() Draws a bitmap from a 16bpp (M565) bitmap stream without loading the complete image. GUI_DrawStreamedBitmap24Ex() Draws a bitmap from a 24bpp bitmap stream without loading the complete image. GUI_GetStreamedBitmapInfo() Returns information about the given stream. GUI_GetStreamedBitmapInfoEx() Returns information about the given stream which can be located on any kind of media. GUI_SetStreamedBitmapHook() Sets a hook function for GUI_DrawStreamedBitmapEx(). Drawing lines GUI_DrawHLine() Draws a horizontal line. GUI_DrawLine() Draws a line from a specified start point to a specified end point (absolute coordinates). GUI_DrawLineRel() Draws a line from the current position to an endpoint specified by X- and Y-distances (relative coordinates). GUI_DrawLineTo() Draws a line from the current position to a specified endpoint. GUI_DrawPolyLine() GUI_DrawVLine() GUI_GetLineStyle() GUI_MoveRel() GUI_MoveTo() GUI_SetLineStyle() Draws a polyline. Draws a vertical line. Returns the current line style. Moves the line pointer relative to its current position. Moves the line pointer to the given position. Sets the current line style. Drawing polygons UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 106 CHAPTER 2-D Graphic Library Routine Description Draws the outline of a polygon. GUI_DrawPolygon() GUI_EnlargePolygon() GUI_FillPolygon() GUI_MagnifyPolygon() GUI_RotatePolygon() Enlarges a polygon. Draws a filled polygon. Magnifies a polygon. Rotates a polygon by a specified angle. Drawing circles Draws the outline of a circle. GUI_DrawCircle() GUI_FillCircle() Draws a filled circle. Drawing ellipses Draws the outline of an ellipse. GUI_DrawEllipse() GUI_FillEllipse() Draws a filled ellipse. Drawing arcs Draws an arc. GUI_DrawArc() Drawing a graph Draws a graph. GUI_DrawGraph() Drawing a pie chart Draws a circle sector. GUI_DrawPie() Saving and restoring the GUI-context Restores the GUI-context. GUI_RestoreContext() GUI_SaveContext() Saves the GUI-context. Clipping Sets the rectangle used for clipping. GUI_SetClipRect() GUI_GetPixelIndex() Description Returns the color index of a given position. Prototype unsigned GUI_GetPixelIndex(int x, int y); Parameter x y Description absolute x-position of the pixel absolute y-position of the pixel UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 107 7.2 Drawing modes emWin can draw in NORMAL mode or in XOR mode. The default is NORMAL mode, in which the content of the display is overdrawn by the graphic. In XOR mode, the content of the display is inverted when it is overdrawn. Restrictions associated with GUI_DRAWMODE_XOR * * * * XOR mode is only useful when using two displayed colors inside the active window or screen. Some drawing functions of emWin do not work precisely with this drawing mode. Generally, this mode works only with a pen size of one pixel. That means before using functions like GUI_DrawLine(), GUI_DrawCircle(), GUI_DrawRect() and so on, you must make sure that the pen size is set to 1 when you are working in XOR mode. When drawing bitmaps with a color depth greater than 1 bit per pixel (bpp) this drawing mode takes no effect. When using drawing functions such as GUI_DrawPolyLine() or multiple calls of GUI_DrawLineTo(), the fulcrums are inverted twice. The result is that these pixels remain in the background color. GUI_GetDrawMode() Description Returns the current drawing mode. Prototype GUI_DRAWMODE GUI_GetDrawMode(void); Return value The currently selected drawing mode. GUI_SetDrawMode() Description Selects the specified drawing mode. Prototype GUI_DRAWMODE GUI_SetDrawMode(GUI_DRAWMODE mode); Parameter mode Description Drawing mode to set. May be a value returned by any routine which sets the drawing mode or one of the constants below. Permitted values for parameter mode GUI_DM_NORMAL Default: Draws points, lines, areas, bitmaps. GUI_DM_XOR Inverts points, lines, areas when overwriting the color of another object on the display. Return value The selected drawing mode. Additional information In addition to setting the drawing mode, this routine may also be used to restore a drawing mode that has previously been changed. If using colors, an inverted pixel is calculated as follows: New pixel color = number of colors - actual pixel color - 1. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 108 CHAPTER 2-D Graphic Library Example // // Showing two circles, the second one XOR-combined with the first: // GUI_Clear(); GUI_SetDrawMode(GUI_DRAWMODE_NORMAL); GUI_FillCircle(120, 64, 40); GUI_SetDrawMode(GUI_DRAWMODE_XOR); GUI_FillCircle(140, 84, 40); Screen shot of above example 7.3 Query current client rectangle GUI_GetClientRect() Description The current client rectangle depends on using the Window Manager or not. If using the Window Manager the function uses WM_GetClientRect to retrieve the client rectangle. If not using the Window Manager the client rectangle corresponds to the complete LCD display. Prototype void GUI_GetClientRect(GUI_RECT * pRect); Parameter pRect Description Pointer to the GUI_RECT-structure to store result in. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 109 7.4 Pen size The pen size determines the thickness of the following vector drawing operations: * GUI_DrawPoint() * GUI_DrawLine() * GUI_DrawLineRel() * GUI_DrawLineTo() * GUI_DrawPolyLine() * GUI_DrawPolygon() * GUI_DrawEllipse() * GUI_DrawArc() Please note that it is not possible to combine line styles with a pen size > 1. GUI_GetPenSize() Description Returns the current pen size. Prototype U8 GUI_GetPenSize(void); GUI_SetPenSize() Description Sets the pen size to be used for further drawing operations. Prototype U8 GUI_SetPenSize(U8 PenSize); Parameter PenSize Description Pen size in pixels to be used. Return value Previous pen size. Add information The pen size should be >= 1. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 110 CHAPTER 7.5 2-D Graphic Library Basic drawing routines The basic drawing routines allow drawing of individual points, horizontal and vertical lines and shapes at any position on the display. Any available drawing mode can be used. Since these routines are called frequently in most applications, they are optimized for speed as much as possible. For example, the horizontal and vertical line functions do not require the use of single-dot routines. GUI_ClearRect() Description Clears a rectangular area at a specified position in the current window by filling it with the background color. Prototype void GUI_ClearRect(int x0, int y0, int x1, int y1); Parameter x0 y0 x1 y1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Related topics GUI_InvertRect(), GUI_FillRect() GUI_CopyRect() Description Copies the content of the given rectangular area to the specified position. Prototype void GUI_CopyRect(int x0, int y0, int x1, int y1, int xSize, int ySize); Parameter x0 y0 x1 y1 xSize ySize Description Upper left X-position of the source rectangle. Upper left Y-position of the source rectangle. Upper left X-position of the destination rectangle. Upper left Y-position of the destination rectangle. X-size of the rectangle. Y-size of the rectangle. Additional information The source and destination rectangle may overlap each other. GUI_DrawGradientH() Description Draws a rectangle filled with a horizontal color gradient. Prototype void GUI_DrawGradientH(int x0, int y0, int x1, int y1, UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 111 GUI_COLOR Color0, GUI_COLOR Color1); Parameter x0 y0 x1 y1 Color0 Color1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Color to be drawn on the leftmost side of the rectangle. Color to be drawn on the rightmost side of the rectangle. Example GUI_DrawGradientH(0, 0, 99, 99, 0x0000FF, 0x00FFFF); Screenshot of above example GUI_DrawGradientV() Description Draws a rectangle filled with a vertical color gradient. Prototype void GUI_DrawGradientV(int x0, int y0, int x1, int y1, GUI_COLOR Color0, GUI_COLOR Color1); Parameter x0 y0 x1 y1 Color0 Color1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Color to be drawn on the topmost side of the rectangle. Color to be drawn on the bottommost side of the rectangle. Example GUI_DrawGradientV(0, 0, 99, 99, 0x0000FF, 0x00FFFF); Screenshot of above example GUI_DrawGradientRoundedH() Description Draws a rectangle with rounded corners filled with a horizontal color gradient. Prototype void GUI_DrawGradientRoundedH(int x0, int y0, int x1, int y1, int rd UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 112 CHAPTER 2-D Graphic Library GUI_COLOR Color0, GUI_COLOR Color1); Parameter x0 y0 x1 y1 rd Color0 Color1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Radius to be used for the rounded corners. Color to be drawn on the leftmost side of the rectangle. Color to be drawn on the rightmost side of the rectangle. Example GUI_DrawGradientRoundedH(0, 0, 99, 99, 25, 0x0000FF, 0x00FFFF); Screenshot of above example GUI_DrawGradientRoundedV() Description Draws a rectangle with rounded corners filled with a vertical color gradient. Prototype void GUI_DrawGradientRoundedV(int x0, int y0, int x1, int y1, GUI_COLOR Color0, GUI_COLOR Color1); Parameter x0 y0 x1 y1 Color0 Color1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Color to be drawn on the leftmost side of the rectangle. Color to be drawn on the rightmost side of the rectangle. Example GUI_DrawGradientRoundedV(0, 0, 99, 99, 25, 0x0000FF, 0x00FFFF); Screenshot of above example GUI_DrawPixel() Description Draws a pixel at a specified position in the current window. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 113 Prototype void GUI_DrawPixel(int x, int y); Parameter x y Description X-position of pixel. Y-position of pixel. Related topics GUI_DrawPoint() GUI_DrawPoint() Description Draws a point with the current pen size at a specified position in the current window. Prototype void GUI_DrawPoint(int x, int y); Parameter x y Description X-position of point. Y-position of point. Related topics GUI_DrawPixel() GUI_DrawRect() Description Draws a rectangle at a specified position in the current window. Prototype void GUI_DrawRect(int x0, int y0, int x1, int y1); Parameter x0 y0 x1 y1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. GUI_DrawRectEx() Description Draws a rectangle at a specified position in the current window. Prototype void GUI_DrawRectEx(const GUI_RECT * pRect); Parameter pRect Description Pointer to a GUI_RECT-structure containing the coordinates of the rectangle GUI_DrawRoundedFrame() Description Draws a frame at a specified position in the current window with rounded corners an a specified width. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 114 CHAPTER 2-D Graphic Library Prototype void GUI_DrawRoundedFrame(int x0, int y0, int x1, int y1, int r, int w); Parameter x0 y0 x1 y1 r w Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Radius to be used for the rounded corners. Width in which the frame is drawn. GUI_DrawRoundedRect() Description Draws a rectangle at a specified position in the current window with rounded corners. Prototype void GUI_DrawRoundedRect(int x0, int y0, int x1, int y1, int r); Parameter x0 y0 x1 y1 r Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Radius to be used for the rounded corners. GUI_FillRect() Description Draws a filled rectangular area at a specified position in the current window. Prototype void GUI_FillRect(int x0, int y0, int x1, int y1); Parameter x0 y0 x1 y1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Additional information Uses the current drawing mode, which normally means all pixels inside the rectangle are set. Related topics GUI_InvertRect(), GUI_ClearRect() GUI_FillRectEx() Description Draws a filled rectangle at a specified position in the current window. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 115 Prototype void GUI_FillRectEx(const GUI_RECT * pRect); Parameter pRect Description Pointer to a GUI_RECT-structure containing the coordinates of the rectangle GUI_FillRoundedRect() Description Draws a filled rectangle at a specified position in the current window with rounded corners. Prototype void GUI_FillRoundedRect(int x0, int y0, int x1, int y1, int r); Parameter x0 y0 x1 y1 r Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Radius to be used for the rounded corners. GUI_InvertRect() Description Draws an inverted rectangular area at a specified position in the current window. Prototype void GUI_InvertRect(int x0, int y0, int x1, int y1); Parameter x0 y0 x1 y1 Description Upper left X-position. Upper left Y-position. Lower right X-position. Lower right Y-position. Related topics GUI_FillRect(), GUI_ClearRect() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 116 CHAPTER 7.6 2-D Graphic Library Alpha blending Alpha blending is a method of combining a foreground image with the background to create the appearance of semi transparency. An alpha value determines how much of a pixel should be visible and how much of the background should show through. Color information emWin internally works with 32 bits of color information: * * * * Bits Bits Bits Bits 0-7: Red 8-15: Green 16-23: Blue 24-31: Alpha information An alpha value of 0 means opaque and a value of 255 means completely transparent. How it works The alpha blending is done completely automatically once it is enabled by using the function GUI_EnableAlpha(). This makes emWin regard the upper 8 bits of the color information as alpha value. Enabling alpha blending is required only for functions which use the background or foreground color. Bitmaps which already contain alpha values (32bpp) are automatically displayed properly, so enabling alpha blending is not required in this case. Example The following small example shows how it works: GUI_EnableAlpha(1); GUI_SetBkColor(GUI_WHITE); GUI_Clear(); GUI_SetColor(GUI_BLACK); GUI_DispStringHCenterAt("Alphablending", 45, 41); GUI_SetColor((0x40uL << 24) | GUI_RED); GUI_FillRect(0, 0, 49, 49); GUI_SetColor((0x80uL << 24) | GUI_GREEN); GUI_FillRect(20, 20, 69, 69); GUI_SetColor((0xC0uL << 24) | GUI_BLUE); GUI_FillRect(40, 40, 89, 89); Older versions In older versions it was required to use the function GUI_SetAlpha() for blending the foreground with the current background color information. This also works but is no longer required. GUI_EnableAlpha() Description Enables or disables automatic alpha blending. Prototype unsigned GUI_EnableAlpha(unsigned OnOff); Parameter OnOff Description 1 enables automatic alpha blending, 0 disables it. Return value Old state. Additional information After enabling automatic alpha blending the color information of each object automatically determines its transparency. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 117 GUI_SetAlpha() (Obsolete) Description Enables software alpha blending for all subsequent drawing operations. Prototype unsigned GUI_SetAlpha(U8 Value); Parameter Alpha Description Alpha value to be used for all subsequent drawing operations. Default is 0 which means no alpha blending. Return value Previous value used for alpha blending. Additional information The function sets the alpha value to be used for all subsequent drawing operations. A value of 0 for parameter Alpha means opaque (alpha blending disabled) and a value of 255 means completely transparent (invisible). Note that software alpha blending increases the CPU load. Further it is strongly recommended to set the alpha value back to the default value after finishing the drawing operations. Example extern const GUI_BITMAP _LogoBitmap; GUI_SetColor(GUI_BLUE); GUI_FillCircle(100, 50, 49); GUI_SetColor(GUI_YELLOW); for (i = 0; i < 100; i++) { U8 Alpha; Alpha = (i * 255 / 100); GUI_SetAlpha(Alpha); GUI_DrawHLine(i, 100 - i, 100 + i); } GUI_SetAlpha(0x80); GUI_DrawBitmap(&_LogoBitmap, 30, 30); GUI_SetColor(GUI_MAGENTA); GUI_SetFont(&GUI_Font24B_ASCII); GUI_SetTextMode(GUI_TM_TRANS); GUI_DispStringHCenterAt("Alphablending", 100, 3); GUI_SetAlpha(0); /* Set back to default (opaque) */ Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 118 CHAPTER 2-D Graphic Library GUI_SetUserAlpha() Description Sets an additional value which is used to calculate the actual alpha value to be used. The actual alpha value is calculated as follows: Alpha = AlphaFromObject + ((255 - AlphaFromObject) * UserAlpha) / 255 Prototype U32 GUI_SetUserAlpha(GUI_ALPHA_STATE * pAlphaState, U32 UserAlpha); Parameter pAlphaState UserAlpha Description Pointer to an GUI_ALPHA_STATE structure to be used to save the current state. Value to be used. Return value Previous user alpha value. Additional information The following function GUI_RestoreUserAlpha() can be used to restore the previous state of the function. GUI_RestoreUserAlpha() Description Restores the previous state of user alpha blending. saved in the structure pointed by. Prototype U32 GUI_RestoreUserAlpha(GUI_ALPHA_STATE * pAlphaState); Parameter pAlphaState Description Pointer to an GUI_ALPHA_STATE structure containing information of the previous state to be restored. Return value Current user alpha value. Example { GUI_ALPHA_STATE AlphaState; } GUI_EnableAlpha(1); GUI_SetBkColor(GUI_WHITE); GUI_Clear(); GUI_SetColor(GUI_BLACK); GUI_DispStringHCenterAt("Alphablending", 45, 41); GUI_SetUserAlpha(&AlphaState, 0xC0); GUI_SetColor(GUI_RED); GUI_FillRect(0, 0, 49, 49); GUI_SetColor(GUI_GREEN); GUI_FillRect(20, 20, 69, 69); GUI_SetColor(GUI_BLUE); GUI_FillRect(40, 40, 89, 89); GUI_RestoreUserAlpha(&AlphaState); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 119 7.7 Drawing bitmaps Generally emWin is able to display any bitmap image at any display position. On 16 bit CPUs (sizeof(int) == 2), the size of one bitmap per default is limited to 64 kb. If larger bitmaps should be displayed with a 16 bit CPU, refer to the chapter "Configuration" on page 1039. GUI_DrawBitmap() Description Draws a bitmap image at a specified position in the current window. Prototype void GUI_DrawBitmap(const GUI_BITMAP * pBM, int x, int y); Parameter pBM x y Description Pointer to the bitmap to display. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Additional information The picture data is interpreted as bit stream starting with the most significant bit (msb) of the first byte. A new line always starts at an even byte address, as the nth line of the bitmap starts at offset n*BytesPerLine. The bitmap can be shown at any point in the client area. Usually, the Bitmap Converter is used to generate bitmaps. For more information, refer to the chapter "Bitmap Converter" on page 177. Example extern const GUI_BITMAP bmSeggerLogoBlue; /* declare external Bitmap */ void main() { GUI_Init(); GUI_DrawBitmap(&bmSeggerLogoBlue, 45, 20); } Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 120 CHAPTER 2-D Graphic Library GUI_DrawBitmapEx() Description This routine makes it possible to scale and/or to mirror a bitmap on the display. Prototype void GUI_DrawBitmapEx(const GUI_BITMAP int x0, int int xCenter, int int xMag, int Parameter pBM x0 y0 xCenter yCenter xMag yMag * pBitmap, y0, yCenter, yMag); Description Pointer to the bitmap to display. X-position of the anchor point in the display. Y-position of the anchor point in the display. X-position of the anchor point in the bitmap. Y-position of the anchor point in the bitmap. Scale factor of X-direction. Scale factor of Y-direction. Additional information A negative value of the xMag-parameter would mirror the bitmap in the X-axis and a negative value of the yMag-parameter would mirror the bitmap in the Y-axis. The unit of xMag- and yMag are thousandth. The position given by the parameter xCenter and yCenter specifies the pixel of the bitmap which should be displayed at the display at position x0/y0 independent of scaling or mirroring. This function can not be used to draw RLE-compressed bitmaps. GUI_DrawBitmapHWAlpha() Description Draws a bitmap with alpha information on a multi layer system with hardware alpha blending support. Prototype void GUI_DrawBitmapHWAlpha(const GUI_BITMAP GUI_UNI_PTR * pBM, int x0, int y0); Parameter pBM x0 y0 Description Pointer to the bitmap to display. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Additional information In emWin logical colors are handled as 32 bit values. The lower 24 bits are used for the color information and the upper 8 bits are used to manage the alpha value. An alpha value of 0 means the image is opaque and a value of 0xFF means completely transparent (invisible). On systems with hardware support for alpha blending the alpha values need to be written to the display controller which does the alpha blending. Normally the alpha format of the hardware is not the same as the alpha definition in emWin described above. Mostly a value of 0 means fully transparent and higher values means the pixel becomes more visible. Because of this in the most cases custom color conversion routines are required to translate a logical color to the required hardware format. The Sample folder contains the example ALPHA_DrawBitmapHWAlpha which shows how to consider the requirement of custom color conversion. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 121 GUI_DrawBitmapMag() Description This routine makes it possible to magnify a bitmap on the display. Prototype void GUI_DrawBitmapMag(const GUI_BITMAP * pBM, int x0, int y0, int XMul, int YMul); Parameter pBM x0 y0 XMul YMul Description Pointer to the bitmap to display. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Magnification factor of X-direction. Magnification factor of Y-direction. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 122 CHAPTER 7.8 2-D Graphic Library Drawing streamed bitmaps Streamed bitmaps can be located in addressable area (RAM or ROM) as well as external memory (e.g. on removable devices). Drawing from addressable memory There are 2 possibilities to display streamed bitmaps which are located on addressable memory. The first one is to use the function GUI_DrawStreamedBitmap() or the function GUI_DrawStreamedBitmapAuto(). The second one is to create a GUI_BITMAP according to the streamed bitmap and use it for a regular call of e.g. GUI_DrawBitmap(). Drawing from external memory Streamed bitmaps which are located on external memory can be drawn using the ...Ex() functions. ...Ex() functions require a pointer to a user defined GetData() function (see "Getting data with the ...Ex() functions" on page 174) in order to have emWin retrieve the stream self-dependently. If the format of the streamed bitmap is unknown at run-time, the function GUI_DrawStreamedBitmapExAuto() should be used. Requirements The ...Ex() functions require to have enough free memory which is assigned to emWin to store at least one line of pixel data. If there is not enough free memory, the function will return immediately without having anything drawn. Using the ...Auto() function causes the linker to add all functions referenced by the ...Auto() function. If there is not enough memory the according function for the specific format should be used (e.g. GUI_DrawStreamedBitmap565Ex()). Available bitmap formats The following table shows the currently supported formats and the availability of according ...Ex() functions: Format Description ...Ex() function available IDX 555 Index based* bitmaps 1-8bpp. 16bpp high color bitmaps, 5 bits blue, 5 bits green, 5 bits red. Yes Yes M555 565 M565 24 Alpha RLEAlpha RLE4 RLE8 RLE16 RLEM16 RLE32 16bpp high color bitmaps, 5 bits red, 5 bits green, 5 bits blue. 16bpp high color bitmaps, 5 bits blue, 6 bits green, 5 bits red. 16bpp high color bitmaps, 5 bits red, 6 bits green, 5 bits blue. 24bpp true color bitmaps, 8 bits blue, 8 bits green, 8 bits red. 32bpp true color bitmaps, 8 bits alpha, 8 bits blue, 8 bits green, 8 bits red. 8bpp alpha channel bitmaps, compressed. 4bpp index based bitmaps, RLE compressed. 8bpp index based bitmaps, RLE compressed. 16bpp (565) high color bitmaps, RLE compressed. 16bpp (M565) high color bitmaps, RLE compressed. 32bpp (8888) true color bitmaps with alpha channel, RLE compressed. Yes Yes Yes Yes No No Yes Yes Yes Yes Yes * Index based bitmaps consist of a palette of colors stated as 32bit values. All other bitmaps do not have a palette and therefore have the bitmap data stored in the format specified in the table. GUI_CreateBitmapFromStream() Description The function creates a bitmap structure by passing any type of bitmap stream. Prototype int GUI_CreateBitmapFromStream(GUI_BITMAP * pBMP, GUI_LOGPALETTE * pPAL, UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 123 const void Parameter * p); Description Pointer to a GUI_BITMAP structure to be initialized by the function. Pointer to a GUI_LOGPALETTE structure to be initialized by the function. pBMP pPAL p Pointer to the data stream. Return value 0 on success, 1 on error. Additional information This function should be used if the data stream can consist of several kinds of bitmap formats or unknown. Disadvantage of using this function is that it has a significant memory footprint. If memory usage (ROM) is a concern, it may be better to use the format specific functions below. Example The following example shows how the GUI_CreateBitmapFromStream() - functions can be used to create and draw a bitmap: void DrawBitmap(const void * pData, int xPos, int yPos) { GUI_BITMAP Bitmap; GUI_LOGPALETTE Palette; GUI_CreateBitmapFromStream(&Bitmap, &Palette, pData); GUI_DrawBitmap(&Bitmap, xPos, yPos); } GUI_CreateBitmapFromStreamIDX(), GUI_CreateBitmapFromStreamRLE4(), GUI_CreateBitmapFromStreamRLE8(), GUI_CreateBitmapFromStream565(), GUI_CreateBitmapFromStreamM565(), GUI_CreateBitmapFromStream555(), GUI_CreateBitmapFromStreamM555(), GUI_CreateBitmapFromStreamRLE16(), GUI_CreateBitmapFromStreamRLEM16(), GUI_CreateBitmapFromStream24(), GUI_CreateBitmapFromStreamAlpha(), GUI_CreateBitmapFromStreamRLEAlpha(), GUI_CreateBitmapFromStreamRLE32() Description These functions create bitmap structures by passing bitmap streams of a known format. Prototype int GUI_CreateBitmapFromStream(GUI_BITMAP * pBMP, GUI_LOGPALETTE * pPAL, const void * p); Parameter pBMP pPAL p Description Pointer to a Pointer to a GUI_BITMAP structure to be initialized by the function. GUI_LOGPALETTE structure to be initialized by the function. Pointer to the data stream. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 124 CHAPTER 2-D Graphic Library Supported data stream formats The following table shows the supported data stream formats for each function: Function Supported stream format GUI_CreateBitmapFromStreamIDX() Streams of index based bitmaps. GUI_CreateBitmapFromStreamRLE4() Streams of RLE4 compressed bitmaps. GUI_CreateBitmapFromStreamRLE8() Streams of RLE8 compressed bitmaps. GUI_CreateBitmapFromStream565() Streams of high color bitmaps (565). GUI_CreateBitmapFromStreamM565() Streams of high color bitmaps (M565). GUI_CreateBitmapFromStream555() Streams of high color bitmaps (555). GUI_CreateBitmapFromStreamM555() Streams of high color bitmaps (M565). GUI_CreateBitmapFromStreamRLE16() Streams of RLE16 compressed bitmaps. GUI_CreateBitmapFromStreamRLEM16() Streams of RLE16 compressed bitmaps, red and blue swapped. GUI_CreateBitmapFromStream24() Streams of 24bpp bitmaps (true color). GUI_CreateBitmapFromStreamAlpha() Streams of 32bpp bitmaps (true color with alpha channel). GUI_CreateBitmapFromStreamRLEAlpha() Streams of RLE compressed 8bpp alpha bitmaps. GUI_CreateBitmapFromStreamRLE32() Streams of RLE32 compressed bitmaps (true color with alpha channel). Return value 0 on success, 1 on error. Additional information These functions should be used if the data stream consists of a known format. This avoids linking of unused code and keeps the binary code small. GUI_DrawStreamedBitmap() Description Draws a bitmap from an indexed based bitmap data stream. Prototype void GUI_DrawStreamedBitmap(const void * p, int x, int y); Parameter p x y Description Pointer to the data stream. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Additional information The Bitmap Converter (see "Bitmap Converter" on page 177) can be used to create bitmap data streams. The format of these streams is not the same as the format of a bmp file. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 125 GUI_DrawStreamedBitmapAuto() Description Draws a bitmap from a bitmap data stream of any supported format. Prototype void GUI_DrawStreamedBitmapAuto(const void * p, int x, int y); Parameter p x y Description Pointer to the data stream. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Additional information Please refer to "GUI_DrawStreamedBitmap()" on page 124. GUI_DrawStreamedBitmapEx() Description This function can be used for drawing index based bitmap data streams if not enough RAM or ROM is available to keep the whole file within the addressable memory (RAM or ROM). The GUI library calls the function pointed by the parameter pfGetData to read the data. This GetData function needs to return the number of read bytes. Prototype int GUI_DrawStreamedBitmapEx(GUI_GET_DATA_FUNC * pfGetData, const void * p, int x, int y); Parameter pfGetData p x y Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value 0 on success, 1 on error. Additional information The function requires at least memory for one line of bitmap data. For more details please also refer to the function GUI_SetStreamedBitmapHook(). GUI_DrawStreamedBitmapExAuto() Description This function can be used for drawing bitmap data streams of any supported format if not enough RAM or ROM is available to keep the whole file within the addressable memory (RAM or ROM). The GUI library calls the function pointed by the parameter pfGetData to read the data. This GetData function needs to return the number of read bytes. Prototype int GUI_DrawStreamedBitmapExAuto(GUI_GET_DATA_FUNC * pfGetData, const void * p, int x, int y); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 126 CHAPTER Parameter pfGetData p x y 2-D Graphic Library Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value 0 on success, 1 on error. Additional information The function requires at least memory for one line of bitmap data. GUI_DrawStreamedBitmap555Ex() GUI_DrawStreamedBitmapM555Ex() GUI_DrawStreamedBitmap565Ex() GUI_DrawStreamedBitmapM565Ex() GUI_DrawStreamedBitmap24Ex() Description This function can be used for drawing bitmap data streams of the respective format if not enough RAM or ROM is available to keep the whole file within the addressable memory (RAM or ROM). The GUI library calls the function pointed by the parameter pfGetData to read the data. This GetData function needs to return the number of read bytes. Prototype int GUI_DrawStreamedBitmapEx(GUI_GET_DATA_FUNC * pfGetData, const void * p, int x, int y); Parameter pfGetData p x y Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value 0 on success, 1 on error. Additional information The functions require at least memory for one line of bitmap data. GUI_GetStreamedBitmapInfo() Description Returns a structure with information about the given data stream. Prototype void GUI_GetStreamedBitmapInfo(const void * p, GUI_BITMAPSTREAM_INFO * pInfo); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 127 Parameter Description Pointer to the data stream. p pInfo Pointer to a GUI_BITMAPSTREAM_INFO structure to be filled by the function. Elements of GUI_BITMAPSTREAM_INFO Data type int int int int int Element Description XSize YSize BitsPerPixel NumColors HasTrans Pixel size in X of the image. Pixel size in Y of the image. Number of bits per pixel. Number of colors in case of an index based image. In case of an index based image 1 if transparency exist, 0 if not. GUI_GetStreamedBitmapInfoEx() Description Returns a structure with information about the given data stream which does not need to be located in the addressable ROM or RAM area of the CPU. Prototype int GUI_GetStreamedBitmapInfoEx(GUI_GET_DATA_FUNC * pfGetData, const void * p, GUI_BITMAPSTREAM_INFO * pInfo); Parameter pfGetData Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. GetData Void pointer passed to the function pointed by p pInfo Pointer to a pfGetData. GUI_BITMAPSTREAM_INFO structure to be filled by the function. Return value 0 on success, 1 on error. Elements of GUI_BITMAPSTREAM_INFO Please refer to GUI_GetStreamedBitmapInfo(). GUI_SetStreamedBitmapHook() Description Sets a hook function to be able to manipulate the palette of a streamed bitmap which is not located in the addressable area of the CPU. The hook function is called when executing GUI_DrawStreamedBitmapEx(). Prototype void GUI_SetStreamedBitmapHook( GUI_BITMAPSTREAM_CALLBACK pfStreamedBitmapHook); Parameter pfStreamedBitmapHook Description Hook function to be called by UM03001 User & Reference Guide for emWin V5.20 GUI_DrawStreamedBitmapEx() . (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 128 CHAPTER 2-D Graphic Library Prototype of hook function void * Hook(GUI_BITMAPSTREAM_PARAM * pParam); Parameter Description Pointer to a GUI_BITMAPSTREAM_PARAM structure pParam Elements of GUI_BITMAPSTREAM_PARAM Data type int U32 void * Element Cmd v p Description Command to be executed. Depends on the command to be executed. Depends on the command to be executed. Supported values for parameter Cmd GUI_BITMAPSTREAM_GET_BUFFER When receiving this command the application can spend a buffer for the palette of a bitmap stream. Parameters: p - Pointer to the buffer or NULL v - Requested buffer size GUI_BITMAPSTREAM_RELEASE_BUFFER If the application has spend a buffer for the palette here the buffer should be released. Parameters: p - Pointer to buffer to be released v - not used GUI_BITMAPSTREAM_MODIFY_PALETTE This command is send after loading the palette and before drawing the image to be able to modify the palette of the streamed image. Parameters: p - Pointer to palette data v - Number of colors in palette Example static void * _cbStreamedBitmapHook(GUI_BITMAPSTREAM_PARAM * pParam) { void * p = NULL; int i, NumColors; U32 Color; U32 * pColor; switch (pParam->Cmd) { case GUI_BITMAPSTREAM_GET_BUFFER: // // Allocate buffer for palette data // p = malloc(pParam->v); break; case GUI_BITMAPSTREAM_RELEASE_BUFFER: // // Release buffer // free(pParam->p); break; case GUI_BITMAPSTREAM_MODIFY_PALETTE: // // Do something with the palette... // NumColors = pParam->v; pColor = (U32 *)pParam->p; Color = *(pColor + pParam->v - 1); for (i = NumColors - 2; i >= 0; i--) { *(pColor + i + 1) = *(pColor + i); } *pColor = Color; break; } return p; } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 129 7.9 Drawing lines The most frequently used drawing routines are those that draw a line from one point to another. GUI_DrawHLine() Description Draws a horizontal line one pixel thick from a specified starting point to a specified endpoint in the current window. Prototype void GUI_DrawHLine(int y, int x0, int x1); Parameter y x0 x1 Description Y-position. X-starting position. X-end position. Additional information If x1 < x0, nothing will be displayed. With most LCD controllers, this routine is executed very quickly because multiple pixels can be set at once and no calculations are needed. If it is clear that horizontal lines are to be drawn, this routine executes faster than the GUI_DrawLine() routine. GUI_DrawLine() Description Draws a line from a specified starting point to a specified endpoint in the current window (absolute coordinates). Prototype void GUI_DrawLine(int x0, int y0, int x1, int y1); Parameter x0 y0 x1 y1 Description X-starting position. Y-starting position. X-end position. Y-end position. Additional information If part of the line is not visible because it is not in the current window or because part of the current window is not visible, this is due to clipping. GUI_DrawLineRel() Description Draws a line from the current (x, y) position to an endpoint specified by X-distance and Y-distance in the current window (relative coordinates). Prototype void GUI_DrawLineRel(int dx, int dy); Parameter dx dy Description Distance in X-direction to end of line to draw. Distance in Y-direction to end of line to draw. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 130 CHAPTER 2-D Graphic Library GUI_DrawLineTo() Description Draws a line from the current (X,Y) position to an endpoint specified by X- and Ycoordinates in the current window. Prototype void GUI_DrawLineTo(int x, int y); Parameter x y Description X-end position. Y-end position. GUI_DrawPolyLine() Description Connects a predefined list of points with lines in the current window. Prototype void GUI_DrawPolyLine(const GUI_POINT * pPoint, int NumPoints, int x, int y); Parameter pPoint NumPoints x y Description Pointer to the polyline to display. Number of points specified in the list of points. X-position of origin. Y-position of origin. Additional information The starting point and endpoint of the polyline need not be identical. GUI_DrawVLine() Description Draws a vertical line one pixel thick from a specified starting point to a specified endpoint in the current window. Prototype void GUI_DrawVLine(int x, int y0, int y1); Parameter x y0 y1 Description X-position. Y-starting position. Y-end position. Additional information If y1 < y0, nothing will be displayed. With most LCD controllers, this routine is executed very quickly because multiple pixels can be set at once and no calculations are needed. If it is clear that vertical lines are to be drawn, this routine executes faster than the GUI_DrawLine() routine. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 131 GUI_GetLineStyle() Description Returns the current line style used by the function GUI_DrawLine. Prototype U8 GUI_GetLineStyle(void); Return value Current line style used by the function GUI_DrawLine. GUI_MoveRel() Description Moves the current line pointer relative to its current position. Prototype void GUI_MoveRel(int dx, int dy); Parameter dx dy Description Distance to move in X. Distance to move in Y. Related topics GUI_DrawLineTo(), GUI_MoveTo() GUI_MoveTo() Description Moves the current line pointer to the given position. Prototype void GUI_MoveTo(int x, int y); Parameter Description New position in X. x y New position in Y. GUI_SetLineStyle() Description Sets the current line style used by the function GUI_DrawLine. Prototype U8 GUI_SetLineStyle(U8 LineStyle); Parameter LineStyle Description New line style to be used. See table below. Permitted values for parameter LineStyle GUI_LS_SOLID GUI_LS_DASH GUI_LS_DOT Lines would be drawn solid (default). Lines would be drawn dashed. Lines would be drawn dotted. GUI_LS_DASHDOT Lines would be drawn alternating with dashes and dots. GUI_LS_DASHDOTDOT Lines would be drawn alternating with dashes and double dots. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 132 CHAPTER 2-D Graphic Library Return value Previous line style used by the function GUI_DrawLine. Additional information This function sets only the line style used by GUI_DrawLine. The style will be used only with a pen size of 1. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 133 7.10 Drawing polygons The polygon drawing routines can be helpful when drawing vectorized symbols. GUI_DrawPolygon() Description Draws the outline of a polygon defined by a list of points in the current window. Prototype void GUI_DrawPolygon(const GUI_POINT * pPoint, int NumPoints, int x, int y); Parameter pPoint NumPoints x y Description Pointer to the polygon to display. Number of points specified in the list of points. X-position of origin. Y-position of origin. Additional information The polyline drawn is automatically closed by connecting the endpoint to the starting point. GUI_EnlargePolygon() Description Enlarges a polygon on all sides by a specified length in pixels. Prototype void GUI_EnlargePolygon(GUI_POINT * pDest, const GUI_POINT * pSrc, int NumPoints, int Len); Parameter pDest pSrc NumPoints Len Description Pointer to the destination polygon. Pointer to the source polygon. Number of points specified in the list of points. Length (in pixels) by which to enlarge the polygon. Additional information Make sure the destination array of points is equal to or larger than the source array. Example const GUI_POINT aPoints[] = { { 40, 20}, { 0, 20}, { 20, 0} }; GUI_POINT aEnlargedPoints[GUI_COUNTOF(aPoints)]; void Sample(void) { int i; GUI_Clear(); GUI_SetDrawMode(GUI_DM_XOR); GUI_FillPolygon(aPoints, GUI_COUNTOF(aPoints), 140, 110); for (i = 1; i < 10; i++) { GUI_EnlargePolygon(aEnlargedPoints, aPoints, GUI_COUNTOF(aPoints), i * 5); GUI_FillPolygon(aEnlargedPoints, GUI_COUNTOF(aPoints), 140, 110); } } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 134 CHAPTER 2-D Graphic Library Screen shot of above example GUI_FillPolygon() Description Draws a filled polygon defined by a list of points in the current window. Prototype void GUI_FillPolygon(const GUI_POINT * pPoint, int NumPoints, int x, int y); Parameter pPoint NumPoints x y Description Pointer to the polygon to display and to fill. Number of points specified in the list of points. X-position of origin. Y-position of origin. Additional information The polyline drawn is automatically closed by connecting the endpoint to the starting point. It is not required that the endpoint touches the outline of the polygon. Rendering a polygon is done by drawing one or more horizontal lines for each y-position of the polygon. Per default the maximum number of points used to draw the horizontal lines for one y-position is 12 (which means 6 lines per y-position). If this value needs to be increased, the macro GUI_FP_MAXCOUNT can be used to set the maximum number of points. Example #define GUI_FP_MAXCOUNT 50 GUI_MagnifyPolygon() Description Magnifies a polygon by a specified factor. Prototype void GUI_MagnifyPolygon(GUI_POINT * pDest, const GUI_POINT * pSrc, int NumPoints, int Mag); Parameter pDest pSrc NumPoints Mag Description Pointer to the destination polygon. Pointer to the source polygon. Number of points specified in the list of points. Factor used to magnify the polygon. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 135 Additional information Make sure the destination array of points is equal to or larger than the source array. Note the difference between enlarging and magnifying a polygon. Calling the function GUI_EnlargePolygon() with the parameter Len = 1 will enlarge the polygon by one pixel on all sides, whereas the call of GUI_MagnifyPolygon() with the parameter Mag = 1 will have no effect. Example const GUI_POINT aPoints[] = { { 0, 20}, { 40, 20}, { 20, 0} }; GUI_POINT aMagnifiedPoints[GUI_COUNTOF(aPoints)]; void Sample(void) { int Mag, y = 0, Count = 4; GUI_Clear(); GUI_SetColor(GUI_GREEN); for (Mag = 1; Mag <= 4; Mag *= 2, Count /= 2) { int i, x = 0; GUI_MagnifyPolygon(aMagnifiedPoints, aPoints, GUI_COUNTOF(aPoints), Mag); for (i = Count; i > 0; i--, x += 40 * Mag) { GUI_FillPolygon(aMagnifiedPoints, GUI_COUNTOF(aPoints), x, y); } y += 20 * Mag; } } Screen shot of above example GUI_RotatePolygon() Description Rotates a polygon by a specified angle. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 136 CHAPTER 2-D Graphic Library Prototype void GUI_RotatePolygon(GUI_POINT * pDest, const GUI_POINT * pSrc, int NumPoints, float Angle); Parameter pDest pSrc NumPoints Angle Description Pointer to the destination polygon. Pointer to the source polygon. Number of points specified in the list of points. Angle in radian used to rotate the polygon. Additional information Make sure the destination array of points is equal to or larger than the source array. Example The following example shows how to draw a polygon. 2DGL_DrawPolygon.c in the examples shipped with emWin. It is available as #include "gui.h" /******************************************************************* * * The points of the arrow */ static const GUI_POINT aPointArrow[] = { { 0, -5}, {-40, -35}, {-10, -25}, {-10, -85}, { 10, -85}, { 10, -25}, { 40, -35}, }; /******************************************************************* * * Draws a polygon */ static void DrawPolygon(void) { int Cnt =0; GUI_SetBkColor(GUI_WHITE); GUI_Clear(); GUI_SetFont(&GUI_Font8x16); GUI_SetColor(0x0); GUI_DispStringAt("Polygons of arbitrary shape ", 0, 0); GUI_DispStringAt("in any color", 120, 20); GUI_SetColor(GUI_BLUE); /* Draw filled polygon */ GUI_FillPolygon (&aPointArrow[0],7,100,100); } /******************************************************************* * * main */ void main(void) { GUI_Init(); DrawPolygon(); while(1) GUI_Delay(100); } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 137 Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 138 CHAPTER 2-D Graphic Library 7.11 Drawing circles GUI_DrawCircle() Description Draws the outline of a circle of specified dimensions, at a specified position in the current window. Prototype void GUI_DrawCircle(int x0, int y0, int r); Parameter x0 y0 r Description X-position of the center of the circle in pixels of the client window. Y-position of the center of the circle in pixels of the client window. Radius of the circle (half the diameter). Must be a positive value. Example // Draw concentric circles void ShowCircles(void) { int i; for (i=10; i<50; i += 3) GUI_DrawCircle(120, 60, i); } Screen shot of above example GUI_FillCircle() Description Draws a filled circle of specified dimensions at a specified position in the current window. Prototype void GUI_FillCircle(int x0, int y0, int r); Parameter x0 y0 r Description X-position of the center of the circle in pixels of the client window. Y-position of the center of the circle in pixels of the client window. Radius of the circle (half the diameter). Must be a positive value. Example GUI_FillCircle(120,60,50); Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 139 7.12 Drawing ellipses GUI_DrawEllipse() Description Draws the outline of an ellipse of specified dimensions, at a specified position in the current window. Prototype void GUI_DrawEllipse(int x0, int y0, int rx, int ry); Parameter x0 y0 rx ry Description X-position of the center of the circle in pixels of the client window. Y-position of the center of the circle in pixels of the client window. X-radius of the ellipse (half the diameter). Must be a positive value. Y-radius of the ellipse (half the diameter). Must be a positive value. Example See the GUI_FillEllipse() example. GUI_FillEllipse() Description Draws a filled ellipse of specified dimensions at a specified position in the current window. Prototype void GUI_FillEllipse(int x0, int y0, int rx, int ry); Parameter x0 y0 rx ry Description X-position of the center of the circle in pixels of the client window. Y-position of the center of the circle in pixels of the client window. X-radius of the ellipse (half the diameter). Must be a positive value. Y-radius of the ellipse (half the diameter). Must be a positive value. Example // Demo ellipses GUI_SetColor(0xff); GUI_FillEllipse(100, 180, 50, 70); GUI_SetColor(0x0); GUI_DrawEllipse(100, 180, 50, 70); GUI_SetColor(0x000000); GUI_FillEllipse(100, 180, 10, 50); Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 140 CHAPTER 2-D Graphic Library 7.13 Drawing arcs GUI_DrawArc() Description Draws an arc of specified dimensions at a specified position in the current window. An arc is a section of the outline of a circle. Prototype void GUI_DrawArc(int xCenter, int yCenter, int rx, int ry, int a0, int a1); Parameter xCenter yCenter rx ry a0 a1 Description Horizontal position of the center in pixels of the client window. Vertical position of the center in pixels of the client window. X-radius (pixels). Y-radius (pixels). Starting angle (degrees). Ending angle (degrees). Limitations Currently the ry parameter is not used. The rx parameter is used instead. Example void DrawArcScale(void) { int x0 = 160; int y0 = 180; int i; char ac[4]; GUI_SetBkColor(GUI_WHITE); GUI_Clear(); GUI_SetPenSize( 5 ); GUI_SetTextMode(GUI_TM_TRANS); GUI_SetFont(&GUI_FontComic18B_ASCII); GUI_SetColor( GUI_BLACK ); GUI_DrawArc( x0,y0,150, 150,-30, 210 ); GUI_Delay(1000); for (i=0; i<= 23; i++) { float a = (-30+i*10)*3.1415926/180; int x = -141*cos(a)+x0; int y = -141*sin(a)+y0; if (i%2 == 0) GUI_SetPenSize( 5 ); else GUI_SetPenSize( 4 ); GUI_DrawPoint(x,y); if (i%2 == 0) { x = -123*cos(a)+x0; y = -130*sin(a)+y0; sprintf(ac, "%d", 10*i); GUI_SetTextAlign(GUI_TA_VCENTER); GUI_DispStringHCenterAt(ac,x,y); } } } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 141 Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 142 CHAPTER 2-D Graphic Library 7.14 Drawing graphs GUI_DrawGraph() Description Draws a graph at once. Prototype void GUI_DrawGraph(I16 * paY, int NumPoints, int x0, int y0); Parameter paY NumPoints x0 y0 Description Pointer to an array containing the Y-values of the graph. Number of Y-values to be displayed. Starting point in x. Starting point in y. Additional information The function first sets the line-cursor to the position specified with x0, y0 and the first Y-value of the given array. Then it starts drawing lines to x0 + 1, y0 + *(paY + 1), x0 + 2, y0 + *(paY + 2) and so on. Example #include "GUI.h" #include I16 aY[100]; void MainTask(void) { int i; GUI_Init(); for (i = 0; i < GUI_COUNTOF(aY); i++) { aY[i] = rand() % 50; } GUI_DrawGraph(aY, GUI_COUNTOF(aY), 0, 0); } Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 143 7.15 Drawing pie charts GUI_DrawPie() Description Draws a circle sector. Prototype void GUI_DrawPie(int x0, int y0, int r, int a0, int a1, int Type); Parameter x0 y0 r a0 a1 Type Description X-position of the center of the circle in pixels of the client window. Y-position of the center of the circle in pixels of the client window. Radius of the circle (half the diameter). Starting angle (degrees). End angle (degrees). (reserved for future use, should be 0) Example int i, a0, a1; const unsigned aValues[] = { 100, 135, 190, 240, 340, 360}; const GUI_COLOR aColors[] = { GUI_BLUE, GUI_GREEN, GUI_RED, GUI_CYAN, GUI_MAGENTA, GUI_YELLOW }; for (i = 0; i < GUI_COUNTOF(aValues); i++) { a0 = (i == 0) ? 0 : aValues[i - 1]; a1 = aValues[i]; GUI_SetColor(aColors[i]); GUI_DrawPie(100, 100, 50, a0, a1, 0); } Screen shot of above example UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 144 CHAPTER 2-D Graphic Library 7.16 Saving and restoring the GUI-context GUI_RestoreContext() Description The function restores the GUI-context. Prototype void GUI_RestoreContext(const GUI_CONTEXT * pContext); Parameter pContext Description Pointer to a GUI_CONTEXT structure containing the new context. Additional information The GUI-context contains the current state of the GUI like the text cursor position, a pointer to the current font and so on. Sometimes it could be useful to save the current state ant to restore it later. For this you can use these functions. GUI_SaveContext() Description The function saves the current GUI-context. (See also GUI_RestoreContext) Prototype void GUI_SaveContext(GUI_CONTEXT * pContext); Parameter pContext Description Pointer to a GUI_CONTEXT structure for saving the current context. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 145 7.17 Clipping GUI_SetClipRect() Description Sets the clipping rectangle used for limiting the output. Prototype void GUI_SetClipRect(const GUI_RECT * pRect); Parameter pRect Description Pointer to the rectangle which should be used for clipping. A NULL pointer should be used to restore the default value. Additional information The clipping area is per default limited to the configured (virtual) display size. Under some circumstances it can be useful to use a smaller clipping rectangle, which can be set using this function. The rectangle referred to should remain unchanged until the function is called again with a NULL pointer. Example The following example shows how to use the function: GUI_RECT Rect = {10, 10, 100, 100}; GUI_SetClipRect(&Rect); . . /* Use the clipping area ... */ . GUI_SetClipRect(NULL); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 146 UM03001 User & Reference Guide for emWin V5.20 CHAPTER 2-D Graphic Library (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 147 Chapter 8 Displaying bitmap files The recommended and most efficient way to display a bitmap known at compile time is to use the Bitmap Converter to convert it into a C file and add it to the project / makefile. For details about the Bitmap Converter, refer to the chapter "Bitmap Converter" on page 177. If the application needs to display images not known at compile time, the image needs to be available in a graphic file format supported by emWin. In this case, the image file can reside in memory or on an other storage device; it can be displayed even if the amount of available memory is less than the size of the image file. emWin currently supports BMP, JPEG, GIF and PNG file formats. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 148 CHAPTER 8.1 Displaying bitmap files BMP file support Although bitmaps which can be used with emWin are normally compiled and linked as C files with the application, there may be situations when using these types of structures is not desirable. A typical example would be an application that continuously references new images, such as bitmaps downloaded by the user. The following functions support bmp files which have been loaded into memory. For images that you plan to re-use (that is, a company logo) it is much more efficient to compile and link it as C file which can be used directly by emWin. This may be easily done with the Bitmap Converter. 8.1.1 Supported formats The BMP file format has been defined by Microsoft. There are a number of different formats as shown in the table below: Bits per pixel 1 4 4 8 8 16 24 32 8.1.2 Indexed yes yes yes yes yes no no no Compression no no yes no yes no no no Supported yes yes yes yes yes yes yes yes BMP file API The table below lists the available BMP file related routines in alphabetical order. Detailed descriptions follows: Routine GUI_BMP_Draw() GUI_BMP_DrawEx() Explanation Draws a BMP file which has been loaded into memory. Draws a BMP file which needs not to be loaded into memory. GUI_BMP_DrawScaled() Draws a BMP file with scaling which has been loaded into memory. GUI_BMP_DrawScaledEx() Draws a BMP file with scaling which needs not to be loaded into memory. GUI_BMP_GetXSize() Returns the X-size of a BMP file loaded into memory. GUI_BMP_GetXSizeEx() Returns the X-size of a BMP file which needs not to be loaded into memory. GUI_BMP_GetYSize() Returns the Y-size of a bitmap loaded into memory. GUI_BMP_GetYSizeEx() Returns the Y-size of a BMP file which needs not to be loaded into memory. GUI_BMP_Serialize() GUI_BMP_SerializeEx() GUI_BMP_SerializeExBpp() Creates a BMP file. Creates a BMP file from the given rectangle. Creates a BMP file from the given rectangle using the specified color depth. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 149 GUI_BMP_Draw() Description Draws a Windows bmp file, which has been loaded into memory, at a specified position in the current window. Prototype int GUI_BMP_Draw(const void * pFileData, int x0, int y0); Parameter pFileData x0 y0 Description Pointer to the start of the memory area in which the bmp file resides. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Additional information The table at the beginning of the chapter shows the supported BMP file formats. The example 2DGL_DrawBMP.c shows how to use the function. GUI_BMP_DrawEx() Description Draws a bmp file, which does not have to be loaded into memory, at a specified position in the current window. Prototype int GUI_BMP_DrawEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0); Parameter pfGetData p x0 y0 Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value Zero on success, nonzero if the function fails. Additional information This function is used for drawing bmp files if not enough RAM is available to load the whole file into memory. The GUI library then calls the function pointed by the parameter pfGetData to read the data. The GetData function needs to return the number of requested bytes. The maximum number of bytes requested by the GUI is the number of bytes needed for drawing one line of the image. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 150 CHAPTER Displaying bitmap files GUI_BMP_DrawScaled() Description Draws a bmp file, which has been loaded into memory, at a specified position in the current window using scaling. Prototype int GUI_BMP_DrawScaled(const void * pFileData, int x0, int y0, int Num, int Denom); Parameter pFileData x0 y0 Num Denom Description Pointer to the start of the memory area in which the bmp file resides. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Numerator to be used for scaling. Denominator used for scaling. Return value Zero on success, nonzero if the function fails. Additional information The function scales the image by building a fraction with the given numerator and denominator. If for example an image should be shrunk to 2/3 of size the parameter Num should be 2 and Denom should be 3. GUI_BMP_DrawScaledEx() Description Draws a bmp file, which does not have to be loaded into memory, at a specified position in the current window using scaling. Prototype int GUI_BMP_DrawScaledEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0, int Num, int Denom); Parameter pfGetData p x0 y0 Num Denom Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Numerator to be used for scaling. Denominator used for scaling. Return value Zero on success, nonzero if the function fails. Additional information The function scales the image by building a fraction with the given numerator and denominator. If for example an image should be shrunk to 2/3 of size the parameter Num should be 2 and Denom should be 3. For more details, refer to "GUI_BMP_DrawEx()" on page 149. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 151 GUI_BMP_GetXSize() Description Returns the X-size of a specified bitmap which has been loaded into memory. Prototype int GUI_BMP_GetXSize(const void * pFileData); Parameter pFileData Description Pointer to the start of the memory area in which the bmp file resides. Return value X-size of the bitmap. GUI_BMP_GetXSizeEx() Description Returns the X-size of a specified bmp file which does not have to be loaded into memory. Prototype int GUI_BMP_GetXSizeEx(GUI_GET_DATA_FUNC * pfGetData, void * p); Parameter Description pfGetData Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. p Void pointer passed to the function pointed by GetData pfGetData. Return value X-size of the bitmap. GUI_BMP_GetYSize() Description Returns the Y-size of a specified bitmap which has been loaded into memory. Prototype int GUI_BMP_GetYSize(const void * pFileData);; Parameter pFileData Description Pointer to the start of the memory area in which the bmp file resides. Return value Y-size of the bitmap. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 152 CHAPTER Displaying bitmap files GUI_BMP_GetYSizeEx() Description Returns the Y-size of a specified bmp file which does not have to be loaded into memory. Prototype int GUI_BMP_GetYSizeEx(GUI_GET_DATA_FUNC * pfGetData, void * p); Parameter Description pfGetData Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. p Void pointer passed to the function pointed by GetData pfGetData. Return value Y-size of the bitmap. GUI_BMP_Serialize() Description The function creates a BMP file containing the complete content of the LCD. The BMP file is created using the color depth which is used in emWin at a maximum of 24 bpp. In case of using a color depth of less than 8bpp the color depth of the BMP file will be 8bpp. The currently selected device is used for reading the pixel data. If a Memory Device is selected it's content is written to the file. Prototype void GUI_BMP_Serialize(GUI_CALLBACK_VOID_U8_P * pfSerialize, void * p); Parameter pfSerialize p Description Pointer to serialization function Pointer to user defined data passed to serialization function Example The following example shows how to create a BMP file under windows. static void _DrawSomething(void) { /* Draw something */ GUI_DrawLine(10, 10, 100, 100); } static void _WriteByte2File(U8 Data, void * p) { U32 nWritten; WriteFile(*((HANDLE *)p), &Data, 1, &nWritten, NULL); } static void _ExportToFile(void) { HANDLE hFile = CreateFile("C:\\GUI_BMP_Serialize.bmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); GUI_BMP_Serialize(_WriteByte2File, &hFile); CloseHandle(hFile); } void MainTask(void) { GUI_Init(); _DrawSomething(); _ExportToFile(); } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 153 GUI_BMP_SerializeEx() Description The function creates a BMP file containing the given area. The BMP file is created using the color depth which is used in emWin at a maximum of 24 bpp. In case of using a color depth of less than 8bpp the color depth of the BMP file will be 8bpp. The currently selected device is used for reading the pixel data. If a Memory Device is selected it's content is written to the file. Prototype void GUI_BMP_SerializeEx(GUI_CALLBACK_VOID_U8_P * pfSerialize, int x0, int y0, int xSize, int ySize, void * p); Parameter pfSerialize x0 y0 xSize ySize p Description Pointer to user defined serialization function. See prototype below. Start position in X to create the BMP file. Start position in Y to create the BMP file. Size in X. Size in Y. Pointer to user defined data passed to serialization function. Prototype of GUI_CALLBACK_VOID_U8_P void GUI_CALLBACK_VOID_U8_P(U8 Data, void * p); Additional information An example can be found in the description of GUI_BMP_Serialize(). GUI_BMP_SerializeExBpp() Description The function creates a BMP file containing the given area using the specified color depth. In case of using a color depth of less than 8bpp the color depth of the BMP file will be 8bpp. The color depth should be a multiple of 8. In case of a system color depth of more than 8bpp the color depth needs to be 16bpp or more. The currently selected device is used for reading the pixel data. If a Memory Device is selected it's content is written to the file. Prototype void GUI_BMP_SerializeExBpp(GUI_CALLBACK_VOID_U8_P * pfSerialize, int x0, int y0, int xSize, int ySize, void * p, int BitsPerPixel); Parameter pfSerialize x0 y0 xSize ySize p BitsPerPixel Description Pointer to user defined serialization function. See prototype below. Start position in X to create the BMP file. Start position in Y to create the BMP file. Size in X. Size in Y. Pointer to user defined data passed to serialization function. Color depth. Prototype of GUI_CALLBACK_VOID_U8_P void GUI_CALLBACK_VOID_U8_P(U8 Data, void * p); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 154 CHAPTER Displaying bitmap files Additional information An example can be found in the description of GUI_BMP_Serialize() above. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 155 8.2 JPEG file support JPEG (pronounced "jay-peg") is a standardized compression method for full-color and gray-scale images. JPEG is intended for compressing "real-world" scenes; line drawings, cartoons and other non-realistic images are not its strong suit. JPEG is lossy, meaning that the output image is not exactly identical to the input image. Hence you must not use JPEG if you have to have identical output bits. However, on typical photographic images, very good compression levels can be obtained with no visible change, and remarkably high compression levels are possible if you can tolerate a low-quality image. 8.2.1 Supported JPEG compression methods This software implements JPEG baseline, extended-sequential and progressive compression processes. Provision is made for supporting all variants of these processes, although some uncommon parameter settings aren't implemented yet. For legal reasons, code for the arithmetic-coding variants of JPEG is not distributed. It appears that the arithmetic coding option of the JPEG spec is covered by patents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot legally be used without obtaining one or more licenses. For this reason, support for arithmetic coding has not been included. (Since arithmetic coding provides only a marginal gain over the unpatented Huffman mode, it is unlikely that very many implementations will support it.) The JPEG file support does not contain provision for the hierarchical or lossless processes defined in the standard. 8.2.2 Converting a JPEG file to C source Under some circumstances it can be useful to add a JPEG file as C file to the project. In this case the JPEG file first needs to be converted to a C file. This can be done using the tool Bin2C.exe shipped with emWin. It can be found in the Tools subfolder. It converts the given binary file (in this case the JPEG file) to a C file. The filename of the C file is the same as the binary file name with the file extension '.c'. The following steps will show how to embed a JPEG file using Bin2C: * Start Bin2C.exe and select the JPEG file to be converted to a C file, for example 'Image.jpeg' and convert it to a C file. * Add the C file to the project. Example The following example shows how to display the converted JPEG file: #include "GUI.h" #include "Image.c" /* Include the converted C file */ void MainTask(void) { GUI_Init(); GUI_JPEG_Draw(acImage, sizeof(acImage), 0, 0); ... } 8.2.3 Displaying JPEG files The graphic library first decodes the graphic information. If the image has to be drawn the decoding process takes considerable time. If a JPEG file is used in a frequently called callback routine of the Window Manager, the decoding process can take a considerable amount of time. The calculation time can be reduced by the use of memory devices. The best way would be to draw the image first into a memory device. In this case the decompression would be executed only one time. For more information about memory devices, refer to chapter "Memory Devices" on page 287. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 156 CHAPTER 8.2.4 Displaying bitmap files Memory usage The JPEG decompression uses app. 33Kb RAM for decompression independent of the image size and a size dependent amount of bytes. The RAM requirement can be calculated as follows: App. RAM requirement = X-Size of image * 80 bytes + 33 Kbytes The X-size dependent amount depends on the compression type of the JPEG file. The following table shows some examples: Size of image in pixels Compression RAM usage [Kbyte] RAM usage, size dependent [Kbyte] H1V1 160x120 45 12 H2V2 GRAY 160x120 160x120 46 38 13 4 The memory required for the decompression is allocated dynamically by the emWin memory management system. After drawing the JPEG image the complete RAM will be released. 8.2.5 Progressive JPEG files Contrary to baseline and extended-sequential JPEG files progressive JPEGs consist of multiple scans. Each of these scans is based on the previous scan(s) and refines the appearance of the JPEG image. This requires scanning the whole file even if only one line needs to be decompressed. If enough RAM is configured for the whole image data, the decompression needs only be done one time. If less RAM is configured, the JPEG decoder uses 'banding' for drawing the image. The more bands required the more times the image needs to be decompressed and the slower the performance. With other words: The more RAM the better the performance. 8.2.6 JPEG file API The table below lists the available JPEG file related routines in alphabetical order. Detailed descriptions follows: Routine GUI_JPEG_Draw() GUI_JPEG_DrawEx() GUI_JPEG_DrawScaled() Explanation Draws a JPEG file which has been loaded into memory. Draws a JPEG file which needs not to be loaded into memory. Draws a JPEG file with scaling which has been loaded into memory. GUI_JPEG_DrawScaledEx() Draws a JPEG file with scaling which needs not to be loaded into memory. GUI_JPEG_GetInfo() Fills a GUI_JPEG_INFO structure from a JPEG file which has been loaded into memory. GUI_JPEG_GetInfoEx() Fills a GUI_JPEG_INFO structure from a JPEG file which needs not to be loaded into memory. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 157 GUI_JPEG_Draw() Description Draws a jpeg file, which has been loaded into memory, at a specified position in the current window. Prototype int GUI_JPEG_Draw(const void * pFileData, int DataSize, int x0, int y0); Parameter pFileData DataSize x0 y0 Description Pointer to the start of the memory area in which the jpeg file resides. Number of bytes of the jpeg file. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value Zero on success, nonzero if the function fails. (The current implementation always returns 0) Additional information The Sample folder contains the example 2DGL_DrawJPG.c which shows how to use the function. GUI_JPEG_DrawEx() Description Draws a jpeg file, which does not have to be loaded into memory, at a specified position in the current window. Prototype int GUI_JPEG_DrawEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0); Parameter pfGetData p x0 y0 Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value Zero on success, nonzero if the function fails. (The current implementation always returns 0) Additional information This function is used for drawing jpegs if not enough RAM is available to load the whole file into memory. The JPEG library then calls the function pointed by the parameter pfGetData to read the data. The GetData function should return the number of available bytes. This could be less or equal the number of requested bytes. The function needs at least to return 1 new byte. The Sample folder contains the example 2DGL_DrawJPGScaled.c which shows how to use a GetData function. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 158 CHAPTER Displaying bitmap files GUI_JPEG_DrawScaled() Description Draws a jpeg file, which has been loaded into memory, at a specified position in the current window using scaling. Prototype int GUI_JPEG_DrawScaled(const void * pFileData, int DataSize, int x0, int y0, int Num, int Denom); Parameter pFileData DataSize x0 y0 Num Denom Description Pointer to the start of the memory area in which the jpeg file resides. Number of bytes of the jpeg file. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Numerator to be used for scaling. Denominator used for scaling. Return value Zero on success, nonzero if the function fails. (The current implementation always returns 0) Additional information The function scales the image by building a fraction with the given numerator and denominator. If for example an image should be shrunk to 2/3 of size the parameter Num should be 2 and Denom should be 3. The Sample folder contains the example 2DGL_DrawJPGScaled.c which shows how to draw scaled JPEGs. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 159 GUI_JPEG_DrawScaledEx() Description Draws a jpeg file, which does not have to be loaded into memory, at a specified position in the current window using scaling. Prototype int GUI_JPEG_DrawScaledEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0, int Num, int Denom); Parameter pfGetData p x0 y0 Num Denom Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Numerator to be used for scaling. Denominator used for scaling. Return value Zero on success, nonzero if the function fails. (The current implementation always returns 0) Additional information The function scales the image by building a fraction with the given numerator and denominator. If for example an image should be shrunk to 2/3 of size the parameter Num should be 2 and Denom should be 3. For more details, refer to "GUI_JPEG_DrawEx()" on page 157. The Sample folder contains the example 2DGL_DrawJPGScaled.c which shows how to use the function. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 160 CHAPTER Displaying bitmap files GUI_JPEG_GetInfo() Description Fills a GUI_JPEG_INFO structure with information about a jpeg file, which has been loaded into memory. Prototype int GUI_JPEG_GetInfo(const void * pFileData, int DataSize, GUI_JPEG_INFO * pInfo); Parameter Description Pointer to the start of the memory area in which the jpeg file resides. pFileData DataSize pInfo Number of bytes of the jpeg file. Pointer to a GUI_JPEG_INFO structure to be filled by the function. Return value Zero on success, nonzero if the function fails. Elements of GUI_JPEG_INFO Data type int int Element XSize YSize Description Pixel size in X of the image. Pixel size in Y of the image. Additional information The Sample folder contains the example 2DGL_DrawJPG.c which shows how to use the function. GUI_JPEG_GetInfoEx() Description Fills a GUI_JPEG_INFO structure with information about a jpeg file, which does not have to be loaded into memory. Prototype int GUI_JPEG_GetInfoEx(GUI_GET_DATA_FUNC * pfGetData, void * p, GUI_JPEG_INFO * pInfo); Parameter pfGetData p pInfo Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. Pointer to a GUI_JPEG_INFO structure to be filled by the function. Return value Zero on success, nonzero if the function fails. Additional information For more details about the function and the parameters pfGetData and p, refer to "GUI_JPEG_GetInfo()" on page 160 and "GUI_JPEG_DrawEx()" on page 157. The Sample folder contains the example 2DGL_DrawJPGScaled.c which shows how to use the function. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 161 8.3 GIF file support The GIF file format (Graphic Interchange Format) has been developed by the CompuServe Information Service in the 1980s. It has been designed to transmit images across data networks. The GIF standard supports interlacing, transparency, application defined data, animations and rendering of raw text. Unsupported data like raw text or application specific data will be ignored by emWin. GIF files uses the LZW (Lempel-Zif-Welch) file compression method for compressing the image data. This compression method works without loosing data. The output image is exactly identical to the input image. 8.3.1 Converting a GIF file to C source Under some circumstances it can be useful to add a GIF file as C file to the project. This can be done by exactly the same way as described before under 'JPEG file support'. 8.3.2 Displaying GIF files The graphic library first decodes the graphic information. If the image has to be drawn the decoding process takes considerable time. If a GIF file is used in a frequently called callback routine of the Window Manager, the decoding process can take a considerable amount of time. The calculation time can be reduced by the use of memory devices. The best way would be to draw the image first into a memory device. In this case the decompression would be executed only one time. For more information about memory devices, refer to the chapter "Memory Devices" on page 287. 8.3.3 Memory usage The GIF decompression routine of emWin needs about 16Kbytes of dynamically allocated RAM for decompression. After drawing an image the RAM used for decompressing will be released. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 162 CHAPTER 8.3.4 Displaying bitmap files GIF file API The table below lists the available GIF file related routines in alphabetical order. Detailed descriptions follows: Routine Explanation GUI_GIF_Draw() Draws the first image of a GIF file which has been loaded into memory. GUI_GIF_DrawEx() Draws the first image of a GIF file which needs not to be loaded into memory. GUI_GIF_DrawSub() Draws the given sub image of a GIF file which has been loaded into memory. GUI_GIF_DrawSubEx() Draws the given sub image of a GIF file which needs not to be loaded into memory. GUI_GIF_DrawSubScaled() Draws the given sub image of a GIF file with scaling which has been loaded into memory. GUI_GIF_DrawSubScaledEx() Draws the given sub image of a GIF file with scaling which needs not to be loaded into memory. GUI_GIF_GetComment() Returns the given comment of a GIF file which has been loaded into memory. GUI_GIF_GetCommentEx() Returns the given comment of a GIF file which needs not to be loaded into memory. GUI_GIF_GetImageInfo() Returns information about the given sub image of a GIF file which has been loaded into memory. GUI_GIF_GetImageInfoEx() Returns information about the given sub image of a GIF file which needs not to be loaded into memory. GUI_GIF_GetInfo() Returns information about a GIF file which has been loaded into memory. GUI_GIF_GetInfoEx() Returns information about a GIF file which needs not to be loaded into memory. GUI_GIF_GetXSize() Returns the X-size of a bitmap loaded into memory. GUI_GIF_GetXSizeEx() Returns the X-size of a bitmap which needs not to be loaded into memory. GUI_GIF_GetYSize() Returns the Y-size of a bitmap loaded into memory. GUI_GIF_GetYSizeEx() Returns the Y-size of a bitmap which needs not to be loaded into memory. GUI_GIF_Draw() Description Draws the first image of a gif file, which has been loaded into memory, at a specified position in the current window. Prototype int GUI_GIF_Draw(const void * pGIF, U32 NumBytes, int x0, int y0); Parameter pGIF NumBytes x0 y0 Description Pointer to the start of the memory area in which the gif file resides. Number of bytes of the gif file. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value 0 on success, != 0 on error. Additional information If the file contains more than one image, the function shows only the first image of the file. Transparency and interlaced images are supported. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 163 GUI_GIF_DrawEx() Description Draws a gif file, which does not have to be loaded into memory, at a specified position in the current window. Prototype int GUI_GIF_DrawEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0); Parameter pfGetData p x0 y0 Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value Zero on success, nonzero if the function fails. Additional information This function is used for drawing gif files if not enough RAM is available to load the whole file into memory. The library calls the function pointed by the parameter pfGetData to read the data. The GetData function should return the number of available bytes. This could be less or equal the number of requested bytes. The function needs at least to return 1 new byte. GUI_GIF_DrawSub() Description Draws the given sub image of a gif file, which has been loaded into memory, at a specified position in the current window. Prototype int GUI_GIF_DrawSub(const void * pGIF, U32 NumBytes, int x0, int y0, int Index); Parameter pGIF NumBytes x0 y0 Index Description Pointer to the start of the memory area in which the gif file resides. Number of bytes of the gif file. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Zero-based index of sub image to be shown. Return value 0 on success, != 0 on error. Additional information The function manages the background pixels between the current and the previous image. If for example sub image #3 should be drawn at offset x20/y20 with a size of w10/h10 and the previous sub image was shown at x15/y15 with a size of w20/h20 and the background needs to be redrawn, the function fills the pixels between the images with the background color. The file 2DGL_DrawGIF.c of the Sample folder shows how to use the function. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 164 CHAPTER Displaying bitmap files GUI_GIF_DrawSubEx() Description Draws the given sub image of a gif file, which does not have to be loaded into memory, at a specified position in the current window. Prototype int GUI_GIF_DrawSubEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0, int Index); Parameter pfGetData p x0 y0 Index Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Zero-based index of sub image to be shown. Return value Zero on success, nonzero if the function fails. Additional information This function is used for drawing gif images if not enough RAM is available to load the whole file into memory. The GUI library then calls the function pointed by the parameter pfGetData to read the data. For more details, refer to the "GUI_GIF_DrawEx()" on page 163. GUI_GIF_DrawSubScaled() Description Draws the given sub image of a gif file, which has been loaded into memory, at a specified position in the current window using scaling. Prototype int GUI_GIF_DrawSubScaled(const void * pGIF, U32 NumBytes, int x0, int y0, int Index, int Num, int Denom); Parameter pGif NumBytes x0 y0 Index Num Denom Description Pointer to the start of the memory area in which the gif file resides. Number of bytes of the gif file. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Zero-based index of sub image to be shown. Numerator to be used for scaling. Denominator used for scaling. Return value Zero on success, nonzero if the function fails. Additional information The function scales the image by building a fraction with the given numerator and denominator. If for example an image should be shrunk to 2/3 of size the parameter Num should be 2 and Denom should be 3. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 165 GUI_GIF_DrawSubScaledEx() Description Draws the given sub image of a gif file, which does not have to be loaded into memory, at a specified position in the current window using scaling. Prototype int GUI_GIF_DrawSubScaledEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0, int Index, int Num, int Denom); Parameter pfGetData p x0 y0 Index Num Denom Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Zero-based index of sub image to be shown. Numerator to be used for scaling. Denominator used for scaling. Return value Zero on success, nonzero if the function fails. Additional information The function scales the image by building a fraction with the given numerator and denominator. If for example an image should be shrunk to 2/3 of size the parameter Num should be 2 and Denom should be 3. GUI_GIF_GetComment() Description Returns the given comment from a GIF image, which has been loaded into memory. Prototype int GUI_GIF_GetComment(const void * pGIF, U32 NumBytes, U8 * pBuffer, int MaxSize, int Index); Parameter pGIF NumBytes pBuffer MaxSize Index Description Pointer to the start of the memory area in which the gif file resides. Number of bytes of the gif file. Pointer to a buffer to be filled with the comment. Size of the buffer. Zero based index of comment to be returned. Return value 0 on success, != 0 on error. Additional information A GIF file can contain 1 or more comments. The function copies the comment into the given buffer. If the comment is larger than the given buffer only the bytes which fit into the buffer will be copied. The file 2DGL_DrawGIF.c of the Sample folder shows how to use the function. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 166 CHAPTER Displaying bitmap files GUI_GIF_GetCommentEx() Description Returns the given comment from a GIF image, which does not have to be loaded into memory. Prototype int GUI_GIF_GetCommentEx(GUI_GET_DATA_FUNC * pfGetData, void * p, U8 * pBuffer, int MaxSize, int Index); Parameter pfGetData p pBuffer MaxSize Index Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. Pointer to a buffer to be filled with the comment. Size of the buffer. Zero based index of comment to be returned. Return value 0 on success, != 0 on error. Additional information For details, refer to "GUI_GIF_GetComment()" on page 165. GUI_GIF_GetImageInfo() Description Returns information about the given sub image of a GIF file, which has been loaded into memory. Prototype int GUI_GIF_GetImageInfo(const void * pGIF, U32 NumBytes, GUI_GIF_IMAGE_INFO * pInfo, int Index); Parameter pGIF NumBytes pInfo Index Description Pointer to the start of the memory area in which the gif file resides. Number of bytes of the gif file. Pointer to a GUI_GIF_IMAGE_INFO structure which will be filled by the function. Zero based index of sub image. Return value 0 on success, != 0 on error. Elements of GUI_GIF_IMAGE_INFO Data type int int int int int Element xPos yPos xSize ySize Delay Description X position of the last drawn image. Y position of the last drawn image. X size of the last drawn image. Y size of the last drawn image. Time in 1/100 seconds the image should be shown in a movie. Additional information If an image needs be shown as a movie this function should be used to get the time the sub image should be visible and the next sub image should be shown. If the delay member is 0 the image should be visible for 1/10 second. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 167 GUI_GIF_GetImageInfoEx() Description Returns information about the given sub image of a GIF file, which needs not to be loaded into memory. Prototype int GUI_GIF_GetImageInfoEx(GUI_GET_DATA_FUNC * pfGetData, void * p, GUI_GIF_IMAGE_INFO * pInfo, int Index); Parameter pfGetData p pInfo Index Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. GetData Void pointer passed to the function pointed by Pointer to a pfGetData. GUI_GIF_IMAGE_INFO structure which will be filled by the function. Zero based index of sub image. Return value 0 on success, != 0 on error. Additional information For more details, refer to "GUI_GIF_GetImageInfo()" on page 166. GUI_GIF_GetInfo() Description Returns an information structure with information about the size and the number of sub images within the given GIF file, which has been loaded into memory. Prototype int GUI_GIF_GetInfo(const void * pGIF, U32 NumBytes, GUI_GIF_INFO * pInfo); Parameter pGIF NumBytes pInfo Description Pointer to the start of the memory area in which the gif file resides. Number of bytes of the gif file. Pointer to a GUI_GIF_INFO structure which will be filled by this function. Return value 0 on success, != 0 on error. Elements of GUI_GIF_INFO Data type int int int Element XSize YSize NumImages Description Pixel size in X of the image. Pixel size in Y of the image. Number of sub images in the file. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 168 CHAPTER Displaying bitmap files GUI_GIF_GetInfoEx() Description Returns an information structure with information about the size and the number of sub images within the given GIF file, which needs not to be loaded into memory. Prototype int GUI_GIF_GetInfoEx(GUI_GET_DATA_FUNC * pfGetData, void * p, GUI_GIF_INFO * pInfo);; Parameter pfGetData p pInfo Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. GetData Void pointer passed to the function pointed by Pointer to a pfGetData. GUI_GIF_INFO structure which will be filled by this function. Return value 0 on success, != 0 on error. Elements of GUI_GIF_INFO Data type int int int Element XSize YSize NumImages Description Pixel size in X of the image. Pixel size in Y of the image. Number of sub images in the file. GUI_GIF_GetXSize() Description Returns the X-size of a specified GIF image, which has been loaded into memory. Prototype int GUI_GIF_GetXSize(const void * pGIF); Parameter pGIF Description Pointer to the start of the memory area in which the gif file resides. Return value X-size of the GIF image. GUI_GIF_GetXSizeEx() Description Returns the X-size of a specified GIF image, which needs not to be loaded into memory. Prototype int GUI_GIF_GetXSizeEx(GUI_GET_DATA_FUNC * pfGetData, void * p); Parameter Description pfGetData Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. p Void pointer passed to the function pointed by GetData pfGetData. Return value X-size of the GIF image. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 169 GUI_GIF_GetYSize() Description Returns the Y-size of a specified GIF image, which has been loaded into memory. Prototype int GUI_GIF_GetYSize(const void * pGIF);; Parameter pGIF Description Pointer to the start of the memory area in which the bmp file resides. Return value Y-size of the GIF image. GUI_GIF_GetYSizeEx() Description Returns the Y-size of a specified GIF image, which needs not to be loaded into memory. Prototype int GUI_GIF_GetYSizeEx(GUI_GET_DATA_FUNC * pfGetData, void * p); Parameter Description pfGetData Pointer to a function which is called for getting data. For details about the GetData function, please refer to "Getting data with the ...Ex() functions" on page 174. p Void pointer passed to the function pointed by pfGetData. Return value Y-size of the GIF image. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 170 CHAPTER 8.4 Displaying bitmap files PNG file support The PNG (Portable Network Graphics) format is an image format which offers lossless data compression and alpha blending by using a non-patented data compression method. Version 1.0 of the PNG specification has been released in 1996. Since the end of 2003 PNG is an international standard (ISO/IEC 15948). The emWin implementation of PNG support is based on the 'libpng' library from Glenn Randers-Pehrson, Guy Eric Schalnat and Andreas Dilger which is freely available under www.libpng.org. It is used in emWin under the copyright notice in GUI\PNG\png.h which allows using the library without any limitation. The PNG library of emWin is available under www.segger.com/link/emwin_png.zip. 8.4.1 Converting a PNG file to C source Under some circumstances it can be useful to add a PNG file as C file to the project. This can be done by exactly the same way as described before under 'JPEG file support'. Further the Bitmap Converter is able to load PNG files and can convert them into C bitmap files. 8.4.2 Displaying PNG files The graphic library first decodes the graphic information. If the image has to be drawn the decoding process takes considerable time. If a PNG file is used in a frequently called callback routine of the Window Manager, the decoding process can take a considerable amount of time. The calculation time can be reduced by the use of memory devices. The best way would be to draw the image first into a memory device. In this case the decompression would be executed only one time. For more information about memory devices, refer to the chapter "Memory Devices" on page 287. 8.4.3 Memory usage The PNG decompression uses app. 21Kbytes of RAM for decompression independent of the image size and a size dependent amount of bytes. The RAM requirement can be calculated as follows: App. RAM requirement = (xSize + 1) * ySize * 4 + 54Kbytes 8.4.4 PNG file API The table below lists the available PNG file related routines in alphabetical order. Detailed descriptions follows: Routine GUI_PNG_Draw() GUI_PNG_DrawEx() GUI_PNG_GetXSize() Explanation Draws the PNG file which has been loaded into memory. Draws the PNG file which needs not to be loaded into memory. Returns the X-size of a bitmap loaded into memory. GUI_PNG_GetXSizeEx() Returns the X-size of a bitmap which needs not to be loaded into memory. GUI_PNG_GetYSize() Returns the Y-size of a bitmap loaded into memory. GUI_PNG_GetYSizeEx() Returns the Y-size of a bitmap which needs not to be loaded into memory. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 171 GUI_PNG_Draw() Description Draws a png file, which has been loaded into memory, at a specified position in the current window. Prototype int GUI_PNG_Draw(const void * pFileData, int FileSize, int x0, int y0); Parameter pFileData FileSize x0 y0 Description Pointer to the start of the memory area in which the png file resides. Number of bytes of the png file. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value Zero on success, nonzero if the function fails. (The current implementation always returns 0) Additional information The Sample folder contains the example 2DGL_DrawPNG.c which shows how to use the function. GUI_PNG_DrawEx() Description Draws a png file, which does not have to be loaded into memory, at a specified position in the current window. Prototype int GUI_PNG_DrawEx(GUI_GET_DATA_FUNC * pfGetData, void * p, int x0, int y0); Parameter pfGetData p x0 y0 Description Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. Void pointer passed to the function pointed by GetData pfGetData. X-position of the upper left corner of the bitmap in the display. Y-position of the upper left corner of the bitmap in the display. Return value Zero on success, nonzero if the function fails. Additional information This function is used for drawing png if not enough RAM is available to load the whole file into memory. The PNG library then calls the function pointed by the parameter pfGetData to read the data. The GetData function should return the number of available bytes. This could be less or equal the number of requested bytes. The function needs at least to return 1 new byte. Note that the PNG library internally allocates a buffer for the complete image. This can not be avoided by using this function. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 172 CHAPTER Displaying bitmap files GUI_PNG_GetXSize() Description Returns the X-size of a specified PNG image, which has been loaded into memory. Prototype int GUI_PNG_GetXSize(const void * pFileData, int FileSize); Parameter pFileData FileSize Description Pointer to the start of the memory area in which the png file resides. Size of the file in bytes. Return value X-size of the PNG image. GUI_PNG_GetXSizeEx() Description Returns the X-size of a specified PNG image, which needs not to be loaded into memory. Prototype int GUI_PNG_GetXSizeEx(GUI_GET_DATA_FUNC * pfGetData, void * p); Parameter Description pfGetData Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. p Void pointer passed to the function pointed by GetData pfGetData. Return value X-size of the PNG image. GUI_PNG_GetYSize() Description Returns the Y-size of a specified PNG image, which has been loaded into memory. Prototype int GUI_PNG_GetYSize(const void * pFileData, int FileSize); Parameter pFileData FileSize Description Pointer to the start of the memory area in which the png file resides. Size of the file in bytes. Return value Y-size of the PNG image. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 173 GUI_PNG_GetYSizeEx() Description Returns the X-size of a specified PNG image, which needs not to be loaded into memory. Prototype int GUI_PNG_GetYSizeEx(GUI_GET_DATA_FUNC * pfGetData, void * p); Parameter Description pfGetData Pointer to a function which is called for getting data. For details about the function, refer to "Getting data with the ...Ex() functions" on page 174. p Void pointer passed to the function pointed by GetData pfGetData. Return value Y-size of the PNG image. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 174 CHAPTER 8.5 Displaying bitmap files Getting data with the ...Ex() functions As well as streamed bitmaps, using BMP, GIF, JPEG and PNG files also works without loading the whole image into RAM. For this case the ...Ex() functions can be used. Common for all of these functions is the use of a 'GetData' function. Please note that the 'GetData' function has to work slightly different depending on the actual task it is used for. See table of parameters and examples below. Prototype of the 'GetData' function int GUI_GET_DATA_FUNC(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off); Parameter p Description Application defined void pointer. BMP, GIF & JPEG: The 'GetData' function has to set the pointer to the location the requested data resides in. ppData Streamed bitmaps & PNG: The location the pointer points to has to be filled by the 'GetData' function. NumBytes Off Number of requested bytes. Defines the offset to use for reading the source data. Additional information "...Ex()"-functions require the 'GetData'-function to fetch at least one pixel line of data. It is recommended to make sure that the 'GetData'-function is able to fetch at least one pixel line of the biggest image used by the application. Internal use of the function In general the 'GetData'-function is called one time at the beginning to retrieve overhead information and, after this, several times to retrieve the actual image data. Return value The number of bytes which were actually read. If the number of read bytes does not match, the drawing function will return immediately. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 175 Example (BMP, GIF and JPEG) The following code excerpt shows how to implement a 'GetData' function for usage with BMP, GIF and JPEG data: int APP_GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) { static char _acBuffer[0x200]; HANDLE * phFile; DWORD NumBytesRead; phFile = (HANDLE *)p; // // Check buffer size // if (NumBytes > sizeof(acBuffer)) { NumBytes = sizeof(acBuffer); } // // Set file pointer to the required position // SetFilePointer(*phFile, Off, 0, FILE_BEGIN); // // Read data into buffer // ReadFile(*phFile, acBuffer, NumBytes, &NumBytesRead, NULL); // // Set data pointer to the beginning of the buffer // *ppData = acBuffer; // // Return number of available bytes // return NumBytesRead; } Example (PNG and streamed bitmap) The following code excerpt shows how to implement a 'GetData' function for usage with PNG and streamed bitmap data: int APP_GetData(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off) { HANDLE * phFile; DWORD NumBytesRead; U8 * pData; pData = (U8 *)*ppData; phFile = (HANDLE *)p; // // Set file pointer to the required position // SetFilePointer(*phFile, Off, 0, FILE_BEGIN); // // Read data into buffer // ReadFile(*phFile, pData, NumBytes, &NumBytesRead, NULL); // // Return number of available bytes // return NumBytesRead; } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 176 UM03001 User & Reference Guide for emWin V5.20 CHAPTER Displaying bitmap files (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 177 Chapter 9 Bitmap Converter The Bitmap Converter is a Windows program which is easy to use. Simply load a bitmap (in the form of a bmp or a gif file) into the application. Convert the color format if you want or have to, and convert it into a C file by saving it in the appropriate format. The C file may then be compiled, allowing the image to be shown on your display with emWin. Screenshot of the Bitmap Converter UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 178 9.1 CHAPTER Bitmap Converter What it does The Bitmap Converter is primarily intended as a tool to convert bitmaps from a PC format to a C file. Bitmaps which can be used with emWin are normally defined as GUI_BITMAP structures in C. The structures -- or rather the picture data which is referenced by these structures -- can be quite large. It is time-consuming and inefficient to generate these bitmaps manually. We therefore recommend using the Bitmap Converter, which automatically generates C files from bitmaps. An other useful feature is the ability to save images as C stream files. The advantage against a normal C file is, that these data streams can be located anywhere on any media whereas C files need to be located in the addressable CPU area. It also features color conversion, so that the resulting C code is not unnecessarily large. You would typically reduce the number of bits per pixel in order to reduce memory consumption. The Bitmap Converter displays the converted image. A number of simple functions can be performed with the Bitmap Converter, including scaling the size, flipping the bitmap horizontally or vertically, rotating it, and inverting the bitmap indices or colors (these features can be found under the Image menu). Any further modifications to an image must be made in a bitmap manipulation program such as Adobe Photoshop or Corel Photopaint. It usually makes the most sense to perform any image modifications in such a program, using the Bitmap Converter for converting purposes only. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 179 9.2 Loading a bitmap 9.2.1 Supported input file formats The Bitmap Converter basically supports Windows bitmap files (*.bmp), "Graphic Interchange Format" (*.gif) and "Portable Network Graphics" (*.png): Windows Bitmap Files (BMP) The Bitmap Converter supports the most common bitmap file formats. Bitmap files of the following formats can be opened by the Bitmap Converter: * * * 1, 4 or 8 bits per pixel (bpp) with palette; 16, 24 or 32 bpp without palette (full-color mode, in which each color is assigned an RGB value); RLE4 and RLE8. Trying to read bitmap files of other formats will cause an error message of the Bitmap Converter. Graphic Interchange Format (GIF) The Bitmap Converter supports reading GIF files. For general editing only the first image of the GIF file is used. GIF image consisting of several images may be converted to animated sprites and animated cursors. Transparency and interlaced GIF images are supported by the converter. Portable Network Graphic (PNG) The PNG format is the most recommended format to create images with alpha blending. The Bitmap Converter supports reading PNG images with alpha channel. 9.2.2 Loading from a file An image file of one of the supported formats may be opened directly in the Bitmap Converter by selecting File/Open. 9.2.3 Using the clipboard Any other type of bitmap (that is, .jpg, .jpeg, .png, .tif) may be opened with another program, copied to the clipboard, and pasted into the Bitmap Converter. This process will achieve the same effect as loading directly from a file. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 180 9.3 CHAPTER Bitmap Converter Color conversion The primary reason for converting the color format of a bitmap is to reduce memory consumption. The most common way of doing this is by using the option Best palette as in the above example, which customizes the palette of a particular bitmap to include only the colors which are used in the image. It is especially useful with fullcolor bitmaps in order to make the palette as small as possible while still fully supporting the image. Once a bitmap file has been opened in the Bitmap Converter, simply select Image/Convert Into/Best palette from the menu. If it is necessary to keep transparency select Image/Convert Into/Best palette + transparency. For certain applications, it may be more efficient to use a fixed color palette, chosen from the menu under Image/Convert Into. For example, suppose a bitmap in fullcolor mode is to be shown on a display which supports only four grayscales. It would be a waste of memory to keep the image in the original format, since it would only appear as four grayscales on the display. The full-color bitmap can be converted into a four-grayscale, 2bpp bitmap for maximum efficiency. The procedure for conversion would be as follows: The Bitmap Converter is opened and the same file is loaded as in steps 1 and 2 of the previous example. The Bitmap Converter displays the loaded bitmap. Choose Image/Convert Into/Gray4 . The Bitmap Converter displays the converted bitmap. UM03001 User & Reference Guide for emWin V5.20 In this example, the image uses less memory since a palette of only 4 grayscales is used instead of the full-color mode. If the target display supports only 4 grayscales, there is no use in having a higher pixel depth as it would only waste memory. (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 181 9.4 Using a custom palette Converting bitmaps to a custom palette and saving them without palette information can save memory and can increase the performance of bitmap drawing operations. More efficient memory utilization Per default each bitmap contains its own palette. Even the smallest bitmaps can contain a large palette with up to 256 colors. In many cases only a small fraction of the palette is used by the bitmap. If using many of these bitmaps the amount of memory used by the palettes can grow rapidly. So it can save much ROM if converting the bitmaps used by emWin to the available hardware palette and saving them as (D)evice (D)ependent (B)itmaps without palette information. Better bitmap drawing performance Before emWin draws a bitmap, it needs to convert each device independent bitmap palette to the available hardware palette. This is required because the pixel indices of the bitmap file are indices into the device independent bitmap palette and not to the available hardware palette. Converting the bitmap to a DDB means that color conversion at run time is not required and speeds up the drawing. 9.4.1 Saving a palette file The Bitmap Converter can save the palette of the currently loaded bitmap into a palette file which can be used for converting other bitmaps with the command Image/ Convert Into/Custom palette. This requires that the current file is a palette based file and not a RGB file. To save the palette the command File/Save palette... can be used. 9.4.2 Palette file format Custom palette files are simple files defining the available colors for conversion. They contain the following: * * * * Header (8 bytes). NumColors (U32, 4 bytes). 0 (4 bytes). U32 Colors[NumColors] (NumColors*4 bytes, type GUI_COLOR). Total file size is therefore: 16 + (NumColors * 4) bytes. A custom palette file with 8 colors would be 16 + (8 * 4) = 48 bytes. At this point, a binary editor must be used in order to create such a file. The maximum number of colors supported is 256; the minimum is 2. Example This example file would define a palette containing 2 colors -- red and white: 0000: 65 6d 57 69 6e 50 61 6c 02 00 00 00 00 00 00 00 0010: ff 00 00 00 ff ff ff 00 The 8 headers make up the first eight bytes of the first line. The U32 is stored lsb first (big endian) and represents the next four bytes, followed by the four 0 bytes. Colors are stored 1 byte per color, where the 4th byte is 0 as follows: RRGGBB00. The second line of code defines the two colors used in this example. 9.4.3 Palette files for fixed palette modes Using the custom palette feature can even make sense with the most common used fixed palette modes, not only with custom hardware palettes. For the most palette based fixed palette modes a palette file can be found in the folder Sample\Palette. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 182 CHAPTER 9.4.4 Bitmap Converter Converting a bitmap The command Image/Convert Into/Custom palette should be used for converting the currently loaded bitmap to a custom palette. The Bitmap Converter tries to find the nearest color of the palette file for each pixel of the currently loaded bitmap. 9.5 Generating C files from bitmaps The main function of the Bitmap Converter is to convert PC-formatted bitmaps into C files which can be used by emWin. Before doing so, however, it is often desirable to modify the color palette of an image so that the generated C file is not excessively large. The bitmap may be saved as a bmp or a gif file (which can be reloaded and used or loaded into other bitmap manipulation programs) or as a C file. A C file will serve as an input file for your C compiler. It may contain a palette (device-independent bitmap, or DIB) or be saved without (device-dependent bitmap, or DDB). DIBs are recommended, as they will display correctly on any display; a DDB will only display correctly on a display which uses the same palette as the bitmap. C files may be generated as "C with palette", "C without palette", "C with palette, compressed" or "C without palette, compressed". For more information on compressed files, see the section "Compressed bitmaps" as well as the example at the end of the chapter. 9.5.1 Supported bitmap formats The following table shows the currently available output formats for C files: Format Color depth Compression Transparency Palette 1 bit per pixel 1bpp no yes yes 2 bits per pixel 4 bits per pixel 2bpp 4bpp no no yes yes yes yes 8 bits per pixel Compressed, RLE4 8bpp 4bpp no yes yes yes yes yes Compressed, RLE8 High color 555 8bpp 15bpp yes no yes no yes no High color 555, red and blue swapped High color 565 15bpp 16bpp no no no no no no High color 565, red and blue swapped High color 565, compressed 16bpp 16bpp no yes no no no no High color 565, red and blue swapped, compressed True color 888 16bpp 24bpp yes no no no no no True color 8888 with alpha channel True color 8888 with alpha channel, compressed 32bpp 32bpp no yes yes yes no no Alpha channel, compressed 8bpp yes yes no 9.5.2 Palette information A bitmap palette is an array of 24 bit RGB color entries. Bitmaps with a color depth from 1 - 8 bpp can be saved with (device independent bitmap, DIB) or without palette information (device dependent bitmap DDB). Device independent bitmaps (DIB) The color information is stored in the form of an index into the color array. Before emWin draws a DIB, it converts the 24 bit RGB colors of the bitmap palette into color indices of the hardware palette. The advantage of using DIBs is that they are hardware independent and can be drawn correctly on systems with different color configurations. The disadvantages are the additional ROM requirement for the palette and the slower performance because of the color conversion. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 183 Device dependent bitmaps (DDB) The pixel information of a DDB is the index of the displays hardware palette. No conversion needs to be done before drawing a DDB. The advantages are less ROM requirement and a better performance. The disadvantage is that these bitmaps can not be displayed correctly on systems with other color configurations. 9.5.3 Transparency A palette based bitmap can be converted to a transparent bitmap. Transparency means each pixel with index 0 will not produce any output. The command Image/ Transparency can be used to select the color which should be used for transparency. After selecting the transparent color, the pixel indices of the image will be recalculated, so that the selected color is on position 0 of the bitmap palette. When saving the bitmap file as C file, it will be saved with the transparency attribute. 9.5.4 Alpha blending Alpha blending is a method of combining an image with the background to create the effect of semi transparency. The alpha value of a pixel determines its transparency. The color of a pixel after drawing the bitmap is a blend of the former color and the color value in the bitmap. In emWin, logical colors are handled as 32 bit values. The lower 24 bits are used for the color information and the upper 8 bits are used to manage the alpha value. An alpha value of 0 means the image is opaque and a value of 0xFF means completely transparent. Whereas BMP and GIF files do not support alpha blending PNG files support alpha blending. So the easiest way to create bitmap files with alpha blending is to load a PNG file. When working with BMP and/or GIF files the Bitmap Converter initially has no information about the alpha values. Loading a PNG file This is the most recommended way for creating bitmaps with an alpha mask: After loading The PNG file contains all required information. Loading the alpha values from an alpha mask bitmap This method loads the alpha values from a separate file. Black pixels of the alpha mask file means opaque and white means transparent. The following table shows an example: Starting point UM03001 User & Reference Guide for emWin V5.20 Alpha mask Result (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 184 CHAPTER Bitmap Converter The command File/Load Alpha Mask can be used for loading an alpha mask. Creating the alpha values from two bitmaps This method uses the difference between the pixels of two pictures to calculate the alpha values. The first image should show the item on a black background. The second image should show the same on a white background. The following table shows an example of how to create the alpha values using the command File/Create Alpha: Starting point Black background White background Result The command File/Create Alpha can be used tor creating the alpha values. 9.5.5 Selecting the best format emWin supports various formats for the generated C file. It depends on several conditions which will be the 'best' format and there is no general rule to be used. Color depth, compression, palette and transparency affect the drawing performance and/or ROM requirement of the bitmap. Color depth In general the lower the color depth the smaller the ROM requirement of the bitmap. Each display driver has been optimized for drawing 1bpp bitmaps (text) and bitmaps with the same color depth as the display. Compression The supported RLE compression method has the best effect on bitmaps with many horizontal sequences of equal-colored pixels. Details later in this chapter. The performance is typically slightly slower than drawing uncompressed bitmaps. Palette The ROM requirement of a palette is 4 bytes for each color. So a palette of 256 colors uses 1 Kbyte. Furthermore emWin needs to convert the colors of the palette before drawing the bitmap. Advantage: Bitmaps are device independent meaning they can be displayed on any display, independent of its color depth and format. Transparency The ROM requirement of transparent bitmaps is the same as without transparency. The performance is with transparency slightly slower than without. High color and true color bitmaps Special consideration is required for bitmaps in these formats. Generally the use of these formats only make sense on displays with a color depth of 15 bits and above. Further it is strongly recommended to save the C files in the exact same format used by the hardware. Note that using the right format will have a positive effect on the drawing performance. If a high color bitmap for example should be shown on a system with a color depth of 16bpp which has the red and blue components swapped, the best format is 'High color 565, red and blue swapped'. Already a slightly other format has the effect, that each pixel needs color conversion, whereas a bitmap in the right format can be rendered very fast without color conversion. The difference of drawing performance in this case can be factor 10 and more. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 185 9.5.6 Saving the file The basic procedure for using the Bitmap Converter is illustrated below: Step 1: Start the application. The Bitmap Converter is opened showing an empty window. Step 2: Load a bitmap into the Bitmap Converter. Choose File/Open . Locate the document you want to open and click Open (must be a bmp file). In this example, the file Logo200.bmp is chosen. The Bitmap Converter displays the loaded bitmap. In this example, the loaded bitmap is in full-color mode. It must be converted to a palette format before a C file can be generated. Step 3: Convert the image if necessary. Choose Image/Convert Select the desired palette. In this example, the option chosen. Into. Best palette is The Bitmap Converter displays the converted bitmap. UM03001 User & Reference Guide for emWin V5.20 The image is unchanged in terms of appearance, but uses less memory since a palette of only 15 colors is used instead of the full-color mode. These 15 colors are the only ones actually required to display this particular image. (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 186 CHAPTER Bitmap Converter Step 4: Save the bitmap as a C file. Choose File/Save As . Select a destination and a name for the C file. Select the file type. In this example, the file is saved as C bitmap file." Click Save . Step 5: Specify bitmap format. If the bitmap should be saved as C file the format should now be specified. Use one of the available formats shown in the dialog. If the bitmap should be saved without palette, activate the check box "Without palette" The Bitmap Converter will create a separate file in the specified destination, containing the C source code for the bitmap. 9.6 Generating C stream files A C stream file consists of the same information as a C file. Contrary to a C file a data stream can be located anywhere and does not need to be compiled or linked with the project. All supported output formats described for C files are also available for C stream files. emWin supports creating bitmaps from data streams and drawing data streams directly. For details about C stream file support please refer to "Drawing bitmaps" on page 119. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 187 9.7 Compressed bitmaps The Bitmap Converter and emWin support run-length encoding (RLE) compression of bitmaps in the resulting source code files. The RLE compression method works most efficiently if your bitmap contains many horizontal sequences of equal-colored pixels. An efficiently compressed bitmap will save a significant amount of space. However, compression is not recommended for photographic images since they do not normally have sequences of identical pixels. It should also be noted that a compressed image may take slightly longer to display. If you want to save a bitmap using RLE compression, you can do so by selecting one of the compressed output formats when saving as a C file: "C with palette, compressed" or "C without palette, compressed". There are no special functions needed for displaying compressed bitmaps; it works in the same way as displaying uncompressed bitmaps. Compression ratios The ratio of compression achieved will vary depending on the bitmap used. The more horizontal uniformity in the image, the better the ratio will be. A higher number of bits per pixel will also result in a higher degree of compression. In the bitmap used in the previous examples, the total number of pixels in the image is (200*94) = 18,800. Since 2 pixels are stored in 1 byte, the total uncompressed size of the image is 18,800/2 = 9,400 bytes. The total compressed size for this particular bitmap is 3,803 bytes for 18,800 pixels (see the example at the end of the chapter). The ratio of compression can therefore be calculated as 9,400/3,803 = 2.47. 9.8 Creating animated sprites / cursors The Bitmap Converter can be used to convert animated GIF files to animated sprites / cursors in C file format. This functionality is offered by the entries in the file menu which are shown below: After clicking one of the according file menu entries, a file dialog appears and an animated GIF file can be chosen. Once this is done the name of the resulting C file needs to be specified. Converting animated GIF files to animated sprites / cursors does not require any further parameters. The process is performed automatically. Since the effort depends on the input GIF file, completing this task may take a moment. The Bitmap Converter can be used again as soon as the mouse cursor is changed to the simple arrow again. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 188 CHAPTER Bitmap Converter Animated Sprite example The following shows the structure of an animated sprite C file as it is generated by the Bitmap Converter. Although animations consist of several images, the palette and pixel data structures are shown only once here. Variable data is described using place holders. File header /********************************************************************* * SEGGER Microcontroller GmbH & Co. KG * * Solutions for real time microcontroller applications * * www.segger.com * ********************************************************************** * * * C-file generated by * * * * Bitmap converter for emWin %_VERSION_%. * * Compiled %_COMPILE_DATE_% * * (C) 1998 - 2013 Segger Microcontroller GmbH & Co. KG * * * ********************************************************************** * * * Source file: %_FILENAME_%.gif (Animated Sprite) * * Dimensions: %_X_SIZE_% * %_Y_SIZE_% * * NumImages: %_NUMBER_OF_IMAGES_% * * Duration: %_OVERALL_DURATION_% * * * ********************************************************************** * * %_USAGE_EXAMPLE_% */ #include #include "GUI.h" #ifndef GUI_CONST_STORAGE #define GUI_CONST_STORAGE const #endif Palette and pixel data static GUI_CONST_STORAGE GUI_COLOR%_FILENAME_%%_INDEX_%[] = { %_COLOR_DATA_% }; static GUI_CONST_STORAGE GUI_LOGPALETTE _Pal%_FILENAME_%%_INDEX_% = { %_NUMBER_OF_COLORS_%, // Number of entries %_TRANSPARENCY_FLAG_%, // No transparency &_Colors%_FILENAME_%%_INDEX_%[0] }; static GUI_CONST_STORAGE unsigned char _ac%_FILENAME_%%_INDEX_%[] = { %_PIXEL_DATA_% }; General data static GUI_CONST_STORAGE GUI_BITMAP _abm%_FILENAME_%[] = { { %_X_SIZE_%, %_Y_SIZE_%, %_BYTES_PER_LINE_%, %_BITS_PER_PIXEL_%, _ac%_FILENAME_%%_INDEX_%, &_Pal%_FILENAME_%%_INDEX_% }, [...] }; const GUI_BITMAP * apbm%_FILENAME_%[] = { &_abm%_FILENAME_%[0], [...] }; const unsigned aDelay%_FILENAME_%[] = { %_DELAY_DATA_% }; /*************************** End of file ****************************/ UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 189 Animated Cursor example The file structure for animated cursors almost equals the structure for animated sprites. Therefor only the differences are mentioned here: The array of bitmap pointers is defined as static: static const GUI_BITMAP * _apbm%_FILENAME_%[] = { [...] }; The array of delays is defined as static: static const unsigned _aDelay%_FILENAME_%[] = { [...] }; A non-static definition of a GUI_CURSOR_ANIM structure is added at the end. const GUI_CURSOR_ANIM Cursor%_FILENAME_% = { _apbm%_FILENAME_%, // Pointer to an array 0, // x coordinate of the 0, // y coordinate of the 0, // Period, should be 0 _aDelay%_FILENAME_%, // Pointer to an array %_NUMBER_OF_IMAGES_% // Number of images }; of bitmaps hot spot hot spot here of periods Additional information The hot spot coordinate define the position which is recognized by emWin when PID events occur. If the hot spot should not be represented by the topmost leftmost pixel, the according values in the GUI_CURSOR_ANIM structure may be modified. The array of delays is always created. In case every image uses the same delay, the forth value in the GUI_CURSOR_ANIM structure may be set accordingly. In this case the array of delays may be deleted after the fifth value of the GUI_CURSOR_ANIM structure was set to NULL. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 190 CHAPTER 9.9 Bitmap Converter Command line usage It is also possible to work with the Bitmap Converter using the command prompt. All conversion functions available in the Bitmap Converter menu are available as commands, and any number of functions may be performed on a bitmap in one command line. 9.9.1 Format for commands Commands are entered using the following format: BmpCvt .bmp <-command> (If more than one command is used, one space is typed between each.) For example, a bitmap with the name logo.bmp is converted into Best palette format and saved as a C file named logo.bmp all at once by entering the following at the command prompt: BmpCvt logo.bmp -convertintobestpalette -saveaslogo,1 -exit Note that while the file to be loaded into the Bitmap Converter always includes its bmp extension, no file extension is written in the -saveas command. An integer is used instead to specify the desired file type. The number 1 in the -saveas command above designates "C with palette". The -exit command automatically closes the program upon completion. See the table below for more information. 9.9.2 Valid command line options The following table lists all permitted Bitmap Converter commands. It can also be viewed at any time by entering BmpCvt -? at the command prompt. Command -convertintobw -convertintogray4 -convertintogray16 -convertintogray64 -convertintogray256 -convertinto111 -convertinto222 -convertinto233 -convertinto323 -convertinto332 -convertinto8666 -convertintorgb -convertintobestpalette -convertintotranspalette Explanation Convert to BW. Convert to Gray4. Convert to Gray16. Convert to Gray64. Convert to Gray256. Convert to 111. Convert to 222. Convert to 233. Convert to 323. Convert to 332. Convert to 8666. Convert to RGB. Convert to best palette. Convert to best palette with transparency. Convert to a custom palette. -convertintocustompalette User-specified filename of desired custom palette. -exit -fliph -flipv -help -invertindices -invertpalette -rotate90cw UM03001 User & Reference Guide for emWin V5.20 Terminate PC program automatically. Flip image horizontally. Flip image vertically. Display this box. Invert indices. Invert palette entries. Rotate image by 90 degrees clockwise. (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 191 Command Explanation Rotate image by 90 degrees counterclockwise. -rotate90ccw -rotate180 -saveas,[,[,]] Rotate image by 180 degrees. Save file as filename . User-specified file name including the file extension. Must be an integer from 1 to 4 as follows: 1 : C with palette (.c file) 2 : Windows Bitmap file (bmp file) 3 : C stream (.dta file) 4: GIF format (gif file) Specifies the bitmap format (only if type == 1): 1: 1 bit per pixel* 2: 2 bits per pixel* 4: 4 bits per pixel* 5: 8 bits per pixel* 6: RLE4 compression* 7: RLE8 compression* 8: High color 565 9: High color 565, red and blue swapped 10: High color 555 11: High color 555, red and blue swapped 12: RLE16 compression 13: RLE16 compression, red and blue swapped 15: True color 32bpp, compressed 16: True color 32bpp 17: True color 24bpp 18: Alpha channel 8bpp, compressed If this parameter is not given, the Bitmap Converter uses the following default formats in dependence of the number of colors of the bitmap: Number of colors <= 2: 1 bit per pixel Number of colors <= 4: 2 bits per pixel Number of colors <= 16: 4 bits per pixel Number of colors <= 256: 8 bits per pixel RGB: High color 565 Saves the bitmap with or without palette (only if type == 1) 0: Save bitmap with palette (default) 1: Save bitmap without palette -transparency Sets the transparent color. RGB color which should be used as trans- parent color. -? Displays the command line table. * Images need to be converted to an according format before they can be stored in a format of 8 or less bpp. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 192 CHAPTER Bitmap Converter 9.10 Example of a converted bitmap A typical example for the use of the Bitmap Converter would be the conversion of your company logo into a C bitmap. Take another look at the example bitmap pictured below: The bitmap is loaded into the Bitmap Converter, converted to Best palette, and saved as "C with palette". The resulting C source code is displayed below (some data is not shown to conserve space). Resulting C code (generated by the Bitmap Converter) /********************************************************************* * SEGGER MICROCONTROLLER SYSTEME GmbH * * Solutions for real time microcontroller applications * * www.segger.com * ********************************************************************** * * C-file generated by * * Bitmap Converter for emWin V5.05. * Compiled Feb 26 2010, 14:49:28 * (C) 1998 - 2013 Segger Microcontroller Systeme GmbH * ********************************************************************** * * Source file: SeggerLogo200 * Dimensions: 200 * 100 * NumColors: 33 * ********************************************************************** */ #include #include "GUI.h" #ifndef GUI_CONST_STORAGE #define GUI_CONST_STORAGE const #endif static GUI_CONST_STORAGE GUI_COLOR ColorsSeggerLogo200[] = { 0xFFFFFF,0x353537,0x9C4B37,0xCDCDCD, [...] }; static GUI_CONST_STORAGE GUI_LOGPALETTE PalSeggerLogo200 = { 33,/* number of entries */ 0, /* No transparency */ &ColorsSeggerLogo200[0] }; static GUI_CONST_STORAGE unsigned char acSeggerLogo200[] = { 0x00, 0x00, /* Not all data is shown in this example */ 0x00, 0x92, [...] 0xC6, 0x22, 0x0A, 0x22 }; extern GUI_CONST_STORAGE GUI_BITMAP bmSeggerLogo200; GUI_CONST_STORAGE GUI_BITMAP bmSeggerLogo200 = { 200, /* XSize */ 100, /* YSize */ 200, /* BytesPerLine */ 8, /* BitsPerPixel */ acSeggerLogo200, /* Pointer to picture data (indices) */ &PalSeggerLogo200 /* Pointer to palette */ }; /*************************** End of file ****************************/ UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 193 Compressing the file We can use the same bitmap image to create a compressed C file, which is done simply by loading and converting the bitmap as before, and saving it as "C with palette, compressed". The source code is displayed below (some data is not shown to conserve space). The compressed image size can be seen towards the end of the file as 3,730 bytes for 18,800 pixels. Resulting compressed C code (generated by the Bitmap Converter) /********************************************************************* * SEGGER MICROCONTROLLER SYSTEME GmbH * * Solutions for real time microcontroller applications * * www.segger.com * ********************************************************************** * * C-file generated by * * Bitmap Converter for emWin V5.05. * Compiled Feb 26 2010, 14:49:28 * (C) 1998 - 2013 Segger Microcontroller Systeme GmbH * ********************************************************************** * * Source file: SeggerLogo200_comp * Dimensions: 200 * 100 * NumColors: 33 * ********************************************************************** */ #include #include "GUI.h" #ifndef GUI_CONST_STORAGE #define GUI_CONST_STORAGE const #endif static GUI_CONST_STORAGE GUI_COLOR ColorsSeggerLogo200_comp[] = { 0xFFFFFF, 0x353537, 0x9C4B37, 0xCDCDCD, [...] }; static GUI_CONST_STORAGE GUI_LOGPALETTE PalSeggerLogo200_comp = { 33,/* number of entries */ 0, /* No transparency */ &ColorsSeggerLogo200_comp[0] }; static GUI_CONST_STORAGE unsigned char acSeggerLogo200_comp[] = { /* RLE: 006 Pixels @ 000,000*/ 6, 0x00, /* RLE: 188 Pixels @ 006,000*/ 188, 0x01, [...] /* RLE: 188 Pixels @ 006,099*/ 188, 0x01, /* RLE: 006 Pixels @ 194,099*/ 6, 0x00, 0 }; /* 3730 for 20000 pixels */ extern GUI_CONST_STORAGE GUI_BITMAP bmSeggerLogo200_comp; GUI_CONST_STORAGE GUI_BITMAP bmSeggerLogo200_comp = { 200, /* XSize */ 100, /* YSize */ 200, /* BytesPerLine */ GUI_COMPRESS_RLE8, /* BitsPerPixel */ acSeggerLogo200_comp, /* Pointer to picture data (indices) */ &PalSeggerLogo200_comp /* Pointer to palette */ ,GUI_DRAW_RLE8 }; /*************************** End of file ****************************/ UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 194 UM03001 User & Reference Guide for emWin V5.20 CHAPTER Bitmap Converter (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 195 Chapter 10 Fonts This chapter describes the various methods of font support in emWin. The most common fonts are shipped with emWin as C font files. All of them contain the ASCII character set and most of them also the characters of ISO 8859-1. In fact, you will probably find that these fonts are fully sufficient for your application. For detailed information about the individual fonts, refer to "Standard fonts" on page 220. emWin is compiled for 8-bit characters, allowing for a maximum of 256 different character codes out of which the first 32 are reserved as control characters. The characters that are available depend on the selected font. For accessing the full Unicode area of 65536 possible characters emWin supports UTF8 decoding which is described in the chapter "Language Support" on page 903. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 196 CHAPTER Fonts 10.1 Introduction The first way of font support was the possibility to use C files with font definitions containing bitmaps with 1bpp pixel information for each character. This kind of font support was limited to use only the fonts which are compiled with the application. Over time, the font support has been improved regarding font quality, ROM requirement, performance, scalability and the ability to add further fonts at run time. In the meantime emWin fonts cover antialiasing, drawing of compound characters like required in Thai language, fonts located on external non addressable media and TrueType support. Except the TrueType font format, which is a vector font, all other kinds of fonts are bitmap fonts. 10.2 Font types emWin supports different internal types of fonts defined by emWin and the commonly used TrueType fonts. Monospaced bitmap fonts Each character of a monospaced bitmap font has the same size. In a proportional font each character has its own width, whereas in a monospaced font the width is defined only one time. The pixel information is saved with 1bpp and covers the whole character area. Proportional bitmap fonts Each character of a proportional bitmap font has the same height and its own width. The pixel information is saved with 1bpp and covers the whole character area. Antialiased fonts with 2 bpp antialiasing information Each character has the same height and its own width. The pixel information is saved with 2bpp antialiasing information and covers the whole character area. Antialiased fonts with 4 bpp antialiasing information Each character has the same height and its own width. The pixel information is saved with 4bpp antialiasing information and covers the whole character area. Extended proportional bitmap fonts Each character of an extended proportional bitmap font has its own height and its own width. The pixel information is saved with 1bpp and covers only the areas of the glyph bitmaps. Extended proportional bitmap fonts with 2 bpp antialiasing information Each character has the same height and its own width. The pixel information is saved with 2bpp antialiasing information and covers only the areas of the glyph bitmaps. Extended proportional bitmap fonts with 4 bpp antialiasing information Each character has the same height and its own width. The pixel information is saved with 4bpp antialiasing information and covers only the areas of the glyph bitmaps. Extended proportional bitmap fonts, framed In some cases, for example in situations, where the background color is unknown at compile time, it can make sense to use a framed font. A framed font is always drawn in transparent mode regardless of the current settings. The character pixels are drawn in the currently selected foreground color and the frame is drawn in background color. A good contrast between foreground and background color makes sure, that the text can be read regardless of the background. Note that this type of font is not suitable for compound characters like in Thai language. It is also not suitable for Arabic fonts. The picture below shows some framed text in front of a photo: UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 197 Table of font types The following table shows the difference between the font types. The pictures only show the pixel information saved in the font file: Prop. bitmap font Prop. bitmap font, AA2 Ext. prop. bitmap font, AA2 Ext. prop. bitmap font, AA4 Prop. bitmap font, AA2 Ext. prop. bitmap font Ext. prop. bitmap font, framed TrueType vector fonts The TrueType font support of emWin means support for the TrueType font file format described later in this chapter. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 198 CHAPTER Fonts 10.3 Font formats The following explains the differences between the supported font formats, when to use them and what is required to be able to use them. 10.3.1 C file format This is the most common way of using fonts. When using fonts in form of C files, we recommend compiling all available fonts and linking them as library modules or putting all of the font object files in a library which you can link with your application. This way you can be sure that only the fonts which are needed by your application are actually linked. The Font Converter may be used to create additional fonts. When to use This format should be used if the fonts are known at compile time and if there is enough addressable memory available for the font data. Requirements In order to be able to use a font C file in your application, the following requirements must be met: * * * The font file is in a form compatible with emWin as C file, object file or library. The font file is linked with your application. The font declaration is contained in the application. Format description A font C file contains at first the pixel information of all characters included by the font. It is followed by a character information table with size information about each character. This table is followed by range information structures for each contiguous area of characters contained in the font file, whereas each structure points to the next one. Note that this method can enlarge a font file a lot if using many separate characters. After the range information structures a GUI_FONT structure follows with the main information like type, pixel size and so on of the font. 10.3.2 System Independent Font (SIF) format System independent fonts are binary data blocks containing the font information. The Font Converter can be used to create system independent fonts. This tool is not part of the basic package. A short description follows later in this chapter. When to use This format should be used if the fonts are not known at compile time and if there is enough addressable memory available for the font data. Requirements In order to be able to use a SIF font file in your application, it is required that the whole file reside in addressable memory (ROM or RAM). Format description The structure of a SIF file is nearly the same as of a C file. It contains the same information in binary format. The sequence of the file components is vice versa: General font information followed by range information structures, character information table and at least pixel information of all characters. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 199 10.3.3 External Bitmap Font (XBF) format As well as SIF fonts XBF fonts are binary data blocks containing the font information and the Font Converter can be used to create XBF files. The Font Converter is not part of the emWin basic package. For details about how to create external binary fonts, please refer to the chapter "Font Converter" on page 243. Advantages Contrary to other fonts, XBF fonts do not have to reside in memory when they are used, whereas all other kinds of emWin fonts need to reside completely in memory. The XBF font file can remain on any external media while it is used. Data access is done by a 'GetData' callback function. The advantage of XBF fonts is that it is possible to use very large fonts on systems with little memory. XBF fonts offer a performance advantage when using fonts including lots of characters which do not follow each other directly in sequence. This kind of character set would cause the Font Converter to create a C file font containing many GUI_FONT_PROP structures having a pointer to the according next one. The more GUI_FONT_PROP structures exist in a font the longer it might take to display a character. XBF fonts just use a memory offset so each character can be found in the same amount of time. When to use This format should be used if there is not enough addressable memory available for the font data and if there is any kind of external media available for storing the fonts. Requirements In order to be able to use a XBF font in your application, a 'GetData' callback function is required which is responsible for getting font data. Format description This format differs in general from SIF and C file format. At first it contains a small block of general font information including the lowest character code and the highest character code. It is followed by an access table containing offset and data size information for each character between lowest and highest character code. If a character does not exist, this information is zero for the according character. The access table is followed by the character information of all characters containing pixel data and character size information. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 200 CHAPTER Fonts 10.3.4 iType font engine support Since version V5.20 emWin also supports using the iType(R) font engine. The iType(R) font engine is a font rendering subsystem developed by Monotype Imaging. It offers a host of advanced capabilities including font linking, font management and discovery, support for various industry standards and font formats in a small memory footprint. iType can be implemented into various platforms. Based on OpenType(R), TrueType(R) and PostScript(R) font formats and packaged as ANSI C code for broad, flexible integration, iType meets stringent size requirements for any applications, including those that support East Asian languages requiring thousands of characters. The glue code to be able to use the iType(R) font engine is freely available under www.segger.com/link/emwin_itype.zip Screenshot Licensing The emWin library of Segger does not provide the iType(R) font engine itself. It provides only the glue code required to be able to use the iType library. Please contact Monotype Imaging under monotypeimaging.com for a licence request if required. When to use This format could be used if high quality fonts need to be scaleable at run-time and/ or advanced font effects are required. Requirements In general the requirements are similar to the requirements of the true type font support described on the next page. For detailed information about requirements and performance please also contact Monotype Imaging under monotypeimaging.com. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 201 10.3.5 TrueType Font (TTF) format TrueType is an outline font standard developed by Apple Computer. It offers font developers a high degree of control over how their fonts are displayed at various font heights. Contrary to bitmap fonts which are based on bitmaps for each character, TrueType fonts are based on vector graphics. The advantage of the vector representation is the loss-free scalability. This implies that each character first needs to be rasterized into a bitmap before it is drawn. To avoid rasterization each time a character is drawn the bitmap data normally is cached by the font engine. This requires a fast CPU and enough RAM. The emWin TTF package is not part of the shipment. It is freely available under www.segger.com/link/emwin_freetype.zip. Licensing The emWin implementation of the TTF support is based on the FreeType font library from David Turner, Robert Wilhelm and Werner Lemberg which is freely available under www.freetype.org. It is used in emWin under the FreeType license which can be found under GUI\TrueType\FTL.txt. It has been slightly adapted and a 'glue' layer with GUI-functions has been added. When to use This format should be used if fonts need to be scaleable at run-time. Requirements * * * CPU: TTF support works only on 32 bit CPUs. Our definition of a 32bit CPU: sizeof(int) = 4. ROM: The ROM requirement of the TTF engine is app. 250K. The exact size depends on the CPU, the compiler and the optimization level of the compiler. RAM: The RAM requirement of the library depends a lot on the used fonts. The basic RAM requirement of the TTF engine is app. 50K. When creating a GUI font with GUI_TTF_CreateFont() the font engine loads all font tables defined in the TTF file required to generate the characters. The table sizes varies a lot between the fonts. The additional required amount of RAM for creating a font can be between a few KB up to more than 1MB. For typical fonts 80-300 Kbytes are required. It depends on the used font file how much RAM is required. At least the TTF engine requires a bitmap cache. Per default the engine uses 200K for the cache. This should be enough for most applications. The TTF engine allocates its memory via the non emWin functions malloc() and free(). It must be made sure that these functions work before using the TTF engine. Format description For details about the TTF format, refer to the information available under www.apple.com. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 202 CHAPTER Fonts 10.4 Converting a TTF file to C source Under some circumstances it can be useful to add a TTF file as 'C' file to the project, for example if no file system is available. This can be done by using the tool Bin2C.exe shipped with emWin. It can be found in the Tools subfolder. It converts the given binary file (in this case the TTF file) to a 'C' file. 10.5 Declaring custom fonts The most recommended way of declaring the prototypes of custom fonts is to put them into an application defined header file. This should be included from each application source file which uses these fonts. It could look like the following example: #include "GUI.h" extern GUI_CONST_STORAGE GUI_FONT GUI_FontApp1; extern GUI_CONST_STORAGE GUI_FONT GUI_FontApp2; Note that this kind of declaring prototypes does not work if the fonts should be used with emWin configuration macros like BUTTON_FONT_DEFAULT or similar. In this case the fonts need to be declared in the configuration file GUIConf.h. The declaration in this case can look like the following example: typedef struct GUI_FONT GUI_FONT; extern const GUI_FONT GUI_FontApp1; #define BUTTON_FONT_DEFAULT &GUI_FontApp1 #define EDIT_FONT_DEFAULT &GUI_FontApp1 The typedef is required because the structure GUI_FONT has not been defined at the early point where GUIConf.h is included by emWin. 10.6 Selecting a font emWin offers different fonts, one of which is always selected. This selection can be changed by calling the function GUI_SetFont() or one of the GUI_XXX_CreateFont() functions, which select the font to use for all text output to follow for the current task. If no font has been selected by your application, the default font is used. This default is configured in GUIConf.h and can be changed. You should make sure that the default font is one that you are actually using in your application because the default font will be linked with your application and will therefore use up ROM memory. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 203 10.7 Font API The table below lists the available font-related routines in alphabetical order within their respective categories. Detailed descriptions can be found in the sections that follow. Routine Explanation C file related font functions Sets the default font GUI_SetDefaultFont() GUI_SetFont() Sets the current font 'SIF' file related font functions GUI_SIF_CreateFont() Creates and selects a font by passing a pointer to system independent font data. GUI_SIF_DeleteFont() Deletes a font created by GUI_SIF_CreateFont() 'TTF' file related font functions Creates a GUI font from a TTF font file. GUI_TTF_CreateFont() GUI_TTF_DestroyCache() GUI_TTF_Done() GUI_TTF_GetFamilyName() GUI_TTF_GetStyleName() GUI_TTF_SetCacheSize() Destroys the cache of the TTF engine. Frees all dynamically allocated memory of the TTF engine. Returns the family name of the font. Returns the style name of the font. Can be used to set the default size of the TTF cache. 'XBF' file related font functions Creates and selects a font by passing a pointer to a callback function, which is responsible for getting data from the XBF font file. GUI_XBF_CreateFont() GUI_XBF_DeleteFont() Deletes a font created by GUI_XBF_CreateFont() Common font-related functions GUI_GetCharDistX() GUI_GetFont() GUI_GetFontDistY() GUI_GetFontInfo() GUI_GetFontSizeY() GUI_GetLeadingBlankCols() GUI_GetStringDistX() GUI_GetTextExtend() Returns the width in pixels (X-size) of a specified character in the current font. Returns a pointer to the currently selected font. Returns the Y-spacing of the current font. Returns a structure containing font information. Returns the height in pixels (Y-size) of the current font. Returns the number of leading blank pixel columns of the given character. Returns the X-size of a text using the current font. Evaluates the size of a text using the current font Returns the number of trailing blank pixel columns of the given GUI_GetTrailingBlankCols() character. Returns the Y-spacing of a particular font. GUI_GetYDistOfFont() Returns the Y-size of a particular font. GUI_GetYSizeOfFont() Evaluates whether a specified character is in a particular font. GUI_IsInFont() Sets the default font to be used after GUI_Init(). GUI_SetDefaultFont() UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 204 CHAPTER Fonts 10.8 C file related font functions GUI_SetDefaultFont() Description Sets the font to be used by default for text output. Prototype void GUI_SetDefaultFont(const GUI_FONT GUI_UNI_PTR * pFont); Parameter pFont Description Pointer to the font to be selected as default Additional information This function is intended to be used in GUI_X_Config(). Defining GUI_DEFAULT_FONT is not mandatory anymore. If there is neither defined GUI_DEFAULT_FONT nor GUI_SetDefaultFont is called, GUI_Font6x8 will be set as the default Font. If none of the emWin fonts shall be used, GUI_DEFAULT_FONT has to be defined by NULL and a custom font needs to be set as default with this function. GUI_SetFont() Description Sets the font to be used for text output. Prototype const GUI_FONT * GUI_SetFont(const GUI_FONT * pNewFont); Parameter pFont Description Pointer to the font to be selected and used. Return value Returns a pointer to the previously selected font so that it may be buffered. Examples Displays example text in 3 different sizes, restoring the former font afterwards: const GUI_FONT GUI_FLASH * OldFont; OldFont = GUI_SetFont(&GUI_Font8x16); // Buffer old font GUI_DispStringAt("This text is 8 by 16 pixels",0,0); GUI_SetFont(&GUI_Font6x8); GUI_DispStringAt("This text is 6 by 8 pixels",0,20); GUI_SetFont(&GUI_Font8); GUI_DispStringAt("This text is proportional",0,40); GUI_SetFont(OldFont); // Restore old font Screen shot of above example: Displays text and value in different fonts: GUI_SetFont(&GUI_Font6x8); GUI_DispString("The result is: "); // Disp text GUI_SetFont(&GUI_Font8x8); GUI_DispDec(42,2); // Disp value Screen shot of above example: UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 205 10.9 'SIF' file related font functions GUI_SIF_CreateFont() Description Sets the font to be used by passing a pointer to system independent font data. Prototype void GUI_SIF_CreateFont(void * pFontData, GUI_FONT * pFont, const GUI_SIF_TYPE * pFontType); Parameter pFontData pFont pFontType Description Pointer to the system independent font data. Pointer to a GUI_FONT structure in RAM filled by the function. See table below. Permitted values for element pFontType GUI_SIF_TYPE_PROP Should be used if the parameter points to a proportional font. GUI_SIF_TYPE_PROP_EXT Should be used if the parameter pFont points to an extended proportional font. GUI_SIF_TYPE_PROP_FRM Should be used if the parameter pFont points to an extended proportional framed font. GUI_SIF_TYPE_PROP_AA2 Should be used if the parameter pFont points to a proportional font, which uses 2bpp antialiasing. GUI_SIF_TYPE_PROP_AA4 Should be used if the parameter pFont points to a proportional font, which uses 4bpp antialiasing. GUI_SIF_TYPE_PROP_AA2_EXT Should be used if the parameter pFont points to an extended proportional font, which uses 2bpp antialiasing. GUI_SIF_TYPE_PROP_AA4_EXT Should be used if the parameter pFont points to an extended proportional font, which uses 4bpp antialiasing. pFont Additional information Contrary to the emWin standard fonts which must be compiled and linked with the application program, system independent fonts (SIF) are binary data blocks containing the font information. The Font Converter can be used to create system independent fonts. This tool is not part of the basic package. A short description follows later in this chapter. For details about how to create system independent fonts, refer to the chapter "Font Converter" on page 243. When using this function emWin needs to fill a GUI_FONT structure with the font information. The user needs to pass a pointer to this structure in the parameter pFont. The contents of this structure must remain valid during the use of the font. The function does not know what kind of font should be created. To tell the function the type of the font to be created it must be passed in the parameter pFontType. This has been done to avoid linkage of code which is not required. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 206 CHAPTER Fonts Example static GUI_FONT _Font; /* Font structure in RAM */ void MainTask(void) { GUI_Init(); GUI_SIF_CreateFont(_DownloadedFont, &_Font, GUI_SIF_TYPE_PROP); GUI_DispString("Hello World!"); while (1) { GUI_Exec(); } } GUI_SIF_DeleteFont() Description Deletes a font pointed by the parameter pFont. Prototype void GUI_SIF_DeleteFont(GUI_FONT * pFont); Parameter pFont Description Pointer to the font to be deleted. Additional information After using a font created with GUI_SIF_CreateFont() the font should be deleted if not used anymore. Example GUI_FONT _Font; /* Font structure in RAM */ GUI_SIF_CreateFont(_DownloadedFont, &_Font, GUI_SIF_TYPE_PROP); /* Use the font */ GUI_SIF_DeleteFont(&_Font); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 207 10.10 'TTF' file related font functions The emWin implementation of TTF file support is based on the FreeType font library from David Turner, Robert Wilhelm and Werner Lemberg. For details, refer to "TrueType Font (TTF) format" on page 201. GUI_TTF_CreateFont() Description Creates and selects an emWin font by using a TTF font file. Prototype int GUI_TTF_CreateFont(GUI_FONT * pFont, GUI_TTF_CS * pCS); Parameter pFont pCS Description Pointer to a Pointer to a GUI_FONT structure in RAM filled by the function. GUI_TTF_CS structure containing the creation parameters. Return value 0 on success, 1 on error. Elements of GUI_TTF_CS Data type Element Description pTTF Pointer to GUI_TTF_DATA structure which contains location and size of the font file to be used. PixelHeight PixelHeight Pixel height of new font. It means the height of the surrounding rectangle between the glyphs 'g' and 'f'. Note that it is not the distance between two lines of text. With other words the value returned by GUI_GetFontSizeY() is not identical with this value. FaceIndex FaceIndex Some font files can contain more than one font face. In case of more than one face this index specifies the zero based face index to be used to create the font. Usually 0. GUI_TTF_DATA * Elements of GUI_TTF_DATA Data type const void * NumBytes Element pData NumBytes Description Pointer to TTF font file in addressable memory area. Size of file in bytes. Additional information When using the function the first time it initializes the TTF engine and the internal cache system. If the cache should use other values as defined per default it needs to be configured before the first call of this function. For details how to configure the cache, refer to "GUI_TTF_SetCacheSize()" on page 209. The internal data cache manages the complete mechanism of creating fonts and caching bitmap data. Font faces are uniquely identified from the cache by the address given in parameter pTTF and the parameter FaceIndex, which normally is 0. If the same font file for example should be used for creating fonts of different sizes the parameter pTTF should point to the same location of a GUI_TTF_DATA structure. The parameter PixelHeight specifies the height of the surrounding rectangle between the glyphs 'g' and 'f'. The value PixelHeight does not represent the offset between lines. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 208 CHAPTER Fonts Example GUI_TTF_CS Cs0, Cs1; GUI_TTF_DATA Data; GUI_FONT Font0, Font1; /* Set parameters for accessing the font file */ Data.pData = aTTF; /* Address */ Data.NumBytes = sizeof(aTTF); /* Size */ /* Set creation parameters of first font */ Cs0.pTTF = &Data; /* Use address of GUI_TTF_DATA */ Cs0.PixelHeight = 24; /* Pixel height */ Cs0.FaceIndex = 0; /* Initialize to 0 */ /* Set creation parameters of second font */ Cs1.pTTF = &Data; /* Use address of GUI_TTF_DATA */ Cs1.PixelHeight = 48; /* Pixel height */ Cs1.FaceIndex = 0; /* Initialize to 0 */ /* Create 2 fonts */ GUI_TTF_CreateFont(&Font0, &Cs0); GUI_TTF_CreateFont(&Font1, &Cs1); /* Draw something using the fonts */ GUI_SetFont(&Font0); GUI_DispString("Hello world\n"); GUI_SetFont(&Font1); GUI_DispString("Hello world"); GUI_TTF_DestroyCache() Description This function frees all memory allocated by the TTF cache system and destroys the cache. Prototype void GUI_TTF_DestroyCache(void); Additional information The next time GUI_TTF_CreateFont() is used emWin automatically creates and initializes a new cache. GUI_TTF_Done() Description This function frees all memory allocated by the TTF engine and its internal cache system. Prototype void GUI_TTF_Done(void); Additional information The next time GUI_TTF_CreateFont() is used emWin automatically initializes the TTF engine and creates and initializes a new cache. GUI_TTF_GetFamilyName() Description The function returns the font family name defined in the font file. Prototype int GUI_TTF_GetFamilyName(GUI_FONT * pFont, char * pBuffer, int NumBytes); UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 209 Parameter pFont pBuffer NumBytes Description Pointer to a GUI_FONT structure which has been created using GUI_TTF_CreateFont(). Buffer to be filled with the family name. Size of buffer in bytes. Return value 0 on success, 1 on error. GUI_TTF_GetStyleName() Description The function returns the style name (bold, regular, ...) defined in the font file. Prototype int GUI_TTF_GetStyleName(GUI_FONT * pFont, char * pBuffer, int NumBytes); Parameter pFont pBuffer NumBytes Description Pointer to a GUI_FONT structure which has been created using GUI_TTF_CreateFont(). Buffer to be filled with the style name. Size of buffer in bytes. Return value 0 on success, 1 on error. GUI_TTF_SetCacheSize() Description Sets the size parameters GUI_TTF_CreateFont(). used to create the cache on the first call of Prototype void GUI_TTF_SetCacheSize(unsigned MaxFaces, unsigned MaxSizes, U32 MaxBytes); Parameter Description MaxFaces Maximum number of font faces the cache should be able to handle simultaneously. 0 selects default value. MaxSizes Maximum number of size objects the cache should be able to handle simultaneously. 0 selects default value. MaxBytes Maximum number of bytes used for the bitmap cache. 0 selects default value. Additional information If for example 3 font faces should be used, each with 2 sizes, the cache should be able to manage 6 size objects. The default values used by the TTF engine are: 2 faces, 4 size objects and 200K of bitmap data cache. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 210 CHAPTER Fonts 10.11 'XBF' file related font functions GUI_XBF_CreateFont() Description Creates and selects a font by passing a pointer to a callback function, which is responsible for getting data from the XBF font file. Prototype int GUI_XBF_CreateFont(GUI_FONT GUI_XBF_DATA const GUI_XBF_TYPE GUI_XBF_GET_DATA_FUNC void Parameter pFont pXBF_Data pFontType * * * * * pFont, pXBF_Data, pFontType, pfGetData, pVoid); Description Pointer to a GUI_FONT structure in RAM filled by the function. Pointer to a GUI_XBF_DATA structure in RAM filled by the function. See table below. pfGetData Pointer to a callback function which is responsible for getting data from the font file. See prototype below. pVoid Application defined pointer passed to the 'GetData' callback function. Permitted values for element pFontType GUI_XBF_TYPE_PROP Should be used if the parameter points to a proportional font. GUI_XBF_TYPE_PROP_EXT Should be used if the parameter pFont points to an extended proportional font. GUI_XBF_TYPE_PROP_FRM Should be used if the parameter pFont points to an extended framed proportional font. GUI_XBF_TYPE_PROP_AA2_EXT Should be used if the parameter pFont points to an extended proportional font, which uses 2bpp antialiasing. GUI_XBF_TYPE_PROP_AA4_EXT Should be used if the parameter pFont points to an extended framed proportional font, which uses 4bpp antialiasing. pFont GUI_XBF_GET_DATA_FUNC int GUI_XBF_GET_DATA_FUNC(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer); The function has to set pBuffer to point to the location the requested data resides in. Additional information The parameter pfGetData should point to an application defined callback routine, which is responsible for getting data from the font. Parameter pVoid is passed to the callback function when requesting font data. It can be used for example to pass a file handle to the callback function. The function requires pointers to a GUI_FONT structure and a GUI_XBF_DATA structure. The function will fill these structures with font information. It is required, that the contents of these structures remain valid during the usage of the font. The function does not know what kind of XBF font has to be created, so the parameter pFontType has to be used to tell the function the type of the font to be created. This has been done to avoid unnecessary linkage of code. The maximum number of data bytes per character is limited to 200 per default. This should cover the most requirements. If loading a character with more bytes a warning will be generated in the debug version. The default value can be increased by adding the following define to the file GUIConf.h: UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 211 #define GUI_MAX_XBF_BYTES 500 // Sets the maximum number of bytes/chars to 500 Example static static GUI_FONT Font; /* GUI_FONT structure in RAM */ GUI_XBF_DATA XBF_Data; /* GUI_XBF_DATA structure in RAM */ static int _cbGetData(U32 Off, U16 NumBytes, void * pVoid, void * pBuffer) { /* The pVoid pointer may be used to get a file handle */ .../* TBD */ /* Set file pointer to the given position */ .../* TBD */ /* Read the required number of bytes into the given buffer */ .../* TBD */ /* Return 0 on success. Return 1 if the function fails. */ } void CreateXBF_Font(void * pVoid) { GUI_XBF_CreateFont(&Font, &XBF_Data, GUI_XBF_TYPE_PROP, _cbGetData, pVoid); /* /* /* /* /* Pointer to GUI_FONT structure */ Pointer to GUI_XBF_DATA structure */ Font type to be created */ Pointer to callback function */ Pointer to be passed to callback */ } GUI_XBF_DeleteFont() Description Deletes an XBF font pointed by the parameter pFont. Prototype void GUI_XBF_DeleteFont(GUI_FONT * pFont); Parameter pFont Description Pointer to the font to be deleted. Additional information After using a font created with GUI_XBF_CreateFont() the font should be deleted if not used anymore. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 212 CHAPTER Fonts 10.12 Common font-related functions GUI_GetFont() Description Returns a pointer to the currently selected font. Prototype const GUI_FONT * GUI_GetFont(void) GUI_GetCharDistX() Description Returns the width in pixels (X-size) used to display a specified character in the currently selected font. Prototype int GUI_GetCharDistX(U16 c); Parameter Description Character to calculate width from. c GUI_GetFontDistY() Description Returns the Y-spacing of the currently selected font. Prototype int GUI_GetFontDistY(void); Additional information The Y-spacing is the vertical distance in pixels between two adjacent lines of text. The returned value is the YDist value of the entry for the currently selected font. The returned value is valid for both proportional and monospaced fonts. GUI_GetFontInfo() Description Calculates a pointer to a GUI_FONTINFO structure of a particular font. Prototype void GUI_GetFontInfo(const GUI_FONT*pFont, GUI_FONTINFO* pfi); Parameter pFont pfi Description Pointer to the font. Pointer to a GUI_FONTINFO structure. Additional information The definition of the GUI_FONTINFO structure is as follows: typedef struct { U16 Flags; } GUI_FONTINFO; The member variable flags can take the following values: GUI_FONTINFO_FLAG_PROP GUI_FONTINFO_FLAG_MONO GUI_FONTINFO_FLAG_AA GUI_FONTINFO_FLAG_AA2 GUI_FONTINFO_FLAG_AA4 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 213 Example Gets the info of GUI_Font6x8. After the calculation, FontInfo.Flags contains the flag GUI_FONTINFO_FLAG_MONO. GUI_FONTINFO FontInfo; GUI_GetFontInfo(&GUI_Font6x8, &FontInfo); GUI_GetFontSizeY() Description Returns the height in pixels (Y-size) of the currently selected font. Prototype int GUI_GetFontSizeY(void); Additional information The returned value is the YSize value of the entry for the currently selected font. This value is less than or equal to the Y-spacing returned by the function GUI_GetFontDistY(). The returned value is valid for both proportional and monospaced fonts. GUI_GetLeadingBlankCols() Description Returns the number of leading blank pixel columns in the currently selected font for the given character. Prototype int GUI_GetLeadingBlankCols(U16 c); Parameter Description Character to be used. c Example The result for the character 'B' shown in the screenshot above should be 2. GUI_GetStringDistX() Description Returns the X-size used to display a specified string in the currently selected font. Prototype int GUI_GetStringDistX(const char GUI_FAR *s); Parameter s Description Pointer to the string. GUI_GetTextExtend() Description Calculates the size of a given string using the current font. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 214 CHAPTER Fonts Prototype void GUI_GetTextExtend(GUI_RECT* pRect, const char* s, int Len); Parameter pRect s Len Description Pointer to GUI_RECT-structure to store result. Pointer to the string. Number of characters of the string. GUI_GetTrailingBlankCols() Description Returns the number of trailing blank pixel columns in the currently selected font for the given character. Prototype int GUI_GetTrailingBlankCols(U16 c); Parameter Description Character to be used. c Example The result for the character 'B' shown in the screenshot above should be 1. GUI_GetYDistOfFont() Description Returns the Y-spacing of a particular font. Prototype int GUI_GetYDistOfFont(const GUI_FONT* pFont); Parameter pFont Description Pointer to the font. Additional information (see GUI_GetFontDistY()) GUI_GetYSizeOfFont() Description Returns the Y-size of a particular font. Prototype int GUI_GetYSizeOfFont(const GUI_FONT* pFont); Parameter pFont Description Pointer to the font. Additional information (see GUI_GetFontSizeY()) UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 215 GUI_IsInFont() Description Evaluates whether a particular font contains a specified character or not. Prototype char GUI_IsInFont(const GUI_FONT * pFont, U16 c); Parameter pFont c Description Pointer to the font. Character to be searched for. Additional information If the pointer pFont is set to 0, the currently selected font is used. Example Evaluates whether the font GUI_FontD32 contains an "X": if (GUI_IsInFont(&GUI_FontD32, 'X') == 0) { GUI_DispString("GUI_FontD32 does not contain 'X'"); } Return value 1, if the character was found. 0, if the character was not found. GUI_SetDefaultFont() Description Sets the default font to be used after GUI_Init(). Prototype void GUI_SetDefaultFont(const GUI_FONT GUI_UNI_PTR * pFont); Parameter pFont Description Pointer to the font to be used. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 216 CHAPTER Fonts 10.13 Character sets 10.13.1 ASCII emWin supports the full set of ASCII characters. These are the following 96 characters from 32 to 127: Hex 0 1 2 ! 2x 3 4 5 6 "# $ % & 7 8 9 A B C D E F '( ) * + , - . / 3x 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 4x @ A B C D E F G H I J K L M N O 5x P Q R S T U V W X Y Z [ \ ] ^ _ a b c d e f g h i j k l m n o q r s t u v w x y z { | } ~ 6x p 7x Unfortunately, as ASCII stands for American Standard Code for Information Interchange, it is designed for American needs. It does not include any of the special characters used in European languages, such as A, O, U, a, a, and others. There is no single standard for these "European extensions" of the ASCII set of characters; several different ones exist. The one used on the Internet and by most Windows programs is ISO 8859-1, a superset of the ASCII set of characters. 10.13.2 ISO 8859-1 Western Latin character set emWin supports the ISO 8859-1, which defines characters as listed below: Code Description Char 160 non-breaking space 161 162 inverted exclamation cent sign 163 164 pound sterling general currency sign 165 166 yen sign broken vertical bar | 167 168 section sign umlaut (dieresis) 169 170 copyright feminine ordinal (c) 171 172 left angle quote, guillemotleft not sign 173 soft hyphen 174 registered trademark (R) 175 176 macron accent degree sign 177 178 plus or minus superscript two 179 180 superscript three acute accent 181 182 micro sign paragraph sign 183 184 middle dot cedilla * 185 186 superscript one masculine ordinal 187 188 right angle quote, guillemot right fraction one-fourth 1/4 189 fraction one-half 1/2 UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 217 Code Description Char 190 fraction three-fourth 3/4 191 inverted question mark 192 capital A, grave accent A 193 capital A, acute accent A 194 capital A, circumflex accent A 195 capital A, tilde A 196 capital A, dieresis or umlaut mark A 197 capital A, ring A 198 capital A, diphthong (ligature) AE 199 capital C, cedilla C 200 capital E, grave accent E 201 capital E, acute accent E 202 capital E, circumflex accent E 203 capital E, dieresis or umlaut mark E 204 capital I, grave accent I 205 capital I, acute accent I 206 capital I, circumflex accent I 207 capital I, dieresis or umlaut mark I 208 Eth, Icelandic 209 N, tilde N 210 capital O, grave accent O 211 212 capital O, acute accent capital O, circumflex accent O O 213 214 capital O, tilde capital O, dieresis or umlaut mark O O 215 216 multiply sign capital O, slash x O 217 218 capital U, grave accent capital U, acute accent U U 219 220 capital U, circumflex accent capital U, dieresis or umlaut mark U U 221 222 capital Y, acute accent THORN, Icelandic Y 223 224 sharp s, German (s-z ligature) small a, grave accent a 225 226 small a, acute accent small a, circumflex accent a a 227 228 small a, tilde small a, dieresis or umlaut mark a a 229 230 small a, ring small ae diphthong (ligature) a ae 231 232 cedilla small e, grave accent c e 233 234 small e, acute accent small e, circumflex accent e e 235 236 small e, dieresis or umlaut mark small i, grave accent e i 237 238 small i, acute accent small i, circumflex accent i i 239 240 small i, dieresis or umlaut mark small eth, Icelandic i 241 242 small n, tilde small o, grave accent n o 243 244 small o, acute accent small o, circumflex accent o o 245 246 small o, tilde small o, dieresis or umlaut mark o o 247 248 division sign small o, slash / o UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 218 CHAPTER Code Description Fonts Char 249 small u, grave accent 250 small u, acute accent u u 251 small u, circumflex accent u 252 small u, dieresis or umlaut mark u 253 small y, acute accent y 254 small thorn, Icelandic 255 small y, dieresis or umlaut mark y 10.13.3 Unicode Unicode is the ultimate in character coding. It is an international standard based on ASCII and ISO 8859-1. Contrary to ASCII, UNICODE requires 16-bit characters because all characters have their own code. Currently, more than 30,000 different characters are defined. However, not all of the character images are defined in emWin. It is the responsibility of the user to define these additional characters. UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 219 10.14 Font Converter Fonts which can be used with emWin must be defined as GUI_FONT structures in C. The structures -- or rather the font data which is referenced by these structures -can be rather large. It is very time-consuming and inefficient to generate these fonts manually. We therefore recommend using the Font Converter, which automatically generates C files from fonts. The Font Converter is a simple Windows program. You need only to load an installed Windows font into the program, edit it if you want or have to, and save it as a C file. The C file may then be compiled, allowing the font to be shown on your display with emWin on demand. The character codes 0x00 - 0x1F and 0x80 - 0x9F are disabled by default. The following is a example screen shot of the Font Converter with a font loaded 10.14.1 Adding fonts Once you have created a font file and linked it to the project, declare the linked font as extern const GUI_FONT, as shown in the example below. Example extern const GUI_FONT GUI_FontNew; int main(void) { GUI_Init(); GUI_Clear(); GUI_SetFont(&GUI_FontNew); GUI_DispString("Hello world\n"); return 0; } UM03001 User & Reference Guide for emWin V5.20 (c) 1997 - 2013 SEGGER Microcontroller GmbH & Co. KG 220 CHAPTER Fonts 10.15 Standard fonts emWin is shipped with a selection of fonts which should cover most of your needs. The standard font package contains monospaced and proportional fonts in different sizes and styles. Monospaced fonts are fonts with a fixed character width, in which all characters have the same width in pixels. Proportional fonts are fonts in which each character has its own individual pixel-width. This chapter provides an overview of the standard emWin fonts. 10.15.1 Font identifier naming convention All standard fonts are named as follows. The elements of the naming convention are then explained in the table: GUI_Font[