From 37966ff16d923bbca53c9464815cb49cbd7fc3be Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 19 Feb 2014 00:36:52 +1000 Subject: Integrate the include files with each module. Simplifies structure of code. --- src/gwin/button.c | 2 +- src/gwin/button.h | 138 ++++++++ src/gwin/checkbox.c | 2 +- src/gwin/checkbox.h | 116 +++++++ src/gwin/class_gwin.h | 216 +++++++++++++ src/gwin/console.c | 2 +- src/gwin/console.h | 172 ++++++++++ src/gwin/gimage.c | 2 +- src/gwin/graph.c | 2 +- src/gwin/graph.h | 186 +++++++++++ src/gwin/gwidget.c | 2 +- src/gwin/gwidget.h | 308 ++++++++++++++++++ src/gwin/gwin.c | 2 +- src/gwin/gwin.mk | 14 - src/gwin/gwm.c | 2 +- src/gwin/image.h | 127 ++++++++ src/gwin/label.c | 2 +- src/gwin/label.h | 72 +++++ src/gwin/list.c | 2 +- src/gwin/list.h | 287 ++++++++++++++++ src/gwin/progressbar.c | 2 +- src/gwin/progressbar.h | 190 +++++++++++ src/gwin/radio.c | 2 +- src/gwin/radio.h | 142 ++++++++ src/gwin/slider.c | 2 +- src/gwin/slider.h | 155 +++++++++ src/gwin/sys_defs.h | 863 +++++++++++++++++++++++++++++++++++++++++++++++++ src/gwin/sys_make.mk | 14 + src/gwin/sys_options.h | 185 +++++++++++ src/gwin/sys_rules.h | 99 ++++++ 30 files changed, 3283 insertions(+), 27 deletions(-) create mode 100644 src/gwin/button.h create mode 100644 src/gwin/checkbox.h create mode 100644 src/gwin/class_gwin.h create mode 100644 src/gwin/console.h create mode 100644 src/gwin/graph.h create mode 100644 src/gwin/gwidget.h delete mode 100644 src/gwin/gwin.mk create mode 100644 src/gwin/image.h create mode 100644 src/gwin/label.h create mode 100644 src/gwin/list.h create mode 100644 src/gwin/progressbar.h create mode 100644 src/gwin/radio.h create mode 100644 src/gwin/slider.h create mode 100644 src/gwin/sys_defs.h create mode 100644 src/gwin/sys_make.mk create mode 100644 src/gwin/sys_options.h create mode 100644 src/gwin/sys_rules.h (limited to 'src/gwin') diff --git a/src/gwin/button.c b/src/gwin/button.c index b0fd973a..72d75225 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -19,7 +19,7 @@ #if GFX_USE_GWIN && GWIN_NEED_BUTTON -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" // Parameters for various shapes #define RND_CNR_SIZE 5 // Rounded corner size for rounded buttons diff --git a/src/gwin/button.h b/src/gwin/button.h new file mode 100644 index 00000000..d11764d6 --- /dev/null +++ b/src/gwin/button.h @@ -0,0 +1,138 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/button.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup Button Button + * @ingroup GWIN + * + * @details GWIN allows it to easily create buttons with different styles + * and check for different meta states such as: PRESSED, CLICKED, + * RELEASED etc. + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_BUTTON must be set to TRUE in your gfxconf.h + * @{ + */ + +#ifndef _GWIN_BUTTON_H +#define _GWIN_BUTTON_H + +/* This file is included within "gwin/gwidget.h" */ + +/** + * @brief The Event Type for a Button Event + */ +#define GEVENT_GWIN_BUTTON (GEVENT_GWIN_FIRST+0) + +/** + * @brief A Button Event + * @note There are currently no GEventGWinButton listening flags - use 0 as the flags to @p gwinAttachListener() + */ +typedef struct GEventGWinButton { + GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) + GHandle button; // The button that has been depressed (actually triggered on release) +} GEventGWinButton; + +/** + * @brief The button widget structure + * @note Do not use the members directly - treat it as a black-box. + */ +typedef struct GButtonObject { + GWidgetObject w; + #if GINPUT_NEED_TOGGLE + uint16_t toggle; + #endif +} GButtonObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a button widget. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gb The GButtonObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialisation parameters + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note A button remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note A button supports mouse and a toggle input. + * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will + * forget the previous toggle. When assigning a toggle the role parameter must be 0. + * + * @api + */ +GHandle gwinGButtonCreate(GDisplay *g, GButtonObject *gb, const GWidgetInit *pInit); +#define gwinButtonCreate(gb, pInit) gwinGButtonCreate(GDISP, gb, pInit) + +/** + * @brief Is the button current pressed + * @return TRUE if the button is depressed + * + * @param[in] gh The window handle (must be a button widget) + * + * @api + */ +bool_t gwinButtonIsPressed(GHandle gh); + +/** + * @brief Some custom button drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different button drawing styles + * + * @param[in] gw The widget object (in this case a button) + * @param[in] param A parameter passed in from the user + * + * @note In your custom button drawing function you may optionally call these + * standard functions and then draw your extra details on top. + * @note The standard functions below ignore the param parameter except for @p gwinButtonDraw_Image(). + * @note The image custom draw function @p gwinButtonDraw_Image() uses param to pass in the gdispImage pointer. + * The image must be already opened before calling @p gwinSetCustomDraw(). The image should be 3 + * times the height of the button. The button image is repeated 3 times vertically, the first (top) for + * the "up" image, the 2nd for the "down" image, and the third (bottom) image for the disabled state. If + * the disabled state is never going to be used then the image can be just 2 times the button height. + * No checking is done to compare the size of the button to the size of the image. + * Note text is drawn on top of the image. + * @note These custom drawing routines don't have to worry about setting clipping as the framework + * sets clipping to the object window prior to calling these routines. + * + * @api + * @{ + */ +void gwinButtonDraw_3D(GWidgetObject *gw, void *param); // @< A standard 3D button +#if GDISP_NEED_ARC || defined(__DOXYGEN__) + void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param); // @< A rounded rectangle button +#endif +#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__) + void gwinButtonDraw_Ellipse(GWidgetObject *gw, void *param); // @< A circular button +#endif +#if GDISP_NEED_CONVEX_POLYGON || defined(__DOXYGEN__) + void gwinButtonDraw_ArrowUp(GWidgetObject *gw, void *param); // @< An up arrow button + void gwinButtonDraw_ArrowDown(GWidgetObject *gw, void *param); // @< A down arrow button + void gwinButtonDraw_ArrowLeft(GWidgetObject *gw, void *param); // @< A left arrow button + void gwinButtonDraw_ArrowRight(GWidgetObject *gw, void *param); // @< A right arrow button +#endif +#if GDISP_NEED_IMAGE || defined(__DOXYGEN__) + void gwinButtonDraw_Image(GWidgetObject *gw, void *param); // @< An image button - see the notes above on the param. +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_BUTTON_H */ +/** @} */ + diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c index 13730d50..8cdd51d9 100644 --- a/src/gwin/checkbox.c +++ b/src/gwin/checkbox.c @@ -19,7 +19,7 @@ #if (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) || defined(__DOXYGEN__) -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" // Our checked state #define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0) diff --git a/src/gwin/checkbox.h b/src/gwin/checkbox.h new file mode 100644 index 00000000..946f7e4a --- /dev/null +++ b/src/gwin/checkbox.h @@ -0,0 +1,116 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/checkbox.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup Checkbox Checkbox + * @ingroup GWIN + * + * @details GWIN allows it to easily create a group of checkbox buttons. + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_CHECKBOX must be set to TRUE in your gfxconf.h + * @{ + */ + +#ifndef _GWIN_CHECKBOX_H +#define _GWIN_CHECKBOX_H + +/* This file is included within "gwin/gwidget.h" */ + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +#define GEVENT_GWIN_CHECKBOX (GEVENT_GWIN_FIRST+2) + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +typedef struct GEventGWinCheckbox { + GEventType type; // The type of this event (GEVENT_GWIN_CHECKBOX) + GHandle checkbox; // The checkbox that has been depressed (actually triggered on release) + bool_t isChecked; // Is the checkbox currently checked or unchecked? +} GEventGWinCheckbox; + +/* A Checkbox window */ +typedef struct GCheckboxObject { + GWidgetObject w; + #if GINPUT_NEED_TOGGLE + uint16_t toggle; + #endif +} GCheckboxObject; + +/** + * @brief Create a checkbox window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gb The GCheckboxObject structure to initialise. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note A checkbox remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note A checkbox supports mouse and a toggle input. + * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will + * forget the previous toggle. When assigning a toggle the role parameter must be 0. + * + * @api + */ +GHandle gwinGCheckboxCreate(GDisplay *g, GCheckboxObject *gb, const GWidgetInit *pInit); +#define gwinCheckboxCreate(gb, pInit) gwinGCheckboxCreate(GDISP, gb, pInit) + +/** + * @brief Set the state of a checkbox + * + * @param[in] gh The window handle (must be a checkbox window) + * @param[in] isChecked TRUE to set the check, FALSE to uncheck. + * + * @api + */ +void gwinCheckboxCheck(GHandle gh, bool_t isChecked); + +/** + * @brief Get the state of a checkbox + * @return TRUE if the checkbox is currently checked + * + * @param[in] gh The window handle (must be a checkbox window) + * + * @api + */ +bool_t gwinCheckboxIsChecked(GHandle gh); + +/** + * @brief Some custom checkbox drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different checkbox drawing styles + * + * @param[in] gw The widget (which must be a checkbox) + * @param[in] param A parameter passed in from the user + * + * @note In your custom checkbox drawing function you may optionally call this + * standard functions and then draw your extra details on top. + * @note The standard functions below ignore the param parameter. + * @note These custom drawing routines don't have to worry about setting clipping as the framework + * sets clipping to the object window prior to calling these routines. + * + * @api + * @{ + */ +void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param); +void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param); +/* @} */ + +#endif /* _GWIN_CHECKBOX_H */ +/** @} */ + diff --git a/src/gwin/class_gwin.h b/src/gwin/class_gwin.h new file mode 100644 index 00000000..ae5ac756 --- /dev/null +++ b/src/gwin/class_gwin.h @@ -0,0 +1,216 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/class_gwin.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup Internal Internal + * @ingroup GWIN + * + * @note These definitions are normally not used by an application program. They are useful + * only if you want to create your own custom GWIN window or widget. + * @note To access these definitions you must include "gwin/class_gwin.h" in your source file. + * + * @{ + */ +#ifndef _CLASS_GWIN_H +#define _CLASS_GWIN_H + +#if GFX_USE_GWIN || defined(__DOXYGEN__) + +/** + * @brief The predefined flags for a Window + * @{ + */ +#define GWIN_FLG_DYNAMIC 0x0001 // @< The GWIN structure is allocated +#define GWIN_FLG_VISIBLE 0x0002 // @< The window is visible +#define GWIN_FLG_MINIMIZED 0x0004 // @< The window is minimized +#define GWIN_FLG_MAXIMIZED 0x0008 // @< The window is maximized +#define GWIN_FLG_ENABLED 0x0010 // @< The window is enabled +#define GWIN_FLG_WIDGET 0x0020 // @< This is a widget +#define GWIN_FLG_ALLOCTXT 0x0040 // @< The widget text is allocated +#define GWIN_FLG_MOUSECAPTURE 0x0080 // @< The widget has captured the mouse +#define GWIN_FIRST_WM_FLAG 0x0100 // @< 4 bits free for the window manager to use +#define GWIN_FIRST_CONTROL_FLAG 0x1000 // @< 4 bits free for Windows and Widgets to use +/* @} */ + +/** + * @brief The Virtual Method Table for a GWIN window + * @{ + */ +typedef struct gwinVMT { + const char * classname; // @< The GWIN classname (mandatory) + size_t size; // @< The size of the class object + void (*Destroy) (GWindowObject *gh); // @< The GWIN destroy function (optional) + void (*Redraw) (GWindowObject *gh); // @< The GWIN redraw routine (optional) + void (*AfterClear) (GWindowObject *gh); // @< The GWIN after-clear function (optional) +} gwinVMT; +/* @} */ + +#if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + + /** + * @brief An toggle/dial instance is not being used + */ + #define GWIDGET_NO_INSTANCE ((uint16_t)-1) + + /** + * @brief The source handle that widgets use when sending events + */ + #define GWIDGET_SOURCE ((GSourceHandle)(void *)_gwidgetCreate) + + /** + * @brief The Virtual Method Table for a widget + * @note A widget must have a destroy function. Either use @p _gwidgetDestroy() or use your own function + * which internally calls @p _gwidgetDestroy(). + * @note A widget must have a redraw function. Use @p _gwidgetRedraw(). + * @note If toggleroles != 0, ToggleAssign(), ToggleGet() and one or both of ToggleOff() and ToggleOn() must be specified. + * @note If dialroles != 0, DialAssign(), DialGet() and DialMove() must be specified. + * @{ + */ + typedef struct gwidgetVMT { + struct gwinVMT g; // @< This is still a GWIN + void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory) + #if GINPUT_NEED_MOUSE + struct { + void (*MouseDown) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse down events (optional) + void (*MouseUp) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse up events (optional) + void (*MouseMove) (GWidgetObject *gw, coord_t x, coord_t y); // @< Process mouse move events (optional) + }; + #endif + #if GINPUT_NEED_TOGGLE + struct { + uint16_t toggleroles; // @< The roles supported for toggles (0->toggleroles-1) + void (*ToggleAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Assign a toggle to a role (optional) + uint16_t (*ToggleGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional) + void (*ToggleOff) (GWidgetObject *gw, uint16_t role); // @< Process toggle off events (optional) + void (*ToggleOn) (GWidgetObject *gw, uint16_t role); // @< Process toggle on events (optional) + }; + #endif + #if GINPUT_NEED_TOGGLE + struct { + uint16_t dialroles; // @< The roles supported for dials (0->dialroles-1) + void (*DialAssign) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the dial instance handle (optional) + uint16_t (*DialGet) (GWidgetObject *gw, uint16_t role); // @< Return the instance for a particular role (optional) + void (*DialMove) (GWidgetObject *gw, uint16_t role, uint16_t value, uint16_t max); // @< Process dial move events (optional) + }; + #endif + } gwidgetVMT; + /* @} */ +#endif + +// These flags are needed whether or not we are running a window manager. +/** + * @brief Flags for redrawing after a visibility change + * @{ + */ +#define GWIN_WMFLG_PRESERVE 0x0001 // @< Preserve whatever existing contents possible if a window can't redraw +#define GWIN_WMFLG_NOBGCLEAR 0x0002 // @< Don't clear the area if the window is not visible +#define GWIN_WMFLG_NOZORDER 0x0004 // @< Don't redraw higher z-order windows that overlap +/* @} */ + +#if GWIN_NEED_WINDOWMANAGER || defined(__DOXYGEN__) + #if 1 // When we know that wmq is the first element of the GWindowObject structure + #define QItem2GWindow(qi) ((GHandle)qi) + #else + #define QItem2GWindow(qi) ((GHandle)(((char *)(qi)) - (size_t)(&(((GWindowObject *)0)->wmq)))) + #endif + + // @note There is only ever one instance of each GWindowManager type + typedef struct GWindowManager { + const struct gwmVMT *vmt; + } GWindowManager; + + /** + * @brief The Virtual Method Table for a window manager + * @{ + */ + typedef struct gwmVMT { + void (*Init) (void); // @< The window manager has just been set as the current window manager + void (*DeInit) (void); // @< The window manager has just been removed as the current window manager + bool_t (*Add) (GHandle gh, const GWindowInit *pInit); // @< A window has been added + void (*Delete) (GHandle gh); // @< A window has been deleted + void (*Redraw) (GHandle gh, int visflags); // @< A window needs to be redraw (or undrawn) + void (*Redim) (GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); // @< A window wants to be moved or resized + void (*Raise) (GHandle gh); // @< A window wants to be on top + void (*MinMax) (GHandle gh, GWindowMinMax minmax); // @< A window wants to be minimized/maximised + } gwmVMT; + /* @} */ + + /** + * @brief The list of all windows in the system + */ + extern gfxQueueASync _GWINList; + + /** + * @brief The current window manager + */ + extern GWindowManager * _GWINwm; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialise (and allocate if necessary) the base GWIN object + * + * @param[in] g The GDisplay to use for this window + * @param[in] pgw The GWindowObject structure. If NULL one is allocated from the heap + * @param[in] pInit The user initialization parameters + * @param[in] vmt The virtual method table for the GWIN object + * @param[in] flags The default flags to use + * + * @return The GHandle of the created window + * + * @notapi + */ +GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit, const gwinVMT *vmt, uint16_t flags); + +#if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + /** + * @brief Initialise (and allocate if necessary) the base Widget object + * + * @param[in] g The GDisplay to display this window on + * @param[in] pgw The GWidgetObject structure. If NULL one is allocated from the heap + * @param[in] pInit The user initialization parameters + * @param[in] vmt The virtual method table for the Widget object + * + * @return The GHandle of the created widget + * + * @notapi + */ + GHandle _gwidgetCreate(GDisplay *g, GWidgetObject *pgw, const GWidgetInit *pInit, const gwidgetVMT *vmt); + + /** + * @brief Destroy the Widget object + * + * @param[in] gh The widget to destroy + * + * @notapi + */ + void _gwidgetDestroy(GHandle gh); + + /** + * @brief Redraw the Widget object + * + * @param[in] gh The widget to redraw + * + * @notapi + */ + void _gwidgetRedraw(GHandle gh); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_GWIN */ + +#endif /* _CLASS_GWIN_H */ +/** @} */ diff --git a/src/gwin/console.c b/src/gwin/console.c index 623404be..0fe4b722 100644 --- a/src/gwin/console.c +++ b/src/gwin/console.c @@ -16,7 +16,7 @@ #include -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" #define GWIN_CONSOLE_USE_CLEAR_LINES TRUE // Clear each line before using it #define GWIN_CONSOLE_USE_FILLED_CHARS FALSE // Use filled characters instead of drawn characters diff --git a/src/gwin/console.h b/src/gwin/console.h new file mode 100644 index 00000000..252b627e --- /dev/null +++ b/src/gwin/console.h @@ -0,0 +1,172 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/console.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup Console Console + * @ingroup GWIN + * + * @details GWIN allows it to create a console/terminal like window. + * You can simply use chprintf() to print to the terminal. + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_CONSOLE must be set to TRUE in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_CONSOLE_H +#define _GWIN_CONSOLE_H + +/* This file is included within "gwin/gwin.h" */ + +// A console window. Supports wrapped text writing and a cursor. +typedef struct GConsoleObject { + GWindowObject g; + coord_t cx, cy; // Cursor position + + #if GWIN_CONSOLE_USE_HISTORY + char * buffer; // buffer to store console content + size_t bufsize; // size of buffer + size_t bufpos; // the position of the next char + #endif + + #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM + struct GConsoleWindowStream_t { + const struct GConsoleWindowVMT_t *vmt; + _base_asynchronous_channel_data + } stream; + #endif + +} GConsoleObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a console window. + * @details A console window allows text to be written. + * @note Text in a console window supports newlines and will wrap text as required. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gc The GConsoleObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note On creation even if the window is visible it is not automatically cleared. + * You may do that by calling @p gwinClear() (possibly after changing your background color) + * @note A console does not save the drawing state. It is not automatically redrawn if the window is moved or + * its visibility state is changed. + * + * @api + */ +GHandle gwinGConsoleCreate(GDisplay *g, GConsoleObject *gc, const GWindowInit *pInit); +#define gwinConsoleCreate(gc, pInit) gwinGConsoleCreate(GDISP, gc, pInit) + +#if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM + /** + * @brief Get a stream from a console window suitable for use with chprintf(). + * @return The stream handle or NULL if this is not a console window. + * + * @param[in] gh The window handle (must be a console window) + * + * @note Only useful in ChibiOS + * + * @api + */ + BaseSequentialStream *gwinConsoleGetStream(GHandle gh); +#endif + +#if GWIN_CONSOLE_USE_HISTORY + /** + * @brief Assign a buffer to keep track of the content while the widget is invisible. + * @pre GWIN_CONSOLE_USE_HISTORY must be set to TRUE in your gfxconf.h + * + * @param[in] gh The window handle (must be a console window) + * @param[in] onoff If TRUE a buffer is allocated to maintain console text + * when the console is obscured or invisible. If FALSE, then + * any existing buffer is deallocated. + * @note When the history buffer is turned on, scrolling is implemented using the + * history buffer. + * + * @return TRUE if the history buffer is now turned on. + */ + bool_t gwinConsoleSetBuffer(GHandle gh, bool_t onoff); +#endif + +/** + * @brief Put a character at the cursor position in the window. + * @note Uses the current foreground color to draw the character and fills the background using the background drawing color + * + * @param[in] gh The window handle (must be a console window) + * @param[in] c The character to draw + * + * @api + */ +void gwinPutChar(GHandle gh, char c); + +/** + * @brief Put a string at the cursor position in the window. It will wrap lines as required. + * @note Uses the current foreground color to draw the string and fills the background using the background drawing color + * + * @param[in] gh The window handle (must be a console window) + * @param[in] str The string to draw + * + * @api + */ +void gwinPutString(GHandle gh, const char *str); + +/** + * @brief Put the character array at the cursor position in the window. It will wrap lines as required. + * @note Uses the current foreground color to draw the string and fills the background using the background drawing color + * + * @param[in] gh The window handle (must be a console window) + * @param[in] str The string to draw + * @param[in] n The number of characters to draw + * + * @api + */ +void gwinPutCharArray(GHandle gh, const char *str, size_t n); + +/** + * @brief Print a formatted string at the cursor position in the window. It will wrap lines as required. + * @details This function implements a minimal printf() like functionality + * The general parameters format is: %[-][width|*][.precision|*][l|L]p. + * The following parameter types (p) are supported: + * - x hexadecimal integer. + * - X hexadecimal long. + * - o octal integer. + * - O octal long. + * - d decimal signed integer. + * - D decimal signed long. + * - u decimal unsigned integer. + * - U decimal unsigned long. + * - c character. + * - s string. + * @note Uses the current foreground color to draw the string and fills the background using the background drawing color + * + * @param[in] gh The window handle (must be a console window) + * @param[in] fmt The format string (as per printf) + * @param[in] ... The format string arguments. + * + * @api + */ +void gwinPrintf(GHandle gh, const char *fmt, ...); + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_CONSOLE_H */ +/** @} */ diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c index e4032b96..953aefc3 100644 --- a/src/gwin/gimage.c +++ b/src/gwin/gimage.c @@ -14,7 +14,7 @@ #if GFX_USE_GWIN && GWIN_NEED_IMAGE -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" #define widget(gh) ((GImageObject *)gh) diff --git a/src/gwin/graph.c b/src/gwin/graph.c index 1d513290..c06639fe 100644 --- a/src/gwin/graph.c +++ b/src/gwin/graph.c @@ -14,7 +14,7 @@ #if GFX_USE_GWIN && GWIN_NEED_GRAPH -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" #define GGRAPH_FLG_CONNECTPOINTS (GWIN_FIRST_CONTROL_FLAG<<0) #define GGRAPH_ARROW_SIZE 5 diff --git a/src/gwin/graph.h b/src/gwin/graph.h new file mode 100644 index 00000000..65a64126 --- /dev/null +++ b/src/gwin/graph.h @@ -0,0 +1,186 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/graph.h + * @brief GWIN GRAPH module header file. + * + * @defgroup Graph Graph + * @ingroup GWIN + * + * @details GWIN allows it to easily draw graphs. + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_GRAPH must be set to TRUE in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_GRAPH_H +#define _GWIN_GRAPH_H + +/* This file is included within "gwin/gwin.h" */ + +typedef enum GGraphPointType_e { + GGRAPH_POINT_NONE, GGRAPH_POINT_DOT, GGRAPH_POINT_SQUARE, GGRAPH_POINT_CIRCLE + } GGraphPointType; + +typedef struct GGraphPointStyle_t { + GGraphPointType type; + coord_t size; + color_t color; + } GGraphPointStyle; + +typedef enum GGraphLineType_e { + GGRAPH_LINE_NONE, GGRAPH_LINE_SOLID, GGRAPH_LINE_DOT, GGRAPH_LINE_DASH + } GGraphLineType; + +typedef struct GGraphLineStyle_t { + GGraphLineType type; + coord_t size; + color_t color; + } GGraphLineStyle; + +typedef struct GGraphGridStyle_t { + GGraphLineType type; + coord_t size; + color_t color; + coord_t spacing; + } GGraphGridStyle; + +typedef struct GGraphStyle_t { + GGraphPointStyle point; + GGraphLineStyle line; + GGraphLineStyle xaxis; + GGraphLineStyle yaxis; + GGraphGridStyle xgrid; + GGraphGridStyle ygrid; + uint16_t flags; + #define GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS 0x0001 + #define GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS 0x0002 + #define GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS 0x0004 + #define GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS 0x0008 + #define GWIN_GRAPH_STYLE_POSITIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS) + #define GWIN_GRAPH_STYLE_NEGATIVE_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS) + #define GWIN_GRAPH_STYLE_XAXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_XAXIS_NEGATIVE_ARROWS) + #define GWIN_GRAPH_STYLE_YAXIS_ARROWS (GWIN_GRAPH_STYLE_YAXIS_POSITIVE_ARROWS|GWIN_GRAPH_STYLE_YAXIS_NEGATIVE_ARROWS) + #define GWIN_GRAPH_STYLE_ALL_AXIS_ARROWS (GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS) +} GGraphStyle; + +// A graph window +typedef struct GGraphObject { + GWindowObject g; + GGraphStyle style; + coord_t xorigin, yorigin; + coord_t lastx, lasty; + } GGraphObject; + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a graph window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gg The GGraphObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note The dimensions and position may be changed to fit on the real screen. + * @note A graph does not save the drawing state. It is not automatically redrawn if the window is moved or + * its visibility state is changed. + * @note The coordinate system within the window for graphing operations (but not for any other drawing + * operation) is relative to the bottom left corner and then shifted right and up by the specified + * graphing x and y origin. Note that this system is inverted in the y direction relative to the display. + * This gives the best graphing arrangement ie. increasing y values are closer to the top of the display. + * + * @api + */ +GHandle gwinGGraphCreate(GDisplay *g, GGraphObject *gg, const GWindowInit *pInit); +#define gwinGraphCreate(gg, pInit) gwinGGraphCreate(GDISP, gg, pInit) + +/** + * @brief Set the style of the graphing operations. + * + * @param[in] gh The window handle (must be a graph window) + * @param[in] pstyle The graph style to set. + * @note The graph is not automatically redrawn. The new style will apply to any new drawing operations. + * + * @api + */ +void gwinGraphSetStyle(GHandle gh, const GGraphStyle *pstyle); + +/** + * @brief Set the origin for graphing operations. + * + * @param[in] gh The window handle (must be a graph window) + * @param[in] x, y The new origin for the graph (in graph coordinates relative to the bottom left corner). + * @note The graph is not automatically redrawn. The new origin will apply to any new drawing operations. + * + * @api + */ +void gwinGraphSetOrigin(GHandle gh, coord_t x, coord_t y); + +/** + * @brief Draw the axis and the background grid. + * + * @param[in] gh The window handle (must be a graph window) + * @note The graph is not automatically cleared. You must do that first by calling gwinClear(). + * + * @api + */ +void gwinGraphDrawAxis(GHandle gh); + +/** + * @brief Start a new set of graphing data. + * @details This prevents a line being drawn from the last data point to the next point to be drawn. + * + * @param[in] gh The window handle (must be a graph window) + * + * @api + */ +void gwinGraphStartSet(GHandle gh); + +/** + * @brief Draw a graph point. + * @details A graph point and a line connecting to the previous point will be drawn. + * + * @param[in] gh The window handle (must be a graph window) + * @param[in] x, y The new point for the graph. + * + * @api + */ +void gwinGraphDrawPoint(GHandle gh, coord_t x, coord_t y); + +/** + * @brief Draw multiple graph points. + * @details A graph point and a line connecting to each previous point will be drawn. + * + * @param[in] gh The window handle (must be a graph window) + * @param[in] points The array of points for the graph. + * @param[in] count The number of points in the array. + * @note This is slightly more efficient than calling gwinGraphDrawPoint() repeatedly. + * + * @api + */ +void gwinGraphDrawPoints(GHandle gh, const point *points, unsigned count); + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_GRAPH_H */ +/** @} */ + diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 75a69667..ad2b7b20 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -11,7 +11,7 @@ #include -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" /* Our listener for events for widgets */ static GListener gl; diff --git a/src/gwin/gwidget.h b/src/gwin/gwidget.h new file mode 100644 index 00000000..4eaf6c81 --- /dev/null +++ b/src/gwin/gwidget.h @@ -0,0 +1,308 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/gwidget.h + * @brief GWIN Widgets header file. + */ + +#ifndef _GWIDGET_H +#define _GWIDGET_H + +/* This file is included within "gwin/gwin.h" */ + +/** + * @defgroup Widget Widget + * @ingroup GWIN + * + * @details A Widget is a GWindow that supports interacting with the user + * via an input device such as a mouse or toggle buttons. It is the + * base class for widgets such as buttons and sliders. + * + * @pre GFX_USE_GWIN and GWIN_NEED_WIDGET must be set to TRUE in your gfxconf.h + * @{ + */ + +// Forward definition +struct GWidgetObject; + +/** + * @brief The GColorSet structure + * @{ + */ +typedef struct GColorSet { + color_t text; // @< The text color + color_t edge; // @< The edge color + color_t fill; // @< The fill color + color_t progress; // @< The color of progress bars +} GColorSet; +/* @} */ + +/** + * @brief The GWidgetStyle structure + * @details A GWidgetStyle is a set of colors that together form a "style". + * These colors should not be confused with the GWindow foreground + * and background colors which are used for drawing operations. + * @{ + */ +typedef struct GWidgetStyle { + color_t background; // @< The window background color + GColorSet enabled; // @< The colors when enabled + GColorSet disabled; // @< The colors when disabled + GColorSet pressed; // @< The colors when pressed +} GWidgetStyle; +/* @} */ + +/** + * @brief We define a couple of GWidgetStyle's that you can use in your + * application. The Black style is the default style if you don't + * specify one. + * @note BlackWidgetStyle means that it is designed for a Black background. + * Similarly WhiteWidgetStyle is designed for a White background. + * @{ + */ +extern const GWidgetStyle BlackWidgetStyle; +extern const GWidgetStyle WhiteWidgetStyle; +/* @} */ + +/** + * @brief Defines a custom drawing function for a widget + */ +typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); + +/** + * @brief The structure to initialise a widget. + * + * @note Some widgets may have extra parameters. + * @note The text element must be static string (not stack allocated). If you want to use + * a dynamic string (eg a stack allocated string) use NULL for this member and then call + * @p gwinSetText() with useAlloc set to TRUE. + * + * @{ + */ +typedef struct GWidgetInit { + GWindowInit g; // @< The GWIN initializer + const char * text; // @< The initial text + CustomWidgetDrawFunction customDraw; // @< A custom draw function - use NULL for the standard + void * customParam; // @< A parameter for the custom draw function (default = NULL) + const GWidgetStyle * customStyle; // @< A custom style to use - use NULL for the default style +} GWidgetInit; +/* @} */ + +/** + * @brief The GWIN Widget structure + * @note A widget is a GWIN window that accepts user input. + * It also has a number of other properties such as its ability + * to redraw itself (a widget maintains drawing state). + * @note Do not access the members directly. Treat it as a black-box and use the method functions. + * + * @{ + */ +typedef struct GWidgetObject { + GWindowObject g; // @< This is still a GWIN + const char * text; // @< The widget text + CustomWidgetDrawFunction fnDraw; // @< The current draw function + void * fnParam; // @< A parameter for the current draw function + const GWidgetStyle * pstyle; // @< The current widget style colors +} GWidgetObject; +/* @} */ + +/** + * A comment/rant on the above structure: + * We would really like the GWindowObject member to be anonymous. While this is + * allowed under the C11, C99, GNU and various other standards which have been + * around forever - compiler support often requires special flags e.g + * gcc requires the -fms-extensions flag (no wonder the language and compilers have + * not really progressed in 30 years). As portability is a key requirement + * we unfortunately won't use this useful feature in case we get a compiler that + * won't support it even with special flags. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Set the default style for widgets created hereafter. + * + * @param[in] pstyle The default style. Passing NULL uses the system compiled style. + * @param[in] updateAll If TRUE then all existing widgets that are using the current default style + * will be updated to use this new style. Widgets that have custom styles different + * from the default style will not be updated. + * + * @note The style must be allocated statically (not on the stack) as only the pointer is stored. + * + * @api + */ +void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll); + +/** + * @brief Get the current default style. + * + * @return The current default style. + * + * @api + */ +const GWidgetStyle *gwinGetDefaultStyle(void); + +/** + * @brief Set the text of a widget. + * + * @param[in] gh The widget handle + * @param[in] text The text to set. This must be a constant string unless useAlloc is set. + * @param[in] useAlloc If TRUE the string specified will be copied into dynamically allocated memory. + * + * @note The widget is automatically redrawn + * @note Non-widgets will ignore this call. + * + * @api + */ +void gwinSetText(GHandle gh, const char *text, bool_t useAlloc); + +/** + * @brief Get the text of a widget. + * @return The widget text or NULL if it isn't a widget + * + * @param[in] gh The widget handle + * + * @api + */ +const char *gwinGetText(GHandle gh); + +/** + * @brief Set the style of a widget. + * + * @param[in] gh The widget handle + * @param[in] pstyle The style to set. This must be a static structure (not allocated on a transient stack). + * Use NULL to reset to the default style. + * + * @note The widget is automatically redrawn + * @note Non-widgets will ignore this call. + * + * @api + */ +void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle); + +/** + * @brief Get the style of a widget. + * @return The widget style or NULL if it isn't a widget + * + * @param[in] gh The widget handle + * + * @api + */ +const GWidgetStyle *gwinGetStyle(GHandle gh); + +/** + * @brief Set the routine to perform a custom widget drawing. + * + * @param[in] gh The widget handle + * @param[in] fn The function to use to draw the widget + * @param[in] param A parameter to pass to the widget drawing function + * + * @note The widget is not automatically redrawn. Call @p gwinDraw() to redraw the widget. + * @note Non-widgets will ignore this call. + * + * @api + */ +void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param); + +/** + * @brief Attach a Listener to listen for widget events + * @return TRUE on success + * + * @param[in] pl The listener + * + * @api + */ +bool_t gwinAttachListener(GListener *pl); + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + /** + * @brief Set the mouse to be used to control the widgets + * @return TRUE on success + * + * @param[in] instance The mouse instance + * + * @note Every widget uses the same mouse. + * + * @api + */ + bool_t gwinAttachMouse(uint16_t instance); +#endif + +#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE + /** + * @brief Attach a toggle to a widget + * @return TRUE on success + * + * @param[in] gh The widget handle + * @param[in] role The function the toggle will perform for the widget + * @param[in] instance The toggle instance + * + * @note See the documentation on the specific widget to see the possible + * values for the role parameter. If it is out of range, this function + * will return FALSE + * + * @api + */ + bool_t gwinAttachToggle(GHandle gh, uint16_t role, uint16_t instance); +#endif + +#if GFX_USE_GINPUT && GINPUT_NEED_DIAL + /** + * @brief Attach a toggle to a widget + * @return TRUE on success + * + * @param[in] gh The widget handle + * @param[in] role The function the dial will perform for the widget + * @param[in] instance The dial instance + * + * @note See the documentation on the specific widget to see the possible + * values for the role parameter. If it is out of range, this function + * will return FALSE + * + * @api + */ + bool_t gwinAttachDial(GHandle gh, uint16_t role, uint16_t instance); +#endif + +#ifdef __cplusplus +} +#endif + +/* Include extra widget types */ +#if GWIN_NEED_BUTTON || defined(__DOXYGEN__) + #include "src/gwin/button.h" +#endif + +#if GWIN_NEED_SLIDER || defined(__DOXYGEN__) + #include "src/gwin/slider.h" +#endif + +#if GWIN_NEED_CHECKBOX || defined(__DOXYGEN__) + #include "src/gwin/checkbox.h" +#endif + +#if GWIN_NEED_RADIO || defined(__DOXYGEN__) + #include "src/gwin/radio.h" +#endif + +#if GWIN_NEED_LABEL || defined(__DOXYGEN__) + #include "src/gwin/label.h" +#endif + +#if GWIN_NEED_LIST || defined(__DOXYGEN__) + #include "src/gwin/list.h" +#endif + +#if GWIN_NEED_PROGRESSBAR || defined(__DOXYGEN__) + #include "src/gwin/progressbar.h" +#endif + +#endif /* _GWIDGET_H */ +/** @} */ diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 485ccaaa..54f42077 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -9,7 +9,7 @@ #if GFX_USE_GWIN -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" // Needed if there is no window manager #define MIN_WIN_WIDTH 1 diff --git a/src/gwin/gwin.mk b/src/gwin/gwin.mk deleted file mode 100644 index 4c670ea2..00000000 --- a/src/gwin/gwin.mk +++ /dev/null @@ -1,14 +0,0 @@ -GFXSRC += $(GFXLIB)/src/gwin/gwin.c \ - $(GFXLIB)/src/gwin/gwidget.c \ - $(GFXLIB)/src/gwin/gwm.c \ - $(GFXLIB)/src/gwin/console.c \ - $(GFXLIB)/src/gwin/graph.c \ - $(GFXLIB)/src/gwin/button.c \ - $(GFXLIB)/src/gwin/slider.c \ - $(GFXLIB)/src/gwin/checkbox.c \ - $(GFXLIB)/src/gwin/gimage.c \ - $(GFXLIB)/src/gwin/label.c \ - $(GFXLIB)/src/gwin/radio.c \ - $(GFXLIB)/src/gwin/list.c \ - $(GFXLIB)/src/gwin/progressbar.c \ - diff --git a/src/gwin/gwm.c b/src/gwin/gwm.c index e7a71737..9c158f68 100644 --- a/src/gwin/gwm.c +++ b/src/gwin/gwm.c @@ -17,7 +17,7 @@ #if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" /*----------------------------------------------- * Data diff --git a/src/gwin/image.h b/src/gwin/image.h new file mode 100644 index 00000000..66aba3d1 --- /dev/null +++ b/src/gwin/image.h @@ -0,0 +1,127 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/image.h + * @brief GWIN image widget header file. + * + * @defgroup Image Image + * @ingroup GWIN + * + * @details GWIN allos it to create an image widget. The widget + * takes no user input. + * + * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre At least one image type must be enabled in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_IMAGE_H +#define _GWIN_IMAGE_H + +// This file is included within "gwin/gwin.h" + +// An image window +typedef struct GImageObject { + GWindowObject g; + gdispImage image; // The image itself + #if GWIN_NEED_IMAGE_ANIMATION + GTimer timer; // Timer used for animated images + #endif +} GImageObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create an image widget. + * @details Display's a picture. + * @return NULL if there is no resultant drawing area, otherwise the widget handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use. + * + * @note The default background color gets set to the current default one. + * @note An image window knows how to redraw. + * + * @api + */ +GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); +#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) + +/** + * @brief Opens the image using a GFILE + * @return TRUE if the image can be opened + * + * @param[in] gh The widget (must be an image widget) + * @param[in] f The open (for reading) GFILE to use + * + * @api + */ +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); + +/** + * @brief Opens the image using the specified filename + * @return TRUE if the open succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] filename The filename to open + * + * @api + */ +#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) + + /** + * @brief Sets the input routines that support reading the image from memory + * in RAM or flash. + * @pre GFILE_NEED_MEMFS must be TRUE + * @return TRUE if the IO open function succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] ptr A pointer to the image in RAM or Flash + * + * @api + */ +#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) + +/** + * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). + * @return TRUE if the IO open function succeeds + * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE + * + * @param[in] gh The widget (must be an image widget) + * @param[in] streamPtr A pointer to the (open) BaseFileStream object. + * + * @api + */ +#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) + +/** + * @brief Cache the image. + * @details Decodes and caches the current frame into RAM. + * + * @param[in] gh The widget (must be an image widget) + * + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @api + */ +gdispImageError gwinImageCache(GHandle gh); + +#ifdef __cplusplus +} +#endif + +#endif // _GWIN_IMAGE_H +/** @} */ + diff --git a/src/gwin/label.c b/src/gwin/label.c index 5619761a..97588a27 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -19,7 +19,7 @@ #if GFX_USE_GWIN && GWIN_NEED_LABEL -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" // macros to assist in data type conversions #define gh2obj ((GLabelObject *)gh) diff --git a/src/gwin/label.h b/src/gwin/label.h new file mode 100644 index 00000000..3fe0f3d7 --- /dev/null +++ b/src/gwin/label.h @@ -0,0 +1,72 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/label.h + * @brief GWIN label widget header file. + * + * @defgroup Label Label + * @ingroup GWIN + * + * @details GWIN allos it to create an label widget. The widget + * takes no user input. + * + * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GDISP_NEED_TEXT must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_LABEL must be set to TRUE in your gfxconf.h + * @pre The fonts you want to use must be enabled in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_LABEL_H +#define _GWIN_LABEL_H + +// This file is included within "gwin/gwin.h" + +// An label window +typedef struct GLabelObject { + GWidgetObject w; +} GLabelObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a label widget. + * @details A label widget is a simple window which has a static text. + * + * @param[in] g The GDisplay to display this window on + * @param[in] widget The label structure to initialise. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialisation parameters to use. + * + * @return NULL if there is no resultat drawing area, otherwise the widget handle. + * + * @api + */ +GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit); +#define gwinLabelCreate(w, pInit) gwinGLabelCreate(GDISP, w, pInit) + +/** + * @brief Border settings for the default rendering routine + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] border Shall a border be rendered? + * + * @api + */ +void gwinLabelSetBorder(GHandle gh, bool_t border); + +#ifdef __cplusplus +} +#endif + +#endif // _GWIN_LABEL_H +/** @} */ + diff --git a/src/gwin/list.c b/src/gwin/list.c index 08e6a96d..5b49811c 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -19,7 +19,7 @@ #if GFX_USE_GWIN && GWIN_NEED_LIST -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" #include #include diff --git a/src/gwin/list.h b/src/gwin/list.h new file mode 100644 index 00000000..cfe6aeb2 --- /dev/null +++ b/src/gwin/list.h @@ -0,0 +1,287 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/list.h + * @brief GWIN list widget header file + * + * @defgroup List List + * @ingroup GWIN + * + * @details GWIN allows it to create a list widget. + * + * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GDISP_NEED_TEXT must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_LIST must be set to TRUE in your gfxconf.h + * @pre The font you want to use must be enabled in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_LIST_H +#define _GWIN_LIST_H + +// This file is included within "gwin/gwin.h" + +/** + * @brief The event type for a list event + */ +#define GEVENT_GWIN_LIST (GEVENT_GWIN_FIRST+4) + +/** + * @brief A list event + */ +typedef struct GEventGWinList { + GEventType type; // The type of this event (GEVENT_GWIN_LIST) + GHandle list; // The list + int item; // The item that has been selected (or unselected in a multi-select listbox) +} GEventGWinList; + +// A list window +typedef struct GListObject { + GWidgetObject w; + + #if GINPUT_NEED_MOUSE + coord_t start_mouse_x; + coord_t start_mouse_y; + coord_t last_mouse_y; + #endif + #if GINPUT_NEED_TOGGLE + uint16_t t_up; + uint16_t t_dn; + #endif + + int cnt; // Number of items currently in the list (quicker than counting each time) + int top; // Viewing offset in pixels from the top of the list + gfxQueueASync list_head; // The list of items +} GListObject; + +/** + * @brief Enum to change the behaviour of the scroll bar + * + * @note Used with @p gwinListSetScroll() + * @note @p scrollAlways always show the scrollbar + * @note @p scrollAuto show the scrollbar when there are more items on the list then fit on the screen + * @note @p scrollSmooth enable touch screen smooth scrolling + */ +typedef enum scroll_t { scrollAlways, scrollAuto, scrollSmooth } scroll_t; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a list widget + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are Black and White. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then + * there is no default font and text drawing operations will not display anything. + * @note A list remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note The list contains no elements after creation. + * @note A slider supports mouse, toggle. Note: toggle only works correctly for single-select lists. + * @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than + * one toggle to a role, it will forget the previous toggle. Two roles are supported: + * Role 0 = toggle for down, role 1 = toggle for up + * + * @param[in] g The GDisplay to display this window on + * @param[in] widget The GListObject structure to initialize. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * @param[in] multiselect If TRUE the list is multi-select instead of single-select. + * + * @return NULL if there is no resulting drawing area, otherwise a window handle. + * + * @api + */ +GHandle gwinGListCreate(GDisplay *g, GListObject *widget, GWidgetInit *pInit, bool_t multiselect); +#define gwinListCreate(w, pInit, m) gwinGListCreate(GDISP, w, pInit, m) + +/** + * @brief Change the behaviour of the scroll bar + * + * @note Current possible values: @p scrollAlways, @p scrollAuto and @p scrollSmooth + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] flag The behaviour to be set + * + * @api + */ +void gwinListSetScroll(GHandle gh, scroll_t flag); + +/** + * @brief Add an item to the list + * + * @note The ID you get returned is not static. If items get removed from the list, the list items get + * reordered. + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The string which shall be displayed in the list afterwards + * @param[in] useAlloc If set to TRUE, the string will be dynamically allocated. A static buffer must be passed otherwise + * + * @return The current ID of the item. The ID might change if you remove items from the middle of the list + * + * @api + */ +int gwinListAddItem(GHandle gh, const char* item, bool_t useAlloc); + +/** + * @brief Get the name behind an item with a given ID + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * + * @return The string of the list item or NULL on error + * + * @api + */ +const char* gwinListItemGetText(GHandle gh, int item); + +/** + * @brief Get the ID of an item with a given name + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] text The item name + * + * @return The id of the list item or -1 on error + * + * @api + */ +int gwinListFindText(GHandle gh, const char* text); + +/** + * @brief Set the custom parameter of an item with a given ID + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * @param[in] param The parameter to be set + * + * @api + */ +void gwinListItemSetParam(GHandle gh, int item, uint16_t param); + +/** + * @brief Get the custom parameter of an item with a given ID + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * + * @return The parameter + * + * @api + */ +uint16_t gwinListItemGetParam(GHandle gh, int item); + +/** + * @brief Delete all the items of the list + * + * @param[in] gh The widget handle (must be a list handle) + * + * @api + */ +void gwinListDeleteAll(GHandle gh); + +/** + * @brief Delete an item from the list + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * + * @api + */ +void gwinListItemDelete(GHandle gh, int item); + +/** + * @brief Get the amount of items within the list + * + * @param[in] gh The widget handle (must be a list handle) + * + * @return The amount of items in the list + * + * @api + */ +int gwinListItemCount(GHandle gh); + +/** + * @brief Check if an item with a given ID is selected + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * + * @return TRUE if the item is selected, FALSE otherwise + * + * @api + */ +bool_t gwinListItemIsSelected(GHandle gh, int item); + +/** + * @brief Get the ID of the selected item + * + * @param[in] gh The widget handle (must be a list handle) + * + * @return The ID of the selected list item for a single-select list. + * + * @note It always returns -1 (nothing selected) for a multi-select list. + * Instead use @p gwinListItemIsSelected() to get the selection status + * for a multi-select list. + * + * @api + */ +int gwinListGetSelected(GHandle gh); + +/** + * @brief Get the text of the selected item + * + * @param[in] gh The widget handle (must be a list handle) + * + * @return The test of the selected list item for a single-select list. + * + * @note It always returns NULL (nothing selected) for a multi-select list. + * + * @api + */ +const char* gwinListGetSelectedText(GHandle gh); + +#if GWIN_NEED_LIST_IMAGES || defined(__DOXYGEN__) + /** + * @brief Set the image for a list item + * + * @pre GWIN_NEED_LIST_IMAGES must be set to true in your gfxconf.h + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] item The item ID + * @param[in] pimg The image to be displayed or NULL to turn off the image for this list item. + * + * @note The image should be up to 4 x (the font height) and a width of (the font height). + * The 1st (top) part of the image is displayed for a selected item. + * The 2nd part of the image is displayed for an unselected item. + * The 3rd part of the image is displayed for a disabled selected item. + * The 4th part of the image is displayed for a disabled unselected item. + * If the image is less than 4 times the font height then the image use is collapsed + * into the available height. For example, an image that equals the font height will use + * the same image for all four states. + * @note The image is only displayed while it is open. It is up to the application to open + * the image. + * @note The same image can be used on more than one list item. + * @note Images are aligned with the top (not the baseline) of the list item. + * @note When any item in the list has an image attached, space is allocated to display + * the images even if the image is closed or has been removed by calling @p gwinListItemSetImage() + * with a NULL image or by calling @p gwinListItemDelete(). The only way to turn-off the image area + * for this list is to call gwinListDeleteAll(). + * + */ + void gwinListItemSetImage(GHandle gh, int item, gdispImage *pimg); +#endif + +#ifdef __cplusplus +} +#endif + +#endif // _GWIN_LIST_H +/** @} */ + diff --git a/src/gwin/progressbar.c b/src/gwin/progressbar.c index a2364d9f..37bad3c8 100644 --- a/src/gwin/progressbar.c +++ b/src/gwin/progressbar.c @@ -19,7 +19,7 @@ #if (GFX_USE_GWIN && GWIN_NEED_PROGRESSBAR) || defined(__DOXYGEN__) -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" // Reset the display position back to the value predicted by the saved progressbar position static void ResetDisplayPos(GProgressbarObject *gsw) { diff --git a/src/gwin/progressbar.h b/src/gwin/progressbar.h new file mode 100644 index 00000000..c9efe46b --- /dev/null +++ b/src/gwin/progressbar.h @@ -0,0 +1,190 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/progressbar.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup Progressbar Progressbar + * @ingroup GWIN + * + * @details Create progressbars with different styles + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_PROGRESSBAR must be set to TRUE in your gfxconf.h + * @{ + */ + +#ifndef _GWIN_PROGRESSBAR_H +#define _GWIN_PROGRESSBAR_H + +// A progressbar window +typedef struct GProgressbarObject { + GWidgetObject w; + coord_t dpos; + int min; + int max; + int res; + int pos; + #if GFX_USE_GTIMER + GTimer gt; + delaytime_t delay; + #endif +} GProgressbarObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a progressbar window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gb The GProgressbarObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note A progressbar remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note The initial progressbar range is from 0 to 100 with an initial position of 0. + * @note A progressbar does not take any GINPUT inputs. + * + * @api + */ +GHandle gwinGProgressbarCreate(GDisplay *g, GProgressbarObject *gb, const GWidgetInit *pInit); +#define gwinProgressbarCreate(w, pInit) gwinGProgressbarCreate(GDISP, w, pInit) + +/** + * @brief Set the progressbar range. + * + * @param[in] gh The window handle (must be a progressbar window) + * @param[in] min The minimum value + * @param[in] max The maximum value + * + * @note The defaults are 0 and 100 + * @note Sets the position to the minimum value. + * @note The progressbar is not automatically drawn. Call gwinProgressbarDraw() after changing the range. + * + * @api + */ +void gwinProgressbarSetRange(GHandle gh, int min, int max); + +/** + * @brief Set the progressbar position. + * + * @param[in] gh The window handle (must be a progressbar window) + * @param[in] pos The new position + * + * @note If the new position is outside the progressbar range then the position + * is set to the closest end of the range. + * @note The progressbar is not automatically drawn. Call gwinProgressbarDraw() after changing the position. + * + * @api + */ +void gwinProgressbarSetPosition(GHandle gh, int pos); + +/** + * @brief Set the resolution for the incrementation and decrementation of the progressbar + * + * @note Default is set to 1 + * + * @param[in] gh The window handle (must be a progressbar window) + * @param[in] res The resolution to be set + * + * @api + */ +void gwinProgressbarSetResolution(GHandle gh, int res); + +/** + * @brief Increment the progressbar value + * + * @details Increments by the resolution set through gwinProgressbarSetResolution() + * + * @param[in] gh The window handle (must be a progressbar window) + * + * @api + */ +void gwinProgressbarIncrement(GHandle gh); + +/** + * @brief Decrement the progressbar value + * + * @details Decrements by the resolution set through gwinProgressbarSetResolution() + * + * @param[in] gh The window handle (must be a progressbar window) + * + * @api + */ +void gwinProgressbarDecrement(GHandle gh); + +/** + * @brief Get the current progressbar position. + * @return The progressbar position + * + * @param[in] gh The window handle (must be a progressbar window) + * + * @note The use of a listener to get the progressbar position is recommended if you + * want continuous updates on the progressbar position. + * + * @api + */ +#define gwinProgressbarGetPosition(gh) (((GProgressbarObject *)(gh))->pos) + +/** + * @brief Automatically increments the progress bar + * + * @note The delay is generated using the GTIMER module which is based on software/virtual timer. + * Therefore, the delay is totally unprecise. + * + * @note The progressbar incrementation starts at the current level. It is not reset to the minimum value. + * + * @note An event is generated once the maximum value has been reached (ToDo) + * + * @param[in] gh The window handle (must be a progressbar window) + * @param[in] delay The incrementation delay (in milliseconds) + * + * @api + */ +void gwinProgressbarStart(GHandle gh, delaytime_t delay); + +/** + * @brief Some custom progressbar drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different progressbar drawing styles + * + * @param[in] gw The widget (which must be a progressbar) + * @param[in] param A parameter passed in from the user + * + * @note In your custom progressbar drawing function you may optionally call this + * standard functions and then draw your extra details on top. + * @note The standard functions below ignore the param parameter except for @p gwinProgressbarDraw_Image(). + * @note The image custom draw function @p gwinProgressbarDraw_Image() uses param to pass in the gdispImage pointer. + * The image must be already opened before calling @p gwinSetCustomDraw(). The image is tiled to fill + * the active area of the progressbar. The normal colors apply to the border and inactive area and the dividing line + * between the active and inactive areas. + * No checking is done to compare the dimensions of the progressbar to the size of the image. + * Note text is drawn on top of the image. + * @note These custom drawing routines don't have to worry about setting clipping as the framework + * sets clipping to the object window prior to calling these routines. + * + * @api + * @{ + */ +void gwinProgressbarDraw_Std(GWidgetObject *gw, void *param); +void gwinProgressbarDraw_Image(GWidgetObject *gw, void *param); +/* @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_PROGRESSBAR_H */ +/** @} */ + diff --git a/src/gwin/radio.c b/src/gwin/radio.c index 7507634c..f50ffe9b 100644 --- a/src/gwin/radio.c +++ b/src/gwin/radio.c @@ -19,7 +19,7 @@ #if GFX_USE_GWIN && GWIN_NEED_RADIO -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" // Our pressed state #define GRADIO_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) diff --git a/src/gwin/radio.h b/src/gwin/radio.h new file mode 100644 index 00000000..3ee2918f --- /dev/null +++ b/src/gwin/radio.h @@ -0,0 +1,142 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/radio.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup RadioButton RadioButton + * @ingroup GWIN + * + * @details GWIN allows it to easily create radio buttons with different styles. + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_RADIO must be set to TRUE in your gfxconf.h + * @{ + */ + +#ifndef _GWIN_RADIO_H +#define _GWIN_RADIO_H + +/* This file is included within "gwin/gwidget.h" */ + +/** + * @brief The Event Type for a Radio Event + */ +#define GEVENT_GWIN_RADIO (GEVENT_GWIN_FIRST+3) + +/** + * @brief A Button Event + * @note There are currently no GEventGWinRadio listening flags - use 0 as the flags to @p gwinAttachListener() + */ +typedef struct GEventGWinRadio { + GEventType type; // The type of this event (GEVENT_GWIN_RADIO) + GHandle radio; // The radio button that has been depressed + uint16_t group; // The group for this radio button +} GEventGWinRadio; + +/** + * @brief The radio button widget structure + * @note Do not use the members directly - treat it as a black-box. + */ +typedef struct GRadioObject { + GWidgetObject w; + #if GINPUT_NEED_TOGGLE + uint16_t toggle; + #endif + uint16_t group; +} GRadioObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a radio widget. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gb The GRadioObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialisation parameters + * @param[in] group The group of radio buttons this radio button belongs to. + * + * @note Only one radio button in any group is ever pressed at one time. Pressing one radio button will + * release all others in the group. + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note A radio button remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note A radio button supports mouse and a toggle input. + * @note When assigning a toggle, only one toggle is supported. If you try to assign more than one toggle it will + * forget the previous toggle. When assigning a toggle the role parameter must be 0. + * + * @api + */ +GHandle gwinGRadioCreate(GDisplay *g, GRadioObject *gb, const GWidgetInit *pInit, uint16_t group); +#define gwinRadioCreate(w, pInit, gr) gwinGRadioCreate(GDISP, w, pInit, gr) + +/** + * @brief Press this radio button (and by definition unset any others in the group) + * + * @param[in] gh The window handle (must be a radio widget) + * + * @api + */ +void gwinRadioPress(GHandle gh); + +/** + * @brief Is the radio button currently pressed + * @return TRUE if the button is pressed + * + * @param[in] gh The window handle (must be a radio widget) + * + * @api + */ +bool_t gwinRadioIsPressed(GHandle gh); + +/** + * @brief Find the currently pressed radio button in the specified group + * @return The handle of the pressed radio button or NULL if none are pressed + * + * @param[in] group The radio button group to be examined + * + * @return The handle of the currently pressed radio button + * + * @api + */ +GHandle gwinRadioGetActive(uint16_t group); + +/** + * @brief Some custom radio button drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different radio button drawing styles + * + * @param[in] gw The widget object (in this case a radio button) + * @param[in] param A parameter passed in from the user + * + * @note In your custom radio drawing function you may optionally call these + * standard functions and then draw your extra details on top. + * @note The standard functions below ignore the param parameter. + * @note These custom drawing routines don't have to worry about setting clipping as the framework + * sets clipping to the object window prior to calling these routines. + * + * @api + * @{ + */ +void gwinRadioDraw_Radio(GWidgetObject *gw, void *param); // @< A standard radio button +void gwinRadioDraw_Button(GWidgetObject *gw, void *param); // @< Draw as a button +void gwinRadioDraw_Tab(GWidgetObject *gw, void *param); // @< Draw as a tab +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_RADIO_H */ +/** @} */ + diff --git a/src/gwin/slider.c b/src/gwin/slider.c index 5d6a5ec0..4c91ede6 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -19,7 +19,7 @@ #if (GFX_USE_GWIN && GWIN_NEED_SLIDER) || defined(__DOXYGEN__) -#include "gwin/class_gwin.h" +#include "src/gwin/class_gwin.h" #ifndef GWIN_SLIDER_DEAD_BAND #define GWIN_SLIDER_DEAD_BAND 5 diff --git a/src/gwin/slider.h b/src/gwin/slider.h new file mode 100644 index 00000000..8f87745c --- /dev/null +++ b/src/gwin/slider.h @@ -0,0 +1,155 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/slider.h + * @brief GWIN Graphic window subsystem header file. + * + * @defgroup Slider Slider + * @ingroup GWIN + * + * @details Create sliders with different styles + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_SLIDER must be set to TRUE in your gfxconf.h + * @{ + */ + +#ifndef _GWIN_SLIDER_H +#define _GWIN_SLIDER_H + +/* This file is included within "gwin/gwidget.h" */ + +#define GEVENT_GWIN_SLIDER (GEVENT_GWIN_FIRST+1) + +typedef struct GEventGWinSlider { + GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) + GHandle slider; // The slider that is returning results + int position; +} GEventGWinSlider; + +// There are currently no GEventGWinSlider listening flags - use 0 + +// A slider window +typedef struct GSliderObject { + GWidgetObject w; + #if GINPUT_NEED_TOGGLE + uint16_t t_dn; + uint16_t t_up; + #endif + #if GINPUT_NEED_DIAL + uint16_t dial; + #endif + coord_t dpos; + int min; + int max; + int pos; +} GSliderObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a slider window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gb The GSliderObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note A slider remembers its normal drawing state. If there is a window manager then it is automatically + * redrawn if the window is moved or its visibility state is changed. + * @note The initial slider range is from 0 to 100 with an initial position of 0. + * @note A slider supports mouse, toggle and dial input. + * @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than + * one toggle to a role it will forget the previous toggle. Two roles are supported: + * Role 0 = toggle for down, Role 1 = toggle for up. + * @note When assigning a dial, only one dial is supported. If you try to assign more than one dial + * it will forget the previous dial. Only dial role 0 is supported. + * + * @api + */ +GHandle gwinGSliderCreate(GDisplay *g, GSliderObject *gb, const GWidgetInit *pInit); +#define gwinSliderCreate(w, pInit) gwinGSliderCreate(GDISP, w, pInit) + +/** + * @brief Set the slider range. + * + * @param[in] gh The window handle (must be a slider window) + * @param[in] min The minimum value + * @param[in] max The maximum value + * @note Sets the position to the minimum value. + * @note The slider is not automatically drawn. Call gwinSliderDraw() after changing the range. + * + * @api + */ +void gwinSliderSetRange(GHandle gh, int min, int max); + +/** + * @brief Set the slider position. + * + * @param[in] gh The window handle (must be a slider window) + * @param[in] pos The new position + * @note If the new position is outside the slider range then the position + * is set to the closest end of the range. + * @note The slider is not automatically drawn. Call gwinSliderDraw() after changing the position. + * + * @api + */ +void gwinSliderSetPosition(GHandle gh, int pos); + +/** + * @brief Get the current slider position. + * @return The slider position + * + * @param[in] gh The window handle (must be a slider window) + * + * @note The use of a listener to get the slider position is recommended if you + * want continuous updates on the slider position. + * + * @api + */ +#define gwinSliderGetPosition(gh) (((GSliderObject *)(gh))->pos) + +/** + * @brief Some custom slider drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different slider drawing styles + * + * @param[in] gw The widget (which must be a slider) + * @param[in] param A parameter passed in from the user + * + * @note In your custom slider drawing function you may optionally call this + * standard functions and then draw your extra details on top. + * @note The standard functions below ignore the param parameter except for @p gwinSliderDraw_Image(). + * @note The image custom draw function @p gwinSliderDraw_Image() uses param to pass in the gdispImage pointer. + * The image must be already opened before calling @p gwinSetCustomDraw(). The image is tiled to fill + * the active area of the slider. The normal colors apply to the border and inactive area and the dividing line + * between the active and inactive areas. + * No checking is done to compare the dimensions of the slider to the size of the image. + * Note text is drawn on top of the image. + * @note These custom drawing routines don't have to worry about setting clipping as the framework + * sets clipping to the object window prior to calling these routines. + * + * @api + * @{ + */ +void gwinSliderDraw_Std(GWidgetObject *gw, void *param); +void gwinSliderDraw_Image(GWidgetObject *gw, void *param); +/* @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_SLIDER_H */ +/** @} */ + diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h new file mode 100644 index 00000000..10b5b564 --- /dev/null +++ b/src/gwin/sys_defs.h @@ -0,0 +1,863 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/sys_defs.h + * + * @defgroup Window Window + * @ingroup GWIN + * + * @details GWIN provides a basic window manager which allows it to easily + * create and destroy different windows at runtime. Each window + * will have it's own properties such as colors as well as + * it's own drawing origin. + * + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @{ + */ + +#ifndef _GWIN_H +#define _GWIN_H + +#include "gfx.h" + +#if GFX_USE_GWIN || defined(__DOXYGEN__) + +/** + * @brief A window object structure + * @note Do not access the members directly. Treat it as a black-box and use the method functions. + * @{ + */ +typedef struct GWindowObject { + #if GWIN_NEED_WINDOWMANAGER + // This MUST be the first member of the struct + gfxQueueASyncItem wmq; // @< The next window (for the window manager) + #endif + const struct gwinVMT *vmt; // @< The VMT for this GWIN + GDisplay * display; // @< The display this window is on. + coord_t x, y; // @< Screen relative position + coord_t width, height; // @< Dimensions of this window + color_t color, bgcolor; // @< The current drawing colors + uint32_t flags; // @< Window flags (the meaning is private to the GWIN class) + #if GDISP_NEED_TEXT + font_t font; // @< The current font + #endif +} GWindowObject, * GHandle; +/* @} */ + +/** + * @brief The structure to initialise a GWIN. + * + * @note Some gwin's will need extra parameters. + * @note The dimensions and position may be changed to fit on the real screen. + * + * @{ + */ +typedef struct GWindowInit { + coord_t x, y; // @< The initial screen position + coord_t width, height; // @< The initial dimension + bool_t show; // @< Should the window be visible initially +} GWindowInit; +/* @} */ + +/** + * @brief A window's minimized, maximized or normal size + */ +typedef enum { GWIN_NORMAL, GWIN_MAXIMIZE, GWIN_MINIMIZE } GWindowMinMax; + +#ifdef __cplusplus +extern "C" { +#endif + +/*------------------------------------------------- + * Window Manager functions + *-------------------------------------------------*/ + +#if GWIN_NEED_WINDOWMANAGER || defined(__DOXYGEN__) + // Forward definition + struct GWindowManager; + + /** + * @brief Set the window manager for the GWIN system. + * + * @param[in] gwm The window manager to use. Can be NULL to turn off the existing window manager. + * + * @note A window manager is responsible for handling when window visibility is changed or + * a window is resized for moved. Note that only saved window states will be redrawn. Each + * window type can save different information (or none at all). See the documentation on each window + * type to see which information it saves (and can therefore be automatically redrawn). + * For window types that do not save any state information, the window manager determines what to do. + * Generally it will just clear the window to its background color. + * + * @api + */ + void gwinSetWindowManager(struct GWindowManager *gwm); +#endif + +/*------------------------------------------------- + * Functions that affect all windows + *-------------------------------------------------*/ + + /** + * @brief Set the default foreground color for all new GWIN windows + * + * @param[in] clr The color to be set + * + * @api + */ + void gwinSetDefaultColor(color_t clr); + + /** + * @brief Get the default foreground color for all new GWIN windows + * + * @return The current default color for all new GWIN windows + * + * @api + */ + color_t gwinGetDefaultColor(void); + + /** + * @brief Set the default background color for all new GWIN windows + * + * @param[in] bgclr The background color + * + * @api + */ + void gwinSetDefaultBgColor(color_t bgclr); + + /** + * @brief Get the default background color for all new GWIN windows + * + * @return The current default background color for all new GWIN windows + * + * @api + */ + color_t gwinGetDefaultBgColor(void); + + #if GDISP_NEED_TEXT || defined(__DOXYGEN__) + /** + * @brief Set the default font for all new GWIN windows + * + * @param[in] font The new font to be set + * + * @api + */ + void gwinSetDefaultFont(font_t font); + + /** + * @brief Get the current default font + * + * @return The current default font + * + * @api + */ + font_t gwinGetDefaultFont(void); + #endif + +/*------------------------------------------------- + * Base functions + *-------------------------------------------------*/ + + /** + * @brief Create a basic window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] pgw The window structure to initialize. If this is NULL the structure is dynamically allocated. + * @param[in] pInit How to initialise the window + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note A basic window does not save the drawing state. It is not automatically redrawn if the window is moved or + * its visibility state is changed. + * + * @api + */ + GHandle gwinGWindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit); + #define gwinWindowCreate(pgw, pInit) gwinGWindowCreate(GDISP, pgw, pInit); + + /** + * @brief Destroy a window (of any type). Releases any dynamically allocated memory. + * + * @param[in] gh The window handle + * + * @api + */ + void gwinDestroy(GHandle gh); + + /** + * @brief Get the real class name of the GHandle + * @details Returns a string describing the object class. + * + * @param[in] gh The window + * + * @return A string describing the object class. + * + * @api + */ + const char* gwinGetClassName(GHandle gh); + + /** + * @brief Get an ID that uniquely describes the class of the GHandle + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetClassID(gh) ((void *)((gh)->vmt)) + + /** + * @brief Get the X coordinate of the window + * @details Returns the X coordinate of the origin of the window. + * The coordinate is relative to the physical screen zero point. + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetScreenX(gh) ((gh)->x) + + /** + * @brief Get the Y coordinate of the window + * @details Returns the Y coordinate of the origin of the window. + * The coordinate is relative to the physical screen zero point. + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetScreenY(gh) ((gh)->y) + + /** + * @brief Get the width of the window + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetWidth(gh) ((gh)->width) + + /** + * @brief Get the height of the window + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetHeight(gh) ((gh)->height) + + /** + * @brief Set foreground color + * @details Set the color which will be used to draw + * + * @param[in] gh The window + * @param[in] clr The color to be set + * + * @api + */ + #define gwinSetColor(gh, clr) (gh)->color = (clr) + + /** + * @brief Set background color + * @details Set the color which will be used as background + * @note gwinClear() must be called to set the background color + * + * @param[in] gh The window + * @param[in] bgclr The background color + * + * @api + */ + #define gwinSetBgColor(gh, bgclr) (gh)->bgcolor = (bgclr) + + /** + * @brief Get the foreground color of a window + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetColor(gh) (gh)->color + + /** + * @brief Get the background color of a window + * + * @param[in] gh The window + * + * @api + */ + #define gwinGetBgColor(gh) (gh)->bgcolor + + /** + * @brief Sets whether a window is visible or not + * + * @param[in] gh The window + * @param[in] visible Whether the window should be visible or not + * + * @note When a window is marked as not visible, drawing operations + * on the window do nothing. + * @note When a window is marked as visible, it is not automatically + * redrawn as many window types don't remember their drawing state. + * Widgets such as Buttons, Sliders etc will be redrawn. + * @note If there is no window manager in use, when a window is marked + * as not visible, nothing is done to remove the window from the screen. + * When there is a window manager, it is up to the window manager to + * handle what happens. + * + * @api + */ + void gwinSetVisible(GHandle gh, bool_t visible); + + /** + * @brief Gets the visibility of a window + * @return TRUE if visible + * + * @param[in] gh The window + * + * @api + */ + bool_t gwinGetVisible(GHandle gh); + + /** + * @brief Enable or disable a window + * + * @param[in] gh The window handle + * @param[in] enabled Enable or disable the window + * + * @note The window is automatically redrawn if it + * supports self-redrawing. + * + * @api + */ + void gwinSetEnabled(GHandle gh, bool_t enabled); + + /** + * @brief Gets the enabled state of a window + * @return TRUE if enabled + * + * @param[in] gh The window + * + * @api + */ + bool_t gwinGetEnabled(GHandle gh); + + /** + * @brief Move a window + * + * @param[in] gh The window + * @param[in] x, y The new position (screen relative) for this window + * + * @note The final window position may not be the requested position. Windows + * are clipped to the screen area and the window manager may also affect the position. + * @note The window is redrawn if it is visible. See the comments in @p gwinSetVisible() + * with regard to what can be redrawn and what can't. + * @note It is up to the window manager to determine what happens with the screen area + * uncovered by moving the window. When there is no window manager, nothing + * is done with the uncovered area. + * + * @api + */ + void gwinMove(GHandle gh, coord_t x, coord_t y); + + /** + * @brief Resize a window + * + * @param[in] gh The window + * @param[in] width, height The new size of the window + * + * @note The final window size may not be the requested size. Windows + * are clipped to the screen area and the window manager may also affect the size. + * @note The window is redrawn if it is visible. See the comments in @p gwinSetVisible() + * with regard to what can be redrawn and what can't. + * @note It is up to the window manager to determine what happens with any screen area + * uncovered by resizing the window. When there is no window manager, nothing + * is done with the uncovered area. + * + * @api + */ + void gwinResize(GHandle gh, coord_t width, coord_t height); + + /** + * @brief Redraw a window + * + * @param[in] gh The window + * + * @note This is normally never required as windows and widgets will redraw as required. + * Note that some windows are incapable of redrawing themselves as they don't save + * their drawing state. + * + * @api + */ + void gwinRedraw(GHandle gh); + + #if GWIN_NEED_WINDOWMANAGER || defined (__DOXYGEN__) + /** + * @brief Redraw a window + * + * @param[in] g The display to redraw. Passing NULL will redraw all displays. + * @param[in] preserve Should the redraw try to preserve existing screen data for those + * windows that can't redraw themselves? + * + * @note This is normally never required as windows and widgets will redraw as required. + * @note Some windows are incapable of redrawing themselves as they don't save + * their drawing state. + * @note This does not clear the background - just redraws the gwin windows (where possible) + * + * @api + */ + void gwinRedrawDisplay(GDisplay *g, bool_t preserve); + + /** + * @brief Minimize, Maximize or Restore a window + * @pre GWIN_NEED_WINDOWMANAGER must be TRUE + * + * @param[in] gh The window + * @param[in] minmax The new minimized/maximized state + * + * @note The final window state may not be the requested state. Window Managers + * do not need to implement changing the minmax state. If there is no + * window manager this call is ignored. + * @note The window is redrawn if it is changed. See the comments in @p gwinSetVisible() + * with regard to what can be redrawn and what can't. + * @note It is up to the window manager to determine what happens with any screen area + * uncovered by resizing the window. + * @note When a window is minimised it may be asked to draw the window or the window + * manager may draw the minimised window. + * + * @api + */ + void gwinSetMinMax(GHandle gh, GWindowMinMax minmax); + + /** + * @brief Get the Minimized/Maximized state of a window + * @pre GWIN_NEED_WINDOWMANAGER must be TRUE + * + * @param[in] gh The window + * + * @api + */ + GWindowMinMax gwinGetMinMax(GHandle gh); + + /** + * @brief Raise a window to the top of the z-order + * @pre GWIN_NEED_WINDOWMANAGER must be TRUE + * + * @param[in] gh The window + * + * @note The window z-order is only supported by some window managers. See the comments + * in @p gwinSetVisible() with regard to what can be redrawn and what can't. + * + * @api + */ + void gwinRaise(GHandle gh); + #endif + + #if GDISP_NEED_TEXT || defined(__DOXYGEN__) + /** + * @brief Set the current font for this window. + * + * @param[in] gh The window handle + * @param[in] font The font to use for text functions + * + * @api + */ + void gwinSetFont(GHandle gh, font_t font); + #endif + +/*------------------------------------------------- + * Drawing functions + *-------------------------------------------------*/ + + /** + * @brief Clear the window + * @note Uses the current background color to clear the window + * + * @param[in] gh The window handle + * + * @api + */ + void gwinClear(GHandle gh); + + /** + * @brief Set a pixel in the window + * @note Uses the current foreground color to set the pixel + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The coordinates of the pixel + * + * @api + */ + void gwinDrawPixel(GHandle gh, coord_t x, coord_t y); + + /** + * @brief Draw a line in the window + * @note Uses the current foreground color to draw the line + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x0,y0 The start position + * @param[in] x1,y1 The end position + * + * @api + */ + void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1); + + /** + * @brief Draw a box in the window + * @note Uses the current foreground color to draw the box + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The start position + * @param[in] cx,cy The size of the box (outside dimensions) + * + * @api + */ + void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy); + + /** + * @brief Fill an rectangular area in the window + * @note Uses the current foreground color to fill the box + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The start position + * @param[in] cx,cy The size of the box (outside dimensions) + * + * @api + */ + void gwinFillArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy); + + /** + * @brief Fill an area in the window using the supplied bitmap. + * @details The bitmap is in the pixel format specified by the low level driver + * @note If GDISP_NEED_ASYNC is defined then the buffer must be static + * or at least retained until this call has finished the blit. You can + * tell when all graphics drawing is finished by @p gdispIsBusy() going FALSE. + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x, y The start filled area + * @param[in] cx, cy The width and height to be filled + * @param[in] srcx, srcy The bitmap position to start the fill from + * @param[in] srccx The width of a line in the bitmap. + * @param[in] buffer The pixels to use to fill the area. + * + * @api + */ + void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer); + +/*------------------------------------------------- + * Circle, ellipse and arc functions + *-------------------------------------------------*/ + + #if GDISP_NEED_CIRCLE || defined(__DOXYGEN__) + /** + * @brief Draw a circle in the window. + * @note Uses the current foreground color to draw the circle + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x, y The center of the circle + * @param[in] radius The radius of the circle + * + * @api + */ + void gwinDrawCircle(GHandle gh, coord_t x, coord_t y, coord_t radius); + + /** + * @brief Draw a filled circle in the window. + * @note Uses the current foreground color to draw the filled circle + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x, y The center of the circle + * @param[in] radius The radius of the circle + * + * @api + */ + void gwinFillCircle(GHandle gh, coord_t x, coord_t y, coord_t radius); + #endif + + #if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__) + /** + * @brief Draw an ellipse. + * @note Uses the current foreground color to draw the ellipse + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The center of the ellipse + * @param[in] a,b The dimensions of the ellipse + * + * @api + */ + void gwinDrawEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b); + + /** + * @brief Draw an filled ellipse. + * @note Uses the current foreground color to draw the filled ellipse + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The center of the ellipse + * @param[in] a,b The dimensions of the ellipse + * + * @api + */ + void gwinFillEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b); + #endif + + #if GDISP_NEED_ARC || defined(__DOXYGEN__) + /* + * @brief Draw an arc in the window. + * @note Uses the current foreground color to draw the arc + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The center point + * @param[in] radius The radius of the arc + * @param[in] start The start angle (0 to 360) + * @param[in] end The end angle (0 to 360) + * + * @api + */ + void gwinDrawArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle); + + /* + * @brief Draw a filled arc in the window. + * @note Uses the current foreground color to draw the filled arc + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The center point + * @param[in] radius The radius of the arc + * @param[in] start The start angle (0 to 360) + * @param[in] end The end angle (0 to 360) + * + * @api + */ + void gwinFillArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle); + #endif + +/*------------------------------------------------- + * Pixel read-back functions + *-------------------------------------------------*/ + + #if GDISP_NEED_PIXELREAD || defined(__DOXYGEN__) + /** + * @brief Get the color of a pixel in the window. + * @return The color of the pixel. + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position in the window + * + * @api + */ + color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y); + #endif + +/*------------------------------------------------- + * Text functions + *-------------------------------------------------*/ + + #if GDISP_NEED_TEXT || defined(__DOXYGEN__) + /** + * @brief Draw a text character at the specified position in the window. + * @pre The font must have been set. + * @note Uses the current foreground color to draw the character + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position for the text + * @param[in] c The character to draw + * + * @api + */ + void gwinDrawChar(GHandle gh, coord_t x, coord_t y, char c); + + /** + * @brief Draw a text character with a filled background at the specified position in the window. + * @pre The font must have been set. + * @note Uses the current foreground color to draw the character and fills the background using the background drawing color + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position for the text + * @param[in] c The character to draw + * + * @api + */ + void gwinFillChar(GHandle gh, coord_t x, coord_t y, char c); + + /** + * @brief Draw a text string in the window + * @pre The font must have been set. + * @note Uses the current foreground color to draw the character + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position for the text + * @param[in] str The string to draw + * + * @api + */ + void gwinDrawString(GHandle gh, coord_t x, coord_t y, const char *str); + + /** + * @brief Draw a text string with a filled background in the window + * @pre The font must have been set. + * @note Uses the current foreground color to draw the character and fills the background using the background drawing color + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position for the text + * @param[in] str The string to draw + * + * @api + */ + void gwinFillString(GHandle gh, coord_t x, coord_t y, const char *str); + + /** + * @brief Draw a text string verticly centered within the specified box. + * @pre The font must have been set. + * @note Uses the current foreground color to draw the character. + * @note The specified box does not need to align with the window box + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position for the text (need to define top-right or base-line - check code) + * @param[in] cx,cy The width and height of the box + * @param[in] str The string to draw + * @param[in] justify Justify the text left, center or right within the box + * + * @api + */ + void gwinDrawStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify); + + /** + * @brief Draw a text string verticly centered within the specified filled box. + * @pre The font must have been set. + * @note Uses the current foreground color to draw the character and fills the background using the background drawing color + * @note The entire box is filled. Note this box does not need to align with the window box + * @note May leave GDISP clipping to this window's dimensions + * + * @param[in] gh The window handle + * @param[in] x,y The position for the text (need to define top-right or base-line - check code) + * @param[in] cx,cy The width and height of the box + * @param[in] str The string to draw + * @param[in] justify Justify the text left, center or right within the box + * + * @api + */ + void gwinFillStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify); + #endif + +/*------------------------------------------------- + * Polygon functions + *-------------------------------------------------*/ + + #if GDISP_NEED_CONVEX_POLYGON || defined(__DOXYGEN__) + /** + * @brief Draw an enclosed polygon (convex, non-convex or complex). + * + * @note Uses the current foreground color. + * + * @param[in] gh The window handle + * @param[in] tx, ty Transform all points in pntarray by tx, ty + * @param[in] pntarray An array of points + * @param[in] cnt The number of points in the array + * + * @api + */ + void gwinDrawPoly(GHandle gh, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt); + + /** + * @brief Fill a convex polygon + * @details Doesn't handle non-convex or complex polygons. + * + * @note Uses the current foreground color. + * + * @param[in] gh The window handle + * @param[in] tx, ty Transform all points in pntarray by tx, ty + * @param[in] pntarray An array of points + * @param[in] cnt The number of points in the array + * + * @note Convex polygons are those that have no internal angles. That is; + * you can draw a line from any point on the polygon to any other point + * on the polygon without it going outside the polygon. In our case we generalise + * this a little by saying that an infinite horizontal line (at any y value) will cross + * no more than two edges on the polygon. Some non-convex polygons do fit this criteria + * and can therefore be drawn. + * @note This routine is designed to be very efficient with even simple display hardware. + * + * @api + */ + void gwinFillConvexPoly(GHandle gh, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt); + #endif + +/*------------------------------------------------- + * Image functions + *-------------------------------------------------*/ + + #if GDISP_NEED_IMAGE || defined(__DOXYGEN__) + /** + * @brief Draw the image + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @param[in] gh The window handle + * @param[in] img The image structure + * @param[in] x,y The window location to draw the image + * @param[in] cx,cy The area on the screen to draw + * @param[in] sx,sy The image position to start drawing at + * + * @pre gdispImageOpen() must have returned successfully. + * + * @note If sx,sy + cx,cy is outside the image boundaries the area outside the image + * is simply not drawn. + * @note If @p gdispImageCache() has been called first for this frame, this routine will draw using a + * fast blit from the cached frame. If not, it reads the input and decodes it as it + * is drawing. This may be significantly slower than if the image has been cached (but + * uses a lot less RAM) + * + * @api + */ + gdispImageError gwinDrawImage(GHandle gh, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); + #endif + +#ifdef __cplusplus +} +#endif + +/*------------------------------------------------- + * Additional functionality + *-------------------------------------------------*/ + + /* Include widgets */ + #if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + #include "src/gwin/gwidget.h" + #endif + + /* Include extra window types */ + #if GWIN_NEED_CONSOLE || defined(__DOXYGEN__) + #include "src/gwin/console.h" + #endif + + #if GWIN_NEED_GRAPH || defined(__DOXYGEN__) + #include "src/gwin/graph.h" + #endif + + #if GWIN_NEED_IMAGE || defined(__DOXYGEN__) + #include "src/gwin/image.h" + #endif + +#endif /* GFX_USE_GWIN */ + +#endif /* _GWIN_H */ +/** @} */ diff --git a/src/gwin/sys_make.mk b/src/gwin/sys_make.mk new file mode 100644 index 00000000..4c670ea2 --- /dev/null +++ b/src/gwin/sys_make.mk @@ -0,0 +1,14 @@ +GFXSRC += $(GFXLIB)/src/gwin/gwin.c \ + $(GFXLIB)/src/gwin/gwidget.c \ + $(GFXLIB)/src/gwin/gwm.c \ + $(GFXLIB)/src/gwin/console.c \ + $(GFXLIB)/src/gwin/graph.c \ + $(GFXLIB)/src/gwin/button.c \ + $(GFXLIB)/src/gwin/slider.c \ + $(GFXLIB)/src/gwin/checkbox.c \ + $(GFXLIB)/src/gwin/gimage.c \ + $(GFXLIB)/src/gwin/label.c \ + $(GFXLIB)/src/gwin/radio.c \ + $(GFXLIB)/src/gwin/list.c \ + $(GFXLIB)/src/gwin/progressbar.c \ + diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h new file mode 100644 index 00000000..02467916 --- /dev/null +++ b/src/gwin/sys_options.h @@ -0,0 +1,185 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file include/gwin/sys_options.h + * @brief GWIN sub-system options header file. + * + * @addtogroup GWIN + * @brief Module which provides a complete GUI toolkit based on widgets + * + * @{ + */ + +#ifndef _GWIN_OPTIONS_H +#define _GWIN_OPTIONS_H + +/** + * @name GWIN Functionality to be included + * @{ + */ + /** + * @brief Should window manager support be included + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_WINDOWMANAGER + #define GWIN_NEED_WIDGET FALSE + #endif + /** + * @brief Should widget functions be included. Needed for any widget (eg Buttons, Sliders etc) + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_WIDGET + #define GWIN_NEED_WIDGET FALSE + #endif + /** + * @brief Should console functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_CONSOLE + #define GWIN_NEED_CONSOLE FALSE + #endif + /** + * @brief Should graph functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_GRAPH + #define GWIN_NEED_GRAPH FALSE + #endif + /** + * @brief Should button functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_BUTTON + #define GWIN_NEED_BUTTON FALSE + #endif + /** + * @brief Should slider functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_SLIDER + #define GWIN_NEED_SLIDER FALSE + #endif + /** + * @brief Should checkbox functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_CHECKBOX + #define GWIN_NEED_CHECKBOX FALSE + #endif + /** + * @brief Should image functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_IMAGE + #define GWIN_NEED_IMAGE FALSE + #endif + /** + * @brief Should label functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_LABEL + #define GWIN_NEED_LABEL FALSE + #endif + /** + * @brief Should radio button functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_RADIO + #define GWIN_NEED_RADIO FALSE + #endif +/** + * @} + * + * @name GWIN Optional Parameters + * @{ + */ + /** + * @brief Buttons should not insist the mouse is over the button on mouse release + * @details Defaults to FALSE + */ + #ifndef GWIN_BUTTON_LAZY_RELEASE + #define GWIN_BUTTON_LAZY_RELEASE FALSE + #endif + /** + * @brief Should the content of the console be saved for redrawing. + * @details Defaults to FALSE + * @details If this feature is enabled, the contents of the console will be saved + * as it is written. If a redraw is required it will be redrawn from the + * history. Scrolling will also use the history buffer if it is turned on. + * @note Using this option allocates the amount of memory to store the + * history based on the minimum character width in the current font + * at the time the history is turned on. Using a fixed width font is a good + * idea to minimize memory usage. + * @note If you change the size of the window or you change the font being displayed + * you should turn off the history and then turn it back on in order to get + * a new buffer of the correct size for the window/font combination. Strange + * redrawing and scrolling effects can occur if the buffer is too small to + * save a complete screen of data. Note the system tries to optimize storage + * so this may only be evident in very limited situations eg with a console + * with many characters in it. + * @note @p gwinConsoleSetBuffer() can be used to turn the history buffer off and on. + */ + #ifndef GWIN_CONSOLE_USE_HISTORY + #define GWIN_CONSOLE_USE_HISTORY FALSE + #endif + /** + * @brief Use font width averaging for the history buffer allocation. + * @details Defaults to FALSE + * @details If this feature is enabled, the width one third of the way between + * the font's character width minimum and maximum will be used instead + * of the font's minimum width. + * @note This option reduces the memory allocation for a variable width font's + * history buffer. Note that strange + * redrawing and scrolling effects can occur if the buffer is too small to + * save a complete screen of data. The system tries to optimize storage + * so this may only be evident in very limited situations eg with a console + * with many characters in it. + */ + #ifndef GWIN_CONSOLE_HISTORY_AVERAGING + #define GWIN_CONSOLE_HISTORY_AVERAGING FALSE + #endif + /** + * @brief Should the history be turned on for all console windows when they are first created. + * @details Defaults to FALSE + * @note @p gwinConsoleSetBuffer() can be used to turn the history buffer off and on at + * any time. + */ + #ifndef GWIN_CONSOLE_HISTORY_ATCREATE + #define GWIN_CONSOLE_HISTORY_ATCREATE FALSE + #endif + /** + * @brief Console Windows need floating point support in @p gwinPrintf + * @details Defaults to FALSE + */ + #ifndef GWIN_CONSOLE_USE_FLOAT + #define GWIN_CONSOLE_USE_FLOAT FALSE + #endif + /** + * @brief Console Windows need BaseStreamSequential support (ChibiOS only) + * @details Defaults to FALSE + * @note To use the ChibiOS basestream functions such as chprintf() + * for printing in a console window you need to set this option to + * TRUE in your gfxconf.h and include in your application source file... + * \#include "chprintf.h" + * In your makefile, as part of your list of C source files, include + * ${CHIBIOS}/os/various/chprintf.c + */ + #ifndef GWIN_CONSOLE_USE_BASESTREAM + #define GWIN_CONSOLE_USE_BASESTREAM FALSE + #endif + /** + * @brief Image windows can optionally support animated images + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_IMAGE_ANIMATION + #define GWIN_NEED_IMAGE_ANIMATION FALSE + #endif +/** @} */ + +#endif /* _GWIN_OPTIONS_H */ +/** @} */ diff --git a/src/gwin/sys_rules.h b/src/gwin/sys_rules.h new file mode 100644 index 00000000..77f029f0 --- /dev/null +++ b/src/gwin/sys_rules.h @@ -0,0 +1,99 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/sys_rules.h + * @brief GWIN safety rules header file. + * + * @addtogroup GWIN + * @{ + */ + +#ifndef _GWIN_RULES_H +#define _GWIN_RULES_H + +#if GFX_USE_GWIN + #if !GFX_USE_GDISP + #error "GWIN: GFX_USE_GDISP must be TRUE when using GWIN" + #endif + #if !GDISP_NEED_CLIP + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE" + #endif + #endif + #if GWIN_NEED_IMAGE + #if !GDISP_NEED_IMAGE + #error "GWIN: GDISP_NEED_IMAGE is required when GWIN_NEED_IMAGE is TRUE." + #endif + #endif + #if GWIN_NEED_RADIO + #if !GDISP_NEED_CIRCLE + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GDISP_NEED_CIRCLE should be set to TRUE for much nicer radio button widgets." + #endif + #endif + #endif + #if GWIN_NEED_BUTTON || GWIN_NEED_SLIDER || GWIN_NEED_CHECKBOX || GWIN_NEED_LABEL || GWIN_NEED_RADIO || GWIN_NEED_LIST || \ + GWIN_NEED_IMAGE || GWIN_NEED_CHECKBOX || GWIN_NEED_PROGRESSBAR + #if !GWIN_NEED_WIDGET + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GWIN_NEED_WIDGET is required when a Widget is used. It has been turned on for you." + #endif + #undef GWIN_NEED_WIDGET + #define GWIN_NEED_WIDGET TRUE + #endif + #endif + #if GWIN_NEED_LIST + #if !GDISP_NEED_TEXT + #error "GWIN: GDISP_NEED_TEXT is required when GWIN_NEED_LIST is TRUE." + #endif + #endif + #if GWIN_NEED_WIDGET + #if !GDISP_NEED_TEXT + #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_WIDGET is TRUE." + #endif + #if !GFX_USE_GINPUT + // This test also ensures that GFX_USE_GEVENT is set + #error "GWIN: GFX_USE_GINPUT (and one or more input sources) is required if GWIN_NEED_WIDGET is TRUE" + #endif + #if !GWIN_NEED_WINDOWMANAGER + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GWIN_NEED_WINDOWMANAGER is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you." + #endif + #undef GWIN_NEED_WINDOWMANAGER + #define GWIN_NEED_WINDOWMANAGER TRUE + #endif + #if !GDISP_NEED_MULTITHREAD + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GDISP_NEED_MULTITHREAD is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you" + #endif + #undef GDISP_NEED_MULTITHREAD + #define GDISP_NEED_MULTITHREAD TRUE + #endif + #endif + #if GWIN_NEED_WINDOWMANAGER + #if !GFX_USE_GQUEUE || !GQUEUE_NEED_ASYNC + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GFX_USE_GQUEUE and GQUEUE_NEED_ASYNC is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." + #endif + #undef GFX_USE_GQUEUE + #undef GQUEUE_NEED_ASYNC + #define GFX_USE_GQUEUE TRUE + #define GQUEUE_NEED_ASYNC TRUE + #endif + #endif + #if GWIN_NEED_CONSOLE + #if !GDISP_NEED_TEXT + #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_CONSOLE is TRUE." + #endif + #endif + #if GWIN_NEED_GRAPH + #endif +#endif + +#endif /* _GWIN_RULES_H */ +/** @} */ -- cgit v1.2.3