Image animation changes
This commit is contained in:
parent
cb28adcfba
commit
386539072c
5 changed files with 57 additions and 33 deletions
|
@ -81,6 +81,8 @@
|
||||||
#define GWIN_NEED_LABEL TRUE
|
#define GWIN_NEED_LABEL TRUE
|
||||||
#define GWIN_NEED_IMAGE TRUE
|
#define GWIN_NEED_IMAGE TRUE
|
||||||
#define GWIN_NEED_RADIO TRUE
|
#define GWIN_NEED_RADIO TRUE
|
||||||
|
#define GWIN_NEED_IMAGE_ANIMATION TRUE
|
||||||
|
|
||||||
|
|
||||||
/* Features for the GINPUT sub-system. */
|
/* Features for the GINPUT sub-system. */
|
||||||
#define GINPUT_NEED_MOUSE TRUE
|
#define GINPUT_NEED_MOUSE TRUE
|
||||||
|
|
|
@ -87,6 +87,8 @@
|
||||||
#define GWIN_NEED_BUTTON FALSE
|
#define GWIN_NEED_BUTTON FALSE
|
||||||
#define GWIN_NEED_SLIDER FALSE
|
#define GWIN_NEED_SLIDER FALSE
|
||||||
#define GWIN_NEED_CHECKBOX FALSE
|
#define GWIN_NEED_CHECKBOX FALSE
|
||||||
|
#define GWIN_NEED_IMAGE FALSE
|
||||||
|
#define GWIN_NEED_RADIO FALSE
|
||||||
|
|
||||||
/* Features for the GEVENT subsystem. */
|
/* Features for the GEVENT subsystem. */
|
||||||
#define GEVENT_ASSERT_NO_RESOURCE FALSE
|
#define GEVENT_ASSERT_NO_RESOURCE FALSE
|
||||||
|
@ -129,6 +131,7 @@
|
||||||
#define GWIN_BUTTON_LAZY_RELEASE FALSE
|
#define GWIN_BUTTON_LAZY_RELEASE FALSE
|
||||||
#define GWIN_CONSOLE_USE_BASESTREAM FALSE
|
#define GWIN_CONSOLE_USE_BASESTREAM FALSE
|
||||||
#define GWIN_CONSOLE_USE_FLOAT FALSE
|
#define GWIN_CONSOLE_USE_FLOAT FALSE
|
||||||
|
#define GWIN_NEED_IMAGE_ANIMATION FALSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Optional Low Level Driver Definitions */
|
/* Optional Low Level Driver Definitions */
|
||||||
|
|
|
@ -33,7 +33,9 @@
|
||||||
typedef struct GImageObject {
|
typedef struct GImageObject {
|
||||||
GWindowObject g;
|
GWindowObject g;
|
||||||
gdispImage image; // The image itself
|
gdispImage image; // The image itself
|
||||||
|
#if GWIN_NEED_IMAGE_ANIMATION
|
||||||
GTimer timer; // Timer used for animated images
|
GTimer timer; // Timer used for animated images
|
||||||
|
#endif
|
||||||
} GImageObject;
|
} GImageObject;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -123,6 +123,13 @@
|
||||||
#ifndef GWIN_CONSOLE_USE_BASESTREAM
|
#ifndef GWIN_CONSOLE_USE_BASESTREAM
|
||||||
#define GWIN_CONSOLE_USE_BASESTREAM FALSE
|
#define GWIN_CONSOLE_USE_BASESTREAM FALSE
|
||||||
#endif
|
#endif
|
||||||
|
/**
|
||||||
|
* @brief Image windows can optionally support animated images
|
||||||
|
* @details Defaults to FALSE
|
||||||
|
*/
|
||||||
|
#ifndef GWIN_NEED_IMAGE_ANIMATION
|
||||||
|
#define GWIN_NEED_IMAGE_ANIMATION FALSE
|
||||||
|
#endif
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* _GWIN_OPTIONS_H */
|
#endif /* _GWIN_OPTIONS_H */
|
||||||
|
|
|
@ -23,9 +23,22 @@ static void _destroy(GWindowObject *gh) {
|
||||||
gdispImageClose(&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) {
|
static void _redraw(GHandle gh) {
|
||||||
coord_t x, y, w, h, dx, dy;
|
coord_t x, y, w, h, dx, dy;
|
||||||
color_t bg;
|
color_t bg;
|
||||||
|
#if GWIN_NEED_IMAGE_ANIMATION
|
||||||
|
delaytime_t delay;
|
||||||
|
#endif
|
||||||
|
|
||||||
// The default display area
|
// The default display area
|
||||||
x = gh->x;
|
x = gh->x;
|
||||||
|
@ -77,8 +90,27 @@ static void _redraw(GHandle gh) {
|
||||||
|
|
||||||
// Display the image
|
// Display the image
|
||||||
gdispImageDraw(&widget(gh)->image, x, y, w, h, dx, dy);
|
gdispImageDraw(&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 = {
|
static const gwinVMT imageVMT = {
|
||||||
"Image", // The class name
|
"Image", // The class name
|
||||||
|
@ -88,27 +120,6 @@ static const gwinVMT imageVMT = {
|
||||||
0, // The after-clear routine
|
0, // The after-clear routine
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the callback for the automated redraw for animated images
|
|
||||||
static void _animatedRedraw(void* gh) {
|
|
||||||
// draw pending frame
|
|
||||||
_redraw((GHandle)gh);
|
|
||||||
|
|
||||||
// read the delay for the next frame and set the timer
|
|
||||||
gtimerStart(&(widget((GHandle)gh)->timer), _animatedRedraw, (void*)gh, FALSE, gdispImageNext(&(widget((GHandle)gh)->image)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for an animated image
|
|
||||||
static bool_t _checkAnimated(GHandle gh) {
|
|
||||||
if (widget(gh)->image.flags & GDISP_IMAGE_FLG_ANIMATED) {
|
|
||||||
gtimerInit(&(widget(gh)->timer));
|
|
||||||
gtimerStart(&(widget(gh)->timer), _animatedRedraw, (void*)gh, FALSE, gdispImageNext(&(widget(gh)->image)));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
GHandle gwinImageCreate(GImageObject *gobj, GWindowInit *pInit) {
|
GHandle gwinImageCreate(GImageObject *gobj, GWindowInit *pInit) {
|
||||||
if (!(gobj = (GImageObject *)_gwindowCreate(&gobj->g, pInit, &imageVMT, 0)))
|
if (!(gobj = (GImageObject *)_gwindowCreate(&gobj->g, pInit, &imageVMT, 0)))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -116,6 +127,11 @@ GHandle gwinImageCreate(GImageObject *gobj, GWindowInit *pInit) {
|
||||||
// Ensure the gdispImageIsOpen() gives valid results
|
// Ensure the gdispImageIsOpen() gives valid results
|
||||||
gobj->image.type = 0;
|
gobj->image.type = 0;
|
||||||
|
|
||||||
|
// Initialise the timer
|
||||||
|
#if GWIN_NEED_IMAGE_ANIMATION
|
||||||
|
gtimerInit(&gobj->timer);
|
||||||
|
#endif
|
||||||
|
|
||||||
gwinSetVisible((GHandle)gobj, pInit->show);
|
gwinSetVisible((GHandle)gobj, pInit->show);
|
||||||
|
|
||||||
return (GHandle)gobj;
|
return (GHandle)gobj;
|
||||||
|
@ -137,10 +153,8 @@ bool_t gwinImageOpenMemory(GHandle gh, const void* memory) {
|
||||||
#if GDISP_NEED_CLIP
|
#if GDISP_NEED_CLIP
|
||||||
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
|
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
if(!_checkAnimated(gh))
|
|
||||||
_redraw(gh);
|
_redraw(gh);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -162,10 +176,8 @@ bool_t gwinImageOpenFile(GHandle gh, const char* filename) {
|
||||||
#if GDISP_NEED_CLIP
|
#if GDISP_NEED_CLIP
|
||||||
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
|
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
if(!_checkAnimated(gh))
|
|
||||||
_redraw(gh);
|
_redraw(gh);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -188,10 +200,8 @@ bool_t gwinImageOpenStream(GHandle gh, void *streamPtr) {
|
||||||
#if GDISP_NEED_CLIP
|
#if GDISP_NEED_CLIP
|
||||||
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
|
gdispSetClip(gh->x, gh->y, gh->width, gh->height);
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
if(!_checkAnimated(gh))
|
|
||||||
_redraw(gh);
|
_redraw(gh);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue