From b316263833c95cf2b8cf14fe890321d5880aa81c Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 23 Jan 2015 17:57:13 +1000 Subject: Implement a "Toggle Button" using a checkbox with a custom draw. Updated the widgets demo to show this. --- src/gwin/gwin_checkbox.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/gwin/gwin_checkbox.h | 1 + 2 files changed, 42 insertions(+) (limited to 'src') diff --git a/src/gwin/gwin_checkbox.c b/src/gwin/gwin_checkbox.c index 72d8dbdf..ff0507d9 100644 --- a/src/gwin/gwin_checkbox.c +++ b/src/gwin/gwin_checkbox.c @@ -16,6 +16,10 @@ #include "gwin_class.h" +// Parameters for button custom draw +#define TOP_FADE 50 // (TOP_FADE/255)% fade to white for top of button +#define BOTTOM_FADE 25 // (BOTTOM_FADE/255)% fade to black for bottom of button + // Our checked state #define GCHECKBOX_FLG_CHECKED (GWIN_FIRST_CONTROL_FLAG<<0) @@ -204,4 +208,41 @@ void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param) { #undef gcw } +#if GWIN_FLAT_STYLING + void gwinCheckboxDraw_Button(GWidgetObject *gw, void *param) { + const GColorSet * pcol; + (void) param; + + if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return; + pcol = getDrawColors(gw); + + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, pcol->fill, justifyCenter); + gdispGDrawLine(gw->g.display, 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); + gdispGDrawLine(gw->g.display, 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); + } +#else + void gwinCheckboxDraw_Button(GWidgetObject *gw, void *param) { + const GColorSet * pcol; + fixed alpha; + fixed dalpha; + coord_t i; + color_t tcol, bcol; + (void) param; + + if (gw->g.vmt != (gwinVMT *)&checkboxVMT) return; + pcol = getDrawColors(gw); + + /* Fill the box blended from variants of the fill color */ + tcol = gdispBlendColor(White, pcol->fill, TOP_FADE); + bcol = gdispBlendColor(Black, pcol->fill, BOTTOM_FADE); + dalpha = FIXED(255)/gw->g.height; + for(alpha = 0, i = 0; i < gw->g.height; i++, alpha += dalpha) + gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y+i, gw->g.x+gw->g.width-2, gw->g.y+i, gdispBlendColor(bcol, tcol, NONFIXED(alpha))); + + gdispGDrawStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width-1, gw->g.height-1, gw->text, gw->g.font, pcol->text, justifyCenter); + gdispGDrawLine(gw->g.display, 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); + gdispGDrawLine(gw->g.display, 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 + #endif /* (GFX_USE_GWIN && GWIN_NEED_CHECKBOX) */ diff --git a/src/gwin/gwin_checkbox.h b/src/gwin/gwin_checkbox.h index 3a67d487..f0a8e9f0 100644 --- a/src/gwin/gwin_checkbox.h +++ b/src/gwin/gwin_checkbox.h @@ -116,6 +116,7 @@ bool_t gwinCheckboxIsChecked(GHandle gh); */ void gwinCheckboxDraw_CheckOnLeft(GWidgetObject *gw, void *param); void gwinCheckboxDraw_CheckOnRight(GWidgetObject *gw, void *param); +void gwinCheckboxDraw_Button(GWidgetObject *gw, void *param); /** @} */ #ifdef __cplusplus -- cgit v1.2.3