From 7baf5c5d448b626d6a062882434b25ca82212d94 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 6 Jun 2013 14:33:32 +1000 Subject: New simplified gwin using a pseudo class structure. --- include/gwin/button.h | 240 +++++++++++++--------------------------------- include/gwin/checkbox.h | 125 ++++++++---------------- include/gwin/class_gwin.h | 123 ++++++++++++++++++++++++ include/gwin/console.h | 33 ++----- include/gwin/graph.h | 23 +---- include/gwin/gwidget.h | 234 ++++++++++++++++++++++++++++++++++++++++++++ include/gwin/gwin.h | 117 ++++++++++------------ include/gwin/internal.h | 41 -------- include/gwin/slider.h | 150 ++++++----------------------- 9 files changed, 552 insertions(+), 534 deletions(-) create mode 100644 include/gwin/class_gwin.h create mode 100644 include/gwin/gwidget.h delete mode 100644 include/gwin/internal.h (limited to 'include/gwin') diff --git a/include/gwin/button.h b/include/gwin/button.h index ed74a80d..1b0ff36b 100644 --- a/include/gwin/button.h +++ b/include/gwin/button.h @@ -24,240 +24,132 @@ #ifndef _GWIN_BUTTON_H #define _GWIN_BUTTON_H -#if GWIN_NEED_BUTTON || defined(__DOXYGEN__) +/* This file is included within "gwin/gwidget.h" */ -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -#define GW_BUTTON 0x0002 +/** + * @brief The Event Type for a Button Event + */ #define GEVENT_GWIN_BUTTON (GEVENT_GWIN_FIRST+0) -/*===========================================================================*/ -/* Type definitions */ -/*===========================================================================*/ - -typedef struct GEventGWinButton_t { +/** + * @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; -// There are currently no GEventGWinButton listening flags - use 0 - -typedef enum GButtonShape_e { - GBTN_3D, GBTN_SQUARE, GBTN_ROUNDED, GBTN_ELLIPSE, GBTN_CUSTOM, - GBTN_ARROW_UP, GBTN_ARROW_DOWN, GBTN_ARROW_LEFT, GBTN_ARROW_RIGHT, -} GButtonShape; - -typedef struct GButtonDrawStyle_t { +/** + * @brief Button colors + */ +typedef struct GButtonColors { color_t color_edge; color_t color_fill; color_t color_txt; -} GButtonDrawStyle; - -typedef enum GButtonType_e { - GBTN_NORMAL, GBTN_TOGGLE -} GButtonType; - -typedef enum GButtonState_e { - GBTN_UP, GBTN_DOWN -} GButtonState; +} GButtonColors; -typedef void (*GButtonDrawFunction)(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); - -// A button window +/** + * @brief The button widget structure + * @note Do not use the members directly - treat it as a black-box. + */ typedef struct GButtonObject_t { - GWindowObject gwin; - - GButtonDrawStyle up; - GButtonDrawStyle dn; - GButtonState state; - GButtonType type; - const char *txt; - GButtonDrawFunction fn; - void *param; - GListener listener; + GWidgetObject w; + GButtonColors c_up; + GButtonColors c_dn; + GButtonColors c_dis; } GButtonObject; -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - #ifdef __cplusplus extern "C" { #endif /** - * @brief Create a button window. + * @brief Create a button widget. * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gb The GButtonObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the bottom left corner of the window + * @param[in] x,y The screen co-ordinates for the top left corner of the window * @param[in] width The width of the window * @param[in] height The height of the window - * @param[in] font The font to use - * @param[in] type The type of button + * * @note The drawing color gets set to White and the background drawing color to Black. + * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() * @note The dimensions and position may be changed to fit on the real screen. - * @note The button is not automatically drawn. Call gwinButtonDraw() after changing the button style or setting the text. + * @note The button is not automatically drawn. Call gwinDraw() to draw it. * * @api */ -GHandle gwinCreateButton(GButtonObject *gb, coord_t x, coord_t y, coord_t width, coord_t height, font_t font, GButtonType type); +GHandle gwinCreateButton(GButtonObject *gb, coord_t x, coord_t y, coord_t width, coord_t height); /** - * @brief Set the style of a button. - * @details The button style is defined by its shape and colours. + * @brief Set the colors of a button. * - * @param[in] gh The window handle (must be a button window) - * @param[in] shape The shape of the button. - * @param[in] pUp The styling for the button when in the up state. - * @param[in] pDown The styling for the button when in the down state. + * @param[in] gh The window handle (must be a button widget) + * @param[in] pUp The colors for the button when in the up state. + * @param[in] pDown The colors for the button when in the down state. + * @param[in] pDisabled The colors for the button when it is disabled. * * @note The button is not automatically redrawn. Call gwinButtonDraw() after changing the button style * @note The button style is copied into the internal button structure - there is no need to - * maintain a static style structures. - * @note The pUp and pDown parameters can be NULL. If they are then the existing color styles + * maintain static style structures (they can be temporary structures on the stack). + * @note The pUp, pDown and pDisabled parameters can be NULL. If they are then the existing color styles * are not changed for that button state. + * @note Some custom drawn buttons will ignore he specified colors * * @api */ -void gwinSetButtonStyle(GHandle gh, GButtonShape shape, const GButtonDrawStyle *pUp, const GButtonDrawStyle *pDown); - -/** - * @brief Set the text of a button. - * - * @param[in] gh The window handle (must be a button window) - * @param[in] txt The button 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 button is not automatically redrawn. Call gwinButtonDraw() after changing the button text. - * - * @api - */ -void gwinSetButtonText(GHandle gh, const char *txt, bool_t useAlloc); - -/** - * @brief Redraw the button. - * - * @param[in] gh The window handle (must be a button window) - * - * @api - */ -void gwinButtonDraw(GHandle gh); - -/** - * @brief Enable or disable a button - * - * @param[in] gh The window handle (must be a button window) - * @param[in] enabled Enable or disable the button - * - * @api - */ -void gwinButtonSetEnabled(GHandle gh, bool_t enabled); - -/** - * @brief Set the callback routine to perform a custom button drawing. - * - * @param[in] gh The window handle (must be a button window) - * @param[in] fn The function to use to draw the button - * @param[in] param A parameter to pass to the button drawing function - * - * @api - */ -void gwinSetButtonCustom(GHandle gh, GButtonDrawFunction fn, void *param); - -/** - * @brief Enable a button - * - * @api - */ -#define gwinEnableButton(gh) gwinButtonSetEnabled( ((GButtonObject *)(gh)), TRUE) - -/** - * @brief Disable a button - * - * @api - */ -#define gwinDisableButton(gh) gwinButtonSetEnabled( ((GButtonObject *)(gh)), FALSE) - -/** - * @brief Get the state of a button - * - * @param[in] gh The window handle (must be a button window) - * - * @api - */ -#define gwinGetButtonState(gh) (((GButtonObject *)(gh))->state) +void gwinSetButtonColors(GHandle gh, const GButtonColors *pUp, const GButtonColors *pDown, const GButtonColors *pDisabled); /** - * @brief Get the source handle of a button - * @details Get the source handle of a button so the application can listen for events + * @brief Is the button current pressed + * @return TRUE if the button is depressed * - * @param[in] gh The window handle + * @param[in] gh The window handle (must be a button widget) * * @api */ -#define gwinGetButtonSource(gh) ((GSourceHandle)(gh)) - -#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE - /** - * @brief Attach a mouse to a button - * - * @param[in] gh The button handle - * @param[in] instance The mouse instance - * - * @api - */ - bool_t gwinAttachButtonMouse(GHandle gh, uint16_t instance); -#endif - -#if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE - /** - * @brief Attach a toggle to a button - * - * @param[in] gh The button handle - * @param[in] instance The toggle instance - * - * @api - */ - bool_t gwinAttachButtonToggle(GHandle gh, uint16_t instance); -#endif +bool_t gwinIsButtonPressed(GHandle gh); /** - * @brief Standard button drawing routines - * @details These routines are called to draw the standard button styles. + * @brief Some custom button drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different button drawing styles * - * @param[in] gh The button handle - * @param[in] enabled Is the button currently enabled or disabled - * @param[in] isdown Is the button currently down (depressed) - * @param[in] txt The text to be display inside the button - * @param[in] pstyle The current drawing style for the state we are in + * @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. It is there - * only to ensure the functions match the GButtonDrawFunction type. - * @note When called by a button press/release the framework ensure that it is - * a button object and sets up clipping to the button object window. These - * drawing routines then don't have to worry about explicitly doing that. + * @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(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); -void gwinButtonDraw_Square(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); +void gwinButtonDraw_3D(GWidgetObject *gw, void *param); // @< A standard 3D button +void gwinButtonDraw_Box(GWidgetObject *gw, void *param); // @< A very simple box style button #if GDISP_NEED_ARC || defined(__DOXYGEN__) - void gwinButtonDraw_Rounded(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); + void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param); // @< A rounded rectangle button #endif #if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__) - void gwinButtonDraw_Ellipse(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); + void gwinButtonDraw_Ellipse(GWidgetObject *gw, void *param); // @< A circular button #endif #if GDISP_NEED_CONVEX_POLYGON || defined(__DOXYGEN__) - void gwinButtonDraw_ArrowUp(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); - void gwinButtonDraw_ArrowDown(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); - void gwinButtonDraw_ArrowLeft(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); - void gwinButtonDraw_ArrowRight(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param); + 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 /** @} */ @@ -265,8 +157,6 @@ void gwinButtonDraw_Square(GHandle gh, bool_t enabled, bool_t isdown, const char } #endif -#endif /* GWIN_NEED_BUTTON */ - #endif /* _GWIN_BUTTON_H */ /** @} */ diff --git a/include/gwin/checkbox.h b/include/gwin/checkbox.h index 1bbdc89b..de49fa01 100644 --- a/include/gwin/checkbox.h +++ b/include/gwin/checkbox.h @@ -12,7 +12,7 @@ * @defgroup Checkbox Checkbox * @ingroup GWIN * - * @details GWIN allows it to easily create checkboxes. + * @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 @@ -22,13 +22,12 @@ #ifndef _GWIN_CHECKBOX_H #define _GWIN_CHECKBOX_H -#if GWIN_NEED_CHECKBOX || defined(__DOXYGEN__) +/* This file is included within "gwin/gwidget.h" */ /*===========================================================================*/ /* Driver constants. */ /*===========================================================================*/ -#define GW_CHECKBOX 0x0005 #define GEVENT_GWIN_CHECKBOX (GEVENT_GWIN_FIRST+2) /*===========================================================================*/ @@ -41,124 +40,76 @@ typedef struct GEventGWinCheckbox_t { bool_t isChecked; // Is the checkbox currently checked or unchecked? } GEventGWinCheckbox; -typedef enum GCheckboxState_e { - GCHBX_UNCHECKED, GCHBX_CHECKED -} GCheckboxState; - -typedef struct GCheckboxColor_t { - color_t border; - color_t checked; - color_t bg; -} GCheckboxColor; - -/* custom rendering interface */ -typedef void (*GCheckboxDrawFunction)(GHandle gh, bool_t enabled, bool_t state, void* param); +typedef struct GCheckboxColors { + color_t color_border; + color_t color_checked; + color_t color_bg; + color_t color_txt; +} GCheckboxColors; /* A Checkbox window */ typedef struct GCheckboxObject_t { - GWindowObject gwin; - GListener listener; - - GCheckboxDrawFunction fn; - GCheckboxColor *colors; - bool_t isChecked; - void *param; + GWidgetObject w; + GCheckboxColors c; } GCheckboxObject; /** - * @brief Create a checkbox window. + * @brief Create a checkbox window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gb The GCheckboxObject structure to initialise. If this is NULL, the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the bottom left corner of the window + * @param[in] x,y The screen co-ordinates for the top left corner of the window * @param[in] width The width of the window * @param[in] height The height of the window * - * @note The checkbox is not automatically drawn. Call gwinCheckboxDraw() after changing the checkbox style. - * - * @return NULL if there is no resultant drawing area, otherwise a window handle. + * @note The drawing color gets set to White and the background drawing color to Black. + * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() + * @note The dimensions and position may be changed to fit on the real screen. + * @note The checkbox is not automatically drawn. Call gwinDraw() to draw it. * * @api */ -GHandle gwinCheckboxCreate(GCheckboxObject *gb, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateCheckbox(GCheckboxObject *gb, coord_t x, coord_t y, coord_t width, coord_t height); /** - * @brief Redraw a checkbox + * @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) + * @param[in] gh The window handle (must be a checkbox window) * * @api */ -void gwinCheckboxDraw(GHandle gh); +bool_t gwinIsCheckboxChecked(GHandle gh); /** - * @brief Enable or disable a button + * @brief Set the colors used to draw the checkbox * * @param[in] gh The window handle (must be a checkbox window) - * @param[in] enabled Enable or disable the button + * @param[in] pColors The colors to use * * @api */ -void gwinCheckboxSetEnabled(GHandle gh, bool_t enabled); +void gwinCheckboxSetColors(GHandle gh, GCheckboxColors *pColors); /** - * @brief Set the callback routine to perform a custom drawing. + * @brief Some custom checkbox drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different checkbox drawing styles * - * @param[in] gh The window handle (must be a checkbox window) - * @param[in] fn The function to use to draw the checkbox - * @param[in] param A parameter to pass to the checkbox drawing function + * @param[in] gw The widget (which must be a checkbox) + * @param[in] param A parameter passed in from the user * - * @api - */ -void gwinCheckboxSetCustom(GHandle gh, GCheckboxDrawFunction fn, void *param); - -/** - * @brief Enable a checkbox - * - * @api - */ -#define gwinCheckboxEnable(gh) gwinCheckboxSetEnabled( ((GCheckboxObject *)(gh)), TRUE) - -/** - * @brief Disable a checkbox - * - * @api -*/ -#define gwinCheckboxDisable(gh) gwinCheckboxSetEnabled( ((GCheckboxObject *)(gh)), FALSE) - -/** - * @brief Get the state of a checkbox - * - * @param[in] gh The window handle (must be a checkbox window) - * - * @return The state of the checkbox (GCHBX_CHECKED or GCHBX_UNCHECKED) - * - * @api - */ -#define gwinCheckboxGetState(gh) (((GCheckboxObject *)(gh))->isChecked) - -/** - * @brief Get the source handle of a checkbox - * @details Get the source handle of a checkbox so the application can listen for events - * - * @param[in] gh The window handle (must be a checkbox window) + * @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 + * @{ */ -#define gwinCheckboxGetSource(gh) ((GSourceHandle)(gh)) - -#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE - /** - * @brief Attach a mouse to a checkbox - * - * @param[in] gh The checkbox handle - * @param[in] instance The mouse instance - * - * @api - */ - bool_t gwinCheckboxAttachMouse(GHandle gh, uint16_t instance); -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ - -#endif /* _GWIN_NEED_CHECKBOX */ +void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param); +void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param); +/* @} */ #endif /* _GWIN_CHECKBOX_H */ /** @} */ diff --git a/include/gwin/class_gwin.h b/include/gwin/class_gwin.h new file mode 100644 index 00000000..b7d8c5a8 --- /dev/null +++ b/include/gwin/class_gwin.h @@ -0,0 +1,123 @@ +/* + * This file is subject to the terms of the GFX License, v1.0. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://chibios-gfx.com/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 Virtual Method Table for a GWIN window + * @{ + */ +typedef struct gwinVMT { + const char *classname; // @< The GWIN classname + void (*Destroy)(GWindowObject *gh); // @< The GWIN Destroy function (optional) + void (*AfterClear)(GWindowObject *gh); // @< The GWIN After-Clear function (optional) +} gwinVMT; +/* @} */ + +/** + * @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 If no MouseDown(), MouseUp() or MouseMove() function is provided, the widget will not accept being attached to a mouse input source. + * @note If no ToggleOn() or ToggleOff() function is provided, the widget will not accept being attached to a toggle input source. + * @note If no DialMove() function is provided, the widget will not accept being attached to a dial input source. + * @note AssignToggle() and AssignDial() enable a widget to handle more than one toggle/dial device attached to the widget. + * For example, a slider might accept two toggles, one for slider-down and one for slider-up. + * The function enables the widget to record that a particular device instance performs each particular role. + * (eg toggle0 = slider-down, toggle1 = slider-up). + * @{ + */ +typedef struct gwidgetVMT { + struct gwinVMT g; // @< This is still a GWIN + void (*DefaultDraw) (GWidgetObject *gw, void *param); // @< The default drawing routine (mandatory) + 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) + void (*ToggleOff) (GWidgetObject *gw, uint16_t instance); // @< Process toggle off events (optional) + void (*ToggleOn) (GWidgetObject *gw, uint16_t instance); // @< Process toggle on events (optional) + void (*DialMove) (GWidgetObject *gw, uint16_t instance, uint16_t value); // @< Process dial move events (optional) + void (*AllEvents) (GWidgetObject *gw, GEvent *pe); // @< Process all events (optional) + bool_t (*AssignToggle) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the toggle instance handle (optional) + bool_t (*AssignDial) (GWidgetObject *gw, uint16_t role, uint16_t instance); // @< Test the role and save the dial instance handle (optional) +} gwidgetVMT; +/* @} */ + +/** + * @brief The predefined flags for a GWIN and a Widget + * @{ + */ +#define GWIN_FLG_DYNAMIC 0x0001 // @< The GWIN structure is allocated +#define GWIN_FLG_WIDGET 0x0002 // @< This is a widget +#define GWIN_FLG_ENABLED 0x0002 // @< The widget is enabled +#define GWIN_FLG_ALLOCTXT 0x0008 // @< The widget text is allocated +#define GWIN_FLG_MOUSECAPTURE 0x0010 // @< The widget has captured the mouse +#define GWIN_FIRST_CONTROL_FLAG 0x0100 // @< Free for GWINs and Widgets to use +/* @} */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialise (and allocate if necessary) the base GWIN object + * + * @param[in] pgw The GWindowObject structure. If NULL one is allocated from the heap + * @param[in] x, y The top left corner of the GWIN relative to the screen + * @param[in] w, h The width and height of the GWIN window + * @param[in] size The size of the GWIN object to allocate + * @param[in] vmt The virtual method table for the GWIN object + * + * @notapi + */ +GHandle _gwinInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwinVMT *vmt); + +/** + * @brief Initialise (and allocate if necessary) the base Widget object + * + * @param[in] pgw The GWidgetObject structure. If NULL one is allocated from the heap + * @param[in] x, y The top left corner of the Widget relative to the screen + * @param[in] w, h The width and height of the Widget window + * @param[in] size The size of the Widget object to allocate + * @param[in] vmt The virtual method table for the Widget object + * + * @notapi + */ +GHandle _gwidgetInit(GWidgetObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwidgetVMT *vmt); + +/** + * @brief Destroy the Widget object + * + * @param[in] gw The widget to destroy + * + * @notapi + */ +void _gwidgetDestroy(GHandle gh); + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_GWIN */ + +#endif /* _CLASS_GWIN_H */ +/** @} */ diff --git a/include/gwin/console.h b/include/gwin/console.h index 4c317cdb..0496c620 100644 --- a/include/gwin/console.h +++ b/include/gwin/console.h @@ -24,22 +24,13 @@ #ifndef _GWIN_CONSOLE_H #define _GWIN_CONSOLE_H -#if GWIN_NEED_CONSOLE || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -#define GW_CONSOLE 0x0001 - -/*===========================================================================*/ -/* Type definitions */ -/*===========================================================================*/ +/* This file is included within "gwin/gwin.h" */ // A console window. Supports wrapped text writing and a cursor. typedef struct GConsoleObject_t { - GWindowObject gwin; - + GWindowObject g; + coord_t cx, cy; // Cursor position + #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM struct GConsoleWindowStream_t { const struct GConsoleWindowVMT_t *vmt; @@ -47,15 +38,8 @@ typedef struct GConsoleObject_t { } stream; #endif - coord_t cx,cy; // Cursor position - uint8_t fy; // Current font height - uint8_t fp; // Current font inter-character spacing } GConsoleObject; -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - #ifdef __cplusplus extern "C" { #endif @@ -67,18 +51,19 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gc The GConsoleObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the bottom left corner of the window + * @param[in] x,y The screen co-ordinates for the top left corner of the window * @param[in] width The width of the window * @param[in] height The height of the window - * @param[in] font The font to use + * * @note The console is not automatically cleared on creation. You must do that by calling gwinClear() (possibly after changing your background color) + * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() * @note If the dispay does not support scrolling, the window will be cleared when the bottom line is reached. * @note The default drawing color gets set to White and the background drawing color to Black. * @note The dimensions and position may be changed to fit on the real screen. * * @api */ -GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height, font_t font); +GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height); #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM /** @@ -157,7 +142,5 @@ void gwinPrintf(GHandle gh, const char *fmt, ...); } #endif -#endif /* GWIN_NEED_CONSOLE */ - #endif /* _GWIN_CONSOLE_H */ /** @} */ diff --git a/include/gwin/graph.h b/include/gwin/graph.h index dea8d4ee..3c4c42a9 100644 --- a/include/gwin/graph.h +++ b/include/gwin/graph.h @@ -22,20 +22,7 @@ #ifndef _GWIN_GRAPH_H #define _GWIN_GRAPH_H -#if GWIN_NEED_GRAPH || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -#define GW_GRAPH 0x0003 - -/*===========================================================================*/ -/* Type definitions */ -/*===========================================================================*/ - -// GDISP now has its own point structure -#define GGraphPoint point +/* This file is included within "gwin/gwin.h" */ typedef enum GGraphPointType_e { GGRAPH_POINT_NONE, GGRAPH_POINT_DOT, GGRAPH_POINT_SQUARE, GGRAPH_POINT_CIRCLE @@ -85,7 +72,7 @@ typedef struct GGraphStyle_t { // A graph window typedef struct GGraphObject_t { - GWindowObject gwin; + GWindowObject g; GGraphStyle style; coord_t xorigin, yorigin; coord_t lastx, lasty; @@ -104,10 +91,12 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gg The GGraphObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the bottom left corner of the window + * @param[in] x,y The screen co-ordinates for the top left corner of the window * @param[in] width The width of the window * @param[in] height The height of the window + * * @note The console is not automatically cleared on creation. You must do that by calling gwinClear() (possibly after changing your background color) + * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() * @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. @@ -187,8 +176,6 @@ void gwinGraphDrawPoints(GHandle gh, const point *points, unsigned count); } #endif -#endif /* GWIN_NEED_GRAPH */ - #endif /* _GWIN_GRAPH_H */ /** @} */ diff --git a/include/gwin/gwidget.h b/include/gwin/gwidget.h new file mode 100644 index 00000000..40124a43 --- /dev/null +++ b/include/gwin/gwidget.h @@ -0,0 +1,234 @@ +/* + * This file is subject to the terms of the GFX License, v1.0. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://chibios-gfx.com/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 must be set to TRUE in your gfxconf.h + * @{ + */ + +// Forward definition +struct GWidgetObject; + +/** + * @brief Defines a custom drawing function for a widget + */ +typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); + +/** + * @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 you 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 + GListener listener; // @< The widget listener + const char * txt; // @< The widget text + CustomWidgetDrawFunction fnDraw; // @< The current draw function + void * fnParam; // @< A parameter for the current draw function +} 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 Enable or disable a widget + * + * @param[in] gh The widget handle + * @param[in] enabled Enable or disable the widget + * + * @note The widget is not automatically redrawn. Call @p gwinDraw() to redraw the widget. + * @note Non-widgets will ignore this call. + * + * @api + */ +void gwinSetEnabled(GHandle gh, bool_t enabled); + +/** + * @brief Enable a widget + * + * @param[in] gh The widget handle + * + * @note The widget is not automatically redrawn. Call @p gwinDraw() to redraw the widget. + * @note Non-widgets will ignore this call. + * + * @api + */ +#define gwinEnable(gh) gwinSetEnabled(gh, TRUE) + +/** + * @brief Disable a widget + * + * @param[in] gh The widget handle + * + * @note The widget is not automatically redrawn. Call @p gwinDraw() to redraw the widget. + * @note Non-widgets will ignore this call. + * + * @api + */ +#define gwinDisable(gh) gwinSetEnabled(gh, FALSE) + +/** + * @brief Redraw the widget + * + * @param[in] gh The widget handle + * + * @note Non-widgets will ignore this call. + * + * @api + */ +void gwinDraw(GHandle gh); + +/** + * @brief Set the text of a widget. + * + * @param[in] gh The widget handle + * @param[in] txt 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 not automatically redrawn. Call @p gwinDraw() to redraw the widget. + * @note Non-widgets will ignore this call. + * + * @api + */ +void gwinSetText(GHandle gh, const char *txt, 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 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 this widget + * @return TRUE on success + * + * @param[in] gh The widget handle + * @param[in] pl The listener + * @param[in] flags Flags to use for listening. For most widgets this should be 0. + * + * @api + */ +bool_t gwinAttachListener(GHandle gh, GListener *pl, unsigned flags); + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + /** + * @brief Attach a mouse to a widget + * @return TRUE on success + * + * @param[in] gh The widget handle + * @param[in] instance The mouse instance + * + * @api + */ + bool_t gwinAttachMouse(GHandle gh, 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 "gwin/button.h" +#endif +#if GWIN_NEED_SLIDER || defined(__DOXYGEN__) + #include "gwin/slider.h" +#endif +#if GWIN_NEED_CHECKBOX || defined(__DOXYGEN__) + #include "gwin/checkbox.h" +#endif + +#endif /* _GWIDGET_H */ +/** @} */ diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h index 6441e5f8..e7c164dc 100644 --- a/include/gwin/gwin.h +++ b/include/gwin/gwin.h @@ -12,14 +12,12 @@ * @defgroup Window Window * @ingroup GWIN * - * @details GWIN provides a basic window manager which allows it to easily - * create and destroy different windows on runtime. Each window - * will have it's own properties such as colors, brushes as well as - * it's own drawing origin. - * Moving the windows around is not supported yet. + * @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 - * * @{ */ @@ -30,30 +28,23 @@ #if GFX_USE_GWIN || defined(__DOXYGEN__) -/*===========================================================================*/ -/* Type definitions */ -/*===========================================================================*/ - -typedef uint16_t GWindowType; -#define GW_WINDOW 0x0000 -#define GW_FIRST_USER_WINDOW 0x8000 - -// A basic window -typedef struct GWindowObject_t { - GWindowType type; // What type of window is this - uint16_t flags; // Internal flags - coord_t x, y; // Screen relative position - coord_t width, height; // Dimensions of this window - color_t color, bgcolor; // Current drawing colors - bool_t enabled; // Enabled/Disabled state +/** + * @brief A window object structure + * @note Do you access the members directly. Treat it as a black-box and use the method functions. + * + * @{ + */ +typedef struct GWindowObject { + const struct gwinVMT *vmt; // @< The VMT for this GWIN + coord_t x, y; // @< Screen relative position + coord_t width, height; // @< Dimensions of this window + color_t color, bgcolor; // @< Current drawing colors + uint16_t flags; // @< Window flags (the meaning is private to the GWIN class) #if GDISP_NEED_TEXT - font_t font; // Current font + font_t font; // @< Current font #endif } GWindowObject, * GHandle; - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ +/* @} */ #ifdef __cplusplus extern "C" { @@ -65,18 +56,20 @@ extern "C" { * @brief Create a basic window. * @return NULL if there is no resultant drawing area, otherwise a window handle. * - * @param[in] gw The window structure to initialize. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen coordinates for the bottom left corner of the window + * @param[in] pgw The window structure to initialize. If this is NULL the structure is dynamically allocated. + * @param[in] x,y The screen coordinates for the top left corner of the window * @param[in] width The width of the window * @param[in] height The height of the window + * * @note The default drawing color gets set to White and the background drawing color to Black. * @note No default font is set so make sure to set one before drawing any text. * @note The dimensions and position may be changed to fit on the real screen. - * @note The window is not automatically cleared on creation. You must do that by calling gwinClear() (possibly after changing your background color) + * @note The window is not automatically cleared on creation. You must do that by calling @p gwinClear() + * (possibly after changing your background color) * * @api */ -GHandle gwinCreateWindow(GWindowObject *gw, coord_t x, coord_t y, coord_t width, coord_t height); +GHandle gwinCreateWindow(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height); /** * @brief Destroy a window (of any type). Releases any dynamically allocated memory. @@ -85,17 +78,22 @@ GHandle gwinCreateWindow(GWindowObject *gw, coord_t x, coord_t y, coord_t width, * * @api */ -void gwinDestroyWindow(GHandle gh); +void gwinDestroy(GHandle gh); /** - * @brief Enable or disable a widget (of any type). + * @brief Get the real class name of the GHandle + * @details Returns a string describing the object class. * - * @param[in] gh The window handle - * @param[in] enabled Enable or disable the widget + * @param[in] gh The window + */ +const char *gwinGetClassName(GHandle gh); + +/** + * @brief Get an ID that uniquely describes the class of the GHandle * - * @api + * @param[in] gh The window */ -void gwinSetEnabled(GHandle gh, bool_t enabled); +#define gwinGetClassID(gh) ((void *)((gh)->vmt)) /** * @brief Get the X coordinate of the window @@ -148,23 +146,16 @@ void gwinSetEnabled(GHandle gh, bool_t enabled); */ #define gwinSetBgColor(gh, bgclr) (gh)->bgcolor = (bgclr) -/** - * @brief Enable a window of any type - * - * @param[in] gh The window handle - */ -#define gwinEnable(gh) gwinSetEnabled(gh, TRUE) - -/** - * @brief Disable a window of any type - * - * @param[in] gh The window handle - */ -#define gwinDisable(gh) gwinSetEnabled(gh, FALSE) - /* Set up for text */ #if GDISP_NEED_TEXT || defined(__DOXYGEN__) + /** + * @brief Set the default font for all new GWIN windows + * + * @param[in] gh The window + */ + void gwinSetDefaultFont(font_t font); + /** * @brief Set the current font for this window. * @@ -178,16 +169,6 @@ void gwinSetEnabled(GHandle gh, bool_t enabled); /* Drawing Functions */ -/** - * @brief Draw the window - * @note Redraws the Window if the GWIN object has a draw routine - * - * @param[in] gh The window handle - * - * @api - */ -void gwinDraw(GHandle gh); - /** * @brief Clear the window * @note Uses the current background color to clear the window @@ -538,12 +519,16 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } #endif +/* Include widgets */ +#include "gwin/gwidget.h" + /* Include extra window types */ -#include "gwin/console.h" /* 0x0001 */ -#include "gwin/button.h" /* 0x0002 */ -#include "gwin/graph.h" /* 0x0003 */ -#include "gwin/slider.h" /* 0x0004 */ -#include "gwin/checkbox.h" /* 0x0005 */ +#if GWIN_NEED_CONSOLE || defined(__DOXYGEN__) + #include "gwin/console.h" +#endif +#if GWIN_NEED_GRAPH || defined(__DOXYGEN__) + #include "gwin/graph.h" +#endif #endif /* GFX_USE_GWIN */ diff --git a/include/gwin/internal.h b/include/gwin/internal.h deleted file mode 100644 index 53392410..00000000 --- a/include/gwin/internal.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ - -/** - * @file include/gwin/internal.h - * @brief GWIN Graphic window subsystem header file. - * - * @addtogroup GWIN - * @{ - */ -#ifndef _GWIN_INTERNAL_H -#define _GWIN_INTERNAL_H - -#if GFX_USE_GWIN || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Sub-system constants. */ -/*===========================================================================*/ - -#define GWIN_FLG_DYNAMIC 0x0001 -#define GBTN_FLG_ALLOCTXT 0x0002 -#define GWIN_FIRST_CONTROL_FLAG 0x0004 - -#ifdef __cplusplus -extern "C" { -#endif - -GHandle _gwinInit(GWindowObject *gw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif /* GFX_USE_GWIN */ - -#endif /* _GWIN_INTERNAL_H */ -/** @} */ diff --git a/include/gwin/slider.h b/include/gwin/slider.h index 5e77a846..41894305 100644 --- a/include/gwin/slider.h +++ b/include/gwin/slider.h @@ -22,19 +22,10 @@ #ifndef _GWIN_SLIDER_H #define _GWIN_SLIDER_H -#if GWIN_NEED_SLIDER || defined(__DOXYGEN__) +/* This file is included within "gwin/gwidget.h" */ -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -#define GW_SLIDER 0x0004 #define GEVENT_GWIN_SLIDER (GEVENT_GWIN_FIRST+1) -/*===========================================================================*/ -/* Type definitions */ -/*===========================================================================*/ - typedef struct GEventGWinSlider_t { GEventType type; // The type of this event (GEVENT_GWIN_BUTTON) GHandle slider; // The slider that is returning results @@ -43,33 +34,24 @@ typedef struct GEventGWinSlider_t { // There are currently no GEventGWinSlider listening flags - use 0 -typedef struct GSliderDrawStyle_t { +typedef struct GSliderColors { color_t color_edge; color_t color_thumb; color_t color_active; color_t color_inactive; -} GSliderDrawStyle; - -typedef void (*GSliderDrawFunction)(GHandle gh, bool_t isVertical, coord_t thumbpos, const GSliderDrawStyle *pstyle, void *param); + color_t color_txt; +} GSliderColors; // A slider window typedef struct GSliderObject_t { - GWindowObject gwin; - - GSliderDrawStyle style; - bool_t tracking; + GWidgetObject w; + GSliderColors c; + coord_t dpos; int min; int max; int pos; - GSliderDrawFunction fn; - void *param; - GListener listener; } GSliderObject; -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - #ifdef __cplusplus extern "C" { #endif @@ -79,12 +61,14 @@ extern "C" { * @return NULL if there is no resultant drawing area, otherwise a window handle. * * @param[in] gb The GSliderObject structure to initialise. If this is NULL the structure is dynamically allocated. - * @param[in] x,y The screen co-ordinates for the bottom left corner of the window + * @param[in] x,y The screen co-ordinates for the top left corner of the window * @param[in] width The width of the window * @param[in] height The height of the window + * * @note The drawing color gets set to White and the background drawing color to Black. + * @note Don't forget to set the font using @p gwinSetFont() or @p gwinSetDefaultFont() * @note The dimensions and position may be changed to fit on the real screen. - * @note The slider is not automatically drawn. Call gwinSliderDraw() after changing the slider style. + * @note The slider is not automatically drawn. Call gwinDraw() to draw it. * @note Sets the slider range from 0 to 100 with an initial position of 0 * * @api @@ -130,51 +114,7 @@ void gwinSetSliderPosition(GHandle gh, int pos); * * @api */ -void gwinSetSliderStyle(GHandle gh, const GSliderDrawStyle *pStyle); - -/** - * @brief Redraw the slider. - * - * @param[in] gh The window handle (must be a slider window) - * - * @api - */ -void gwinSliderDraw(GHandle gh); - -/** - * @brief Enable or disable a button - * - * @param[in] gh The window handle (must be a slider window) - * @param[in] enabled Enable or disable the slider - * - * @api - */ -void gwinSliderSetEnabled(GHandle gh, bool_t enabled); - -/** - * @brief Set the callback routine to perform a custom slider drawing. - * - * @param[in] gh The window handle (must be a slider window) - * @param[in] fn The function to use to draw the slider - * @param[in] param A parameter to pass to the slider drawing function - * - * @api - */ -void gwinSetSliderCustom(GHandle gh, GSliderDrawFunction fn, void *param); - -/** - * @brief Enable a slider - * - * @api - */ -#define gwinEnableSlider(gh) gwinSliderSetEnabled( ((GSliderObject *)(gh)), TRUE) - -/** - * @brief Disable a slider - * - * @api - */ -#define gwinDisableSlider(gh) gwinSliderSetEnabled( ((GSliderObject *)(gh)), FALSE) +void gwinSetSliderColors(GHandle gh, const GSliderColors *pStyle); /** * @brief Get the current slider position. @@ -190,69 +130,35 @@ void gwinSetSliderCustom(GHandle gh, GSliderDrawFunction fn, void *param); #define gwinGetSliderPosition(gh) (((GSliderObject *)(gh))->pos) /** - * @brief Get the source handle of a slider - * @details Get the source handle of a slider so the application can listen for events + * @brief Some custom slider drawing routines + * @details These function may be passed to @p gwinSetCustomDraw() to get different slider drawing styles * - * @param[in] gh The window handle - * - * @api - */ -#define gwinGetSliderSource(gh) ((GSourceHandle)(gh)) - -#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE - /** - * @brief Attach a mouse source - * @details Attach a mouse to a slider - * - * @param[in] gh The slider handle - * @param[in] instance The mouse instance - * - * @api - */ - bool_t gwinAttachSliderMouse(GHandle gh, uint16_t instance); -#endif - -#if GFX_USE_GINPUT && GINPUT_NEED_DIAL - /** - * @brief Attach a dial source - * @details Attach a dial to a slider - * - * @param[in] gh The dial handle - * @param[in] instance The dial instance - * - * @api - */ - bool_t gwinAttachSliderDial(GHandle gh, uint16_t instance); -#endif - -/** - * @brief Standard slider drawing routines - * @details This routine is called to draw the standard slider. - * - * @param[in] gh The slider handle - * @param[in] isVertical The slider is vertically oriented instead of horizontal - * @param[in] thumbpos The position of the slider (0..cx-1 or cy-1..0) - * @param[in] pstyle The current drawing style + * @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. It is there - * only to ensure the functions match the GSliderDrawFunction type. - * @note When called by a slider the framework ensure that it is - * a slider object and sets up clipping to the slider object window. These - * drawing routines then don't have to worry about explicitly doing that. + * @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(GHandle gh, bool_t isVertical, coord_t thumbpos, const GSliderDrawStyle *pstyle, void *param); +void gwinSliderDraw_Std(GWidgetObject *gw, void *param); +void gwinSliderDraw_Image(GWidgetObject *gw, void *param); +/* @} */ #ifdef __cplusplus } #endif -#endif /* GWIN_NEED_SLIDER */ - #endif /* _GWIN_SLIDER_H */ /** @} */ -- cgit v1.2.3