From 135f8f5ecac5bc04bc18438bf78fd7ba82c40816 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 28 Apr 2014 23:20:51 +0200 Subject: Added gwinLabelSetAttribute() --- src/gwin/label.c | 43 +++++++++++++++++++++++++++++++++++++++---- src/gwin/label.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/label.c b/src/gwin/label.c index a5064818..167ded84 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -23,6 +23,7 @@ // macros to assist in data type conversions #define gh2obj ((GLabelObject *)gh) +#define gw2obj ((GLabelObject *)gw) // flags for the GLabelObject #define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG << 0) @@ -57,10 +58,26 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { return; } - // render the text - 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); + #if GWIN_LABEL_ATTRIBUTE + if (gw2obj->attr != 0) { + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw2obj->attr, gw->g.font, + (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, + justifyLeft); + + gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, 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); + } else { + 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); + + } + #else + 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); + #endif // render the border (if any) if (gw->g.flags & GLABEL_FLG_BORDER) @@ -124,6 +141,11 @@ GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit) // no borders by default flags &=~ GLABEL_FLG_BORDER; + #if GWIN_LABEL_ATTRIBUTE + widget->tab = 0; + widget->attr = 0; + #endif + widget->w.g.flags |= flags; gwinSetVisible(&widget->w.g, pInit->g.show); @@ -141,6 +163,19 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) { gh2obj->w.g.flags &=~ GLABEL_FLG_BORDER; } +#if GWIN_LABEL_ATTRIBUTE + void gwinLabelSetAttribute(GHandle gh, coord_t tab, char* attr) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&labelVMT) + return; + + gh2obj->tab = tab; + gh2obj->attr = attr; + + gwinRedraw(gh); + } +#endif // GWIN_LABEL_ATTRIBUTE + #endif // GFX_USE_GWIN && GFX_NEED_LABEL /** @} */ diff --git a/src/gwin/label.h b/src/gwin/label.h index 9d62738d..5cf87ad1 100644 --- a/src/gwin/label.h +++ b/src/gwin/label.h @@ -32,6 +32,11 @@ // An label window typedef struct GLabelObject { GWidgetObject w; + + #if GWIN_LABEL_ATTRIBUTE + coord_t tab; + char* attr; + #endif } GLabelObject; #ifdef __cplusplus @@ -63,6 +68,29 @@ GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit); */ void gwinLabelSetBorder(GHandle gh, bool_t border); +#if GWIN_LABEL_ATTRIBUTE + /** + * @brief Add an attribute in front of the actualy label text + * @detail Often you want to display a text like this: + * Current IP: 192.168.1.42 + * In that case, one the actual IP will be variable, the text in front of it + * always remains the same. The static text is called the attribute and can be + * set using this function. + * Furthermore, the tab can be set in order to vertically align multiple labels. + * Please check out the website for further explanation, illustraions and usage + * examples. + * + * @note The attribute text is currently not being allocated + * + * @param[in] gh The widget handle (must be a label handle) + * @param[in] tab The distance of the label text from the left widget edge + * @param[in] attr The attribute to be displayed + * + * @api + */ + void gwinLabelSetAttribute(GHandle gh, coord_t tab, char* attr); +#endif + #ifdef __cplusplus } #endif -- cgit v1.2.3 From a0b11f764b6c2e52d7a41d7bfda438a4e7a9a5b0 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 28 Apr 2014 23:31:33 +0200 Subject: typo --- src/gwin/label.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gwin') diff --git a/src/gwin/label.h b/src/gwin/label.h index 5cf87ad1..eafa8d91 100644 --- a/src/gwin/label.h +++ b/src/gwin/label.h @@ -73,7 +73,7 @@ void gwinLabelSetBorder(GHandle gh, bool_t border); * @brief Add an attribute in front of the actualy label text * @detail Often you want to display a text like this: * Current IP: 192.168.1.42 - * In that case, one the actual IP will be variable, the text in front of it + * In that case, the actual IP will be variable, the text in front of it * always remains the same. The static text is called the attribute and can be * set using this function. * Furthermore, the tab can be set in order to vertically align multiple labels. -- cgit v1.2.3 From 56b8dfc72f2adf3bd214428f5fa4f81d8b41b437 Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 29 Apr 2014 09:00:06 +1000 Subject: New label attribute is const. Also updated comments. --- src/gwin/label.c | 2 +- src/gwin/label.h | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/label.c b/src/gwin/label.c index 167ded84..574dc8b7 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -164,7 +164,7 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) { } #if GWIN_LABEL_ATTRIBUTE - void gwinLabelSetAttribute(GHandle gh, coord_t tab, char* attr) { + void gwinLabelSetAttribute(GHandle gh, coord_t tab, const char* attr) { // is it a valid handle? if (gh->vmt != (gwinVMT *)&labelVMT) return; diff --git a/src/gwin/label.h b/src/gwin/label.h index eafa8d91..708599a6 100644 --- a/src/gwin/label.h +++ b/src/gwin/label.h @@ -35,7 +35,7 @@ typedef struct GLabelObject { #if GWIN_LABEL_ATTRIBUTE coord_t tab; - char* attr; + const char* attr; #endif } GLabelObject; @@ -70,7 +70,7 @@ void gwinLabelSetBorder(GHandle gh, bool_t border); #if GWIN_LABEL_ATTRIBUTE /** - * @brief Add an attribute in front of the actualy label text + * @brief Add an text attribute in front of the normal label text * @detail Often you want to display a text like this: * Current IP: 192.168.1.42 * In that case, the actual IP will be variable, the text in front of it @@ -80,7 +80,11 @@ void gwinLabelSetBorder(GHandle gh, bool_t border); * Please check out the website for further explanation, illustraions and usage * examples. * - * @note The attribute text is currently not being allocated + * @note The attribute text is not copied into private memory and so it + * must be a constant string, not one allocated in a stack buffer. + * @note Use of this construct is discouraged. The appropriate way is to + * create two labels - one for the static text and one for the + * dynamic text. * * @param[in] gh The widget handle (must be a label handle) * @param[in] tab The distance of the label text from the left widget edge @@ -88,7 +92,7 @@ void gwinLabelSetBorder(GHandle gh, bool_t border); * * @api */ - void gwinLabelSetAttribute(GHandle gh, coord_t tab, char* attr); + void gwinLabelSetAttribute(GHandle gh, coord_t tab, const char* attr); #endif #ifdef __cplusplus -- cgit v1.2.3 From 70c96543fcd20a0d323170e4f8392a0494de2cd4 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 29 Apr 2014 08:21:18 +0200 Subject: doxygen --- src/gwin/label.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/label.h b/src/gwin/label.h index 708599a6..b7218193 100644 --- a/src/gwin/label.h +++ b/src/gwin/label.h @@ -68,10 +68,10 @@ GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit); */ void gwinLabelSetBorder(GHandle gh, bool_t border); -#if GWIN_LABEL_ATTRIBUTE +#if GWIN_LABEL_ATTRIBUTE || defined(__DOXYGEN__) /** * @brief Add an text attribute in front of the normal label text - * @detail Often you want to display a text like this: + * @details Often you want to display a text like this: * Current IP: 192.168.1.42 * In that case, the actual IP will be variable, the text in front of it * always remains the same. The static text is called the attribute and can be -- cgit v1.2.3 From eae98a50d9f6f5c94c918ea77c4adde146c790c1 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 30 Apr 2014 20:55:45 +0200 Subject: Added gwinEnable() and gwinDisable() --- src/gwin/sys_defs.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/gwin') diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index ac2c98c7..f4e1c2f7 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -336,6 +336,24 @@ extern "C" { */ void gwinSetEnabled(GHandle gh, bool_t enabled); + /** + * @brief Enables a widget + * + * @param[in] gh The window handle + * + * @api + */ + #define gwinEnable(gh) gwinSetEnabled(gh, TRUE); + + /** + * @brief Disables a widget + * + * @param[in] gh The window handle + * + * @api + */ + #define gwinDisable(gh) gwinSetEnabled(gh, FALSE); + /** * @brief Gets the enabled state of a window * @return TRUE if enabled -- cgit v1.2.3 From 2c57363efc343ae521857cddbcfbcaec50eaedab Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Wed, 30 Apr 2014 21:11:54 +0200 Subject: slider does not change position if disabled --- src/gwin/slider.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/gwin') diff --git a/src/gwin/slider.c b/src/gwin/slider.c index 4c91ede6..ace90365 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -262,6 +262,10 @@ void gwinSliderSetPosition(GHandle gh, int pos) { if (gh->vmt != (gwinVMT *)&sliderVMT) return; + // do not change the position if disabled + if (!gwinGetEnabled(gh)) + return; + if (gsw->min <= gsw->max) { if (pos < gsw->min) gsw->pos = gsw->min; else if (pos > gsw->max) gsw->pos = gsw->max; -- cgit v1.2.3 From 3f254e76019f574a74d7a7d419ccb97fbc8db958 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 07:25:43 +1000 Subject: Revert "slider does not change position if disabled" This reverts commit 2c57363efc343ae521857cddbcfbcaec50eaedab. --- src/gwin/slider.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/slider.c b/src/gwin/slider.c index ace90365..4c91ede6 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -262,10 +262,6 @@ void gwinSliderSetPosition(GHandle gh, int pos) { if (gh->vmt != (gwinVMT *)&sliderVMT) return; - // do not change the position if disabled - if (!gwinGetEnabled(gh)) - return; - if (gsw->min <= gsw->max) { if (pos < gsw->min) gsw->pos = gsw->min; else if (pos > gsw->max) gsw->pos = gsw->max; -- cgit v1.2.3 From cf548f0e9c8a13741489a6b3368da1f8040301e2 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 13:53:46 +1000 Subject: Fix some gwin list widget mouse bugs --- src/gwin/list.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/list.c b/src/gwin/list.c index 50c669f0..cb17b671 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -93,10 +93,9 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { coord_t sy; #endif - // dont render if render has been disabled - if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) { + // don't render if render has been disabled + if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) return; - } ps = (gw->g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; @@ -209,24 +208,23 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { // a mouse down has occurred over the list area static void MouseDown(GWidgetObject* gw, coord_t x, coord_t y) { - int pgsz; - coord_t iheight; - (void) x; + coord_t iheight, pgsz; + // Save our mouse start position gw2obj->start_mouse_x = x; gw2obj->start_mouse_y = y; gw2obj->last_mouse_y = y; - iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; - pgsz = (gw->g.height-2); - if (pgsz < 1) pgsz = 1; - // For smooth scrolling, scrolling is done in the MouseMove and selection is done on MouseUp if (gw->g.flags & GLIST_FLG_SCROLLSMOOTH) return; + // Some initial stuff + iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; + pgsz = gw->g.height-2; + // Handle click over the scroll bar - if (gw2obj->cnt > (pgsz / iheight) && x >= gw->g.width-(SCROLLWIDTH+2)) { + if (x >= gw->g.width-(SCROLLWIDTH+2) && (gw2obj->cnt > pgsz/iheight || (gw->g.flags & GLIST_FLG_SCROLLALWAYS))) { if (y < 2*ARROW) { if (gw2obj->top > 0) { gw2obj->top -= iheight; -- cgit v1.2.3 From 96cec5349a40bb55b9c65e19234234d2ab197b48 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 13:54:38 +1000 Subject: Prevent gwinGetStyle() being called on a non-widget --- src/gwin/gwidget.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gwin') diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index ad2b7b20..181b7425 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -371,6 +371,9 @@ void gwinSetStyle(GHandle gh, const GWidgetStyle *pstyle) { } const GWidgetStyle *gwinGetStyle(GHandle gh) { + if (!(gh->flags & GWIN_FLG_WIDGET)) + return 0; + return gw->pstyle; } -- cgit v1.2.3 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/button.c | 45 +++++++++++++++++------ src/gwin/button.h | 2 +- src/gwin/radio.c | 98 ++++++++++++++++++++++++++++++++++++++------------ src/gwin/sys_options.h | 9 +++++ 4 files changed, 121 insertions(+), 33 deletions(-) (limited to 'src/gwin') 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); + + 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); + 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 (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 */ /** @} */ 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 -- 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/button.c | 6 ++++-- src/gwin/radio.c | 15 +++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/button.c b/src/gwin/button.c index 59c7f689..f34e4ba3 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -25,6 +25,8 @@ #define RND_CNR_SIZE 5 // Rounded corner size for rounded buttons #define ARROWHEAD_DIVIDER 4 // A quarter of the height for the arrow head #define ARROWBODY_DIVIDER 4 // A quarter of the width for the arrow body +#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 pressed state #define GBUTTON_FLG_PRESSED (GWIN_FIRST_CONTROL_FLAG<<0) @@ -189,8 +191,8 @@ static const GColorSet *getDrawColors(GWidgetObject *gw) { 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, 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))); 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 From b37370bdb5e3f5ffa325619c78d31c9993e79745 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 16:45:26 +1000 Subject: Added extra safety to GWIN objects --- src/gwin/gimage.c | 8 +++ src/gwin/label.c | 85 ++++++++++++----------- src/gwin/list.c | 200 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 157 insertions(+), 136 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/gimage.c b/src/gwin/gimage.c index 953aefc3..fdc6df84 100644 --- a/src/gwin/gimage.c +++ b/src/gwin/gimage.c @@ -140,6 +140,10 @@ GHandle gwinGImageCreate(GDisplay *g, GImageObject *gobj, GWindowInit *pInit) { } bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&imageVMT) + return FALSE; + if (gdispImageIsOpen(&widget(gh)->image)) gdispImageClose(&widget(gh)->image); @@ -159,6 +163,10 @@ bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { } gdispImageError gwinImageCache(GHandle gh) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&imageVMT) + return GDISP_IMAGE_ERR_BADFORMAT; + return gdispImageCache(&widget(gh)->image); } diff --git a/src/gwin/label.c b/src/gwin/label.c index 574dc8b7..8960300b 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -45,44 +45,7 @@ static coord_t getheight(const char *text, font_t font, coord_t maxwidth) { return gdispGetFontMetric(font, fontHeight); } -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, 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); - - return; - } - - #if GWIN_LABEL_ATTRIBUTE - if (gw2obj->attr != 0) { - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw2obj->attr, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - - gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, 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); - } else { - 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); - - } - #else - 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); - #endif - - // render the border (if any) - if (gw->g.flags & GLABEL_FLG_BORDER) - 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 void gwinLabelDefaultDraw(GWidgetObject *gw, void *param); static const gwidgetVMT labelVMT = { { @@ -138,9 +101,6 @@ GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit) if (!(widget = (GLabelObject *)_gwidgetCreate(g, &widget->w, pInit, &labelVMT))) return 0; - // no borders by default - flags &=~ GLABEL_FLG_BORDER; - #if GWIN_LABEL_ATTRIBUTE widget->tab = 0; widget->attr = 0; @@ -176,6 +136,49 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) { } #endif // GWIN_LABEL_ATTRIBUTE +static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { + coord_t w, h; + (void) param; + + // is it a valid handle? + if (gw->g.vmt != (gwinVMT *)&labelVMT) + return; + + 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); + + return; + } + + #if GWIN_LABEL_ATTRIBUTE + if (gw2obj->attr != 0) { + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw2obj->attr, gw->g.font, + (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, + justifyLeft); + + gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, 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); + } else { + 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); + + } + #else + 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); + #endif + + // render the border (if any) + if (gw->g.flags & GLABEL_FLG_BORDER) + 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); +} + #endif // GFX_USE_GWIN && GFX_NEED_LABEL /** @} */ diff --git a/src/gwin/list.c b/src/gwin/list.c index cb17b671..788e8828 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -76,101 +76,7 @@ static void sendListEvent(GWidgetObject *gw, int item) { } } -static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { - (void)param; - - #if GDISP_NEED_CONVEX_POLYGON - static const point upArrow[] = { {0, ARROW}, {ARROW, ARROW}, {ARROW/2, 0} }; - static const point downArrow[] = { {0, 0}, {ARROW, 0}, {ARROW/2, ARROW} }; - #endif - - const gfxQueueASyncItem* qi; - int i; - coord_t x, y, iheight, iwidth; - color_t fill; - const GColorSet * ps; - #if GWIN_NEED_LIST_IMAGES - coord_t sy; - #endif - - // don't render if render has been disabled - if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) - return; - - ps = (gw->g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; - iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; - x = 1; - - // the scroll area - if (gw->g.flags & GLIST_FLG_SCROLLSMOOTH) { - iwidth = gw->g.width - 2 - 4; - if (gw2obj->cnt > 0) { - int max_scroll_value = gw2obj->cnt * iheight - gw->g.height-2; - if (max_scroll_value > 0) { - int bar_height = (gw->g.height-2) * (gw->g.height-2) / (gw2obj->cnt * iheight); - gdispGFillArea(gw->g.display, gw->g.x + gw->g.width-4, gw->g.y + 1, 2, gw->g.height-1, gw->pstyle->background); - gdispGFillArea(gw->g.display, gw->g.x + gw->g.width-4, gw->g.y + gw2obj->top * ((gw->g.height-2)-bar_height) / max_scroll_value, 2, bar_height, ps->edge); - } - } - } else if ((gw2obj->cnt > (gw->g.height-2) / iheight) || (gw->g.flags & GLIST_FLG_SCROLLALWAYS)) { - iwidth = gw->g.width - (SCROLLWIDTH+3); - gdispGFillArea(gw->g.display, gw->g.x+iwidth+2, gw->g.y+1, SCROLLWIDTH, gw->g.height-2, gdispBlendColor(ps->fill, gw->pstyle->background, 128)); - gdispGDrawLine(gw->g.display, gw->g.x+iwidth+1, gw->g.y+1, gw->g.x+iwidth+1, gw->g.y+gw->g.height-2, ps->edge); - #if GDISP_NEED_CONVEX_POLYGON - gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+(ARROW/2+1), upArrow, 3, ps->fill); - gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+gw->g.height-(ARROW+ARROW/2+1), downArrow, 3, ps->fill); - #else - #warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLGON is turned on" - gdispGFillArea(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+(ARROW/2+1), ARROW, ARROW, ps->fill); - gdispGFillArea(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+gw->g.height-(ARROW+ARROW/2+1), ARROW, ARROW, ps->fill); - #endif - } else - iwidth = gw->g.width - 2; - - #if GWIN_NEED_LIST_IMAGES - if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { - x += iheight; - iwidth -= iheight; - } - #endif - - - // Find the top item - for (qi = gfxQueueASyncPeek(&gw2obj->list_head), i = iheight - 1; i < gw2obj->top && qi; qi = gfxQueueASyncNext(qi), i+=iheight); - - // the list frame - gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, ps->edge); - - // Set the clipping region so we do not override the frame. - gdispGSetClip(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2); - - // Draw until we run out of room or items - for (y = 1-(gw2obj->top%iheight); y < gw->g.height-2 && qi; qi = gfxQueueASyncNext(qi), y += iheight) { - fill = (qi2li->flags & GLIST_FLG_SELECTED) ? ps->fill : gw->pstyle->background; - gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, iheight, fill); - #if GWIN_NEED_LIST_IMAGES - if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { - // Clear the image area - if (qi2li->pimg && gdispImageIsOpen(qi2li->pimg)) { - // Calculate which image - sy = (qi2li->flags & GLIST_FLG_SELECTED) ? 0 : (iheight-VERTICAL_PADDING); - if (!(gw->g.flags & GWIN_FLG_ENABLED)) - sy += 2*(iheight-VERTICAL_PADDING); - while (sy > qi2li->pimg->height) - sy -= iheight-VERTICAL_PADDING; - // Draw the image - gdispImageSetBgColor(qi2li->pimg, fill); - gdispGImageDraw(gw->g.display, qi2li->pimg, gw->g.x+1, gw->g.y+y, iheight-VERTICAL_PADDING, iheight-VERTICAL_PADDING, 0, sy); - } - } - #endif - gdispGFillStringBox(gw->g.display, gw->g.x+x+HORIZONTAL_PADDING, gw->g.y+y, iwidth-HORIZONTAL_PADDING, iheight, qi2li->text, gw->g.font, ps->text, fill, justifyLeft); - } - - // Fill any remaining item space - if (y < gw->g.height-1) - gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, gw->g.height-1-y, gw->pstyle->background); -} +static void gwinListDefaultDraw(GWidgetObject* gw, void* param); #if GINPUT_NEED_MOUSE static void MouseSelect(GWidgetObject* gw, coord_t x, coord_t y) { @@ -448,6 +354,10 @@ void gwinListSetScroll(GHandle gh, scroll_t flag) { int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { ListItem *newItem; + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&listVMT) + return -1; + if (useAlloc) { size_t len = strlen(item_name)+1; if (!(newItem = gfxAlloc(sizeof(ListItem) + len))) @@ -685,6 +595,106 @@ const char* gwinListGetSelectedText(GHandle gh) { } #endif +static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { + (void)param; + + #if GDISP_NEED_CONVEX_POLYGON + static const point upArrow[] = { {0, ARROW}, {ARROW, ARROW}, {ARROW/2, 0} }; + static const point downArrow[] = { {0, 0}, {ARROW, 0}, {ARROW/2, ARROW} }; + #endif + + const gfxQueueASyncItem* qi; + int i; + coord_t x, y, iheight, iwidth; + color_t fill; + const GColorSet * ps; + #if GWIN_NEED_LIST_IMAGES + coord_t sy; + #endif + + // is it a valid handle? + if (gw->g.vmt != (gwinVMT *)&listVMT) + return; + + // don't render if render has been disabled + if (!(gw->g.flags & GLIST_FLG_ENABLERENDER)) + return; + + ps = (gw->g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; + iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; + x = 1; + + // the scroll area + if (gw->g.flags & GLIST_FLG_SCROLLSMOOTH) { + iwidth = gw->g.width - 2 - 4; + if (gw2obj->cnt > 0) { + int max_scroll_value = gw2obj->cnt * iheight - gw->g.height-2; + if (max_scroll_value > 0) { + int bar_height = (gw->g.height-2) * (gw->g.height-2) / (gw2obj->cnt * iheight); + gdispGFillArea(gw->g.display, gw->g.x + gw->g.width-4, gw->g.y + 1, 2, gw->g.height-1, gw->pstyle->background); + gdispGFillArea(gw->g.display, gw->g.x + gw->g.width-4, gw->g.y + gw2obj->top * ((gw->g.height-2)-bar_height) / max_scroll_value, 2, bar_height, ps->edge); + } + } + } else if ((gw2obj->cnt > (gw->g.height-2) / iheight) || (gw->g.flags & GLIST_FLG_SCROLLALWAYS)) { + iwidth = gw->g.width - (SCROLLWIDTH+3); + gdispGFillArea(gw->g.display, gw->g.x+iwidth+2, gw->g.y+1, SCROLLWIDTH, gw->g.height-2, gdispBlendColor(ps->fill, gw->pstyle->background, 128)); + gdispGDrawLine(gw->g.display, gw->g.x+iwidth+1, gw->g.y+1, gw->g.x+iwidth+1, gw->g.y+gw->g.height-2, ps->edge); + #if GDISP_NEED_CONVEX_POLYGON + gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+(ARROW/2+1), upArrow, 3, ps->fill); + gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+gw->g.height-(ARROW+ARROW/2+1), downArrow, 3, ps->fill); + #else + #warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLGON is turned on" + gdispGFillArea(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+(ARROW/2+1), ARROW, ARROW, ps->fill); + gdispGFillArea(gw->g.display, gw->g.x+iwidth+((SCROLLWIDTH-ARROW)/2+2), gw->g.y+gw->g.height-(ARROW+ARROW/2+1), ARROW, ARROW, ps->fill); + #endif + } else + iwidth = gw->g.width - 2; + + #if GWIN_NEED_LIST_IMAGES + if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { + x += iheight; + iwidth -= iheight; + } + #endif + + + // Find the top item + for (qi = gfxQueueASyncPeek(&gw2obj->list_head), i = iheight - 1; i < gw2obj->top && qi; qi = gfxQueueASyncNext(qi), i+=iheight); + + // the list frame + gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, ps->edge); + + // Set the clipping region so we do not override the frame. + gdispGSetClip(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2); + + // Draw until we run out of room or items + for (y = 1-(gw2obj->top%iheight); y < gw->g.height-2 && qi; qi = gfxQueueASyncNext(qi), y += iheight) { + fill = (qi2li->flags & GLIST_FLG_SELECTED) ? ps->fill : gw->pstyle->background; + gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, iheight, fill); + #if GWIN_NEED_LIST_IMAGES + if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { + // Clear the image area + if (qi2li->pimg && gdispImageIsOpen(qi2li->pimg)) { + // Calculate which image + sy = (qi2li->flags & GLIST_FLG_SELECTED) ? 0 : (iheight-VERTICAL_PADDING); + if (!(gw->g.flags & GWIN_FLG_ENABLED)) + sy += 2*(iheight-VERTICAL_PADDING); + while (sy > qi2li->pimg->height) + sy -= iheight-VERTICAL_PADDING; + // Draw the image + gdispImageSetBgColor(qi2li->pimg, fill); + gdispGImageDraw(gw->g.display, qi2li->pimg, gw->g.x+1, gw->g.y+y, iheight-VERTICAL_PADDING, iheight-VERTICAL_PADDING, 0, sy); + } + } + #endif + gdispGFillStringBox(gw->g.display, gw->g.x+x+HORIZONTAL_PADDING, gw->g.y+y, iwidth-HORIZONTAL_PADDING, iheight, qi2li->text, gw->g.font, ps->text, fill, justifyLeft); + } + + // Fill any remaining item space + if (y < gw->g.height-1) + gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, gw->g.height-1-y, gw->pstyle->background); +} + #endif // GFX_USE_GWIN && GWIN_NEED_LIST /** @} */ -- cgit v1.2.3 From 763fd061ecd6c9bb4877b5b6f5a01ce363ef09a4 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 May 2014 16:45:55 +1000 Subject: Fixed enable bug in progress bar --- src/gwin/progressbar.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src/gwin') diff --git a/src/gwin/progressbar.c b/src/gwin/progressbar.c index 7c34607f..c64e2119 100644 --- a/src/gwin/progressbar.c +++ b/src/gwin/progressbar.c @@ -43,7 +43,7 @@ static const gwidgetVMT progressbarVMT = { { "Progressbar", // The classname sizeof(GProgressbarObject), // The object size - _destroy, // The destroy routine + _destroy, // The destroy routine _gwidgetRedraw, // The redraw routine 0, // The after-clear routine }, @@ -180,7 +180,7 @@ void gwinProgressbarDecrement(GHandle gh) { } // used by gwinProgressbarStart(); -void _progressbarCallback(void *param) { +static void _progressbarCallback(void *param) { #define gsw ((GProgressbarObject *)gh) GHandle gh = (GHandle)param; @@ -206,11 +206,13 @@ void gwinProgressbarStart(GHandle gh, delaytime_t delay) { gtimerInit(&(gsw->gt)); gtimerStart(&(gsw->gt), _progressbarCallback, gh, FALSE, gsw->delay); - // if this is not made, the progressbar will not start when the it's already visible - if (gsw->w.g.flags & GWIN_FLG_VISIBLE) { - gwinSetVisible(gh, FALSE); - gwinSetVisible(gh, TRUE); - } + #if 0 + // if this is not made, the progressbar will not start when it's already visible + if (gsw->w.g.flags & GWIN_FLG_VISIBLE) { + gwinSetVisible(gh, FALSE); + gwinSetVisible(gh, TRUE); + } + #endif #undef gsw } @@ -239,13 +241,6 @@ void gwinProgressbarDraw_Std(GWidgetObject *gw, void *param) { if (gw->g.vmt != (gwinVMT *)&progressbarVMT) return; - // disable the auto-update timer if any - #if GFX_USE_GTIMER - if (gtimerIsActive(&(gsw->gt)) && !(gw->g.flags & GWIN_FLG_ENABLED)) { - gtimerStop(&(gsw->gt)); - } - #endif - // get the colors right if ((gw->g.flags & GWIN_FLG_ENABLED)) pcol = &gw->pstyle->pressed; -- cgit v1.2.3