diff options
Diffstat (limited to 'src/gwin')
-rw-r--r-- | src/gwin/gwin.c | 12 | ||||
-rw-r--r-- | src/gwin/image.c | 58 |
2 files changed, 45 insertions, 25 deletions
diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index c1122b3f..75f1b2d3 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -479,18 +479,6 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor } #endif -#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 - return gdispImageDraw(img, gh->x+x, gh->y+y, cx, cy, sx, sy); - } -#endif - #endif /* GFX_USE_GWIN */ /** @} */ diff --git a/src/gwin/image.c b/src/gwin/image.c index 35a0471d..64a27840 100644 --- a/src/gwin/image.c +++ b/src/gwin/image.c @@ -16,21 +16,17 @@ #include "gwin/class_gwin.h" -static void _destroy(GWindowObject *gh) { - (void)gh; +#define widget(gh) ((GImageWidget*)gh) - return; -} - -static void _redraw(GWindowObject *gh) { - (void)gh; +static void _destroy(GWindowObject *gh) { + if (gdispImageIsOpen(&widget(gh)->image)) + gdispImageClose(&widget(gh)->image); return; } static void _afterClear(GWindowObject *gh) { - ((GImageWidget *)gh)->cx = 0; - ((GImageWidget *)gh)->cy = 0; + (void)gh; return; } @@ -39,7 +35,7 @@ static const gwinVMT imageVMT = { "Image", // The class name sizeof(GImageWidget), // The object size _destroy, // The destroy routine - _redraw, // The redraw routine + 0, _afterClear, // The after-clear routine }; @@ -47,17 +43,53 @@ GHandle gwinImageCreate(GImageWidget *widget, GWindowInit *pInit) { if (!(widget = (GImageWidget *)_gwindowCreate(&widget->g, pInit, &imageVMT, 0))) return 0; - widget->cx = 0; - widget->cy = 0; + widget->image = gfxAlloc(sizeof(gdispImage)); + if (widget->image == NULL) + return 0; + + widget->g.x = pInit->x; + widget->g.y = pInit->y; + widget->g.width = pInit->width; + widget->g.height = pInit->height; + widget->bgColor = Black; gwinSetVisible((GHandle)widget, pInit->show); return (GHandle)widget; } -void gwinImageDisplay(GImageWidget *widget, gdispImage *image) { +bool_t gwinImageOpenMemory(GHandle gh, const void* memory) { + bool_t err; + err = gdispImageSetMemoryReader(widget(gh)->image, memory); + gdispImageOpen(widget(gh)->image); + + return err; } +#if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_POSIX || defined(__DOXYGEN__) +bool_t gwinImageOpenFile(GHandle gh, const char* filename) { + return gdispImageSetFileReader(widget(gh)->image, filename); +} +#endif + +#if GFX_USE_OS_CHIBIOS || defined(__DOXYGEN__) +bool_t gwinImageOpenStream(GHandle gh, void *streamPtr) { + return gdispImageSetBaseFileStreamReader(widget(gh)->image, streamPtr); +} +#endif + +gdispImageError gwinImageCache(GHandle gh) { + return gdispImageCache(widget(gh)->image); +} + +void gwinImageSetBgColor(GHandle gh, color_t bgColor) { + widget(gh)->bgColor = bgColor; +} + +void gwinImageDraw(GHandle gh) { + gdispImageDraw(widget(gh)->image, widget(gh)->g.x, widget(gh)->g.y, widget(gh)->g.width, widget(gh)->g.height, 0, 0); +} + #endif // GFX_USE_GWIN && GWIN_NEED_IMAGE /** @} */ |