From ef0a1ef054d100eace7cc58941b27c2d5ed67518 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 13:57:44 +1000 Subject: Much improved appearance for buttons and tabs. Also add GWIN_FLAT_STYLING to allow low color (eg monochrome) displays to get the old simplified look. --- src/gwin/radio.c | 98 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 22 deletions(-) (limited to 'src/gwin/radio.c') diff --git a/src/gwin/radio.c b/src/gwin/radio.c index f50ffe9b..882be503 100644 --- a/src/gwin/radio.c +++ b/src/gwin/radio.c @@ -21,6 +21,8 @@ #include "src/gwin/class_gwin.h" +#define GRADIO_TAB_CNR 3 + // Our pressed state #define GRADIO_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) @@ -195,34 +197,86 @@ void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) { #undef gcw } -void gwinRadioDraw_Button(GWidgetObject *gw, void *param) { - const GColorSet * pcol; - (void) param; - - if (gw->g.vmt != (gwinVMT *)&radioVMT) 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); -} - -void gwinRadioDraw_Tab(GWidgetObject *gw, void *param) { - const GColorSet * pcol; - (void) param; +#if GWIN_FLAT_STYLING + void gwinRadioDraw_Button(GWidgetObject *gw, void *param) { + const GColorSet * pcol; + (void) param; - if (gw->g.vmt != (gwinVMT *)&radioVMT) return; - pcol = getDrawColors(gw); + if (gw->g.vmt != (gwinVMT *)&radioVMT) return; + pcol = getDrawColors(gw); - if ((gw->g.flags & GRADIO_FLG_PRESSED)) { - gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); - gdispGFillStringBox(gw->g.display, 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 { 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); } -} + void gwinRadioDraw_Tab(GWidgetObject *gw, void *param) { + const GColorSet * pcol; + (void) param; + + if (gw->g.vmt != (gwinVMT *)&radioVMT) return; + pcol = getDrawColors(gw); + + if ((gw->g.flags & GRADIO_FLG_PRESSED)) { + gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, pcol->edge); + gdispGFillStringBox(gw->g.display, 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 { + 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 gwinRadioDraw_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 *)&radioVMT) return; + pcol = getDrawColors(gw); + + /* Fill the box blended from variants of the fill color */ + tcol = gdispBlendColor(White, pcol->fill, 50); + bcol = gdispBlendColor(Black, pcol->fill, 25); + 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); + } + void gwinRadioDraw_Tab(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 *)&radioVMT) return; + pcol = getDrawColors(gw); + + if ((gw->g.flags & GRADIO_FLG_PRESSED)) { + tcol = gdispBlendColor(pcol->edge, gw->pstyle->background, 128); + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, pcol->text, gw->g.bgcolor, justifyCenter); + gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y, gw->g.x+gw->g.width-(GRADIO_TAB_CNR+1), gw->g.y, tcol); + gdispGDrawLine(gw->g.display, gw->g.x+gw->g.width-(GRADIO_TAB_CNR+1), gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+GRADIO_TAB_CNR, tcol); + gdispGDrawLine(gw->g.display, gw->g.x+gw->g.width-1, gw->g.y+GRADIO_TAB_CNR, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, tcol); + } else { + /* Fill the box blended from variants of the fill color */ + tcol = gdispBlendColor(White, pcol->fill, 50); + bcol = gdispBlendColor(Black, pcol->fill, 25); + 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))); + 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); + gdispGDrawStringBox(gw->g.display, 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 #endif /* GFX_USE_GWIN && GWIN_NEED_BUTTON */ /** @} */ -- cgit v1.2.3 From 558ee7282d9f753519d7a813f1b9206c31e6f247 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 16:44:11 +1000 Subject: Make some GWIN constants into #defines --- src/gwin/radio.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/gwin/radio.c') diff --git a/src/gwin/radio.c b/src/gwin/radio.c index 882be503..8dc3ba6b 100644 --- a/src/gwin/radio.c +++ b/src/gwin/radio.c @@ -21,7 +21,10 @@ #include "src/gwin/class_gwin.h" -#define GRADIO_TAB_CNR 3 +#define GRADIO_TAB_CNR 3 // Diagonal corner on active tab +#define GRADIO_TOP_FADE 50 // (GRADIO_TOP_FADE/255)% fade to white for top of tab/button +#define GRADIO_BOTTOM_FADE 25 // (GRADIO_BOTTOM_FADE/255)% fade to black for bottom of tab/button +#define GRADIO_OUTLINE_FADE 128 // (GRADIO_OUTLINE_FADE/255)% fade to background for active tab edge // Our pressed state #define GRADIO_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) @@ -238,8 +241,8 @@ void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) { pcol = getDrawColors(gw); /* Fill the box blended from variants of the fill color */ - tcol = gdispBlendColor(White, pcol->fill, 50); - bcol = gdispBlendColor(Black, pcol->fill, 25); + tcol = gdispBlendColor(White, pcol->fill, GRADIO_TOP_FADE); + bcol = gdispBlendColor(Black, pcol->fill, GRADIO_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))); @@ -260,15 +263,15 @@ void gwinRadioDraw_Radio(GWidgetObject *gw, void *param) { pcol = getDrawColors(gw); if ((gw->g.flags & GRADIO_FLG_PRESSED)) { - tcol = gdispBlendColor(pcol->edge, gw->pstyle->background, 128); + tcol = gdispBlendColor(pcol->edge, gw->pstyle->background, GRADIO_OUTLINE_FADE); gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, pcol->text, gw->g.bgcolor, justifyCenter); gdispGDrawLine(gw->g.display, gw->g.x, gw->g.y, gw->g.x+gw->g.width-(GRADIO_TAB_CNR+1), gw->g.y, tcol); gdispGDrawLine(gw->g.display, gw->g.x+gw->g.width-(GRADIO_TAB_CNR+1), gw->g.y, gw->g.x+gw->g.width-1, gw->g.y+GRADIO_TAB_CNR, tcol); gdispGDrawLine(gw->g.display, gw->g.x+gw->g.width-1, gw->g.y+GRADIO_TAB_CNR, gw->g.x+gw->g.width-1, gw->g.y+gw->g.height-1, tcol); } else { /* Fill the box blended from variants of the fill color */ - tcol = gdispBlendColor(White, pcol->fill, 50); - bcol = gdispBlendColor(Black, pcol->fill, 25); + tcol = gdispBlendColor(White, pcol->fill, GRADIO_TOP_FADE); + bcol = gdispBlendColor(Black, pcol->fill, GRADIO_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))); -- cgit v1.2.3