diff options
Diffstat (limited to 'src/gwin/gwin.c')
-rw-r--r-- | src/gwin/gwin.c | 401 |
1 files changed, 59 insertions, 342 deletions
diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 2e4144a7..e1625b13 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -11,10 +11,6 @@ #include "src/gwin/class_gwin.h" -// Needed if there is no window manager -#define MIN_WIN_WIDTH 1 -#define MIN_WIN_HEIGHT 1 - /*----------------------------------------------- * Data *-----------------------------------------------*/ @@ -37,64 +33,15 @@ static color_t defaultBgColor = Black; * Helper Routines *-----------------------------------------------*/ -#if GWIN_NEED_WINDOWMANAGER - #define _gwm_redraw(gh, flags) _GWINwm->vmt->Redraw(gh, flags) - #define _gwm_move(gh,x,y) _GWINwm->vmt->Move(gh,x,y); - #define _gwm_resize(gh,w,h) _GWINwm->vmt->Size(gh,w,h); -#else - static void _gwm_redraw(GHandle gh, int flags) { - if ((gh->flags & GWIN_FLG_SYSVISIBLE)) { - if (gh->vmt->Redraw) { - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - gh->vmt->Redraw(gh); - } else if (!(flags & GWIN_WMFLG_PRESERVE)) { - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); - if (gh->vmt->AfterClear) - gh->vmt->AfterClear(gh); - } - } else if (!(flags & GWIN_WMFLG_NOBGCLEAR)) { - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, defaultBgColor); - } - } - static void _gwm_resize(GHandle gh, coord_t width, coord_t height) { - gh->width = width; gh->height = height; - if (gh->width < MIN_WIN_WIDTH) { gh->width = MIN_WIN_WIDTH; } - if (gh->height < MIN_WIN_HEIGHT) { gh->height = MIN_WIN_HEIGHT; } - if (gh->x+gh->width > gdispGetWidth()) gh->width = gdispGetWidth() - gh->x; - if (gh->y+gh->height > gdispGetHeight()) gh->height = gdispGetHeight() - gh->y; - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE|GWIN_WMFLG_NOBGCLEAR); - } - static void _gwm_move(GHandle gh, coord_t x, coord_t y) { - gh->x = x; gh->y = y; - if (gh->x < 0) gh->x = 0; - if (gh->y < 0) gh->y = 0; - if (gh->x > gdispGetWidth()-MIN_WIN_WIDTH) gh->x = gdispGetWidth()-MIN_WIN_WIDTH; - if (gh->y > gdispGetHeight()-MIN_WIN_HEIGHT) gh->y = gdispGetHeight()-MIN_WIN_HEIGHT; - if (gh->x+gh->width > gdispGetWidth()) gh->width = gdispGetWidth() - gh->x; - if (gh->y+gh->height > gdispGetHeight()) gh->height = gdispGetHeight() - gh->y; - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE|GWIN_WMFLG_NOBGCLEAR); - } -#endif - /*----------------------------------------------- * Class Routines *-----------------------------------------------*/ void _gwinInit(void) { - #if GWIN_NEED_WINDOWMANAGER - extern void _gwmInit(void); + extern void _gwmInit(void); - _gwmInit(); - #endif + _gwmInit(); #if GWIN_NEED_WIDGET extern void _gwidgetInit(void); @@ -109,6 +56,8 @@ void _gwinInit(void) void _gwinDeinit(void) { + extern void _gwmDeinit(void); + #if GWIN_NEED_CONTAINERS extern void _gcontainerDeinit(void); @@ -119,11 +68,8 @@ void _gwinDeinit(void) _gwidgetDeinit(); #endif - #if GWIN_NEED_WINDOWMANAGER - extern void _gwmDeinit(void); - _gwmDeinit(); - #endif + _gwmDeinit(); } // Internal routine for use by GWIN components only @@ -146,35 +92,11 @@ GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit pgw->font = defaultFont; #endif - #if GWIN_NEED_CONTAINERS - if (pInit->parent) { - if (!(pInit->parent->flags & GWIN_FLG_CONTAINER) || pgw->display != pInit->parent->display) { - if ((pgw->flags & GWIN_FLG_DYNAMIC)) - gfxFree(pgw); - return 0; - } - pgw->parent = pInit->parent; - } else - pgw->parent = 0; - #endif - - #if GWIN_NEED_WINDOWMANAGER - if (!_GWINwm->vmt->Add(pgw, pInit)) { - if ((pgw->flags & GWIN_FLG_DYNAMIC)) - gfxFree(pgw); - return 0; - } - #else - pgw->x = pgw->y = pgw->width = pgw->height = 0; - _gwm_move(pgw, pInit->x, pInit->y); - _gwm_resize(pgw, pInit->width, pInit->height); - #endif - - #if GWIN_NEED_CONTAINERS - // Notify the parent it has been added - if (pgw->parent && ((gcontainerVMT *)pgw->parent->vmt)->NotifyAdd) - ((gcontainerVMT *)pgw->parent->vmt)->NotifyAdd(pgw->parent, pgw); - #endif + if (!_gwinWMAdd(pgw, pInit)) { + if ((pgw->flags & GWIN_FLG_DYNAMIC)) + gfxFree(pgw); + return 0; + } return (GHandle)pgw; } @@ -264,126 +186,14 @@ const char *gwinGetClassName(GHandle gh) { return gh->vmt->classname; } -#if GWIN_NEED_CONTAINERS - // These two sub-functions set/clear system visibility recursively. - static bool_t setSysVisFlag(GHandle gh) { - // If we are now visible and our parent is visible - if ((gh->flags & GWIN_FLG_VISIBLE) && (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSVISIBLE))) { - gh->flags |= GWIN_FLG_SYSVISIBLE; - return TRUE; - } - return FALSE; - } - static bool_t clrSysVisFlag(GHandle gh) { - // If we are now not visible but our parent is visible - if (!(gh->flags & GWIN_FLG_VISIBLE) || (gh->parent && !(gh->parent->flags & GWIN_FLG_SYSVISIBLE))) { - gh->flags &= ~GWIN_FLG_SYSVISIBLE; - return TRUE; - } - return FALSE; - } - void gwinSetVisible(GHandle gh, bool_t visible) { - if (visible) { - if (!(gh->flags & GWIN_FLG_VISIBLE)) { - gh->flags |= GWIN_FLG_VISIBLE; - _gwinRecurse(gh, setSysVisFlag); - _gwm_redraw(gh, 0); - } - } else { - if ((gh->flags & GWIN_FLG_VISIBLE)) { - gh->flags &= ~GWIN_FLG_VISIBLE; - _gwinRecurse(gh, clrSysVisFlag); - _gwm_redraw(gh, 0); - } - } - } -#else - void gwinSetVisible(GHandle gh, bool_t visible) { - if (visible) { - if (!(gh->flags & GWIN_FLG_VISIBLE)) { - gh->flags |= (GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE); - _gwm_redraw(gh, 0); - } - } else { - if ((gh->flags & GWIN_FLG_VISIBLE)) { - gh->flags &= ~(GWIN_FLG_VISIBLE|GWIN_FLG_SYSVISIBLE); - _gwm_redraw(gh, 0); - } - } - } -#endif - bool_t gwinGetVisible(GHandle gh) { return (gh->flags & GWIN_FLG_SYSVISIBLE) ? TRUE : FALSE; } -#if GWIN_NEED_CONTAINERS - // These two sub-functions set/clear system enable recursively. - static bool_t setSysEnaFlag(GHandle gh) { - // If we are now enabled and our parent is enabled - if ((gh->flags & GWIN_FLG_ENABLED) && (!gh->parent || (gh->parent->flags & GWIN_FLG_SYSENABLED))) { - gh->flags |= GWIN_FLG_SYSENABLED; - return TRUE; - } - return FALSE; - } - static bool_t clrSysEnaFlag(GHandle gh) { - // If we are now not enabled but our parent is enabled - if (!(gh->flags & GWIN_FLG_ENABLED) || (gh->parent && !(gh->parent->flags & GWIN_FLG_SYSENABLED))) { - gh->flags &= ~GWIN_FLG_SYSENABLED; - return TRUE; - } - return FALSE; - } - void gwinSetEnabled(GHandle gh, bool_t enabled) { - if (enabled) { - if (!(gh->flags & GWIN_FLG_ENABLED)) { - gh->flags |= GWIN_FLG_ENABLED; - _gwinRecurse(gh, setSysEnaFlag); - if ((gh->flags & GWIN_FLG_SYSVISIBLE)) - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE); - } - } else { - if ((gh->flags & GWIN_FLG_ENABLED)) { - gh->flags &= ~GWIN_FLG_ENABLED; - _gwinRecurse(gh, clrSysEnaFlag); - if ((gh->flags & GWIN_FLG_SYSVISIBLE)) - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE); - } - } - } -#else - void gwinSetEnabled(GHandle gh, bool_t enabled) { - if (enabled) { - if (!(gh->flags & GWIN_FLG_ENABLED)) { - gh->flags |= (GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED); - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE|GWIN_WMFLG_NOBGCLEAR); - } - } else { - if ((gh->flags & GWIN_FLG_ENABLED)) { - gh->flags &= ~(GWIN_FLG_ENABLED|GWIN_FLG_SYSENABLED); - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE|GWIN_WMFLG_NOBGCLEAR); - } - } - } -#endif - bool_t gwinGetEnabled(GHandle gh) { return (gh->flags & GWIN_FLG_SYSENABLED) ? TRUE : FALSE; } -void gwinMove(GHandle gh, coord_t x, coord_t y) { - _gwm_move(gh, x, y); -} - -void gwinResize(GHandle gh, coord_t width, coord_t height) { - _gwm_resize(gh, width, height); -} - -void gwinRedraw(GHandle gh) { - _gwm_redraw(gh, GWIN_WMFLG_PRESERVE|GWIN_WMFLG_NOBGCLEAR); -} - #if GDISP_NEED_TEXT void gwinSetFont(GHandle gh, font_t font) { gh->font = font; @@ -396,247 +206,154 @@ void gwinClear(GHandle gh) { * still call the AfterClear() routine as some widgets will * need this to clear internal buffers or similar */ - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) { - if (gh->vmt->AfterClear) - gh->vmt->AfterClear(gh); - } else { - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - + if (_gwinDrawStart(gh)) { gdispGFillArea(gh->display, gh->x, gh->y, gh->width, gh->height, gh->bgcolor); - if (gh->vmt->AfterClear) - gh->vmt->AfterClear(gh); + _gwinDrawEnd(gh); } - - #if GWIN_NEED_CONTAINERS - for (gh = gwinGetFirstChild(gh); gh; gh = gwinGetSibling(gh)) - gwinRedraw(gh); - #endif + if (gh->vmt->AfterClear) + gh->vmt->AfterClear(gh); } void gwinDrawPixel(GHandle gh, coord_t x, coord_t y) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawPixel(gh->display, gh->x+x, gh->y+y, gh->color); + _gwinDrawEnd(gh); } void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawLine(gh->display, gh->x+x0, gh->y+y0, gh->x+x1, gh->y+y1, gh->color); + _gwinDrawEnd(gh); } void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawBox(gh->display, gh->x+x, gh->y+y, cx, cy, gh->color); + _gwinDrawEnd(gh); } void gwinFillArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGFillArea(gh->display, gh->x+x, gh->y+y, cx, cy, gh->color); + _gwinDrawEnd(gh); } 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_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGBlitArea(gh->display, gh->x+x, gh->y+y, cx, cy, srcx, srcy, srccx, buffer); + _gwinDrawEnd(gh); } #if GDISP_NEED_CIRCLE void gwinDrawCircle(GHandle gh, coord_t x, coord_t y, coord_t radius) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawCircle(gh->display, gh->x+x, gh->y+y, radius, gh->color); + _gwinDrawEnd(gh); } void gwinFillCircle(GHandle gh, coord_t x, coord_t y, coord_t radius) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGFillCircle(gh->display, gh->x+x, gh->y+y, radius, gh->color); + _gwinDrawEnd(gh); } #endif #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_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawEllipse(gh->display, gh->x+x, gh->y+y, a, b, gh->color); + _gwinDrawEnd(gh); } void gwinFillEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGFillEllipse(gh->display, gh->x+x, gh->y+y, a, b, gh->color); + _gwinDrawEnd(gh); } #endif #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_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawArc(gh->display, gh->x+x, gh->y+y, radius, startangle, endangle, gh->color); + _gwinDrawEnd(gh); } void gwinFillArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGFillArc(gh->display, gh->x+x, gh->y+y, radius, startangle, endangle, gh->color); + _gwinDrawEnd(gh); } #endif #if GDISP_NEED_PIXELREAD color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return defaultBgColor; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; return gdispGGetPixelColor(gh->display, gh->x+x, gh->y+y); + _gwinDrawEnd(gh); } #endif #if GDISP_NEED_TEXT void gwinDrawChar(GHandle gh, coord_t x, coord_t y, char c) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE) || !gh->font) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!gh->font || !_gwinDrawStart(gh)) return; gdispGDrawChar(gh->display, gh->x+x, gh->y+y, c, gh->font, gh->color); + _gwinDrawEnd(gh); } void gwinFillChar(GHandle gh, coord_t x, coord_t y, char c) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE) || !gh->font) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!gh->font || !_gwinDrawStart(gh)) return; gdispGFillChar(gh->display, gh->x+x, gh->y+y, c, gh->font, gh->color, gh->bgcolor); + _gwinDrawEnd(gh); } void gwinDrawString(GHandle gh, coord_t x, coord_t y, const char *str) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE) || !gh->font) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!gh->font || !_gwinDrawStart(gh)) return; gdispGDrawString(gh->display, gh->x+x, gh->y+y, str, gh->font, gh->color); + _gwinDrawEnd(gh); } void gwinFillString(GHandle gh, coord_t x, coord_t y, const char *str) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE) || !gh->font) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!gh->font || !_gwinDrawStart(gh)) return; gdispGFillString(gh->display, gh->x+x, gh->y+y, str, gh->font, gh->color, gh->bgcolor); + _gwinDrawEnd(gh); } void gwinDrawStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE) || !gh->font) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!gh->font || !_gwinDrawStart(gh)) return; gdispGDrawStringBox(gh->display, gh->x+x, gh->y+y, cx, cy, str, gh->font, gh->color, justify); + _gwinDrawEnd(gh); } void gwinFillStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, justify_t justify) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE) || !gh->font) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!gh->font || !_gwinDrawStart(gh)) return; gdispGFillStringBox(gh->display, gh->x+x, gh->y+y, cx, cy, str, gh->font, gh->color, gh->bgcolor, justify); + _gwinDrawEnd(gh); } #endif #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_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGDrawPoly(gh->display, tx+gh->x, ty+gh->y, pntarray, cnt, gh->color); + _gwinDrawEnd(gh); } void gwinFillConvexPoly(GHandle gh, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt) { - if (!(gh->flags & GWIN_FLG_SYSVISIBLE)) - return; - - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif + if (!_gwinDrawStart(gh)) return; gdispGFillConvexPoly(gh->display, tx+gh->x, ty+gh->y, pntarray, cnt, gh->color); + _gwinDrawEnd(gh); } #endif #if GDISP_NEED_IMAGE gdispImageError gwinDrawImage(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_SYSVISIBLE)) - return GDISP_IMAGE_ERR_OK; + gdispImageError ret; - #if GDISP_NEED_CLIP - gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); - #endif - return gdispGImageDraw(gh->display, img, gh->x+x, gh->y+y, cx, cy, sx, sy); + if (!_gwinDrawStart(gh)) return GDISP_IMAGE_ERR_OK; + ret = gdispGImageDraw(gh->display, img, gh->x+x, gh->y+y, cx, cy, sx, sy); + _gwinDrawEnd(gh); + return ret; } #endif |