From 248335c513fe92d1629f2c34c5777ef9b628d09e Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 24 Oct 2013 04:13:07 +0200 Subject: Added gwinLabelSetBorder() --- src/gwin/label.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src/gwin/label.c') diff --git a/src/gwin/label.c b/src/gwin/label.c index a933b3ac..750cb4fb 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -21,16 +21,22 @@ #include "gwin/class_gwin.h" -#define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG<<0) -#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1) +// macros to assist in data type conversions +#define gh2obj ((GLabelObject *)gh) -// Simple: single line with no wrapping +// flags for the GLabelObject +#define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG << 0) +#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG << 1) +#define GLABEL_FLG_BORDER (GWIN_FIRST_CONTROL_FLAG << 2) + +// simple: single line with no wrapping static coord_t getwidth(const char *text, font_t font, coord_t maxwidth) { (void) maxwidth; + return gdispGetStringWidth(text, font)+2; // Allow one pixel of padding on each side } -// Simple: single line with no wrapping +// simple: single line with no wrapping static coord_t getheight(const char *text, font_t font, coord_t maxwidth) { (void) text; (void) maxwidth; @@ -47,12 +53,18 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { if (gw->g.width != w || gw->g.height != h) { gwinResize(&gw->g, w, h); + return; } + // render the text 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); + + // render the border (if any) + if (gw->g.flags & GLABEL_FLG_BORDER) + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text); } static const gwidgetVMT labelVMT = { @@ -109,12 +121,25 @@ GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit) { if (!(widget = (GLabelObject *)_gwidgetCreate(&widget->w, pInit, &labelVMT))) return 0; - widget->w.g.flags |= flags; + // no borders by default + widget->w.g.flags &=~ GLABEL_FLG_BORDER; gwinSetVisible(&widget->w.g, pInit->g.show); + return (GHandle)widget; } +void gwinLabelSetBorder(GHandle gh, bool_t border) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&labelVMT) + return; + + if (border) + gh2obj->w.g.flags |= GLABEL_FLG_BORDER; + else + gh2obj->w.g.flags &=~ GLABEL_FLG_BORDER; +} + #endif // GFX_USE_GWIN && GFX_NEED_LABEL /** @} */ -- cgit v1.2.3 From 825bbf26a1bf11d7148a16229f6515fae5efb276 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 24 Oct 2013 04:31:31 +0200 Subject: fixed label bugs --- src/gwin/label.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/gwin/label.c') diff --git a/src/gwin/label.c b/src/gwin/label.c index 750cb4fb..65afff7e 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -64,7 +64,7 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { // render the border (if any) if (gw->g.flags & GLABEL_FLG_BORDER) - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text); + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); } static const gwidgetVMT labelVMT = { @@ -122,8 +122,9 @@ GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit) { return 0; // no borders by default - widget->w.g.flags &=~ GLABEL_FLG_BORDER; + flags &=~ GLABEL_FLG_BORDER; + widget->w.g.flags |= flags; gwinSetVisible(&widget->w.g, pInit->g.show); return (GHandle)widget; -- cgit v1.2.3 From 7a7e223d152b42553f7e6ce0220dd5d736b89c56 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 24 Oct 2013 18:36:11 +1000 Subject: Add multiple display support to GWIN. You can now create windows on multiple displays. --- src/gwin/label.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gwin/label.c') diff --git a/src/gwin/label.c b/src/gwin/label.c index 65afff7e..5619761a 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -48,8 +48,8 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { coord_t w, h; (void) param; - 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; + w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.width; + h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.height; if (gw->g.width != w || gw->g.height != h) { gwinResize(&gw->g, w, h); @@ -58,13 +58,13 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { } // render the text - gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, + gdispGFillStringBox(gw->g.display, 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); // render the border (if any) if (gw->g.flags & GLABEL_FLG_BORDER) - gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); + gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); } static const gwidgetVMT labelVMT = { @@ -102,23 +102,23 @@ static const gwidgetVMT labelVMT = { #endif }; -GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit) { +GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit) { uint16_t flags = 0; // auto assign width if (pInit->g.width <= 0) { flags |= GLABEL_FLG_WAUTO; - pInit->g.width = getwidth(pInit->text, gwinGetDefaultFont(), gdispGetWidth() - pInit->g.x); + pInit->g.width = getwidth(pInit->text, gwinGetDefaultFont(), gdispGGetWidth(g) - pInit->g.x); } // auto assign height if (pInit->g.height <= 0) { flags |= GLABEL_FLG_HAUTO; - pInit->g.height = getheight(pInit->text, gwinGetDefaultFont(), gdispGetWidth() - pInit->g.x); + pInit->g.height = getheight(pInit->text, gwinGetDefaultFont(), gdispGGetWidth(g) - pInit->g.x); } - if (!(widget = (GLabelObject *)_gwidgetCreate(&widget->w, pInit, &labelVMT))) + if (!(widget = (GLabelObject *)_gwidgetCreate(g, &widget->w, pInit, &labelVMT))) return 0; // no borders by default -- cgit v1.2.3