From 777ec6af7c1b594f7b7a9cbaaf7ead90d8fb7e8f Mon Sep 17 00:00:00 2001 From: inmarket Date: Sat, 8 Jun 2013 02:27:59 +1000 Subject: [PATCH] Add a simple GWIN window manager, Change the way GWIN visibility works --- demos/modules/gadc/gwinosc.c | 2 +- demos/modules/gaudin/gwinosc.c | 2 +- gfxconf.example.h | 4 +- include/gfx_rules.h | 54 +- include/gwin/button.h | 11 +- include/gwin/class_gwin.h | 172 +++-- include/gwin/console.h | 12 +- include/gwin/graph.h | 11 +- include/gwin/gwidget.h | 39 +- include/gwin/gwin.h | 1070 +++++++++++++++++++------------- include/gwin/options.h | 38 +- src/gfx.c | 2 +- src/gqueue/gqueue.c | 29 +- src/gwin/button.c | 9 +- src/gwin/checkbox.c | 5 +- src/gwin/console.c | 3 +- src/gwin/graph.c | 3 +- src/gwin/gwidget.c | 46 +- src/gwin/gwin.c | 298 +++++++-- src/gwin/gwin.mk | 1 + src/gwin/gwm.c | 144 +++++ src/gwin/slider.c | 7 +- 22 files changed, 1301 insertions(+), 661 deletions(-) create mode 100644 src/gwin/gwm.c diff --git a/demos/modules/gadc/gwinosc.c b/demos/modules/gadc/gwinosc.c index 589fdb9e..88e61334 100644 --- a/demos/modules/gadc/gwinosc.c +++ b/demos/modules/gadc/gwinosc.c @@ -47,7 +47,7 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coord_t cy, uint32_t physdev, uint32_t frequency) { /* Initialise the base class GWIN */ - if (!(gs = (GScopeObject *)_gwinInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject)))) + if (!(gs = (GScopeObject *)_gwindowInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject)))) return 0; /* Initialise the scope object members and allocate memory for buffers */ diff --git a/demos/modules/gaudin/gwinosc.c b/demos/modules/gaudin/gwinosc.c index 82ed4b44..e90430d3 100644 --- a/demos/modules/gaudin/gwinosc.c +++ b/demos/modules/gaudin/gwinosc.c @@ -54,7 +54,7 @@ GHandle gwinCreateScope(GScopeObject *gs, coord_t x, coord_t y, coord_t cx, coord_t cy, uint16_t channel, uint32_t frequency) { /* Initialise the base class GWIN */ - if (!(gs = (GScopeObject *)_gwinInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject)))) + if (!(gs = (GScopeObject *)_gwindowInit((GWindowObject *)gs, x, y, cx, cy, sizeof(GScopeObject)))) return 0; /* Initialise the scope object members and allocate memory for buffers */ diff --git a/gfxconf.example.h b/gfxconf.example.h index 3cdd56fe..1797cadc 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -80,9 +80,11 @@ #define TDISP_NEED_MULTITHREAD FALSE /* Features for the GWIN subsystem. */ -#define GWIN_NEED_BUTTON FALSE +#define GWIN_NEED_WINDOWMANAGER FALSE #define GWIN_NEED_CONSOLE FALSE #define GWIN_NEED_GRAPH FALSE +#define GWIN_NEED_WIDGET FALSE +#define GWIN_NEED_BUTTON FALSE #define GWIN_NEED_SLIDER FALSE #define GWIN_NEED_CHECKBOX FALSE diff --git a/include/gfx_rules.h b/include/gfx_rules.h index 4b7e9506..7e14ef9d 100644 --- a/include/gfx_rules.h +++ b/include/gfx_rules.h @@ -46,29 +46,15 @@ #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE" #endif #endif - #if GWIN_NEED_BUTTON - #if !GDISP_NEED_TEXT - #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_BUTTON is TRUE." - #endif - #if !GFX_USE_GEVENT + #if GWIN_NEED_WINDOWMANAGER + #if !GFX_USE_GQUEUE || !GQUEUE_NEED_ASYNC #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GFX_USE_GEVENT is required if GWIN_NEED_BUTTON is TRUE. It has been turned on for you." + #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_GEVENT - #define GFX_USE_GEVENT TRUE - #endif - #if !GFX_USE_GINPUT || !(GINPUT_NEED_MOUSE || GINPUT_NEED_TOGGLE) - #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: You have set GWIN_NEED_BUTTON to TRUE but no supported GINPUT (mouse/toggle) devices have been included" - #endif - #endif - #if !GDISP_NEED_MULTITHREAD && !GDISP_NEED_ASYNC - #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: Either GDISP_NEED_MULTITHREAD or GDISP_NEED_ASYNC is required if GWIN_NEED_BUTTON is TRUE." - #warning "GWIN: GDISP_NEED_MULTITHREAD has been turned on for you." - #endif - #undef GDISP_NEED_MULTITHREAD - #define GDISP_NEED_MULTITHREAD TRUE + #undef GFX_USE_GQUEUE + #undef GQUEUE_NEED_ASYNC + #define GFX_USE_GQUEUE TRUE + #define GQUEUE_NEED_ASYNC TRUE #endif #endif #if GWIN_NEED_CONSOLE @@ -78,6 +64,32 @@ #endif #if GWIN_NEED_GRAPH #endif + #if GWIN_NEED_BUTTON || GWIN_NEED_SLIDER || GWIN_NEED_CHECKBOX + #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_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 !GDISP_NEED_MULTITHREAD && !GDISP_NEED_ASYNC + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: Either GDISP_NEED_MULTITHREAD or GDISP_NEED_ASYNC is required if GWIN_NEED_WIDGET is TRUE." + #warning "GWIN: GDISP_NEED_MULTITHREAD has been turned on for you." + #endif + #undef GDISP_NEED_MULTITHREAD + #define GDISP_NEED_MULTITHREAD TRUE + #endif + #endif #endif #if GFX_USE_GINPUT diff --git a/include/gwin/button.h b/include/gwin/button.h index 1b0ff36b..53096ea3 100644 --- a/include/gwin/button.h +++ b/include/gwin/button.h @@ -73,10 +73,15 @@ extern "C" { * @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 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 The button is not automatically drawn. Call gwinDraw() to draw it. + * @note A button remembers its normal button 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 button is initially marked as invisible so that more properties can be set before display. + * Call @p gwinSetVisible() to display it when ready. * * @api */ diff --git a/include/gwin/class_gwin.h b/include/gwin/class_gwin.h index b7d8c5a8..5e3cb01f 100644 --- a/include/gwin/class_gwin.h +++ b/include/gwin/class_gwin.h @@ -23,56 +23,92 @@ #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_WIDGET 0x0010 // @< This is a widget +#define GWIN_FLG_ENABLED 0x0020 // @< The widget is enabled +#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 - void (*Destroy)(GWindowObject *gh); // @< The GWIN Destroy function (optional) - void (*AfterClear)(GWindowObject *gh); // @< The GWIN After-Clear function (optional) + const char * classname; // @< The GWIN classname (mandatory) + 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; /* @} */ -/** - * @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; -/* @} */ +#if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + /** + * @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 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; + /* @} */ +#endif -/** - * @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 -/* @} */ +#if GWIN_NEED_WINDOWMANAGER || defined(__DOXYGEN__) + // @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, coord_t x, coord_t y, coord_t w, coord_t h); // @< A window has been added + void (*Delete) (GHandle gh); // @< A window has been deleted + void (*Visible) (GHandle gh); // @< A window has changed its visibility state + 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; +#endif #ifdef __cplusplus extern "C" { @@ -86,32 +122,44 @@ extern "C" { * @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 + * @param[in] flags The default flags to use * * @notapi */ -GHandle _gwinInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwinVMT *vmt); +GHandle _gwindowInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t w, coord_t h, size_t size, const gwinVMT *vmt, uint16_t flags); -/** - * @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); +#if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + /** + * @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); + /** + * @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 } diff --git a/include/gwin/console.h b/include/gwin/console.h index 0496c620..349efeb8 100644 --- a/include/gwin/console.h +++ b/include/gwin/console.h @@ -55,11 +55,15 @@ extern "C" { * @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 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 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 On creation the window is marked as visible but 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 */ diff --git a/include/gwin/graph.h b/include/gwin/graph.h index 3c4c42a9..f1ea9450 100644 --- a/include/gwin/graph.h +++ b/include/gwin/graph.h @@ -95,8 +95,15 @@ extern "C" { * @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 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 On creation the window is marked as visible but is not automatically cleared. You may do that by calling @p gwinClear() + * (possibly after changing your background color) + * @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. diff --git a/include/gwin/gwidget.h b/include/gwin/gwidget.h index 40124a43..21cfd4ac 100644 --- a/include/gwin/gwidget.h +++ b/include/gwin/gwidget.h @@ -74,48 +74,13 @@ extern "C" { * @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 The widget is automatically redrawn. * @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. * @@ -123,7 +88,7 @@ void gwinDraw(GHandle gh); * @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 The widget is automatically redrawn * @note Non-widgets will ignore this call. * * @api diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h index 7a6aba09..d915a4f0 100644 --- a/include/gwin/gwin.h +++ b/include/gwin/gwin.h @@ -30,521 +30,713 @@ /** * @brief A window object structure - * @note Do you access the members directly. Treat it as a black-box and use the method functions. - * + * @note Do not 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 -#endif + #if GWIN_NEED_WINDOWMANAGER + gfxQueueASyncItem wmq; // @< The next window (for the window manager) + #endif + 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; // @< The current drawing colors + uint16_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 A window's minimized, maximized or normal size + */ +typedef enum { GWIN_NORMAL, GWIN_MAXIMIZE, GWIN_MINIMIZE } GWindowMinMax; + #ifdef __cplusplus extern "C" { #endif -/* Base Functions */ +/*------------------------------------------------- + * Window Manager functions + *-------------------------------------------------*/ -/** - * @brief Create a basic window. - * @return NULL if there is no resultant drawing area, otherwise a window handle. - * - * @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 @p gwinClear() - * (possibly after changing your background color) - * - * @api - */ -GHandle gwinCreateWindow(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height); +#if GWIN_NEED_WINDOWMANAGER + // Forward definition + struct GWindowManager; -/** - * @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 - */ -const char *gwinGetClassName(GHandle gh); - -/** - * @brief Get an ID that uniquely describes the class of the GHandle - * - * @param[in] gh The window - */ -#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 - */ -#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 - */ -#define gwinGetScreenY(gh) ((gh)->y) - -/** - * @brief Get the width of the window - * - * @param[in] gh The window - */ -#define gwinGetWidth(gh) ((gh)->width) - -/** - * @brief Get the height of the window - * - * @param[in] gh The window - */ -#define gwinGetHeight(gh) ((gh)->height) - -/** - * @brief Set the default foreground color for all new GWIN windows - * - * @param[in] gh The window - * @param[in] clr The color to be set - */ -void gwinSetDefaultColor(color_t clr); - -/** - * @brief Set the default background color for all new GWIN windows - * - * @param[in] gh The window - * @param[in] bgclr The background color - */ -void gwinSetDefaultBgColor(color_t bgclr); - -/** - * @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 - */ -#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 - */ -#define gwinSetBgColor(gh, bgclr) (gh)->bgcolor = (bgclr) - -/* Set up for text */ - -#if GDISP_NEED_TEXT || defined(__DOXYGEN__) /** - * @brief Set the default font for all new GWIN windows + * @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] gh The window - */ - void gwinSetDefaultFont(font_t font); - - /** - * @brief Set the current font for this window. - * - * @param[in] gh The window handle - * @param[in] font The font to use for text functions + * @param[in] clr The color to be set * * @api */ - void gwinSetFont(GHandle gh, font_t font); -#endif + void gwinSetDefaultColor(color_t clr); -/* 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 Functions */ - -#if GDISP_NEED_CIRCLE || defined(__DOXYGEN__) /** - * @brief Draw a circle in the window. - * @note Uses the current foreground color to draw the circle + * @brief Set the default background color for all new GWIN windows + * + * @param[in] gh The window + * @param[in] bgclr The background color + * + * @api + */ + void gwinSetDefaultBgColor(color_t bgclr); + + #if GDISP_NEED_TEXT || defined(__DOXYGEN__) + /** + * @brief Set the default font for all new GWIN windows + * + * @param[in] gh The window + * + * @api + */ + void gwinSetDefaultFont(font_t font); + #endif + + +/*------------------------------------------------- + * Base functions + *-------------------------------------------------*/ + + /** + * @brief Create a basic window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @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 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 On creation the window is marked as visible. + * @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 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. + * + * @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 + * + * @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 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 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 Minimize, Maximize or Restore a window + * + * @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 + * + * @param[in] gh The window + * + * @api + */ + GWindowMinMax gwinGetMinMax(GHandle gh); + + /** + * @brief Raise a window to the top of the z-order + * + * @param[in] gh The window + * + * @note The window z-order is only supported by some window managers. If there is no + * window manager this call simple tries to redraw the window. See the comments + * in @p gwinSetVisible() with regard to what can be redrawn and what can't. + * + * @api + */ + void gwinRaise(GHandle gh); + + #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 center of the circle - * @param[in] radius The radius of the circle + * @param[in] x,y The coordinates of the pixel * * @api */ - void gwinDrawCircle(GHandle gh, coord_t x, coord_t y, coord_t radius); + void gwinDrawPixel(GHandle gh, coord_t x, coord_t y); /** - * @brief Draw a filled circle in the window. - * @note Uses the current foreground color to draw the filled circle + * @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] x, y The center of the circle - * @param[in] radius The radius of the circle + * @param[in] x0,y0 The start position + * @param[in] x1,y1 The end position * * @api */ - void gwinFillCircle(GHandle gh, coord_t x, coord_t y, coord_t radius); -#endif + void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1); -/* Ellipse Functions */ - -#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__) /** - * @brief Draw an ellipse. - * @note Uses the current foreground color to draw the ellipse + * @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 center of the ellipse - * @param[in] a,b The dimensions of the ellipse + * @param[in] x,y The start position + * @param[in] cx,cy The size of the box (outside dimensions) * * @api */ - void gwinDrawEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b); + void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy); /** - * @brief Draw an filled ellipse. - * @note Uses the current foreground color to draw the filled ellipse + * @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 center of the ellipse - * @param[in] a,b The dimensions of the ellipse + * @param[in] x,y The start position + * @param[in] cx,cy The size of the box (outside dimensions) * * @api */ - void gwinFillEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b); -#endif + void gwinFillArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy); -/* Arc Functions */ - -#if GDISP_NEED_ARC || defined(__DOXYGEN__) - /* - * @brief Draw an arc in the window. - * @note Uses the current foreground color to draw the arc + /** + * @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 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) + * @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 gwinDrawArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle); + 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); - /* - * @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 +/*------------------------------------------------- + * Circle, ellipse and arc functions + *-------------------------------------------------*/ -/* Read a pixel Function */ + #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); -#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 + /** + * @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 -/* Extra Text Functions */ + #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); -#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 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 - /** - * @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); + #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 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 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 - /** - * @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); +/*------------------------------------------------- + * Pixel read-back functions + *-------------------------------------------------*/ - /** - * @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); + #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 - /** - * @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 +/*------------------------------------------------- + * Text 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); + #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 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 + /** + * @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); -#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) - */ - gdispImageError gwinImageDraw(GHandle gh, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); -#endif + /** + * @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 gwinImageDraw(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 -/* Include widgets */ -#include "gwin/gwidget.h" +/*------------------------------------------------- + * Additional functionality + *-------------------------------------------------*/ -/* Include extra window types */ -#if GWIN_NEED_CONSOLE || defined(__DOXYGEN__) - #include "gwin/console.h" -#endif -#if GWIN_NEED_GRAPH || defined(__DOXYGEN__) - #include "gwin/graph.h" -#endif + /* Include widgets */ + #if GWIN_NEED_WIDGET || defined(__DOXYGEN__) + #include "gwin/gwidget.h" + #endif + + /* Include extra window types */ + #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/options.h b/include/gwin/options.h index 683a6e55..3619e075 100644 --- a/include/gwin/options.h +++ b/include/gwin/options.h @@ -21,20 +21,22 @@ * @{ */ /** - * @brief Should button functions be included. + * @brief Should a window manager be used. * @details Defaults to FALSE */ - #ifndef GWIN_NEED_BUTTON - #define GWIN_NEED_BUTTON FALSE + #ifndef GWIN_NEED_WINDOWMANAGER + #define GWIN_NEED_WINDOWMANAGER 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 - * @note To use chprintf() for printing in a console window you need to - * include in your application source file... - * \#include "chprintf.h" - * Also in your makefile, as part of your list of C source files, include - * ${CHIBIOS}/os/various/chprintf.c */ #ifndef GWIN_NEED_CONSOLE #define GWIN_NEED_CONSOLE FALSE @@ -46,6 +48,13 @@ #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 @@ -53,6 +62,13 @@ #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 /** * @} * @@ -76,6 +92,12 @@ /** * @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 diff --git a/src/gfx.c b/src/gfx.c index 2b307426..3856eea3 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -32,7 +32,7 @@ void DEPRECATED("Use gfxInit() instead") gdispInit() { gfxInit(); } /* These init functions are defined by each module but not published */ extern void _gosInit(void); -#if GFX_USE_GDISP && (GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC) +#if GFX_USE_GDISP extern void _gdispInit(void); #endif #if GFX_USE_TDISP diff --git a/src/gqueue/gqueue.c b/src/gqueue/gqueue.c index d515a425..11d10c0a 100644 --- a/src/gqueue/gqueue.c +++ b/src/gqueue/gqueue.c @@ -21,6 +21,9 @@ * @file src/gqueue/gqueue.c * @brief GQUEUE source file. */ + +#include "gfx.h" + #if GFX_USE_GQUEUE #if GQUEUE_NEED_ASYNC @@ -34,7 +37,7 @@ gfxSystemLock(); if ((pi = pqueue->head)) pqueue->head = pi->next; - gfxSytemUnlock(); + gfxSystemUnlock(); return pi; } void gfxQueueASyncPut(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { @@ -58,13 +61,15 @@ gfxSystemUnlock(); } void gfxQueueASyncRemove(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { + gfxQueueASyncItem *pi; + if (!pitem) return; gfxSystemLock(); if (pqueue->head) { if (pqueue->head == pitem) { pqueue->head = pitem->next; } else { - for(gfxQueueASyncItem *pi = pqueue->head; pi->next; pi = pi->next) { + for(pi = pqueue->head; pi->next; pi = pi->next) { if (pi->next == pitem) { pi->next = pitem->next; if (pqueue->tail == pitem) @@ -80,8 +85,10 @@ return pqueue->head == NULL; } bool_t gfxQueueASyncIsIn(gfxQueueASync *pqueue, gfxQueueASyncItem *pitem) { + gfxQueueASyncItem *pi; + gfxSystemLock(); - for(gfxQueueASyncItem *pi = pqueue->head; pi; pi = pi->next) { + for(pi = pqueue->head; pi; pi = pi->next) { if (pi == pitem) { gfxSystemUnlock(); return TRUE; @@ -132,13 +139,15 @@ gfxSemSignal(&pqueue->sem); } void gfxQueueGSyncRemove(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { + gfxQueueGSyncItem *pi; + if (!pitem) return; gfxSystemLock(); if (pqueue->head) { if (pqueue->head == pitem) { pqueue->head = pitem->next; } else { - for(gfxQueueGSyncItem *pi = pqueue->head; pi->next; pi = pi->next) { + for(pi = pqueue->head; pi->next; pi = pi->next) { if (pi->next == pitem) { pi->next = pitem->next; if (pqueue->tail == pitem) @@ -154,8 +163,10 @@ return pqueue->head == NULL; } bool_t gfxQueueGSyncIsIn(gfxQueueGSync *pqueue, gfxQueueGSyncItem *pitem) { + gfxQueueGSyncItem *pi; + gfxSystemLock(); - for(gfxQueueGSyncItem *pi = pqueue->head; pi; pi = pi->next) { + for(pi = pqueue->head; pi; pi = pi->next) { if (pi == pitem) { gfxSystemUnlock(); return TRUE; @@ -214,6 +225,8 @@ return gfxSemWait(&pitem->sem, ms); } void gfxQueueFSyncRemove(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem) { + gfxQueueFSyncItem *pi; + if (!pitem) return; gfxSystemLock(); if (pqueue->head) { @@ -225,7 +238,7 @@ gfxSemDestroy(&pitem->sem); return; } - for(gfxQueueFSyncItem *pi = pqueue->head; pi->next; pi = pi->next) { + for(pi = pqueue->head; pi->next; pi = pi->next) { if (pi->next == pitem) { pi->next = pitem->next; if (pqueue->tail == pitem) @@ -240,8 +253,10 @@ return pqueue->head == NULL; } bool_t gfxQueueFSyncIsIn(gfxQueueFSync *pqueue, gfxQueueFSyncItem *pitem) { + gfxQueueASyncItem *pi; + gfxSystemLock(); - for(gfxQueueFSyncItem *pi = pqueue->head; pi; pi = pi->next) { + for(pi = pqueue->head; pi; pi = pi->next) { if (pi == pitem) { gfxSystemUnlock(); return TRUE; diff --git a/src/gwin/button.c b/src/gwin/button.c index 1ebc8ee5..83b81b03 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -40,6 +40,7 @@ static const gwidgetVMT buttonVMT = { { "Button", // The classname _gwidgetDestroy, // The destroy routine + _gwidgetRedraw, // The redraw routine 0, // The after-clear routine }, gwinButtonDraw_3D, // The default drawing routine @@ -94,14 +95,14 @@ static void SendButtonEvent(GWidgetObject *gw) { static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) { (void) x; (void) y; gw->g.flags |= GBUTTON_FLG_PRESSED; - gwinDraw((GHandle)gw); + _gwidgetRedraw((GHandle)gw); } // A mouse up has occurred (it may or may not be over the button) static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) { (void) x; (void) y; gw->g.flags &= ~GBUTTON_FLG_PRESSED; - gwinDraw((GHandle)gw); + _gwidgetRedraw((GHandle)gw); #if !GWIN_BUTTON_LAZY_RELEASE // If the mouse up was not over the button then cancel the event @@ -116,14 +117,14 @@ static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) { static void ToggleOff(GWidgetObject *gw, uint16_t instance) { (void) instance; gw->g.flags &= ~GBUTTON_FLG_PRESSED; - gwinDraw((GHandle)gw); + _gwidgetRedraw((GHandle)gw); } // A toggle on has occurred static void ToggleOn(GWidgetObject *gw, uint16_t instance) { (void) instance; gw->g.flags |= GBUTTON_FLG_PRESSED; - gwinDraw((GHandle)gw); + _gwidgetRedraw((GHandle)gw); // Trigger the event on button down (different than for mouse/touch) SendButtonEvent(gw); } diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c index d35f271c..893dab9c 100644 --- a/src/gwin/checkbox.c +++ b/src/gwin/checkbox.c @@ -33,6 +33,7 @@ static const gwidgetVMT checkboxVMT = { { "Checkbox", // The classname _gwidgetDestroy, // The destroy routine + _gwidgetRedraw, // The redraw routine 0, // The after-clear routine }, gwinCheckboxDraw_CheckOnLeft, // The default drawing routine @@ -78,7 +79,7 @@ static void SendCheckboxEvent(GWidgetObject *gw) { static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) { (void) x; (void) y; gw->g.flags ^= GCHECKBOX_FLG_CHECKED; - gwinDraw((GHandle)gw); + _gwidgetRedraw((GHandle)gw); SendCheckboxEvent(gw); } @@ -86,7 +87,7 @@ static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) { static void ToggleOn(GWidgetObject *gw, uint16_t instance) { (void) instance; gw->g.flags ^= GCHECKBOX_FLG_CHECKED; - gwinDraw((GHandle)gw); + _gwidgetRedraw((GHandle)gw); SendCheckboxEvent(gw); } diff --git a/src/gwin/console.c b/src/gwin/console.c index d9bda362..c4b2798d 100644 --- a/src/gwin/console.c +++ b/src/gwin/console.c @@ -61,11 +61,12 @@ static void AfterClear(GWindowObject *gh) { static const gwinVMT consoleVMT = { "Console", // The classname 0, // The destroy routine + 0, // The redraw routine AfterClear, // The after-clear routine }; GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gc = (GConsoleObject *)_gwinInit((GWindowObject *)gc, x, y, width, height, sizeof(GConsoleObject), &consoleVMT))) + if (!(gc = (GConsoleObject *)_gwindowInit((GWindowObject *)gc, x, y, width, height, sizeof(GConsoleObject), &consoleVMT, GWIN_FLG_VISIBLE))) return 0; #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM gc->stream.vmt = &GWindowConsoleVMT; diff --git a/src/gwin/graph.c b/src/gwin/graph.c index 0ae9822b..393297e7 100644 --- a/src/gwin/graph.c +++ b/src/gwin/graph.c @@ -32,6 +32,7 @@ static const GGraphStyle GGraphDefaultStyle = { static const gwinVMT graphVMT = { "Graph", // The classname 0, // The destroy routine + 0, // The redraw routine 0, // The after-clear routine }; @@ -164,7 +165,7 @@ static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t } GHandle gwinCreateGraph(GGraphObject *gg, coord_t x, coord_t y, coord_t width, coord_t height) { - if (!(gg = (GGraphObject *)_gwinInit((GWindowObject *)gg, x, y, width, height, sizeof(GGraphObject), &graphVMT))) + if (!(gg = (GGraphObject *)_gwindowInit((GWindowObject *)gg, x, y, width, height, sizeof(GGraphObject), &graphVMT, GWIN_FLG_VISIBLE))) return 0; gg->xorigin = gg->yorigin = 0; gg->lastx = gg->lasty = 0; diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 3f23140c..773a715d 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -7,7 +7,7 @@ #include "gfx.h" -#if GFX_USE_GWIN +#if GFX_USE_GWIN && GWIN_NEED_WIDGET #include @@ -24,7 +24,7 @@ static void gwidgetCallback(void *param, GEvent *pe) { #define pde ((GEventDial *)pe) // check if widget is disabled - if (!(gw->g.flags & GWIN_FLG_ENABLED)) + if ((gw->g.flags & (GWIN_FLG_ENABLED|GWIN_FLG_VISIBLE)) != (GWIN_FLG_ENABLED|GWIN_FLG_VISIBLE)) return; // Process via AllEvents() if it is defined @@ -87,10 +87,9 @@ static void gwidgetCallback(void *param, GEvent *pe) { } GHandle _gwidgetInit(GWidgetObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size, const gwidgetVMT *vmt) { - if (!(pgw = (GWidgetObject *)_gwinInit((GWindowObject *)pgw, x, y, width, height, size, (const gwinVMT *)vmt))) + if (!(pgw = (GWidgetObject *)_gwindowInit((GWindowObject *)pgw, x, y, width, height, size, (const gwinVMT *)vmt, GWIN_FLG_WIDGET|GWIN_FLG_ENABLED))) return 0; - pgw->g.flags |= (GWIN_FLG_WIDGET|GWIN_FLG_ENABLED); pgw->txt = ""; pgw->fnDraw = vmt->DefaultDraw; pgw->fnParam = 0; @@ -101,9 +100,6 @@ GHandle _gwidgetInit(GWidgetObject *pgw, coord_t x, coord_t y, coord_t width, co } void _gwidgetDestroy(GHandle gh) { - if (!(gh->flags & GWIN_FLG_WIDGET)) - return; - // Deallocate the text (if necessary) if ((gh->flags & GWIN_FLG_ALLOCTXT)) { gh->flags &= ~GWIN_FLG_ALLOCTXT; @@ -112,21 +108,10 @@ void _gwidgetDestroy(GHandle gh) { // Untangle the listeners (both on us and to us). geventDetachSource(&gw->listener, 0); geventDetachSourceListeners((GSourceHandle)gh); - gh->flags &= ~GWIN_FLG_WIDGET; } -void gwinSetEnabled(GHandle gh, bool_t enabled) { - if (!(gh->flags & GWIN_FLG_WIDGET)) - return; - - if (enabled) - gh->flags |= GWIN_FLG_ENABLED; - else - gh->flags &= ~GWIN_FLG_ENABLED; -} - -void gwinDraw(GHandle gh) { - if (!(gh->flags & GWIN_FLG_WIDGET)) +void _gwidgetRedraw(GHandle gh) { + if (!(gh->flags & GWIN_FLG_VISIBLE)) return; #if GDISP_NEED_CLIP @@ -136,6 +121,23 @@ void gwinDraw(GHandle gh) { gw->fnDraw(gw, gw->fnParam); } +void gwinSetEnabled(GHandle gh, bool_t enabled) { + if (!(gh->flags & GWIN_FLG_WIDGET)) + return; + + if (enabled) { + if (!(gh->flags & GWIN_FLG_ENABLED)) { + gh->flags |= GWIN_FLG_ENABLED; + _gwidgetRedraw(gh); + } + } else { + if ((gh->flags & GWIN_FLG_ENABLED)) { + gh->flags &= ~GWIN_FLG_ENABLED; + _gwidgetRedraw(gh); + } + } +} + void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc) { if (!(gh->flags & GWIN_FLG_WIDGET)) return; @@ -162,6 +164,7 @@ void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc) { } gw->txt = txt ? txt : ""; + _gwidgetRedraw(gh); } const char *gwinGetText(GHandle gh) { @@ -177,6 +180,7 @@ void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param) { gw->fnDraw = fn ? fn : wvmt->DefaultDraw; gw->fnParam = param; + _gwidgetRedraw(gh); } bool_t gwinAttachListener(GHandle gh, GListener *pl, unsigned flags) { @@ -249,6 +253,6 @@ bool_t gwinAttachListener(GHandle gh, GListener *pl, unsigned flags) { } #endif -#endif /* GFX_USE_GWIN */ +#endif /* GFX_USE_GWIN && GWIN_NEED_WIDGET */ /** @} */ diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 163e821d..3e790d38 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -11,70 +11,121 @@ #include "gwin/class_gwin.h" +// Needed if there is no window manager +#define MIN_WIN_WIDTH 1 +#define MIN_WIN_HEIGHT 1 + +/*----------------------------------------------- + * Data + *-----------------------------------------------*/ + static const gwinVMT basegwinVMT = { "GWIN", // The classname 0, // The destroy routine + 0, // The redraw routine 0, // The after-clear routine }; -static font_t defaultFont; static color_t defaultFgColor = White; static color_t defaultBgColor = Black; +#if GDISP_NEED_TEXT + static font_t defaultFont; +#endif +#if GWIN_NEED_WINDOWMANAGER + gfxQueueASync _GWINList; + extern GWindowManager GNullWindowManager; + static GWindowManager * cwm; +#endif + +/*----------------------------------------------- + * Helper Routines + *-----------------------------------------------*/ + +#if !GWIN_NEED_WINDOWMANAGER + static void _gwm_vis(GHandle gh) { + if (gh->vmt->Redraw) { + #if GDISP_NEED_CLIP + gdispSetClip(gh->x, gh->y, gh->width, gh->height); + #endif + gh->vmt->Redraw(gh); + } else + gwinClear(gh); + } + static void _gwm_redim(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h) { + if (x < 0) { w += x; x = 0; } + if (y < 0) { h += y; y = 0; } + if (x > gdispGetWidth()-MIN_WIN_WIDTH) x = gdispGetWidth()-MIN_WIN_WIDTH; + if (y > gdispGetHeight()-MIN_WIN_HEIGHT) y = gdispGetHeight()-MIN_WIN_HEIGHT; + if (w < MIN_WIN_WIDTH) { w = MIN_WIN_WIDTH; } + if (h < MIN_WIN_HEIGHT) { h = MIN_WIN_HEIGHT; } + if (x+w > gdispGetWidth()) w = gdispGetWidth() - x; + if (y+h > gdispGetHeight()) h = gdispGetHeight() - y; + gh->x = x; gh->y = y; + gh->width = w; gh->height = h; + } +#endif + +/*----------------------------------------------- + * Class Routines + *-----------------------------------------------*/ + +void _gwinInit(void) { + #if GWIN_NEED_WINDOWMANAGER + gfxQueueASyncInit(&_GWINList); + cwm = &GNullWindowManager; + cwm->vmt->Init(); + #endif +} // Internal routine for use by GWIN components only -// Initialise a window creating it dynamicly if required. -GHandle _gwinInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size, const gwinVMT *vmt) { - coord_t w, h; - - // Check the window size against the screen size - w = gdispGetWidth(); - h = gdispGetHeight(); - if (x < 0) { width += x; x = 0; } - if (y < 0) { height += y; y = 0; } - if (x >= w || y >= h) return 0; - if (x+width > w) width = w - x; - if (y+height > h) height = h - y; - +// Initialise a window creating it dynamically if required. +GHandle _gwindowInit(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size, const gwinVMT *vmt, uint16_t flags) { // Allocate the structure if necessary if (!pgw) { if (!(pgw = (GWindowObject *)gfxAlloc(size))) return 0; - pgw->flags = GWIN_FLG_DYNAMIC; + pgw->flags = flags|GWIN_FLG_DYNAMIC; } else - pgw->flags = 0; + pgw->flags = flags; // Initialise all basic fields pgw->vmt = vmt; - pgw->x = x; - pgw->y = y; - pgw->width = width; - pgw->height = height; pgw->color = defaultFgColor; pgw->bgcolor = defaultBgColor; #if GDISP_NEED_TEXT pgw->font = defaultFont; #endif + + #if GWIN_NEED_WINDOWMANAGER + if (!cwm->vmt->Add(pgw, x, y, width, height)) { + if ((pgw->flags & GWIN_FLG_DYNAMIC)) + gfxFree(pgw); + return 0; + } + #else + _gwm_redim(pgw, x, y, width, height); + if ((pgw->flags & GWIN_FLG_VISIBLE)) + _gwm_vis(pgw); + #endif + return (GHandle)pgw; } -GHandle gwinCreateWindow(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height) { - return _gwinInit(pgw, x, y, width, height, sizeof(GWindowObject), &basegwinVMT); -} +/*----------------------------------------------- + * Routines that affect all windows + *-----------------------------------------------*/ -void gwinDestroy(GHandle gh) { - if (gh->vmt->Destroy) - gh->vmt->Destroy(gh); - - // Clean up the structure - if (gh->flags & GWIN_FLG_DYNAMIC) { - gh->flags = 0; // To be sure, to be sure - gfxFree((void *)gh); +#if GWIN_NEED_WINDOWMANAGER + void gwinSetWindowManager(struct GWindowManager *gwm) { + if (!gwm) + gwm = &GNullWindowManager; + if (cwm != gwm) { + cwm->vmt->DeInit(); + cwm = gwm; + cwm->vmt->Init(); + } } -} - -const char *gwinGetClassName(GHandle gh) { - return gh->vmt->classname; -} +#endif void gwinSetDefaultColor(color_t clr) { defaultFgColor = clr; @@ -88,13 +139,119 @@ void gwinSetDefaultBgColor(color_t bgclr) { void gwinSetDefaultFont(font_t font) { defaultFont = font; } +#endif +/*----------------------------------------------- + * The GWindow Routines + *-----------------------------------------------*/ + +GHandle gwinCreateWindow(GWindowObject *pgw, coord_t x, coord_t y, coord_t width, coord_t height) { + return _gwindowInit(pgw, x, y, width, height, sizeof(GWindowObject), &basegwinVMT, GWIN_FLG_VISIBLE); +} + +void gwinDestroy(GHandle gh) { + // Remove from the window manager + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->Delete(gh); + #endif + + // Class destroy routine + if (gh->vmt->Destroy) + gh->vmt->Destroy(gh); + + // Clean up the structure + if (gh->flags & GWIN_FLG_DYNAMIC) + gfxFree((void *)gh); + + gh->flags = 0; // To be sure, to be sure +} + +const char *gwinGetClassName(GHandle gh) { + return gh->vmt->classname; +} + +void gwinSetVisible(GHandle gh, bool_t visible) { + if (visible) { + if (!(gh->flags & GWIN_FLG_VISIBLE)) { + gh->flags |= GWIN_FLG_VISIBLE; + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->Visible(gh); + #else + _gwm_vis(gh); + #endif + } + } else { + if ((gh->flags & GWIN_FLG_VISIBLE)) { + gh->flags &= ~GWIN_FLG_VISIBLE; + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->Visible(gh); + #endif + } + } +} + +bool_t gwinGetVisible(GHandle gh) { + return (gh->flags & GWIN_FLG_VISIBLE) ? TRUE : FALSE; +} + +void gwinMove(GHandle gh, coord_t x, coord_t y) { + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->Redim(gh, x, y, gh->width, gh->height); + #else + _gwm_redim(gh, x, y, gh->width, gh->height); + #endif +} + +void gwinResize(GHandle gh, coord_t width, coord_t height) { + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->Redim(gh, gh->x, gh->y, width, height); + #else + _gwm_redim(gh, gh->x, gh->y, width, height); + #endif +} + +void gwinSetMinMax(GHandle gh, GWindowMinMax minmax) { + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->MinMax(gh, minmax); + #else + (void) gh; + (void) minmax; + #endif +} + +void gwinRaise(GHandle gh) { + #if GWIN_NEED_WINDOWMANAGER + cwm->vmt->Raise(gh); + #else + if ((gh->flags & GWIN_FLG_VISIBLE)) { + if (gh->vmt->Redraw) { + #if GDISP_NEED_CLIP + gdispSetClip(gh->x, gh->y, gh->width, gh->height); + #endif + gh->vmt->Redraw(gh); + } + } + #endif +} + +GWindowMinMax gwinGetMinMax(GHandle gh) { + if (gh->flags & GWIN_FLG_MINIMIZED) + return GWIN_MINIMIZE; + if (gh->flags & GWIN_FLG_MAXIMIZED) + return GWIN_MAXIMIZE; + return GWIN_NORMAL; +} + +#if GDISP_NEED_TEXT void gwinSetFont(GHandle gh, font_t font) { gh->font = font; } #endif void gwinClear(GHandle gh) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -104,6 +261,9 @@ void gwinClear(GHandle gh) { } void gwinDrawPixel(GHandle gh, coord_t x, coord_t y) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -111,6 +271,9 @@ void gwinDrawPixel(GHandle gh, coord_t x, coord_t y) { } void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -118,6 +281,9 @@ void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1) { } void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -125,6 +291,9 @@ void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { } void gwinFillArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -132,6 +301,9 @@ void gwinFillArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { } 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) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -140,6 +312,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_CIRCLE void gwinDrawCircle(GHandle gh, coord_t x, coord_t y, coord_t radius) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -147,6 +322,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillCircle(GHandle gh, coord_t x, coord_t y, coord_t radius) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -156,6 +334,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_ELLIPSE void gwinDrawEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -163,6 +344,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -172,6 +356,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_ARC void gwinDrawArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -179,6 +366,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -188,6 +378,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_PIXELREAD color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -197,7 +390,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_TEXT void gwinDrawChar(GHandle gh, coord_t x, coord_t y, char c) { - if (!gh->font) return; + if (!((gh->flags & GWIN_FLG_VISIBLE)) || !gh->font) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -205,7 +400,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillChar(GHandle gh, coord_t x, coord_t y, char c) { - if (!gh->font) return; + if (!((gh->flags & GWIN_FLG_VISIBLE)) || !gh->font) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -213,7 +410,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinDrawString(GHandle gh, coord_t x, coord_t y, const char *str) { - if (!gh->font) return; + if (!((gh->flags & GWIN_FLG_VISIBLE)) || !gh->font) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -221,7 +420,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillString(GHandle gh, coord_t x, coord_t y, const char *str) { - if (!gh->font) return; + if (!((gh->flags & GWIN_FLG_VISIBLE)) || !gh->font) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -229,7 +430,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinDrawStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify) { - if (!gh->font) return; + if (!((gh->flags & GWIN_FLG_VISIBLE)) || !gh->font) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -237,7 +440,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify) { - if (!gh->font) return; + if (!((gh->flags & GWIN_FLG_VISIBLE)) || !gh->font) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -247,6 +452,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_CONVEX_POLYGON void gwinDrawPoly(GHandle gh, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -254,6 +462,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } void gwinFillConvexPoly(GHandle gh, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif @@ -263,6 +474,9 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor #if GDISP_NEED_IMAGE gdispImageError gwinImageDraw(GHandle gh, gdispImage *img, coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy) { + if (!((gh->flags & GWIN_FLG_VISIBLE))) + return GDISP_IMAGE_ERR_OK; + #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif diff --git a/src/gwin/gwin.mk b/src/gwin/gwin.mk index 90a8e9b4..fb8fdfd1 100644 --- a/src/gwin/gwin.mk +++ b/src/gwin/gwin.mk @@ -1,5 +1,6 @@ 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 \ diff --git a/src/gwin/gwm.c b/src/gwin/gwm.c new file mode 100644 index 00000000..bc561345 --- /dev/null +++ b/src/gwin/gwm.c @@ -0,0 +1,144 @@ +/* + * 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 + */ + +#include "gfx.h" + +// Used by the NULL window manager +#define MIN_WIN_WIDTH 3 +#define MIN_WIN_HEIGHT 3 + +/*----------------------------------------------- + * The default window manager (GNullWindowManager) + *-----------------------------------------------*/ + +#if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER + +#include "gwin/class_gwin.h" + +/*----------------------------------------------- + * Data + *-----------------------------------------------*/ + +static void WM_Init(void); +static void WM_DeInit(void); +static bool_t WM_Add(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); +static void WM_Delete(GHandle gh); +static void WM_Visible(GHandle gh); +static void WM_Redim(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h); +static void WM_Raise(GHandle gh); +static void WM_MinMax(GHandle gh, GWindowMinMax minmax); + +static const gwmVMT GNullWindowManagerVMT = { + WM_Init, + WM_DeInit, + WM_Add, + WM_Delete, + WM_Visible, + WM_Redim, + WM_Raise, + WM_MinMax, +}; + +const GWindowManager GNullWindowManager = { + &GNullWindowManagerVMT, +}; + +/*----------------------------------------------- + * Window Manager Routines + *-----------------------------------------------*/ + +static void WM_Init(void) { + // We don't need to do anything here. + // A full window manager would move the windows around, add borders etc + + // clear the screen + // cycle through the windows already defined displaying them + // or cut all the window areas out of the screen and clear the remainder +} + +static void WM_DeInit(void) { + // We don't need to do anything here. + // A full window manager would remove any borders etc +} + +static bool_t WM_Add(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h) { + // Put it on the queue + gfxQueueASyncPut(&_GWINList, &gh->wmq); + + // Make sure the size is valid + WM_Redim(gh, x, y, w, h); + + // Display it if it is visible + WM_Visible(gh); + return TRUE; +} + +static void WM_Delete(GHandle gh) { + // A real window manager would make the window invisible + // (and then clear the area underneath) + + // Just remove it from the queue + gfxQueueASyncRemove(&_GWINList, &gh->wmq); +} + +static void WM_Visible(GHandle gh) { + if ((gh->flags & GWIN_FLG_VISIBLE)) { + if (gh->vmt->Redraw) { + #if GDISP_NEED_CLIP + gdispSetClip(gh->x, gh->y, gh->width, gh->height); + #endif + gh->vmt->Redraw(gh); + } else + gwinClear(gh); + // A real window manager would also redraw the borders + } + + // else + // A real window manager would make the window invisible + // (and then clear the area underneath) + +} + +static void WM_Redim(GHandle gh, coord_t x, coord_t y, coord_t w, coord_t h) { + // This is the simplest way of doing it - just clip the the screen + // If it won't fit on the screen move it around until it does. + if (x < 0) { w += x; x = 0; } + if (y < 0) { h += y; y = 0; } + if (x > gdispGetWidth()-MIN_WIN_WIDTH) x = gdispGetWidth()-MIN_WIN_WIDTH; + if (y > gdispGetHeight()-MIN_WIN_HEIGHT) y = gdispGetHeight()-MIN_WIN_HEIGHT; + if (w < MIN_WIN_WIDTH) { w = MIN_WIN_WIDTH; } + if (h < MIN_WIN_HEIGHT) { h = MIN_WIN_HEIGHT; } + if (x+w > gdispGetWidth()) w = gdispGetWidth() - x; + if (y+h > gdispGetHeight()) h = gdispGetHeight() - y; + gh->x = x; gh->y = y; + gh->width = w; gh->height = h; +} + +static void WM_MinMax(GHandle gh, GWindowMinMax minmax) { + (void)gh; (void) minmax; + // We don't support minimising, maximising or restoring +} + +static void WM_Raise(GHandle gh) { + // Take it off the list and then put it back on top + // The order of the list then reflects the z-order. + gfxQueueASyncRemove(&_GWINList, &gh->wmq); + gfxQueueASyncPut(&_GWINList, &gh->wmq); + + // Redraw the window + if ((gh->flags & GWIN_FLG_VISIBLE)) { + if (gh->vmt->Redraw) { + #if GDISP_NEED_CLIP + gdispSetClip(gh->x, gh->y, gh->width, gh->height); + #endif + gh->vmt->Redraw(gh); + } + } +} + +#endif /* GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER */ +/** @} */ diff --git a/src/gwin/slider.c b/src/gwin/slider.c index a0289d3d..1a1855a9 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -35,6 +35,7 @@ static const gwidgetVMT sliderVMT = { { "Slider", // The classname _gwidgetDestroy, // The destroy routine + _gwidgetRedraw, // The redraw routine 0, // The after-clear routine }, gwinSliderDraw_Std, // The default drawing routine @@ -101,7 +102,7 @@ static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) { if (x < 0 || x >= gh->width || y < 0 || y >= gh->height) { // No - restore the slider ResetDisplayPos(gsw); - gwinDraw(gh); + _gwidgetRedraw(gh); return; } #endif @@ -124,7 +125,7 @@ static void MouseUp(GWidgetObject *gw, coord_t x, coord_t y) { } ResetDisplayPos(gsw); - gwinDraw(gh); + _gwidgetRedraw(gh); // Generate the event SendSliderEvent(gw); @@ -154,7 +155,7 @@ static void MouseMove(GWidgetObject *gw, coord_t x, coord_t y) { } // Update the display - gwinDraw(&gw->g); + _gwidgetRedraw(&gw->g); #undef gsw }