diff --git a/gfxconf.example.h b/gfxconf.example.h index 18437a4d..5be67335 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -149,6 +149,7 @@ #define GWIN_NEED_LIST_IMAGES FALSE #define GWIN_NEED_PROGRESSBAR FALSE #define GWIN_NEED_FRAME FALSE + #define GWIN_FLAT_STYLING FALSE /////////////////////////////////////////////////////////////////////////// diff --git a/src/gwin/button.c b/src/gwin/button.c index 72d75225..59c7f689 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -109,7 +109,7 @@ static const gwidgetVMT buttonVMT = { _gwidgetRedraw, // The redraw routine 0, // The after-clear routine }, - gwinButtonDraw_3D, // The default drawing routine + gwinButtonDraw_Normal, // The default drawing routine #if GINPUT_NEED_MOUSE { MouseDown, // Process mouse down events @@ -164,17 +164,42 @@ static const GColorSet *getDrawColors(GWidgetObject *gw) { return &gw->pstyle->enabled; } -void gwinButtonDraw_3D(GWidgetObject *gw, void *param) { - const GColorSet * pcol; - (void) param; +#if GWIN_FLAT_STYLING + void gwinButtonDraw_Normal(GWidgetObject *gw, void *param) { + const GColorSet * pcol; + (void) param; - if (gw->g.vmt != (gwinVMT *)&buttonVMT) return; - pcol = getDrawColors(gw); + if (gw->g.vmt != (gwinVMT *)&buttonVMT) 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 gwinButtonDraw_Normal(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 *)&buttonVMT) 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); -} + /* 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); + } +#endif #if GDISP_NEED_ARC void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param) { diff --git a/src/gwin/button.h b/src/gwin/button.h index dad0cc91..6dd78488 100644 --- a/src/gwin/button.h +++ b/src/gwin/button.h @@ -111,7 +111,7 @@ bool_t gwinButtonIsPressed(GHandle gh); * @api * @{ */ -void gwinButtonDraw_3D(GWidgetObject *gw, void *param); // @< A standard 3D button +void gwinButtonDraw_Normal(GWidgetObject *gw, void *param); // @< A standard button #if GDISP_NEED_ARC || defined(__DOXYGEN__) void gwinButtonDraw_Rounded(GWidgetObject *gw, void *param); // @< A rounded rectangle button #endif 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 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); - 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); } -} + 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 */ /** @} */ diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h index 656e0e3f..aa296026 100644 --- a/src/gwin/sys_options.h +++ b/src/gwin/sys_options.h @@ -98,6 +98,15 @@ * @name GWIN Optional Parameters * @{ */ + /** + * @brief Use flat styling for controls rather than a 3D look + * @details Defaults to FALSE + * @note This may appear better on color-restricted displays + * @note Flat styling is less graphics and cpu intensive (marginally) than the default 3D look. + */ + #ifndef GWIN_FLAT_STYLING + #define GWIN_FLAT_STYLING FALSE + #endif /** * @brief Buttons should not insist the mouse is over the button on mouse release * @details Defaults to FALSE