From 15baf7a5c72cace67403e939c90140a4f35f9f22 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 8 May 2014 13:20:12 +0200 Subject: Bug fix - GWIN_NEED_PROGRESSBAR not set to FALSE by default --- src/gwin/sys_options.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/gwin') diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h index aa296026..34c4f074 100644 --- a/src/gwin/sys_options.h +++ b/src/gwin/sys_options.h @@ -57,6 +57,13 @@ #ifndef GWIN_NEED_BUTTON #define GWIN_NEED_BUTTON FALSE #endif + /** + * @brief Should progressbar functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_PROGRESSBAR + #define GWIN_NEED_PROGRESSBAR FALSE + #endif /** * @brief Should slider functions be included. * @details Defaults to FALSE -- cgit v1.2.3 From 5979acc7f6f1b2d2c76ff80c651b78516335b567 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 8 May 2014 14:37:13 +0200 Subject: Introducing GWIN_PROGRESSBAR_AUTO for the automatic incremental function of the progressbar widget --- src/gwin/progressbar.c | 92 ++++++++++++++++++++++++-------------------------- src/gwin/progressbar.h | 54 +++++++++++++++-------------- src/gwin/sys_options.h | 7 ++++ src/gwin/sys_rules.h | 5 +++ 4 files changed, 85 insertions(+), 73 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/progressbar.c b/src/gwin/progressbar.c index c64e2119..0ad7a230 100644 --- a/src/gwin/progressbar.c +++ b/src/gwin/progressbar.c @@ -84,6 +84,10 @@ GHandle gwinGProgressbarCreate(GDisplay *g, GProgressbarObject *gs, const GWidge gs->pos = 0; gs->delay = 0; + #if GWIN_PROGRESSBAR_AUTO + gtimerInit(&gs->gt); + #endif + ResetDisplayPos(gs); gwinSetVisible((GHandle)gs, pInit->g.show); @@ -179,54 +183,48 @@ void gwinProgressbarDecrement(GHandle gh) { #undef gsw } -// used by gwinProgressbarStart(); -static void _progressbarCallback(void *param) { - #define gsw ((GProgressbarObject *)gh) - GHandle gh = (GHandle)param; - - if (gh->vmt != (gwinVMT *)&progressbarVMT) - return; - - gwinProgressbarIncrement(gh); - - if (gsw->pos < gsw->max) +#if GWIN_PROGRESSBAR_AUTO + // used by gwinProgressbarStart(); + static void _progressbarCallback(void *param) { + #define gsw ((GProgressbarObject *)gh) + GHandle gh = (GHandle)param; + + if (gh->vmt != (gwinVMT *)&progressbarVMT) + return; + + gwinProgressbarIncrement(gh); + + if (gsw->pos < gsw->max) + gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay); + + #undef gsw + } + + void gwinProgressbarStart(GHandle gh, delaytime_t delay) { + #define gsw ((GProgressbarObject *)gh) + + if (gh->vmt != (gwinVMT *)&progressbarVMT) + return; + + gsw->delay = delay; + + gtimerInit(&(gsw->gt)); gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay); - - #undef gsw -} - -void gwinProgressbarStart(GHandle gh, delaytime_t delay) { - #define gsw ((GProgressbarObject *)gh) - - if (gh->vmt != (gwinVMT *)&progressbarVMT) - return; - - gsw->delay = delay; - - gtimerInit(&(gsw->gt)); - gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay); - - #if 0 - // if this is not made, the progressbar will not start when it's already visible - if (gsw->w.g.flags & GWIN_FLG_VISIBLE) { - gwinSetVisible(gh, FALSE); - gwinSetVisible(gh, TRUE); - } - #endif - - #undef gsw -} - -void gwinProgressbarStop(GHandle gh) { - #define gsw ((GProgressbarObject *)gh) - - if (gh->vmt != (gwinVMT *)&progressbarVMT) - return; - - gtimerStop(&(gsw->gt)); - - #undef gsw -} + + #undef gsw + } + + void gwinProgressbarStop(GHandle gh) { + #define gsw ((GProgressbarObject *)gh) + + if (gh->vmt != (gwinVMT *)&progressbarVMT) + return; + + gtimerStop(&(gsw->gt)); + + #undef gsw + } +#endif /* GWIN_PROGRESSBAR_AUTO */ /*---------------------------------------------------------- * Custom Draw Routines diff --git a/src/gwin/progressbar.h b/src/gwin/progressbar.h index fcf76b12..5253ba0c 100644 --- a/src/gwin/progressbar.h +++ b/src/gwin/progressbar.h @@ -30,7 +30,7 @@ typedef struct GProgressbarObject { int max; int res; int pos; - #if GFX_USE_GTIMER + #if GWIN_PROGRESSBAR_AUTO GTimer gt; delaytime_t delay; #endif @@ -147,31 +147,33 @@ void gwinProgressbarDecrement(GHandle gh); */ #define gwinProgressbarReset(gh) gwinProgressbarSetPosition(gh, ((GProgressbarObject *)(gh))->min) -/** - * @brief Automatically increments the progress bar - * - * @note The delay is generated using the GTIMER module which is based on software/virtual timer. - * Therefore, the delay is totally unprecise. - * - * @note The progressbar incrementation starts at the current level. It is not reset to the minimum value. - * - * @note An event is generated once the maximum value has been reached (ToDo) - * - * @param[in] gh The window handle (must be a progressbar window) - * @param[in] delay The incrementation delay (in milliseconds) - * - * @api - */ -void gwinProgressbarStart(GHandle gh, delaytime_t delay); - -/** - * @brief Stop the timer which is started by @p gwinProgressbarStart() - * - * @param[in] gh The window handle (must be a progressbar window) - * - * @api - */ -void gwinProgressbarStop(GHandle gh); +#if GWIN_PROGRESSBAR_AUTO + /** + * @brief Automatically increments the progress bar + * + * @note The delay is generated using the GTIMER module which is based on software/virtual timer. + * Therefore, the delay is totally unprecise. + * + * @note The progressbar incrementation starts at the current level. It is not reset to the minimum value. + * + * @note An event is generated once the maximum value has been reached (ToDo) + * + * @param[in] gh The window handle (must be a progressbar window) + * @param[in] delay The incrementation delay (in milliseconds) + * + * @api + */ + void gwinProgressbarStart(GHandle gh, delaytime_t delay); + + /** + * @brief Stop the timer which is started by @p gwinProgressbarStart() + * + * @param[in] gh The window handle (must be a progressbar window) + * + * @api + */ + void gwinProgressbarStop(GHandle gh); +#endif /* GWIN_PROGRESSBAR_AUTO */ /** * @brief Some custom progressbar drawing routines diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h index 34c4f074..41bc551f 100644 --- a/src/gwin/sys_options.h +++ b/src/gwin/sys_options.h @@ -214,6 +214,13 @@ #ifndef GWIN_NEED_IMAGE_ANIMATION #define GWIN_NEED_IMAGE_ANIMATION FALSE #endif + /** + * @brief Enable the API to automatically increment the progressbar over time + * @details Defaults to FALSE + */ + #ifndef GWIN_PROGRESSBAR_AUTO + #define GWIN_PROGRESSBAR_AUTO FALSE + #endif /** @} */ #endif /* _GWIN_OPTIONS_H */ diff --git a/src/gwin/sys_rules.h b/src/gwin/sys_rules.h index 77f029f0..30dac1bb 100644 --- a/src/gwin/sys_rules.h +++ b/src/gwin/sys_rules.h @@ -93,6 +93,11 @@ #endif #if GWIN_NEED_GRAPH #endif + #if GWIN_PROGRESSBAR_AUTO + #if !GFX_USE_GTIMER + #error "GWIN: GFX_USE_GTIMER is required if GWIN_PROGRESSBAR_AUTO is TRUE." + #endif + #endif #endif #endif /* _GWIN_RULES_H */ -- cgit v1.2.3 From a9ead70e09ab3cc227b72f3dcd56d03b24f3b53d Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 9 May 2014 10:39:10 +0200 Subject: Imagebox widget bug fix that could cause gwinImageOpenFile() to crash --- src/gwin/gimage.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gwin') diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c index fdc6df84..44ba785a 100644 --- a/src/gwin/gimage.c +++ b/src/gwin/gimage.c @@ -128,6 +128,7 @@ GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { // Ensure the gdispImageIsOpen() gives valid results gobj->image.type = 0; + gobj->image.fns = 0; // Initialise the timer #if GWIN_NEED_IMAGE_ANIMATION -- cgit v1.2.3 From 52262dbafe3709528a0832f159f6f2bd55105cc1 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 9 May 2014 10:58:23 +0200 Subject: progressbar widget cleanup --- src/gwin/progressbar.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gwin') diff --git a/src/gwin/progressbar.c b/src/gwin/progressbar.c index 0ad7a230..524a5346 100644 --- a/src/gwin/progressbar.c +++ b/src/gwin/progressbar.c @@ -208,7 +208,6 @@ void gwinProgressbarDecrement(GHandle gh) { gsw->delay = delay; - gtimerInit(&(gsw->gt)); gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay); #undef gsw -- cgit v1.2.3 From 82a3f8491f6ec3b6bbb161167fc435acbfacc3a1 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 9 May 2014 12:07:08 +0200 Subject: Renaming image widget files to appropriate name --- src/gwin/gimage.c | 175 --------------------------------------------------- src/gwin/image.h | 127 ------------------------------------- src/gwin/imagebox.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/gwin/imagebox.h | 127 +++++++++++++++++++++++++++++++++++++ src/gwin/sys_defs.h | 2 +- src/gwin/sys_make.mk | 2 +- 6 files changed, 304 insertions(+), 304 deletions(-) delete mode 100644 src/gwin/gimage.c delete mode 100644 src/gwin/image.h create mode 100644 src/gwin/imagebox.c create mode 100644 src/gwin/imagebox.h (limited to 'src/gwin') diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c deleted file mode 100644 index 44ba785a..00000000 --- a/src/gwin/gimage.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gwin/gimage.c - * @brief GWIN sub-system image code. - */ - -#include "gfx.h" - -#if GFX_USE_GWIN && GWIN_NEED_IMAGE - -#include "src/gwin/class_gwin.h" - -#define widget(gh) ((GImageObject *)gh) - -static void _destroy(GWindowObject *gh) { - if (gdispImageIsOpen(&widget(gh)->image)) - gdispImageClose(&widget(gh)->image); -} - -#if GWIN_NEED_IMAGE_ANIMATION - static void _redraw(GHandle gh); - - static void _timer(void *gh) { - // We need to re-test the visibility in case it has been made invisible since the last frame. - if ((((GHandle)gh)->flags & GWIN_FLG_VISIBLE)) - _redraw((GHandle)gh); - } -#endif - -static void _redraw(GHandle gh) { - coord_t x, y, w, h, dx, dy; - color_t bg; - #if GWIN_NEED_IMAGE_ANIMATION - delaytime_t delay; - #endif - - // The default display area - dx = 0; - dy = 0; - x = gh->x; - y = gh->y; - w = gh->width; - h = gh->height; - bg = gwinGetDefaultBgColor(); - - // If the image isn't open just clear the area - if (!gdispImageIsOpen(&widget(gh)->image)) { - gdispGFillArea(gh->display, x, y, w, h, bg); - return; - } - - // Center horizontally if the area is larger than the image - if (widget(gh)->image.width < w) { - w = widget(gh)->image.width; - dx = (gh->width-w)/2; - x += dx; - if (dx) - gdispGFillArea(gh->display, gh->x, y, dx, h, bg); - gdispGFillArea(gh->display, x+w, y, gh->width-dx-w, h, bg); - dx = 0; - } - - // Center image horizontally if the area is smaller than the image - else if (widget(gh)->image.width > w) { - dx = (widget(gh)->image.width - w)/2; - } - - // Center vertically if the area is larger than the image - if (widget(gh)->image.height < h) { - h = widget(gh)->image.height; - dy = (gh->height-h)/2; - y += dy; - if (dy) - gdispGFillArea(gh->display, x, gh->y, w, dy, bg); - gdispGFillArea(gh->display, x, y+h, w, gh->height-dy-h, bg); - dy = 0; - } - - // Center image vertically if the area is smaller than the image - else if (widget(gh)->image.height > h) { - dy = (widget(gh)->image.height - h)/2; - } - - // Reset the background color in case it has changed - gdispImageSetBgColor(&widget(gh)->image, bg); - - // Display the image - gdispGImageDraw(gh->display, &widget(gh)->image, x, y, w, h, dx, dy); - - #if GWIN_NEED_IMAGE_ANIMATION - // read the delay for the next frame - delay = gdispImageNext(&widget((GHandle)gh)->image); - - // Wait for that delay if required - switch(delay) { - case TIME_INFINITE: - // Everything is done - break; - case TIME_IMMEDIATE: - // We can't allow a continuous loop here as it would lock the system up so we delay for the minimum period - delay = 1; - // Fall through - default: - // Start the timer to draw the next frame of the animation - gtimerStart(&widget((GHandle)gh)->timer, _timer, (void*)gh, FALSE, delay); - break; - } - #endif -} - -static const gwinVMT imageVMT = { - "Image", // The class name - sizeof(GImageObject), // The object size - _destroy, // The destroy routine - _redraw, // The redraw routine - 0, // The after-clear routine -}; - -GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { - if (!(gobj = (GImageObject *)_gwindowCreate(g, &gobj->g, pInit, &imageVMT, 0))) - return 0; - - // Ensure the gdispImageIsOpen() gives valid results - gobj->image.type = 0; - gobj->image.fns = 0; - - // Initialise the timer - #if GWIN_NEED_IMAGE_ANIMATION - gtimerInit(&gobj->timer); - #endif - - gwinSetVisible((GHandle)gobj, pInit->show); - - return (GHandle)gobj; -} - -bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { - // is it a valid handle? - if (gh->vmt != (gwinVMT *)&imageVMT) - return FALSE; - - if (gdispImageIsOpen(&widget(gh)->image)) - gdispImageClose(&widget(gh)->image); - - if ((gdispImageOpenGFile(&widget(gh)->image, f) & GDISP_IMAGE_ERR_UNRECOVERABLE)) - return FALSE; - - if ((gh->flags & GWIN_FLG_VISIBLE)) { - // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw - // but we put it in for safety anyway - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - _redraw(gh); - } - - return TRUE; -} - -gdispImageError gwinImageCache(GHandle gh) { - // is it a valid handle? - if (gh->vmt != (gwinVMT *)&imageVMT) - return GDISP_IMAGE_ERR_BADFORMAT; - - return gdispImageCache(&widget(gh)->image); -} - -#endif // GFX_USE_GWIN && GWIN_NEED_IMAGE -/** @} */ diff --git a/src/gwin/image.h b/src/gwin/image.h deleted file mode 100644 index fdaabc92..00000000 --- a/src/gwin/image.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gwin/image.h - * @brief GWIN image widget header file. - * - * @defgroup Image Image - * @ingroup GWIN - * - * @details GWIN allos it to create an image widget. The widget - * takes no user input. - * - * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h - * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h - * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h - * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h - * @pre At least one image type must be enabled in your gfxconf.h - * - * @{ - */ - -#ifndef _GWIN_IMAGE_H -#define _GWIN_IMAGE_H - -// This file is included within "gwin/gwin.h" - -// An image window -typedef struct GImageObject { - GWindowObject g; - gdispImage image; // The image itself - #if GWIN_NEED_IMAGE_ANIMATION - GTimer timer; // Timer used for animated images - #endif -} GImageObject; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Create an image widget. - * @details Display's a picture. - * @return NULL if there is no resultant drawing area, otherwise the widget handle. - * - * @param[in] g The GDisplay to display this window on - * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. - * @param[in] pInit The initialization parameters to use. - * - * @note The default background color gets set to the current default one. - * @note An image window knows how to redraw. - * - * @api - */ -GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); -#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) - -/** - * @brief Opens the image using a GFILE - * @return TRUE if the image can be opened - * - * @param[in] gh The widget (must be an image widget) - * @param[in] f The open (for reading) GFILE to use - * - * @api - */ -bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); - -/** - * @brief Opens the image using the specified filename - * @return TRUE if the open succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] filename The filename to open - * - * @api - */ -#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) - - /** - * @brief Sets the input routines that support reading the image from memory - * in RAM or flash. - * @pre GFILE_NEED_MEMFS must be TRUE - * @return TRUE if the IO open function succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] ptr A pointer to the image in RAM or Flash - * - * @api - */ -#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) - -/** - * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). - * @return TRUE if the IO open function succeeds - * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE - * - * @param[in] gh The widget (must be an image widget) - * @param[in] streamPtr A pointer to the (open) BaseFileStream object. - * - * @api - */ -#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) - -/** - * @brief Cache the image. - * @details Decodes and caches the current frame into RAM. - * - * @param[in] gh The widget (must be an image widget) - * - * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. - * - * @api - */ -gdispImageError gwinImageCache(GHandle gh); - -#ifdef __cplusplus -} -#endif - -#endif // _GWIN_IMAGE_H -/** @} */ - diff --git a/src/gwin/imagebox.c b/src/gwin/imagebox.c new file mode 100644 index 00000000..44ba785a --- /dev/null +++ b/src/gwin/imagebox.c @@ -0,0 +1,175 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/gimage.c + * @brief GWIN sub-system image code. + */ + +#include "gfx.h" + +#if GFX_USE_GWIN && GWIN_NEED_IMAGE + +#include "src/gwin/class_gwin.h" + +#define widget(gh) ((GImageObject *)gh) + +static void _destroy(GWindowObject *gh) { + if (gdispImageIsOpen(&widget(gh)->image)) + gdispImageClose(&widget(gh)->image); +} + +#if GWIN_NEED_IMAGE_ANIMATION + static void _redraw(GHandle gh); + + static void _timer(void *gh) { + // We need to re-test the visibility in case it has been made invisible since the last frame. + if ((((GHandle)gh)->flags & GWIN_FLG_VISIBLE)) + _redraw((GHandle)gh); + } +#endif + +static void _redraw(GHandle gh) { + coord_t x, y, w, h, dx, dy; + color_t bg; + #if GWIN_NEED_IMAGE_ANIMATION + delaytime_t delay; + #endif + + // The default display area + dx = 0; + dy = 0; + x = gh->x; + y = gh->y; + w = gh->width; + h = gh->height; + bg = gwinGetDefaultBgColor(); + + // If the image isn't open just clear the area + if (!gdispImageIsOpen(&widget(gh)->image)) { + gdispGFillArea(gh->display, x, y, w, h, bg); + return; + } + + // Center horizontally if the area is larger than the image + if (widget(gh)->image.width < w) { + w = widget(gh)->image.width; + dx = (gh->width-w)/2; + x += dx; + if (dx) + gdispGFillArea(gh->display, gh->x, y, dx, h, bg); + gdispGFillArea(gh->display, x+w, y, gh->width-dx-w, h, bg); + dx = 0; + } + + // Center image horizontally if the area is smaller than the image + else if (widget(gh)->image.width > w) { + dx = (widget(gh)->image.width - w)/2; + } + + // Center vertically if the area is larger than the image + if (widget(gh)->image.height < h) { + h = widget(gh)->image.height; + dy = (gh->height-h)/2; + y += dy; + if (dy) + gdispGFillArea(gh->display, x, gh->y, w, dy, bg); + gdispGFillArea(gh->display, x, y+h, w, gh->height-dy-h, bg); + dy = 0; + } + + // Center image vertically if the area is smaller than the image + else if (widget(gh)->image.height > h) { + dy = (widget(gh)->image.height - h)/2; + } + + // Reset the background color in case it has changed + gdispImageSetBgColor(&widget(gh)->image, bg); + + // Display the image + gdispGImageDraw(gh->display, &widget(gh)->image, x, y, w, h, dx, dy); + + #if GWIN_NEED_IMAGE_ANIMATION + // read the delay for the next frame + delay = gdispImageNext(&widget((GHandle)gh)->image); + + // Wait for that delay if required + switch(delay) { + case TIME_INFINITE: + // Everything is done + break; + case TIME_IMMEDIATE: + // We can't allow a continuous loop here as it would lock the system up so we delay for the minimum period + delay = 1; + // Fall through + default: + // Start the timer to draw the next frame of the animation + gtimerStart(&widget((GHandle)gh)->timer, _timer, (void*)gh, FALSE, delay); + break; + } + #endif +} + +static const gwinVMT imageVMT = { + "Image", // The class name + sizeof(GImageObject), // The object size + _destroy, // The destroy routine + _redraw, // The redraw routine + 0, // The after-clear routine +}; + +GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { + if (!(gobj = (GImageObject *)_gwindowCreate(g, &gobj->g, pInit, &imageVMT, 0))) + return 0; + + // Ensure the gdispImageIsOpen() gives valid results + gobj->image.type = 0; + gobj->image.fns = 0; + + // Initialise the timer + #if GWIN_NEED_IMAGE_ANIMATION + gtimerInit(&gobj->timer); + #endif + + gwinSetVisible((GHandle)gobj, pInit->show); + + return (GHandle)gobj; +} + +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&imageVMT) + return FALSE; + + if (gdispImageIsOpen(&widget(gh)->image)) + gdispImageClose(&widget(gh)->image); + + if ((gdispImageOpenGFile(&widget(gh)->image, f) & GDISP_IMAGE_ERR_UNRECOVERABLE)) + return FALSE; + + if ((gh->flags & GWIN_FLG_VISIBLE)) { + // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw + // but we put it in for safety anyway + #if GDISP_NEED_CLIP + gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); + #endif + _redraw(gh); + } + + return TRUE; +} + +gdispImageError gwinImageCache(GHandle gh) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&imageVMT) + return GDISP_IMAGE_ERR_BADFORMAT; + + return gdispImageCache(&widget(gh)->image); +} + +#endif // GFX_USE_GWIN && GWIN_NEED_IMAGE +/** @} */ diff --git a/src/gwin/imagebox.h b/src/gwin/imagebox.h new file mode 100644 index 00000000..fdaabc92 --- /dev/null +++ b/src/gwin/imagebox.h @@ -0,0 +1,127 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/image.h + * @brief GWIN image widget header file. + * + * @defgroup Image Image + * @ingroup GWIN + * + * @details GWIN allos it to create an image widget. The widget + * takes no user input. + * + * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre At least one image type must be enabled in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_IMAGE_H +#define _GWIN_IMAGE_H + +// This file is included within "gwin/gwin.h" + +// An image window +typedef struct GImageObject { + GWindowObject g; + gdispImage image; // The image itself + #if GWIN_NEED_IMAGE_ANIMATION + GTimer timer; // Timer used for animated images + #endif +} GImageObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create an image widget. + * @details Display's a picture. + * @return NULL if there is no resultant drawing area, otherwise the widget handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use. + * + * @note The default background color gets set to the current default one. + * @note An image window knows how to redraw. + * + * @api + */ +GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); +#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) + +/** + * @brief Opens the image using a GFILE + * @return TRUE if the image can be opened + * + * @param[in] gh The widget (must be an image widget) + * @param[in] f The open (for reading) GFILE to use + * + * @api + */ +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); + +/** + * @brief Opens the image using the specified filename + * @return TRUE if the open succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] filename The filename to open + * + * @api + */ +#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) + + /** + * @brief Sets the input routines that support reading the image from memory + * in RAM or flash. + * @pre GFILE_NEED_MEMFS must be TRUE + * @return TRUE if the IO open function succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] ptr A pointer to the image in RAM or Flash + * + * @api + */ +#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) + +/** + * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). + * @return TRUE if the IO open function succeeds + * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE + * + * @param[in] gh The widget (must be an image widget) + * @param[in] streamPtr A pointer to the (open) BaseFileStream object. + * + * @api + */ +#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) + +/** + * @brief Cache the image. + * @details Decodes and caches the current frame into RAM. + * + * @param[in] gh The widget (must be an image widget) + * + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @api + */ +gdispImageError gwinImageCache(GHandle gh); + +#ifdef __cplusplus +} +#endif + +#endif // _GWIN_IMAGE_H +/** @} */ + diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index f4e1c2f7..53ed016b 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -874,7 +874,7 @@ extern "C" { #endif #if GWIN_NEED_IMAGE || defined(__DOXYGEN__) - #include "src/gwin/image.h" + #include "src/gwin/imagebox.h" #endif #endif /* GFX_USE_GWIN */ diff --git a/src/gwin/sys_make.mk b/src/gwin/sys_make.mk index 4c670ea2..1e2404e6 100644 --- a/src/gwin/sys_make.mk +++ b/src/gwin/sys_make.mk @@ -6,7 +6,7 @@ GFXSRC += $(GFXLIB)/src/gwin/gwin.c \ $(GFXLIB)/src/gwin/button.c \ $(GFXLIB)/src/gwin/slider.c \ $(GFXLIB)/src/gwin/checkbox.c \ - $(GFXLIB)/src/gwin/gimage.c \ + $(GFXLIB)/src/gwin/imagebox.c \ $(GFXLIB)/src/gwin/label.c \ $(GFXLIB)/src/gwin/radio.c \ $(GFXLIB)/src/gwin/list.c \ -- cgit v1.2.3 From ec09292542874ee8290f460413afef0adf789039 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 9 May 2014 12:20:32 +0200 Subject: Revert "Renaming image widget files to appropriate name" This reverts commit 82a3f8491f6ec3b6bbb161167fc435acbfacc3a1. --- src/gwin/gimage.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/gwin/image.h | 127 +++++++++++++++++++++++++++++++++++++ src/gwin/imagebox.c | 175 --------------------------------------------------- src/gwin/imagebox.h | 127 ------------------------------------- src/gwin/sys_defs.h | 2 +- src/gwin/sys_make.mk | 2 +- 6 files changed, 304 insertions(+), 304 deletions(-) create mode 100644 src/gwin/gimage.c create mode 100644 src/gwin/image.h delete mode 100644 src/gwin/imagebox.c delete mode 100644 src/gwin/imagebox.h (limited to 'src/gwin') diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c new file mode 100644 index 00000000..44ba785a --- /dev/null +++ b/src/gwin/gimage.c @@ -0,0 +1,175 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/gimage.c + * @brief GWIN sub-system image code. + */ + +#include "gfx.h" + +#if GFX_USE_GWIN && GWIN_NEED_IMAGE + +#include "src/gwin/class_gwin.h" + +#define widget(gh) ((GImageObject *)gh) + +static void _destroy(GWindowObject *gh) { + if (gdispImageIsOpen(&widget(gh)->image)) + gdispImageClose(&widget(gh)->image); +} + +#if GWIN_NEED_IMAGE_ANIMATION + static void _redraw(GHandle gh); + + static void _timer(void *gh) { + // We need to re-test the visibility in case it has been made invisible since the last frame. + if ((((GHandle)gh)->flags & GWIN_FLG_VISIBLE)) + _redraw((GHandle)gh); + } +#endif + +static void _redraw(GHandle gh) { + coord_t x, y, w, h, dx, dy; + color_t bg; + #if GWIN_NEED_IMAGE_ANIMATION + delaytime_t delay; + #endif + + // The default display area + dx = 0; + dy = 0; + x = gh->x; + y = gh->y; + w = gh->width; + h = gh->height; + bg = gwinGetDefaultBgColor(); + + // If the image isn't open just clear the area + if (!gdispImageIsOpen(&widget(gh)->image)) { + gdispGFillArea(gh->display, x, y, w, h, bg); + return; + } + + // Center horizontally if the area is larger than the image + if (widget(gh)->image.width < w) { + w = widget(gh)->image.width; + dx = (gh->width-w)/2; + x += dx; + if (dx) + gdispGFillArea(gh->display, gh->x, y, dx, h, bg); + gdispGFillArea(gh->display, x+w, y, gh->width-dx-w, h, bg); + dx = 0; + } + + // Center image horizontally if the area is smaller than the image + else if (widget(gh)->image.width > w) { + dx = (widget(gh)->image.width - w)/2; + } + + // Center vertically if the area is larger than the image + if (widget(gh)->image.height < h) { + h = widget(gh)->image.height; + dy = (gh->height-h)/2; + y += dy; + if (dy) + gdispGFillArea(gh->display, x, gh->y, w, dy, bg); + gdispGFillArea(gh->display, x, y+h, w, gh->height-dy-h, bg); + dy = 0; + } + + // Center image vertically if the area is smaller than the image + else if (widget(gh)->image.height > h) { + dy = (widget(gh)->image.height - h)/2; + } + + // Reset the background color in case it has changed + gdispImageSetBgColor(&widget(gh)->image, bg); + + // Display the image + gdispGImageDraw(gh->display, &widget(gh)->image, x, y, w, h, dx, dy); + + #if GWIN_NEED_IMAGE_ANIMATION + // read the delay for the next frame + delay = gdispImageNext(&widget((GHandle)gh)->image); + + // Wait for that delay if required + switch(delay) { + case TIME_INFINITE: + // Everything is done + break; + case TIME_IMMEDIATE: + // We can't allow a continuous loop here as it would lock the system up so we delay for the minimum period + delay = 1; + // Fall through + default: + // Start the timer to draw the next frame of the animation + gtimerStart(&widget((GHandle)gh)->timer, _timer, (void*)gh, FALSE, delay); + break; + } + #endif +} + +static const gwinVMT imageVMT = { + "Image", // The class name + sizeof(GImageObject), // The object size + _destroy, // The destroy routine + _redraw, // The redraw routine + 0, // The after-clear routine +}; + +GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { + if (!(gobj = (GImageObject *)_gwindowCreate(g, &gobj->g, pInit, &imageVMT, 0))) + return 0; + + // Ensure the gdispImageIsOpen() gives valid results + gobj->image.type = 0; + gobj->image.fns = 0; + + // Initialise the timer + #if GWIN_NEED_IMAGE_ANIMATION + gtimerInit(&gobj->timer); + #endif + + gwinSetVisible((GHandle)gobj, pInit->show); + + return (GHandle)gobj; +} + +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&imageVMT) + return FALSE; + + if (gdispImageIsOpen(&widget(gh)->image)) + gdispImageClose(&widget(gh)->image); + + if ((gdispImageOpenGFile(&widget(gh)->image, f) & GDISP_IMAGE_ERR_UNRECOVERABLE)) + return FALSE; + + if ((gh->flags & GWIN_FLG_VISIBLE)) { + // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw + // but we put it in for safety anyway + #if GDISP_NEED_CLIP + gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); + #endif + _redraw(gh); + } + + return TRUE; +} + +gdispImageError gwinImageCache(GHandle gh) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&imageVMT) + return GDISP_IMAGE_ERR_BADFORMAT; + + return gdispImageCache(&widget(gh)->image); +} + +#endif // GFX_USE_GWIN && GWIN_NEED_IMAGE +/** @} */ diff --git a/src/gwin/image.h b/src/gwin/image.h new file mode 100644 index 00000000..fdaabc92 --- /dev/null +++ b/src/gwin/image.h @@ -0,0 +1,127 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/image.h + * @brief GWIN image widget header file. + * + * @defgroup Image Image + * @ingroup GWIN + * + * @details GWIN allos it to create an image widget. The widget + * takes no user input. + * + * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre At least one image type must be enabled in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_IMAGE_H +#define _GWIN_IMAGE_H + +// This file is included within "gwin/gwin.h" + +// An image window +typedef struct GImageObject { + GWindowObject g; + gdispImage image; // The image itself + #if GWIN_NEED_IMAGE_ANIMATION + GTimer timer; // Timer used for animated images + #endif +} GImageObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create an image widget. + * @details Display's a picture. + * @return NULL if there is no resultant drawing area, otherwise the widget handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use. + * + * @note The default background color gets set to the current default one. + * @note An image window knows how to redraw. + * + * @api + */ +GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); +#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) + +/** + * @brief Opens the image using a GFILE + * @return TRUE if the image can be opened + * + * @param[in] gh The widget (must be an image widget) + * @param[in] f The open (for reading) GFILE to use + * + * @api + */ +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); + +/** + * @brief Opens the image using the specified filename + * @return TRUE if the open succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] filename The filename to open + * + * @api + */ +#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) + + /** + * @brief Sets the input routines that support reading the image from memory + * in RAM or flash. + * @pre GFILE_NEED_MEMFS must be TRUE + * @return TRUE if the IO open function succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] ptr A pointer to the image in RAM or Flash + * + * @api + */ +#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) + +/** + * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). + * @return TRUE if the IO open function succeeds + * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE + * + * @param[in] gh The widget (must be an image widget) + * @param[in] streamPtr A pointer to the (open) BaseFileStream object. + * + * @api + */ +#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) + +/** + * @brief Cache the image. + * @details Decodes and caches the current frame into RAM. + * + * @param[in] gh The widget (must be an image widget) + * + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @api + */ +gdispImageError gwinImageCache(GHandle gh); + +#ifdef __cplusplus +} +#endif + +#endif // _GWIN_IMAGE_H +/** @} */ + diff --git a/src/gwin/imagebox.c b/src/gwin/imagebox.c deleted file mode 100644 index 44ba785a..00000000 --- a/src/gwin/imagebox.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gwin/gimage.c - * @brief GWIN sub-system image code. - */ - -#include "gfx.h" - -#if GFX_USE_GWIN && GWIN_NEED_IMAGE - -#include "src/gwin/class_gwin.h" - -#define widget(gh) ((GImageObject *)gh) - -static void _destroy(GWindowObject *gh) { - if (gdispImageIsOpen(&widget(gh)->image)) - gdispImageClose(&widget(gh)->image); -} - -#if GWIN_NEED_IMAGE_ANIMATION - static void _redraw(GHandle gh); - - static void _timer(void *gh) { - // We need to re-test the visibility in case it has been made invisible since the last frame. - if ((((GHandle)gh)->flags & GWIN_FLG_VISIBLE)) - _redraw((GHandle)gh); - } -#endif - -static void _redraw(GHandle gh) { - coord_t x, y, w, h, dx, dy; - color_t bg; - #if GWIN_NEED_IMAGE_ANIMATION - delaytime_t delay; - #endif - - // The default display area - dx = 0; - dy = 0; - x = gh->x; - y = gh->y; - w = gh->width; - h = gh->height; - bg = gwinGetDefaultBgColor(); - - // If the image isn't open just clear the area - if (!gdispImageIsOpen(&widget(gh)->image)) { - gdispGFillArea(gh->display, x, y, w, h, bg); - return; - } - - // Center horizontally if the area is larger than the image - if (widget(gh)->image.width < w) { - w = widget(gh)->image.width; - dx = (gh->width-w)/2; - x += dx; - if (dx) - gdispGFillArea(gh->display, gh->x, y, dx, h, bg); - gdispGFillArea(gh->display, x+w, y, gh->width-dx-w, h, bg); - dx = 0; - } - - // Center image horizontally if the area is smaller than the image - else if (widget(gh)->image.width > w) { - dx = (widget(gh)->image.width - w)/2; - } - - // Center vertically if the area is larger than the image - if (widget(gh)->image.height < h) { - h = widget(gh)->image.height; - dy = (gh->height-h)/2; - y += dy; - if (dy) - gdispGFillArea(gh->display, x, gh->y, w, dy, bg); - gdispGFillArea(gh->display, x, y+h, w, gh->height-dy-h, bg); - dy = 0; - } - - // Center image vertically if the area is smaller than the image - else if (widget(gh)->image.height > h) { - dy = (widget(gh)->image.height - h)/2; - } - - // Reset the background color in case it has changed - gdispImageSetBgColor(&widget(gh)->image, bg); - - // Display the image - gdispGImageDraw(gh->display, &widget(gh)->image, x, y, w, h, dx, dy); - - #if GWIN_NEED_IMAGE_ANIMATION - // read the delay for the next frame - delay = gdispImageNext(&widget((GHandle)gh)->image); - - // Wait for that delay if required - switch(delay) { - case TIME_INFINITE: - // Everything is done - break; - case TIME_IMMEDIATE: - // We can't allow a continuous loop here as it would lock the system up so we delay for the minimum period - delay = 1; - // Fall through - default: - // Start the timer to draw the next frame of the animation - gtimerStart(&widget((GHandle)gh)->timer, _timer, (void*)gh, FALSE, delay); - break; - } - #endif -} - -static const gwinVMT imageVMT = { - "Image", // The class name - sizeof(GImageObject), // The object size - _destroy, // The destroy routine - _redraw, // The redraw routine - 0, // The after-clear routine -}; - -GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { - if (!(gobj = (GImageObject *)_gwindowCreate(g, &gobj->g, pInit, &imageVMT, 0))) - return 0; - - // Ensure the gdispImageIsOpen() gives valid results - gobj->image.type = 0; - gobj->image.fns = 0; - - // Initialise the timer - #if GWIN_NEED_IMAGE_ANIMATION - gtimerInit(&gobj->timer); - #endif - - gwinSetVisible((GHandle)gobj, pInit->show); - - return (GHandle)gobj; -} - -bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { - // is it a valid handle? - if (gh->vmt != (gwinVMT *)&imageVMT) - return FALSE; - - if (gdispImageIsOpen(&widget(gh)->image)) - gdispImageClose(&widget(gh)->image); - - if ((gdispImageOpenGFile(&widget(gh)->image, f) & GDISP_IMAGE_ERR_UNRECOVERABLE)) - return FALSE; - - if ((gh->flags & GWIN_FLG_VISIBLE)) { - // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw - // but we put it in for safety anyway - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - _redraw(gh); - } - - return TRUE; -} - -gdispImageError gwinImageCache(GHandle gh) { - // is it a valid handle? - if (gh->vmt != (gwinVMT *)&imageVMT) - return GDISP_IMAGE_ERR_BADFORMAT; - - return gdispImageCache(&widget(gh)->image); -} - -#endif // GFX_USE_GWIN && GWIN_NEED_IMAGE -/** @} */ diff --git a/src/gwin/imagebox.h b/src/gwin/imagebox.h deleted file mode 100644 index fdaabc92..00000000 --- a/src/gwin/imagebox.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gwin/image.h - * @brief GWIN image widget header file. - * - * @defgroup Image Image - * @ingroup GWIN - * - * @details GWIN allos it to create an image widget. The widget - * takes no user input. - * - * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h - * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h - * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h - * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h - * @pre At least one image type must be enabled in your gfxconf.h - * - * @{ - */ - -#ifndef _GWIN_IMAGE_H -#define _GWIN_IMAGE_H - -// This file is included within "gwin/gwin.h" - -// An image window -typedef struct GImageObject { - GWindowObject g; - gdispImage image; // The image itself - #if GWIN_NEED_IMAGE_ANIMATION - GTimer timer; // Timer used for animated images - #endif -} GImageObject; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Create an image widget. - * @details Display's a picture. - * @return NULL if there is no resultant drawing area, otherwise the widget handle. - * - * @param[in] g The GDisplay to display this window on - * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. - * @param[in] pInit The initialization parameters to use. - * - * @note The default background color gets set to the current default one. - * @note An image window knows how to redraw. - * - * @api - */ -GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); -#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) - -/** - * @brief Opens the image using a GFILE - * @return TRUE if the image can be opened - * - * @param[in] gh The widget (must be an image widget) - * @param[in] f The open (for reading) GFILE to use - * - * @api - */ -bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); - -/** - * @brief Opens the image using the specified filename - * @return TRUE if the open succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] filename The filename to open - * - * @api - */ -#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) - - /** - * @brief Sets the input routines that support reading the image from memory - * in RAM or flash. - * @pre GFILE_NEED_MEMFS must be TRUE - * @return TRUE if the IO open function succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] ptr A pointer to the image in RAM or Flash - * - * @api - */ -#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) - -/** - * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). - * @return TRUE if the IO open function succeeds - * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE - * - * @param[in] gh The widget (must be an image widget) - * @param[in] streamPtr A pointer to the (open) BaseFileStream object. - * - * @api - */ -#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) - -/** - * @brief Cache the image. - * @details Decodes and caches the current frame into RAM. - * - * @param[in] gh The widget (must be an image widget) - * - * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. - * - * @api - */ -gdispImageError gwinImageCache(GHandle gh); - -#ifdef __cplusplus -} -#endif - -#endif // _GWIN_IMAGE_H -/** @} */ - diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index 53ed016b..f4e1c2f7 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -874,7 +874,7 @@ extern "C" { #endif #if GWIN_NEED_IMAGE || defined(__DOXYGEN__) - #include "src/gwin/imagebox.h" + #include "src/gwin/image.h" #endif #endif /* GFX_USE_GWIN */ diff --git a/src/gwin/sys_make.mk b/src/gwin/sys_make.mk index 1e2404e6..4c670ea2 100644 --- a/src/gwin/sys_make.mk +++ b/src/gwin/sys_make.mk @@ -6,7 +6,7 @@ GFXSRC += $(GFXLIB)/src/gwin/gwin.c \ $(GFXLIB)/src/gwin/button.c \ $(GFXLIB)/src/gwin/slider.c \ $(GFXLIB)/src/gwin/checkbox.c \ - $(GFXLIB)/src/gwin/imagebox.c \ + $(GFXLIB)/src/gwin/gimage.c \ $(GFXLIB)/src/gwin/label.c \ $(GFXLIB)/src/gwin/radio.c \ $(GFXLIB)/src/gwin/list.c \ -- cgit v1.2.3 From 9e8b38ba943b339b966b1011bab899720d6305fc Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:25:31 +1000 Subject: Add gwinClearInit() and gwinWidgetClearInit() to clear gwin initialisation structures. Incorporate into demo's --- src/gwin/gwidget.c | 8 ++++++++ src/gwin/gwidget.h | 16 ++++++++++++++++ src/gwin/gwin.c | 8 ++++++++ src/gwin/sys_defs.h | 18 +++++++++++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src/gwin') diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 181b7425..c46520ea 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -297,6 +297,14 @@ void _gwidgetRedraw(GHandle gh) { gw->fnDraw(gw, gw->fnParam); } +void gwinWidgetClearInit(GWidgetInit *pwi) { + char *p; + unsigned len; + + for(p = (char *)pwi, len = sizeof(GWidgetInit); len; len--) + *p++ = 0; +} + void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll) { if (!pstyle) pstyle = &BlackWidgetStyle; diff --git a/src/gwin/gwidget.h b/src/gwin/gwidget.h index 96832fe3..8373e2d0 100644 --- a/src/gwin/gwidget.h +++ b/src/gwin/gwidget.h @@ -78,6 +78,10 @@ typedef void (*CustomWidgetDrawFunction)(struct GWidgetObject *gw, void *param); * @brief The structure to initialise a widget. * * @note Some widgets may have extra parameters. + * @note If you create this structure on the stack, you should always memset + * it to all zero's first in case a future version of the software + * add's extra fields. Alternatively you can use @p gwinWidgetClearInit() + * to clear it. * @note The text element must be static string (not stack allocated). If you want to use * a dynamic string (eg a stack allocated string) use NULL for this member and then call * @p gwinSetText() with useAlloc set to TRUE. @@ -126,6 +130,18 @@ typedef struct GWidgetObject { extern "C" { #endif +/** + * @brief Clear a GWidgetInit structure to all zero's + * @note This function is provided just to prevent problems + * on operating systems where using memset() causes issues + * in the users application. + * + * @param[in] pwi The GWidgetInit structure to clear + * + * @api + */ +void gwinWidgetClearInit(GWidgetInit *pwi); + /** * @brief Set the default style for widgets created hereafter. * diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 54f42077..93c17f3a 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -149,6 +149,14 @@ GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit * Routines that affect all windows *-----------------------------------------------*/ +void gwinClearInit(GWindowInit *pwi) { + char *p; + unsigned len; + + for(p = (char *)pwi, len = sizeof(GWindowInit); len; len--) + *p++ = 0; +} + void gwinSetDefaultColor(color_t clr) { defaultFgColor = clr; } diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index f4e1c2f7..fa5084a3 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -34,7 +34,7 @@ */ typedef struct GWindowObject { #if GWIN_NEED_WINDOWMANAGER - // This MUST be the first member of the struct + // This MUST be the first member of the structure gfxQueueASyncItem wmq; // @< The next window (for the window manager) #endif const struct gwinVMT *vmt; // @< The VMT for this GWIN @@ -54,6 +54,10 @@ typedef struct GWindowObject { * * @note Some gwin's will need extra parameters. * @note The dimensions and position may be changed to fit on the real screen. + * @note If you create this structure on the stack, you should always memset + * it to all zero's first in case a future version of the software + * add's extra fields. Alternatively you can use @p gwinClearInit() + * to clear it. * * @{ */ @@ -102,6 +106,18 @@ extern "C" { * Functions that affect all windows *-------------------------------------------------*/ + /** + * @brief Clear a GWindowInit structure to all zero's + * @note This function is provided just to prevent problems + * on operating systems where using memset() causes issues + * in the users application. + * + * @param[in] pwi The GWindowInit structure to clear + * + * @api + */ + void gwinClearInit(GWindowInit *pwi); + /** * @brief Set the default foreground color for all new GWIN windows * -- cgit v1.2.3 From cf5867b33d76d775782412d74733d221136af556 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:30:00 +1000 Subject: New gdispImageInit() call to initialise a gdispImage structure Use in gwinImage --- src/gwin/gimage.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c index 44ba785a..07d27dd0 100644 --- a/src/gwin/gimage.c +++ b/src/gwin/gimage.c @@ -127,8 +127,7 @@ GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { return 0; // Ensure the gdispImageIsOpen() gives valid results - gobj->image.type = 0; - gobj->image.fns = 0; + gdispImageInit(&gobj->image); // Initialise the timer #if GWIN_NEED_IMAGE_ANIMATION -- cgit v1.2.3 From 6d2c8f0f509f2e66d4fea444ce220550a0df6da5 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:32:29 +1000 Subject: GWIN creation and destruction bug fixes --- src/gwin/class_gwin.h | 2 +- src/gwin/gwin.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/class_gwin.h b/src/gwin/class_gwin.h index 49fc6084..50dd480e 100644 --- a/src/gwin/class_gwin.h +++ b/src/gwin/class_gwin.h @@ -170,7 +170,7 @@ extern "C" { * * @notapi */ -GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit, const gwinVMT *vmt, uint16_t flags); +GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit, const gwinVMT *vmt, uint32_t flags); #if GWIN_NEED_WIDGET || defined(__DOXYGEN__) /** diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 93c17f3a..84443f9f 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -114,7 +114,7 @@ void _gwinDeinit(void) // Internal routine for use by GWIN components only // Initialise a window creating it dynamically if required. -GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit, const gwinVMT *vmt, uint16_t flags) { +GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit, const gwinVMT *vmt, uint32_t flags) { // Allocate the structure if necessary if (!pgw) { if (!(pgw = gfxAlloc(vmt->size))) @@ -197,6 +197,9 @@ GHandle gwinGWindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pI } void gwinDestroy(GHandle gh) { + if (!gh) + return; + // Make the window invisible gwinSetVisible(gh, FALSE); -- cgit v1.2.3 From 0f109512fde45684fe36e84101a84f7280b28394 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:33:33 +1000 Subject: gwinImage animated gif bug fix --- src/gwin/gimage.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c index 07d27dd0..9d6363ba 100644 --- a/src/gwin/gimage.c +++ b/src/gwin/gimage.c @@ -26,10 +26,20 @@ static void _destroy(GWindowObject *gh) { #if GWIN_NEED_IMAGE_ANIMATION static void _redraw(GHandle gh); - static void _timer(void *gh) { + static void _timer(void *param) { + #define gh ((GHandle)param) + // We need to re-test the visibility in case it has been made invisible since the last frame. - if ((((GHandle)gh)->flags & GWIN_FLG_VISIBLE)) - _redraw((GHandle)gh); + if ((gh->flags & GWIN_FLG_VISIBLE)) { + // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw + // but we put it in for safety anyway + #if GDISP_NEED_CLIP + gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); + #endif + _redraw(gh); + } + + #undef gh } #endif -- cgit v1.2.3 From de5a9837773ebeadaae90b3bdf32df190f4192d8 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:34:12 +1000 Subject: GWIN window manager comment updates --- src/gwin/gwm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/gwm.c b/src/gwin/gwm.c index 9c158f68..3140b03f 100644 --- a/src/gwin/gwm.c +++ b/src/gwin/gwm.c @@ -127,7 +127,7 @@ void gwinRedrawDisplay(GDisplay *g, bool_t preserve) { } /*----------------------------------------------- - * Window Manager Routines + * "Null" Window Manager Routines *-----------------------------------------------*/ static void WM_Init(void) { @@ -145,9 +145,9 @@ static void WM_DeInit(void) { } static bool_t WM_Add(GHandle gh, const GWindowInit *pInit) { - // Note the window will not be marked as visible yet + // Note the window will not currently be marked as visible - // Put it on the queue + // Put it on the end of the queue gfxQueueASyncPut(&_GWINList, &gh->wmq); // Make sure the size is valid @@ -156,7 +156,7 @@ static bool_t WM_Add(GHandle gh, const GWindowInit *pInit) { } static void WM_Delete(GHandle gh) { - // Remove it from the queue + // Remove it from the window list gfxQueueASyncRemove(&_GWINList, &gh->wmq); } -- cgit v1.2.3 From 28f10aaa3a67a288a051c841866f6c68a90e880f Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:35:30 +1000 Subject: Rename GWIN image header file to be consistent with all other controls and with its source file --- src/gwin/gimage.h | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gwin/image.h | 127 ---------------------------------------------------- src/gwin/sys_defs.h | 2 +- 3 files changed, 128 insertions(+), 128 deletions(-) create mode 100644 src/gwin/gimage.h delete mode 100644 src/gwin/image.h (limited to 'src/gwin') diff --git a/src/gwin/gimage.h b/src/gwin/gimage.h new file mode 100644 index 00000000..fdaabc92 --- /dev/null +++ b/src/gwin/gimage.h @@ -0,0 +1,127 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/image.h + * @brief GWIN image widget header file. + * + * @defgroup Image Image + * @ingroup GWIN + * + * @details GWIN allos it to create an image widget. The widget + * takes no user input. + * + * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h + * @pre At least one image type must be enabled in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_IMAGE_H +#define _GWIN_IMAGE_H + +// This file is included within "gwin/gwin.h" + +// An image window +typedef struct GImageObject { + GWindowObject g; + gdispImage image; // The image itself + #if GWIN_NEED_IMAGE_ANIMATION + GTimer timer; // Timer used for animated images + #endif +} GImageObject; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create an image widget. + * @details Display's a picture. + * @return NULL if there is no resultant drawing area, otherwise the widget handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use. + * + * @note The default background color gets set to the current default one. + * @note An image window knows how to redraw. + * + * @api + */ +GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); +#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) + +/** + * @brief Opens the image using a GFILE + * @return TRUE if the image can be opened + * + * @param[in] gh The widget (must be an image widget) + * @param[in] f The open (for reading) GFILE to use + * + * @api + */ +bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); + +/** + * @brief Opens the image using the specified filename + * @return TRUE if the open succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] filename The filename to open + * + * @api + */ +#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) + + /** + * @brief Sets the input routines that support reading the image from memory + * in RAM or flash. + * @pre GFILE_NEED_MEMFS must be TRUE + * @return TRUE if the IO open function succeeds + * + * @param[in] gh The widget (must be an image widget) + * @param[in] ptr A pointer to the image in RAM or Flash + * + * @api + */ +#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) + +/** + * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). + * @return TRUE if the IO open function succeeds + * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE + * + * @param[in] gh The widget (must be an image widget) + * @param[in] streamPtr A pointer to the (open) BaseFileStream object. + * + * @api + */ +#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) + +/** + * @brief Cache the image. + * @details Decodes and caches the current frame into RAM. + * + * @param[in] gh The widget (must be an image widget) + * + * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. + * + * @api + */ +gdispImageError gwinImageCache(GHandle gh); + +#ifdef __cplusplus +} +#endif + +#endif // _GWIN_IMAGE_H +/** @} */ + diff --git a/src/gwin/image.h b/src/gwin/image.h deleted file mode 100644 index fdaabc92..00000000 --- a/src/gwin/image.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gwin/image.h - * @brief GWIN image widget header file. - * - * @defgroup Image Image - * @ingroup GWIN - * - * @details GWIN allos it to create an image widget. The widget - * takes no user input. - * - * @pre GFX_USE_GDISP must be set to TRUE in your gfxconf.h - * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h - * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h - * @pre GWIN_NEED_IMAGE must be set to TRUE in your gfxconf.h - * @pre At least one image type must be enabled in your gfxconf.h - * - * @{ - */ - -#ifndef _GWIN_IMAGE_H -#define _GWIN_IMAGE_H - -// This file is included within "gwin/gwin.h" - -// An image window -typedef struct GImageObject { - GWindowObject g; - gdispImage image; // The image itself - #if GWIN_NEED_IMAGE_ANIMATION - GTimer timer; // Timer used for animated images - #endif -} GImageObject; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Create an image widget. - * @details Display's a picture. - * @return NULL if there is no resultant drawing area, otherwise the widget handle. - * - * @param[in] g The GDisplay to display this window on - * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated. - * @param[in] pInit The initialization parameters to use. - * - * @note The default background color gets set to the current default one. - * @note An image window knows how to redraw. - * - * @api - */ -GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit); -#define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit) - -/** - * @brief Opens the image using a GFILE - * @return TRUE if the image can be opened - * - * @param[in] gh The widget (must be an image widget) - * @param[in] f The open (for reading) GFILE to use - * - * @api - */ -bool_t gwinImageOpenGFile(GHandle gh, GFILE *f); - -/** - * @brief Opens the image using the specified filename - * @return TRUE if the open succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] filename The filename to open - * - * @api - */ -#define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb")) - - /** - * @brief Sets the input routines that support reading the image from memory - * in RAM or flash. - * @pre GFILE_NEED_MEMFS must be TRUE - * @return TRUE if the IO open function succeeds - * - * @param[in] gh The widget (must be an image widget) - * @param[in] ptr A pointer to the image in RAM or Flash - * - * @api - */ -#define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb")) - -/** - * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card). - * @return TRUE if the IO open function succeeds - * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE - * - * @param[in] gh The widget (must be an image widget) - * @param[in] streamPtr A pointer to the (open) BaseFileStream object. - * - * @api - */ -#define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb")) - -/** - * @brief Cache the image. - * @details Decodes and caches the current frame into RAM. - * - * @param[in] gh The widget (must be an image widget) - * - * @return GDISP_IMAGE_ERR_OK (0) on success or an error code. - * - * @api - */ -gdispImageError gwinImageCache(GHandle gh); - -#ifdef __cplusplus -} -#endif - -#endif // _GWIN_IMAGE_H -/** @} */ - diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index fa5084a3..c632b069 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -890,7 +890,7 @@ extern "C" { #endif #if GWIN_NEED_IMAGE || defined(__DOXYGEN__) - #include "src/gwin/image.h" + #include "src/gwin/gimage.h" #endif #endif /* GFX_USE_GWIN */ -- cgit v1.2.3 From f9b6b1697da42673ffe466edf9945ece0996ec1a Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:36:14 +1000 Subject: GWIN label bug fix and simplification --- src/gwin/label.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/label.c b/src/gwin/label.c index 8960300b..2aa0c860 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -138,6 +138,7 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) { static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { coord_t w, h; + color_t c; (void) param; // is it a valid handle? @@ -146,6 +147,7 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.width; h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.height; + c = (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text; if (gw->g.width != w || gw->g.height != h) { gwinResize(&gw->g, w, h); @@ -154,29 +156,18 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { } #if GWIN_LABEL_ATTRIBUTE - if (gw2obj->attr != 0) { - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw2obj->attr, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - - gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - } else { - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - - } + if (gw2obj->attr) { + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw2obj->tab, h, gw2obj->attr, gw->g.font, c, gw->pstyle->background, justifyLeft); + gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, w-gw2obj->tab, h, gw->text, gw->g.font, c, gw->pstyle->background, justifyLeft); + } else + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justifyLeft); #else - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justifyLeft); #endif // render the border (if any) if (gw->g.flags & GLABEL_FLG_BORDER) - gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); + gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, w, h, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); } #endif // GFX_USE_GWIN && GFX_NEED_LABEL -- cgit v1.2.3 From 1478fdf41e3731cafacd22ff6f530fb724c02df3 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 9 May 2014 21:37:06 +1000 Subject: Re-order GWIN sys_rules to simplify ready for new functionality. --- src/gwin/sys_rules.h | 53 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/sys_rules.h b/src/gwin/sys_rules.h index 30dac1bb..f9f00a48 100644 --- a/src/gwin/sys_rules.h +++ b/src/gwin/sys_rules.h @@ -17,6 +17,7 @@ #define _GWIN_RULES_H #if GFX_USE_GWIN + // Sub-system rules #if !GFX_USE_GDISP #error "GWIN: GFX_USE_GDISP must be TRUE when using GWIN" #endif @@ -25,33 +26,20 @@ #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE" #endif #endif - #if GWIN_NEED_IMAGE - #if !GDISP_NEED_IMAGE - #error "GWIN: GDISP_NEED_IMAGE is required when GWIN_NEED_IMAGE is TRUE." - #endif - #endif - #if GWIN_NEED_RADIO - #if !GDISP_NEED_CIRCLE - #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GDISP_NEED_CIRCLE should be set to TRUE for much nicer radio button widgets." - #endif - #endif - #endif + + // Objects require their super-class #if GWIN_NEED_BUTTON || GWIN_NEED_SLIDER || GWIN_NEED_CHECKBOX || GWIN_NEED_LABEL || GWIN_NEED_RADIO || GWIN_NEED_LIST || \ GWIN_NEED_IMAGE || GWIN_NEED_CHECKBOX || GWIN_NEED_PROGRESSBAR #if !GWIN_NEED_WIDGET #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GWIN_NEED_WIDGET is required when a Widget is used. It has been turned on for you." + #warning "GWIN: GWIN_NEED_WIDGET is required when a widget is used. It has been turned on for you." #endif #undef GWIN_NEED_WIDGET #define GWIN_NEED_WIDGET TRUE #endif #endif - #if GWIN_NEED_LIST - #if !GDISP_NEED_TEXT - #error "GWIN: GDISP_NEED_TEXT is required when GWIN_NEED_LIST is TRUE." - #endif - #endif + + // Rules for the super-classes #if GWIN_NEED_WIDGET #if !GDISP_NEED_TEXT #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_WIDGET is TRUE." @@ -86,16 +74,35 @@ #define GQUEUE_NEED_ASYNC TRUE #endif #endif + + // Rules for individual objects + #if GWIN_NEED_LIST + #if !GDISP_NEED_TEXT + #error "GWIN: GDISP_NEED_TEXT is required when GWIN_NEED_LIST is TRUE." + #endif + #endif + #if GWIN_NEED_RADIO + #if !GDISP_NEED_CIRCLE + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GDISP_NEED_CIRCLE should be set to TRUE for much nicer radio button widgets." + #endif + #endif + #endif + #if GWIN_NEED_IMAGE + #if !GDISP_NEED_IMAGE + #error "GWIN: GDISP_NEED_IMAGE is required when GWIN_NEED_IMAGE is TRUE." + #endif + #endif #if GWIN_NEED_CONSOLE #if !GDISP_NEED_TEXT #error "GWIN: GDISP_NEED_TEXT is required if GWIN_NEED_CONSOLE is TRUE." #endif #endif - #if GWIN_NEED_GRAPH - #endif - #if GWIN_PROGRESSBAR_AUTO - #if !GFX_USE_GTIMER - #error "GWIN: GFX_USE_GTIMER is required if GWIN_PROGRESSBAR_AUTO is TRUE." + #if GWIN_NEED_PROGRESSBAR + #if GWIN_PROGRESSBAR_AUTO + #if !GFX_USE_GTIMER + #error "GWIN: GFX_USE_GTIMER is required if GWIN_PROGRESSBAR_AUTO is TRUE." + #endif #endif #endif #endif -- cgit v1.2.3