From 3957505ab119b21c7b0f4e72f56030c97711988a Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 7 Jul 2013 19:40:37 +1000 Subject: GWIN renaming, tidy up, color styles --- src/gwin/button.c | 150 ++++++++++++++++++++-------------------------------- src/gwin/checkbox.c | 76 +++++++++++++++----------- src/gwin/console.c | 4 +- src/gwin/gimage.c | 8 +-- src/gwin/graph.c | 2 +- src/gwin/gwidget.c | 138 ++++++++++++++++++++++++++++++++++++++++------- src/gwin/gwin.c | 74 ++++++-------------------- src/gwin/gwm.c | 41 +++++++++++++- src/gwin/label.c | 26 ++++----- src/gwin/radio.c | 111 ++++++++++++++------------------------ src/gwin/slider.c | 90 +++++++++++++++---------------- 11 files changed, 384 insertions(+), 336 deletions(-) (limited to 'src') diff --git a/src/gwin/button.c b/src/gwin/button.c index 73f56c2e..e6f628c3 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -29,23 +29,6 @@ // Our pressed state #define GBUTTON_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) -// Default color scheme -static const GButtonColors GButtonDefaultColorsUp = { - HTML2COLOR(0x404040), // color_up_edge; - HTML2COLOR(0xE0E0E0), // color_up_fill; - HTML2COLOR(0x000000), // color_up_txt; -}; -static const GButtonColors GButtonDefaultColorsDown = { - HTML2COLOR(0x404040), // color_dn_edge; - HTML2COLOR(0x808080), // color_dn_fill; - HTML2COLOR(0x404040), // color_dn_txt; -}; -static const GButtonColors GButtonDefaultColorsDisabled = { - HTML2COLOR(0x808080), // color_dis_edge; - HTML2COLOR(0xE0E0E0), // color_dis_fill; - HTML2COLOR(0xC0C0C0), // color_dis_txt; -}; - // Send the button event static void SendButtonEvent(GWidgetObject *gw) { GSourceListener * psl; @@ -153,30 +136,18 @@ static const gwidgetVMT buttonVMT = { #endif }; -GHandle gwinCreateButton(GButtonObject *gw, const GWidgetInit *pInit) { +GHandle gwinButtonCreate(GButtonObject *gw, const GWidgetInit *pInit) { if (!(gw = (GButtonObject *)_gwidgetCreate(&gw->w, pInit, &buttonVMT))) return 0; #if GINPUT_NEED_TOGGLE gw->toggle = GWIDGET_NO_INSTANCE; #endif - gw->c_up = GButtonDefaultColorsUp; - gw->c_dn = GButtonDefaultColorsDown; - gw->c_dis = GButtonDefaultColorsDisabled; gwinSetVisible((GHandle)gw, pInit->g.show); return (GHandle)gw; } -void gwinSetButtonColors(GHandle gh, const GButtonColors *pUp, const GButtonColors *pDown, const GButtonColors *pDisabled) { - if (gh->vmt != (gwinVMT *)&buttonVMT) - return; - - if (pUp) ((GButtonObject *)gh)->c_up = *pUp; - if (pDown) ((GButtonObject *)gh)->c_dn = *pDown; - if (pDisabled) ((GButtonObject *)gh)->c_dis = *pDisabled; -} - -bool_t gwinIsButtonPressed(GHandle gh) { +bool_t gwinButtonIsPressed(GHandle gh) { if (gh->vmt != (gwinVMT *)&buttonVMT) return FALSE; @@ -187,73 +158,64 @@ bool_t gwinIsButtonPressed(GHandle gh) { * Custom Draw Routines *----------------------------------------------------------*/ -static GButtonColors *getDrawColors(GWidgetObject *gw) { - if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &((GButtonObject *)gw)->c_dis; - if ((gw->g.flags & GBUTTON_FLG_PRESSED)) return &((GButtonObject *)gw)->c_dn; - return &((GButtonObject *)gw)->c_up; +static const GColorSet *getDrawColors(GWidgetObject *gw) { + if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled; + if ((gw->g.flags & GBUTTON_FLG_PRESSED)) return &gw->pstyle->pressed; + return &gw->pstyle->enabled; } void gwinButtonDraw_3D(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); - gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter); - gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->color_edge); - gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->color_edge); -} - -void gwinButtonDraw_Box(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; - - if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; - pcol = getDrawColors(gw); - - gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter); - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->color_edge); + gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter); + gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->edge); + gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->edge); } #if GDISP_NEED_ARC void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); if (gw->g.width >= 2*RND_CNR_SIZE+10) { - gdispFillRoundedBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, RND_CNR_SIZE-1, pcol->color_fill); - gdispDrawStringBox(gw->g.x+1, gw->g.y+RND_CNR_SIZE, gw->g.width-2, gw->g.height-(2*RND_CNR_SIZE), gw->txt, gw->g.font, pcol->color_txt, justifyCenter); - gdispDrawRoundedBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, RND_CNR_SIZE, pcol->color_edge); + gdispFillRoundedBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, RND_CNR_SIZE-1, pcol->fill); + gdispDrawStringBox(gw->g.x+1, gw->g.y+RND_CNR_SIZE, gw->g.width-2, gw->g.height-(2*RND_CNR_SIZE), gw->text, gw->g.font, pcol->text, justifyCenter); + gdispDrawRoundedBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, RND_CNR_SIZE, pcol->edge); } else { - gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter); - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->color_edge); + gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter); + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); } } #endif #if GDISP_NEED_ELLIPSE void gwinButtonDraw_Ellipse(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); - gdispFillEllipse(gw->g.x+1, gw->g.y+1, gw->g.width/2-1, gw->g.height/2-1, pcol->color_fill); - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter); - gdispDrawEllipse(gw->g.x, gw->g.y, gw->g.width/2, gw->g.height/2, pcol->color_edge); + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); + gdispFillEllipse(gw->g.x+1, gw->g.y+1, gw->g.width/2-1, gw->g.height/2-1, pcol->fill); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); + gdispDrawEllipse(gw->g.x, gw->g.y, gw->g.width/2, gw->g.height/2, pcol->edge); } #endif #if GDISP_NEED_CONVEX_POLYGON void gwinButtonDraw_ArrowUp(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; - point arw[7]; + const GColorSet * pcol; + (void) param; + point arw[7]; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); @@ -266,15 +228,16 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) { arw[5].x = (gw->g.width - gw->g.width/ARROWBODY_DIVIDER)/2; arw[5].y = gw->g.height/ARROWHEAD_DIVIDER; arw[6].x = 0; arw[6].y = gw->g.height/ARROWHEAD_DIVIDER; - gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill); - gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge); - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter); + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); + gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill); + gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); } void gwinButtonDraw_ArrowDown(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; - point arw[7]; + const GColorSet * pcol; + (void) param; + point arw[7]; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); @@ -287,15 +250,16 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) { arw[5].x = (gw->g.width - gw->g.width/ARROWBODY_DIVIDER)/2; arw[5].y = gw->g.height-1-gw->g.height/ARROWHEAD_DIVIDER; arw[6].x = 0; arw[6].y = gw->g.height-1-gw->g.height/ARROWHEAD_DIVIDER; - gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill); - gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge); - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter); + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); + gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill); + gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); } void gwinButtonDraw_ArrowLeft(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; - point arw[7]; + const GColorSet * pcol; + (void) param; + point arw[7]; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); @@ -308,15 +272,16 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) { arw[5].x = gw->g.width/ARROWHEAD_DIVIDER; arw[5].y = (gw->g.height + gw->g.height/ARROWBODY_DIVIDER)/2; arw[6].x = gw->g.width/ARROWHEAD_DIVIDER; arw[6].y = gw->g.height-1; - gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill); - gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge); - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter); + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); + gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill); + gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); } void gwinButtonDraw_ArrowRight(GWidgetObject *gw, void *param) { - (void) param; - GButtonColors * pcol; - point arw[7]; + const GColorSet * pcol; + (void) param; + point arw[7]; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; pcol = getDrawColors(gw); @@ -329,32 +294,31 @@ void gwinButtonDraw_Box(GWidgetObject *gw, void *param) { arw[5].x = gw->g.width-1-gw->g.width/ARROWHEAD_DIVIDER; arw[5].y = (gw->g.height + gw->g.height/ARROWBODY_DIVIDER)/2; arw[6].x = gw->g.width-1-gw->g.width/ARROWHEAD_DIVIDER; arw[6].y = gw->g.height-1; - gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_fill); - gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->color_edge); - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter); + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); + gdispFillConvexPoly(gw->g.x, gw->g.y, arw, 7, pcol->fill); + gdispDrawPoly(gw->g.x, gw->g.y, arw, 7, pcol->edge); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); } #endif #if GDISP_NEED_IMAGE || defined(__DOXYGEN__) void gwinButtonDraw_Image(GWidgetObject *gw, void *param) { - GButtonColors * pcol; - coord_t sy; + const GColorSet * pcol; + coord_t sy; if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; + pcol = getDrawColors(gw); if (!(gw->g.flags & GWIN_FLG_ENABLED)) { - pcol = &((GButtonObject *)gw)->c_dis; sy = 2 * gw->g.height; } else if ((gw->g.flags & GBUTTON_FLG_PRESSED)) { - pcol = &((GButtonObject *)gw)->c_dn; sy = gw->g.height; } else { - pcol = &((GButtonObject *)gw)->c_up; sy = 0; } gdispImageDraw((gdispImage *)param, gw->g.x, gw->g.y, gw->g.width, gw->g.height, 0, sy); - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, justifyCenter); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); } #endif diff --git a/src/gwin/checkbox.c b/src/gwin/checkbox.c index 74d612d2..84eb3b9f 100644 --- a/src/gwin/checkbox.c +++ b/src/gwin/checkbox.c @@ -24,13 +24,6 @@ // Our checked state #define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0) -static const GCheckboxColors defaultColors = { - Black, // border - Grey, // selected - White, // background - Black, // text -}; - // Send the checkbox event static void SendCheckboxEvent(GWidgetObject *gw) { GSourceListener * psl; @@ -115,70 +108,89 @@ static const gwidgetVMT checkboxVMT = { #endif }; -GHandle gwinCreateCheckbox(GCheckboxObject *gb, const GWidgetInit *pInit) { +GHandle gwinCheckboxCreate(GCheckboxObject *gb, const GWidgetInit *pInit) { if (!(gb = (GCheckboxObject *)_gwidgetCreate(&gb->w, pInit, &checkboxVMT))) return 0; #if GINPUT_NEED_TOGGLE gb->toggle = GWIDGET_NO_INSTANCE; #endif - gb->c = defaultColors; // assign the default colors gwinSetVisible((GHandle)gb, pInit->g.show); return (GHandle)gb; } -bool_t gwinIsCheckboxChecked(GHandle gh) { +void gwinCheckboxCheck(GHandle gh, bool_t isChecked) { + if (gh->vmt != (gwinVMT *)&checkboxVMT) + return; + + if (isChecked) { + if ((gh->flags & GCHECKBOX_FLG_CHECKED)) return; + gh->flags |= GCHECKBOX_FLG_CHECKED; + } else { + if (!(gh->flags & GCHECKBOX_FLG_CHECKED)) return; + gh->flags &= ~GCHECKBOX_FLG_CHECKED; + } + _gwidgetRedraw(gh); + SendCheckboxEvent((GWidgetObject *)gh); +} + +bool_t gwinCheckboxIsChecked(GHandle gh) { if (gh->vmt != (gwinVMT *)&checkboxVMT) return FALSE; return (gh->flags & GCHECKBOX_FLG_CHECKED) ? TRUE : FALSE; } -void gwinCheckboxSetColors(GHandle gh, GCheckboxColors *pColors) { - if (gh->vmt != (gwinVMT *)&checkboxVMT) - return; +/*---------------------------------------------------------- + * Custom Draw Routines + *----------------------------------------------------------*/ - ((GCheckboxObject *)gh)->c = *pColors; +static const GColorSet *getDrawColors(GWidgetObject *gw) { + if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled; + if ((gw->g.flags & GCHECKBOX_FLG_CHECKED)) return &gw->pstyle->pressed; + return &gw->pstyle->enabled; } void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param) { - #define gcw ((GCheckboxObject *)gw) - coord_t ld, df; - (void) param; + #define gcw ((GCheckboxObject *)gw) + coord_t ld, df; + const GColorSet * pcol; + (void) param; - if (gw->g.vmt != (gwinVMT *)&checkboxVMT) - return; + if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return; + pcol = getDrawColors(gw); ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height; - gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gcw->c.color_bg); - gdispDrawBox(gw->g.x, gw->g.y, ld, ld, gcw->c.color_border); + gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gw->pstyle->background); + gdispDrawBox(gw->g.x, gw->g.y, ld, ld, pcol->edge); df = ld < 4 ? 1 : 2; if (gw->g.flags & GCHECKBOX_FLG_CHECKED) - gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, gcw->c.color_checked); + gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill); - gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->txt, gw->g.font, gcw->c.color_txt, gcw->c.color_bg, justifyLeft); + gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft); #undef gcw } void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) { - #define gcw ((GCheckboxObject *)gw) - coord_t ep, ld, df; - (void) param; + #define gcw ((GCheckboxObject *)gw) + coord_t ep, ld, df; + const GColorSet * pcol; + (void) param; - if (gw->g.vmt != (gwinVMT *)&checkboxVMT) - return; + if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return; + pcol = getDrawColors(gw); ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height; ep = gw->g.width-ld-1; - gdispFillArea(gw->g.x+ep-1, gw->g.y+1, ld, ld-2, gcw->c.color_bg); - gdispDrawBox(gw->g.x+ep, gw->g.y, ld, ld, gcw->c.color_border); + gdispFillArea(gw->g.x+ep-1, gw->g.y+1, ld, ld-2, gw->pstyle->background); + gdispDrawBox(gw->g.x+ep, gw->g.y, ld, ld, pcol->edge); df = ld < 4 ? 1 : 2; if (gw->g.flags & GCHECKBOX_FLG_CHECKED) - gdispFillArea(gw->g.x+ep+df, gw->g.y+df, ld-2*df, ld-2*df, gcw->c.color_checked); + gdispFillArea(gw->g.x+ep+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill); - gdispFillStringBox(gw->g.x, gw->g.y, ep, gw->g.height, gw->txt, gw->g.font, gcw->c.color_txt, gcw->c.color_bg, justifyRight); + gdispFillStringBox(gw->g.x, gw->g.y, ep, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyRight); #undef gcw } diff --git a/src/gwin/console.c b/src/gwin/console.c index 105cc79d..06648e9b 100644 --- a/src/gwin/console.c +++ b/src/gwin/console.c @@ -66,7 +66,7 @@ static const gwinVMT consoleVMT = { AfterClear, // The after-clear routine }; -GHandle gwinCreateConsole(GConsoleObject *gc, const GWindowInit *pInit) { +GHandle gwinConsoleCreate(GConsoleObject *gc, const GWindowInit *pInit) { if (!(gc = (GConsoleObject *)_gwindowCreate(&gc->g, pInit, &consoleVMT, 0))) return 0; #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM @@ -79,7 +79,7 @@ GHandle gwinCreateConsole(GConsoleObject *gc, const GWindowInit *pInit) { } #if GFX_USE_OS_CHIBIOS && GWIN_CONSOLE_USE_BASESTREAM - BaseSequentialStream *gwinGetConsoleStream(GHandle gh) { + BaseSequentialStream *gwinConsoleGetStream(GHandle gh) { if (gh->vmt != &consoleVMT) return 0; return (BaseSequentialStream *)&(((GConsoleObject *)(gh))->stream); diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c index 464bc595..eef47dc7 100644 --- a/src/gwin/gimage.c +++ b/src/gwin/gimage.c @@ -16,7 +16,7 @@ #include "gwin/class_gwin.h" -#define widget(gh) ((GImageWidget*)gh) +#define widget(gh) ((GImageObject *)gh) static void _destroy(GWindowObject *gh) { if (gdispImageIsOpen(&widget(gh)->image)) @@ -80,14 +80,14 @@ static void _redraw(GHandle gh) { static const gwinVMT imageVMT = { "Image", // The class name - sizeof(GImageWidget), // The object size + sizeof(GImageObject), // The object size _destroy, // The destroy routine _redraw, // The redraw routine 0, // The after-clear routine }; -GHandle gwinImageCreate(GImageWidget *gobj, GWindowInit *pInit) { - if (!(gobj = (GImageWidget *)_gwindowCreate(&gobj->g, pInit, &imageVMT, 0))) +GHandle gwinImageCreate(GImageObject *gobj, GWindowInit *pInit) { + if (!(gobj = (GImageObject *)_gwindowCreate(&gobj->g, pInit, &imageVMT, 0))) return 0; // Ensure the gdispImageIsOpen() gives valid results diff --git a/src/gwin/graph.c b/src/gwin/graph.c index 049f52e0..de447f4f 100644 --- a/src/gwin/graph.c +++ b/src/gwin/graph.c @@ -165,7 +165,7 @@ static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t } } -GHandle gwinCreateGraph(GGraphObject *gg, const GWindowInit *pInit) { +GHandle gwinGraphCreate(GGraphObject *gg, const GWindowInit *pInit) { if (!(gg = (GGraphObject *)_gwindowCreate(&gg->g, pInit, &graphVMT, 0))) return 0; gg->xorigin = gg->yorigin = 0; diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 6440f171..8fc6ba77 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -14,7 +14,67 @@ #include "gwin/class_gwin.h" /* Our listener for events for widgets */ -static GListener gl; +static GListener gl; + +/* Our default style - a white background theme */ +const GWidgetStyle WhiteWidgetStyle = { + HTML2COLOR(0xFFFFFF), // window background + + // enabled color set + { + HTML2COLOR(0x000000), // text + HTML2COLOR(0x404040), // edge + HTML2COLOR(0xE0E0E0), // fill + HTML2COLOR(0xE0E0E0), // progress - inactive area + }, + + // disabled color set + { + HTML2COLOR(0xC0C0C0), // text + HTML2COLOR(0x808080), // edge + HTML2COLOR(0xE0E0E0), // fill + HTML2COLOR(0xC0E0C0), // progress - active area + }, + + // pressed color set + { + HTML2COLOR(0x404040), // text + HTML2COLOR(0x404040), // edge + HTML2COLOR(0x808080), // fill + HTML2COLOR(0x00E000), // progress - active area + }, +}; + +/* Our black style */ +const GWidgetStyle BlackWidgetStyle = { + HTML2COLOR(0x000000), // window background + + // enabled color set + { + HTML2COLOR(0xC0C0C0), // text + HTML2COLOR(0xC0C0C0), // edge + HTML2COLOR(0x606060), // fill + HTML2COLOR(0x404040), // progress - inactive area + }, + + // disabled color set + { + HTML2COLOR(0x808080), // text + HTML2COLOR(0x404040), // edge + HTML2COLOR(0x404040), // fill + HTML2COLOR(0x004000), // progress - active area + }, + + // pressed color set + { + HTML2COLOR(0xFFFFFF), // text + HTML2COLOR(0xC0C0C0), // edge + HTML2COLOR(0xE0E0E0), // fill + HTML2COLOR(0x008000), // progress - active area + }, +}; + +static const GWidgetStyle * defaultStyle = &BlackWidgetStyle; /* We use these everywhere in this file */ #define gw ((GWidgetObject *)gh) @@ -169,9 +229,10 @@ GHandle _gwidgetCreate(GWidgetObject *pgw, const GWidgetInit *pInit, const gwidg if (!(pgw = (GWidgetObject *)_gwindowCreate(&pgw->g, &pInit->g, &vmt->g, GWIN_FLG_WIDGET|GWIN_FLG_ENABLED))) return 0; - pgw->txt = pInit->text ? pInit->text : ""; - pgw->fnDraw = vmt->DefaultDraw; - pgw->fnParam = 0; + pgw->text = pInit->text ? pInit->text : ""; + pgw->fnDraw = pInit->customDraw ? pInit->customDraw : vmt->DefaultDraw; + pgw->fnParam = pInit->customParam; + pgw->pstyle = pInit->customStyle ? pInit->customStyle : defaultStyle; return &pgw->g; } @@ -184,7 +245,7 @@ void _gwidgetDestroy(GHandle gh) { // Deallocate the text (if necessary) if ((gh->flags & GWIN_FLG_ALLOCTXT)) { gh->flags &= ~GWIN_FLG_ALLOCTXT; - gfxFree((void *)gw->txt); + gfxFree((void *)gw->text); } #if GFX_USE_GINPUT && GINPUT_NEED_TOGGLE @@ -226,32 +287,60 @@ void _gwidgetRedraw(GHandle gh) { gw->fnDraw(gw, gw->fnParam); } -void gwinSetText(GHandle gh, const char *txt, bool_t useAlloc) { +void gwinSetDefaultStyle(const GWidgetStyle *pstyle, bool_t updateAll) { + if (!pstyle) + pstyle = &BlackWidgetStyle; + + if (updateAll) { + const gfxQueueASyncItem * qi; + GHandle gh; + + for(qi = gfxQueueASyncPeek(&_GWINList); qi; qi = gfxQueueASyncNext(qi)) { + gh = QItem2GWindow(qi); + if ((gh->flags & GWIN_FLG_WIDGET) && ((GWidgetObject *)gh)->pstyle == defaultStyle) + gwinSetStyle(gh, pstyle); + } + } + gwinSetDefaultBgColor(pstyle->background); + defaultStyle = pstyle; +} + +/** + * @brief Get the current default style. + * + * @api + */ +const GWidgetStyle *gwinGetDefaultStyle(void) { + return defaultStyle; +} + + +void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) { if (!(gh->flags & GWIN_FLG_WIDGET)) return; // Dispose of the old string if ((gh->flags & GWIN_FLG_ALLOCTXT)) { gh->flags &= ~GWIN_FLG_ALLOCTXT; - if (gw->txt) { - gfxFree((void *)gw->txt); - gw->txt = ""; + if (gw->text) { + gfxFree((void *)gw->text); + gw->text = ""; } } // Alloc the new text if required - if (txt && !*txt) txt = 0; - if (txt && useAlloc) { + if (!text || !*text) + gw->text = ""; + else if (useAlloc) { char *str; - if ((str = (char *)gfxAlloc(strlen(txt)+1))) { + if ((str = (char *)gfxAlloc(strlen(text)+1))) { gh->flags |= GWIN_FLG_ALLOCTXT; - strcpy(str, txt); + strcpy(str, text); } - txt = (const char *)str; - } - - gw->txt = txt ? txt : ""; + gw->text = (const char *)str; + } else + gw->text = text; _gwidgetRedraw(gh); } @@ -259,7 +348,20 @@ const char *gwinGetText(GHandle gh) { if (!(gh->flags & GWIN_FLG_WIDGET)) return 0; - return gw->txt; + return gw->text; +} + +void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle) { + if (!(gh->flags & GWIN_FLG_WIDGET)) + return; + gw->pstyle = pstyle ? pstyle : defaultStyle; + gh->bgcolor = pstyle->background; + gh->color = pstyle->enabled.text; + _gwidgetRedraw(gh); +} + +const GWidgetStyle *gwinGetStyle(GHandle gh) { + return gw->pstyle; } void gwinSetCustomDraw(GHandle gh, CustomWidgetDrawFunction fn, void *param) { diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 92b6cc03..2fd0c905 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -32,11 +32,6 @@ static color_t defaultBgColor = Black; #if GDISP_NEED_TEXT static font_t defaultFont; #endif -#if GWIN_NEED_WINDOWMANAGER - gfxQueueASync _GWINList; - extern GWindowManager GNullWindowManager; - static GWindowManager * cwm; -#endif /*----------------------------------------------- * Helper Routines @@ -52,9 +47,9 @@ static color_t defaultBgColor = Black; } else gwinClear(gh); } - static void _gwm_redim(GHandle gh, const GWindowInit *pInit) { - gh->x = pInit->x; gh->y = pInit->y; - gh->width = pInit->width; gh->height = pInit->height; + static void _gwm_redim(GHandle gh, coord_t x, coord_t y, coord_t width, coord_t height) { + gh->x = x; gh->y = y; + gh->width = width; gh->height = height; if (gh->x < 0) { gh->width += gh->x; gh->x = 0; } if (gh->y < 0) { gh->height += gh->y; gh->y = 0; } if (gh->x > gdispGetWidth()-MIN_WIN_WIDTH) gh->x = gdispGetWidth()-MIN_WIN_WIDTH; @@ -87,9 +82,9 @@ void _gwinInit(void) { _gwidgetInit(); #endif #if GWIN_NEED_WINDOWMANAGER - gfxQueueASyncInit(&_GWINList); - cwm = &GNullWindowManager; - cwm->vmt->Init(); + extern void _gwmInit(void); + + _gwmInit(); #endif } @@ -113,7 +108,7 @@ GHandle _gwindowCreate(GWindowObject *pgw, const GWindowInit *pInit, const gwinV #endif #if GWIN_NEED_WINDOWMANAGER - if (!cwm->vmt->Add(pgw, pInit)) { + if (!_GWINwm->vmt->Add(pgw, pInit)) { if ((pgw->flags & GWIN_FLG_DYNAMIC)) gfxFree(pgw); return 0; @@ -129,18 +124,6 @@ GHandle _gwindowCreate(GWindowObject *pgw, const GWindowInit *pInit, const gwinV * Routines that affect all windows *-----------------------------------------------*/ -#if GWIN_NEED_WINDOWMANAGER - void gwinSetWindowManager(struct GWindowManager *gwm) { - if (!gwm) - gwm = &GNullWindowManager; - if (cwm != gwm) { - cwm->vmt->DeInit(); - cwm = gwm; - cwm->vmt->Init(); - } - } -#endif - void gwinSetDefaultColor(color_t clr) { defaultFgColor = clr; } @@ -171,7 +154,7 @@ color_t gwinGetDefaultBgColor(void) { * The GWindow Routines *-----------------------------------------------*/ -GHandle gwinCreateWindow(GWindowObject *pgw, const GWindowInit *pInit) { +GHandle gwinWindowCreate(GWindowObject *pgw, const GWindowInit *pInit) { if (!(pgw = _gwindowCreate(pgw, pInit, &basegwinVMT, 0))) return 0; gwinSetVisible(pgw, pInit->show); @@ -181,7 +164,7 @@ GHandle gwinCreateWindow(GWindowObject *pgw, const GWindowInit *pInit) { void gwinDestroy(GHandle gh) { // Remove from the window manager #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->Delete(gh); + _GWINwm->vmt->Delete(gh); #endif // Class destroy routine @@ -204,7 +187,7 @@ void gwinSetVisible(GHandle gh, bool_t visible) { if (!(gh->flags & GWIN_FLG_VISIBLE)) { gh->flags |= GWIN_FLG_VISIBLE; #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->Visible(gh); + _GWINwm->vmt->Visible(gh); #else _gwm_vis(gh); #endif @@ -213,7 +196,7 @@ void gwinSetVisible(GHandle gh, bool_t visible) { if ((gh->flags & GWIN_FLG_VISIBLE)) { gh->flags &= ~GWIN_FLG_VISIBLE; #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->Visible(gh); + _GWINwm->vmt->Visible(gh); #endif } } @@ -253,7 +236,7 @@ bool_t gwinGetEnabled(GHandle gh) { void gwinMove(GHandle gh, coord_t x, coord_t y) { #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->Redim(gh, x, y, gh->width, gh->height); + _GWINwm->vmt->Redim(gh, x, y, gh->width, gh->height); #else _gwm_redim(gh, x, y, gh->width, gh->height); #endif @@ -261,44 +244,21 @@ void gwinMove(GHandle gh, coord_t x, coord_t y) { void gwinResize(GHandle gh, coord_t width, coord_t height) { #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->Redim(gh, gh->x, gh->y, width, height); + _GWINwm->vmt->Redim(gh, gh->x, gh->y, width, height); #else _gwm_redim(gh, gh->x, gh->y, width, height); #endif } -void gwinSetMinMax(GHandle gh, GWindowMinMax minmax) { +void gwinRedraw(GHandle gh) { #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->MinMax(gh, minmax); + gwinRaise(gh); #else - (void) gh; - (void) minmax; + if ((gh->flags & GWIN_FLG_VISIBLE)) + _gwm_vis(gh); #endif } -void gwinRaise(GHandle gh) { - #if GWIN_NEED_WINDOWMANAGER - cwm->vmt->Raise(gh); - #else - if ((gh->flags & GWIN_FLG_VISIBLE)) { - if (gh->vmt->Redraw) { - #if GDISP_NEED_CLIP - gdispSetClip(gh->x, gh->y, gh->width, gh->height); - #endif - gh->vmt->Redraw(gh); - } - } - #endif -} - -GWindowMinMax gwinGetMinMax(GHandle gh) { - if (gh->flags & GWIN_FLG_MINIMIZED) - return GWIN_MINIMIZE; - if (gh->flags & GWIN_FLG_MAXIMIZED) - return GWIN_MAXIMIZE; - return GWIN_NORMAL; -} - #if GDISP_NEED_TEXT void gwinSetFont(GHandle gh, font_t font) { gh->font = font; diff --git a/src/gwin/gwm.c b/src/gwin/gwm.c index 88d61a21..f9f56838 100644 --- a/src/gwin/gwm.c +++ b/src/gwin/gwm.c @@ -43,10 +43,49 @@ static const gwmVMT GNullWindowManagerVMT = { WM_MinMax, }; -const GWindowManager GNullWindowManager = { +static const GWindowManager GNullWindowManager = { &GNullWindowManagerVMT, }; +gfxQueueASync _GWINList; +GWindowManager * _GWINwm; + +/*----------------------------------------------- + * Window Routines + *-----------------------------------------------*/ + +void _gwmInit(void) { + gfxQueueASyncInit(&_GWINList); + _GWINwm = (GWindowManager *)&GNullWindowManager; + _GWINwm->vmt->Init(); +} + +void gwinSetWindowManager(struct GWindowManager *gwm) { + if (!gwm) + gwm = (GWindowManager *)&GNullWindowManager; + if (_GWINwm != gwm) { + _GWINwm->vmt->DeInit(); + _GWINwm = gwm; + _GWINwm->vmt->Init(); + } +} + +void gwinSetMinMax(GHandle gh, GWindowMinMax minmax) { + _GWINwm->vmt->MinMax(gh, minmax); +} + +void gwinRaise(GHandle gh) { + _GWINwm->vmt->Raise(gh); +} + +GWindowMinMax gwinGetMinMax(GHandle gh) { + if (gh->flags & GWIN_FLG_MINIMIZED) + return GWIN_MINIMIZE; + if (gh->flags & GWIN_FLG_MAXIMIZED) + return GWIN_MAXIMIZE; + return GWIN_NORMAL; +} + /*----------------------------------------------- * Window Manager Routines *-----------------------------------------------*/ diff --git a/src/gwin/label.c b/src/gwin/label.c index cd469210..71ed18eb 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -25,38 +25,40 @@ #define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1) // Simple: single line with no wrapping -static coord_t getwidth(const char *txt, font_t font, coord_t maxwidth) { +static coord_t getwidth(const char *text, font_t font, coord_t maxwidth) { (void) maxwidth; - return gdispGetStringWidth(txt, font)+2; // Allow one pixel of padding on each side + return gdispGetStringWidth(text, font)+2; // Allow one pixel of padding on each side } // Simple: single line with no wrapping -static coord_t getheight(const char *txt, font_t font, coord_t maxwidth) { - (void) txt; +static coord_t getheight(const char *text, font_t font, coord_t maxwidth) { + (void) text; (void) maxwidth; return gdispGetFontMetric(font, fontHeight); } static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { - (void) param; - coord_t w, h; + coord_t w, h; + (void) param; - w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->txt, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.width; - h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->txt, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.height; + w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->text, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.width; + h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->text, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.height; if (gw->g.width != w || gw->g.height != h) { gwinResize(&gw->g, w, h); return; } - gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->txt, gw->g.font, gw->g.color, gw->g.bgcolor, justifyLeft); + gdispFillStringBox(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); } static const gwidgetVMT labelVMT = { { "Label", // The class name - sizeof(GLabelWidget), // The object size + sizeof(GLabelObject), // The object size _gwidgetDestroy, // The destroy routine _gwidgetRedraw, // The redraw routine 0, // The after-clear routine @@ -88,7 +90,7 @@ static const gwidgetVMT labelVMT = { #endif }; -GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) { +GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit) { uint16_t flags = 0; // auto assign width @@ -103,7 +105,7 @@ GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) { pInit->g.height = getheight(pInit->text, gwinGetDefaultFont(), gdispGetWidth() - pInit->g.x); } - if (!(widget = (GLabelWidget *)_gwidgetCreate(&widget->w, pInit, &labelVMT))) + if (!(widget = (GLabelObject *)_gwidgetCreate(&widget->w, pInit, &labelVMT))) return 0; widget->w.g.flags |= flags; diff --git a/src/gwin/radio.c b/src/gwin/radio.c index d1c65dbc..26ff0b83 100644 --- a/src/gwin/radio.c +++ b/src/gwin/radio.c @@ -24,25 +24,8 @@ // Our pressed state #define GRADIO_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) -// Default color scheme -static const GRadioColors GRadioDefaultColorsUp = { - HTML2COLOR(0x404040), // color_up_edge; - HTML2COLOR(0xE0E0E0), // color_up_fill; - HTML2COLOR(0x000000), // color_up_txt; -}; -static const GRadioColors GRadioDefaultColorsDown = { - HTML2COLOR(0x404040), // color_dn_edge; - HTML2COLOR(0x808080), // color_dn_fill; - HTML2COLOR(0x404040), // color_dn_txt; -}; -static const GRadioColors GRadioDefaultColorsDisabled = { - HTML2COLOR(0x808080), // color_dis_edge; - HTML2COLOR(0xE0E0E0), // color_dis_fill; - HTML2COLOR(0xC0C0C0), // color_dis_txt; -}; - // Send the button event -static void SendButtonEvent(GWidgetObject *gw) { +static void SendRadioEvent(GWidgetObject *gw) { GSourceListener * psl; GEvent * pe; #define pbe ((GEventGWinRadio *)pe) @@ -66,7 +49,7 @@ static void SendButtonEvent(GWidgetObject *gw) { static void MouseDown(GWidgetObject *gw, coord_t x, coord_t y) { (void) x; (void) y; - gwinPressRadio((GHandle)gw); + gwinRadioPress((GHandle)gw); } #endif @@ -75,7 +58,7 @@ static void SendButtonEvent(GWidgetObject *gw) { static void ToggleOn(GWidgetObject *gw, uint16_t role) { (void) role; - gwinPressRadio((GHandle)gw); + gwinRadioPress((GHandle)gw); } static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) { @@ -125,7 +108,7 @@ static const gwidgetVMT radioVMT = { #endif }; -GHandle gwinCreateRadio(GRadioObject *gw, const GWidgetInit *pInit, uint16_t group) { +GHandle gwinRadioCreate(GRadioObject *gw, const GWidgetInit *pInit, uint16_t group) { if (!(gw = (GRadioObject *)_gwidgetCreate(&gw->w, pInit, &radioVMT))) return 0; @@ -133,53 +116,33 @@ GHandle gwinCreateRadio(GRadioObject *gw, const GWidgetInit *pInit, uint16_t gro gw->toggle = GWIDGET_NO_INSTANCE; #endif gw->group = group; - gw->c_up = GRadioDefaultColorsUp; - gw->c_dn = GRadioDefaultColorsDown; - gw->c_dis = GRadioDefaultColorsDisabled; gwinSetVisible((GHandle)gw, pInit->g.show); return (GHandle)gw; } -void gwinSetRadioColors(GHandle gh, const GRadioColors *pUp, const GRadioColors *pDown, const GRadioColors *pDisabled) { - if (gh->vmt != (gwinVMT *)&radioVMT) - return; - - if (pUp) ((GRadioObject *)gh)->c_up = *pUp; - if (pDown) ((GRadioObject *)gh)->c_dn = *pDown; - if (pDisabled) ((GRadioObject *)gh)->c_dis = *pDisabled; -} - -void gwinPressRadio(GHandle gh) { +void gwinRadioPress(GHandle gh) { GHandle gx; if (gh->vmt != (gwinVMT *)&radioVMT || (gh->flags & GRADIO_FLG_PRESSED)) return; - if ((gx = gwinActiveRadio(((GRadioObject *)gh)->group))) { + if ((gx = gwinRadioGetActive(((GRadioObject *)gh)->group))) { gx->flags &= ~GRADIO_FLG_PRESSED; _gwidgetRedraw(gx); } gh->flags |= GRADIO_FLG_PRESSED; _gwidgetRedraw(gh); - SendButtonEvent((GWidgetObject *)gh); + SendRadioEvent((GWidgetObject *)gh); } -bool_t gwinIsRadioPressed(GHandle gh) { +bool_t gwinRadioIsPressed(GHandle gh) { if (gh->vmt != (gwinVMT *)&radioVMT) return FALSE; return (gh->flags & GRADIO_FLG_PRESSED) ? TRUE : FALSE; } -/** - * @brief Find the currently pressed radio button in the specified group - * @return The handle of the pressed radio button or NULL if none are pressed - * - * @param[in] gh The window handle (must be a radio widget) - * - * @api - */ -GHandle gwinActiveRadio(uint16_t group) { +GHandle gwinRadioGetActive(uint16_t group) { const gfxQueueASyncItem * qi; GHandle gh; @@ -195,17 +158,17 @@ GHandle gwinActiveRadio(uint16_t group) { * Custom Draw Routines *----------------------------------------------------------*/ -static GRadioColors *getDrawColors(GWidgetObject *gw) { - if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &((GRadioObject *)gw)->c_dis; - if ((gw->g.flags & GRADIO_FLG_PRESSED)) return &((GRadioObject *)gw)->c_dn; - return &((GRadioObject *)gw)->c_up; +static const GColorSet *getDrawColors(GWidgetObject *gw) { + if (!(gw->g.flags & GWIN_FLG_ENABLED)) return &gw->pstyle->disabled; + if ((gw->g.flags & GRADIO_FLG_PRESSED)) return &gw->pstyle->pressed; + return &gw->pstyle->enabled; } void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) { - #define gcw ((GRadioObject *)gw) - coord_t ld, df; - GRadioColors * pcol; - (void) param; + #define gcw ((GRadioObject *)gw) + coord_t ld, df; + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&radioVMT) return; pcol = getDrawColors(gw); @@ -213,46 +176,52 @@ void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) { ld = gw->g.width < gw->g.height ? gw->g.width : gw->g.height; #if GDISP_NEED_CIRCLE - df = ld/2; - gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->g.bgcolor); - gdispDrawCircle(gw->g.x+df, gw->g.y+df, df, pcol->color_edge); + df = (ld-1)/2; + gdispFillArea(gw->g.x, gw->g.y, ld, ld, gw->pstyle->background); + gdispDrawCircle(gw->g.x+df, gw->g.y+df, df, pcol->edge); if (gw->g.flags & GRADIO_FLG_PRESSED) - gdispFillCircle(gw->g.x+df, gw->g.y+df, df <= 2 ? 1 : (df-2), pcol->color_fill); + gdispFillCircle(gw->g.x+df, gw->g.y+df, df <= 2 ? 1 : (df-2), pcol->fill); #else - gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gw->g.bgcolor); - gdispDrawBox(gw->g.x, gw->g.y, ld, ld, pcol->color_edge); + gdispFillArea(gw->g.x+1, gw->g.y+1, ld, ld-2, gw->pstyle->background); + gdispDrawBox(gw->g.x, gw->g.y, ld, ld, pcol->edge); df = ld < 4 ? 1 : 2; if (gw->g.flags & GRADIO_FLG_PRESSED) - gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->color_fill); + gdispFillArea(gw->g.x+df, gw->g.y+df, ld-2*df, ld-2*df, pcol->fill); #endif - gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->txt, gw->g.font, pcol->color_txt, gw->g.bgcolor, justifyLeft); + gdispFillStringBox(gw->g.x+ld+1, gw->g.y, gw->g.width-ld-1, gw->g.height, gw->text, gw->g.font, pcol->text, gw->pstyle->background, justifyLeft); #undef gcw } void gwinRadioDraw_Button(GWidgetObject *gw, void *param) { - (void) param; - GRadioColors * pcol; + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&radioVMT) return; pcol = getDrawColors(gw); - gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter); - gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->color_edge); - gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->color_edge); + gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter); + gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->edge); + gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->edge); } void gwinRadioDraw_Tab(GWidgetObject *gw, void *param) { - (void) param; - GRadioColors * pcol; + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&radioVMT) return; pcol = getDrawColors(gw); - gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, pcol->color_txt, pcol->color_fill, justifyCenter); - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->color_edge); + if ((gw->g.flags & GRADIO_FLG_PRESSED)) { + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); + gdispFillStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter); + } else { + gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter); + gdispDrawLine(gw->g.x+gw->g.width-1, gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, pcol->edge); + gdispDrawLine(gw->g.x, gw->g.y+gw->g.height-1, gw->g.x+gw->g.width-2, gw->g.y+gw->g.height-1, pcol->edge); + } } #endif /* GFX_USE_GWIN && GWIN_NEED_BUTTON */ diff --git a/src/gwin/slider.c b/src/gwin/slider.c index 5aa320f8..4d9c3510 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -29,14 +29,6 @@ #define GWIN_SLIDER_TOGGLE_INC 20 // How many toggles to go from minimum to maximum #endif -static const GSliderColors GSliderDefaultColors = { - HTML2COLOR(0x404040), // color_edge - HTML2COLOR(0x000000), // color_thumb - HTML2COLOR(0x00E000), // color_active - HTML2COLOR(0xE0E0E0), // color_inactive - HTML2COLOR(0xFFFFFF), // color_txt -}; - // Send the slider event static void SendSliderEvent(GWidgetObject *gw) { GSourceListener * psl; @@ -146,10 +138,10 @@ static void ResetDisplayPos(GSliderObject *gsw) { #define gsw ((GSliderObject *)gw) if (role) { - gwinSetSliderPosition((GHandle)gw, gsw->pos+(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC); + gwinSliderSetPosition((GHandle)gw, gsw->pos+(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC); SendSliderEvent(gw); } else { - gwinSetSliderPosition((GHandle)gw, gsw->pos-(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC); + gwinSliderSetPosition((GHandle)gw, gsw->pos-(gsw->max-gsw->min)/GWIN_SLIDER_TOGGLE_INC); SendSliderEvent(gw); } #undef gsw @@ -231,7 +223,7 @@ static const gwidgetVMT sliderVMT = { #endif }; -GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) { +GHandle gwinSliderCreate(GSliderObject *gs, const GWidgetInit *pInit) { if (!(gs = (GSliderObject *)_gwidgetCreate(&gs->w, pInit, &sliderVMT))) return 0; #if GINPUT_NEED_TOGGLE @@ -241,7 +233,6 @@ GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) { #if GINPUT_NEED_DIAL gs->dial = GWIDGET_NO_INSTANCE; #endif - gs->c = GSliderDefaultColors; gs->min = 0; gs->max = 100; gs->pos = 0; @@ -250,7 +241,7 @@ GHandle gwinCreateSlider(GSliderObject *gs, const GWidgetInit *pInit) { return (GHandle)gs; } -void gwinSetSliderRange(GHandle gh, int min, int max) { +void gwinSliderSetRange(GHandle gh, int min, int max) { #define gsw ((GSliderObject *)gh) if (gh->vmt != (gwinVMT *)&sliderVMT) @@ -265,7 +256,7 @@ void gwinSetSliderRange(GHandle gh, int min, int max) { #undef gsw } -void gwinSetSliderPosition(GHandle gh, int pos) { +void gwinSliderSetPosition(GHandle gh, int pos) { #define gsw ((GSliderObject *)gh) if (gh->vmt != (gwinVMT *)&sliderVMT) @@ -284,61 +275,70 @@ void gwinSetSliderPosition(GHandle gh, int pos) { #undef gsw } -void gwinSetSliderColors(GHandle gh, const GSliderColors *pColors) { - if (gh->vmt != (gwinVMT *)&sliderVMT) - return; - - ((GSliderObject *)gh)->c = *pColors; -} +/*---------------------------------------------------------- + * Custom Draw Routines + *----------------------------------------------------------*/ void gwinSliderDraw_Std(GWidgetObject *gw, void *param) { - #define gsw ((GSliderObject *)gw) - (void) param; + #define gsw ((GSliderObject *)gw) + const GColorSet * pcol; + (void) param; if (gw->g.vmt != (gwinVMT *)&sliderVMT) return; + if ((gw->g.flags & GWIN_FLG_ENABLED)) + pcol = &gw->pstyle->pressed; + else + pcol = &gw->pstyle->disabled; + if (gw->g.width < gw->g.height) { // Vertical slider if (gsw->dpos != gw->g.height-1) - gdispFillArea(gw->g.x, gw->g.y+gsw->dpos, gw->g.width, gw->g.height - gsw->dpos, gsw->c.color_active); + gdispFillArea(gw->g.x, gw->g.y+gsw->dpos, gw->g.width, gw->g.height - gsw->dpos, pcol->progress); // Active Area if (gsw->dpos != 0) - gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gsw->c.color_inactive); - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge); - gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, gsw->c.color_thumb); + gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gw->pstyle->enabled.progress); // Inactive area + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge + gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, pcol->edge); // Thumb if (gsw->dpos >= 2) - gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos-2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos-2, gsw->c.color_thumb); + gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos-2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos-2, pcol->edge); // Thumb if (gsw->dpos <= gw->g.height-2) - gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos+2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos+2, gsw->c.color_thumb); + gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos+2, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos+2, pcol->edge); // Thumb // Horizontal slider } else { if (gsw->dpos != gw->g.width-1) - gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gsw->c.color_inactive); + gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gw->pstyle->enabled.progress); // Inactive area if (gsw->dpos != 0) - gdispFillArea(gw->g.x, gw->g.y, gsw->dpos, gw->g.height, gsw->c.color_active); - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge); - gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, gsw->c.color_thumb); + gdispFillArea(gw->g.x, gw->g.y, gsw->dpos, gw->g.height, pcol->progress); // Active Area + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge + gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, pcol->edge); // Thumb if (gsw->dpos >= 2) - gdispDrawLine(gw->g.x+gsw->dpos-2, gw->g.y, gw->g.x+gsw->dpos-2, gw->g.y+gw->g.height-1, gsw->c.color_thumb); + gdispDrawLine(gw->g.x+gsw->dpos-2, gw->g.y, gw->g.x+gsw->dpos-2, gw->g.y+gw->g.height-1, pcol->edge); // Thumb if (gsw->dpos <= gw->g.width-2) - gdispDrawLine(gw->g.x+gsw->dpos+2, gw->g.y, gw->g.x+gsw->dpos+2, gw->g.y+gw->g.height-1, gsw->c.color_thumb); + gdispDrawLine(gw->g.x+gsw->dpos+2, gw->g.y, gw->g.x+gsw->dpos+2, gw->g.y+gw->g.height-1, pcol->edge); // Thumb } - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, gsw->c.color_txt, justifyCenter); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); #undef gsw } void gwinSliderDraw_Image(GWidgetObject *gw, void *param) { - #define gsw ((GSliderObject *)gw) - #define gi ((gdispImage *)param) - coord_t z, v; + #define gsw ((GSliderObject *)gw) + #define gi ((gdispImage *)param) + const GColorSet * pcol; + coord_t z, v; if (gw->g.vmt != (gwinVMT *)&sliderVMT) return; + if ((gw->g.flags & GWIN_FLG_ENABLED)) + pcol = &gw->pstyle->pressed; + else + pcol = &gw->pstyle->disabled; + if (gw->g.width < gw->g.height) { // Vertical slider if (gsw->dpos != 0) // The unfilled area - gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gsw->c.color_inactive); + gdispFillArea(gw->g.x, gw->g.y, gw->g.width, gsw->dpos, gw->pstyle->enabled.progress); // Inactive area if (gsw->dpos != gw->g.height-1) { // The filled area for(z=gw->g.height, v=gi->height; z > gsw->dpos;) { z -= v; @@ -349,13 +349,13 @@ void gwinSliderDraw_Image(GWidgetObject *gw, void *param) { gdispImageDraw(gi, gw->g.x, gw->g.y+z, gw->g.width, v, 0, gi->height-v); } } - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge); - gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, gsw->c.color_thumb); + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge + gdispDrawLine(gw->g.x, gw->g.y+gsw->dpos, gw->g.x+gw->g.width-1, gw->g.y+gsw->dpos, pcol->edge); // Thumb // Horizontal slider } else { if (gsw->dpos != gw->g.width-1) // The unfilled area - gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gsw->c.color_inactive); + gdispFillArea(gw->g.x+gsw->dpos, gw->g.y, gw->g.width-gsw->dpos, gw->g.height, gw->pstyle->enabled.progress); // Inactive area if (gsw->dpos != 0) { // The filled area for(z=0, v=gi->width; z < gsw->dpos; z += v) { if (z+v > gsw->dpos) @@ -363,10 +363,10 @@ void gwinSliderDraw_Image(GWidgetObject *gw, void *param) { gdispImageDraw(gi, gw->g.x+z, gw->g.y, v, gw->g.height, 0, 0); } } - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gsw->c.color_edge); - gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, gsw->c.color_thumb); + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); // Edge + gdispDrawLine(gw->g.x+gsw->dpos, gw->g.y, gw->g.x+gsw->dpos, gw->g.y+gw->g.height-1, pcol->edge); // Thumb } - gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->txt, gw->g.font, gsw->c.color_txt, justifyCenter); + gdispDrawStringBox(gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2, gw->text, gw->g.font, pcol->text, justifyCenter); #undef gsw } -- cgit v1.2.3