aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-05-01 18:10:31 +1000
committerinmarket <andrewh@inmarket.com.au>2014-05-01 18:10:31 +1000
commitcb99e4ab091fafbee0389a30b6fbe8ee0ffc778e (patch)
treeae2dd49581767de13bcef903bcc8e0a7a76fc898 /src
parent2bef66a6875171942a1d71e40669247d26ce505b (diff)
parent763fd061ecd6c9bb4877b5b6f5a01ce363ef09a4 (diff)
downloaduGFX-cb99e4ab091fafbee0389a30b6fbe8ee0ffc778e.tar.gz
uGFX-cb99e4ab091fafbee0389a30b6fbe8ee0ffc778e.tar.bz2
uGFX-cb99e4ab091fafbee0389a30b6fbe8ee0ffc778e.zip
Merge branch 'master' into gwin
Diffstat (limited to 'src')
-rw-r--r--src/gdisp/image.c2
-rw-r--r--src/gwin/button.c47
-rw-r--r--src/gwin/button.h2
-rw-r--r--src/gwin/gimage.c8
-rw-r--r--src/gwin/gwidget.c3
-rw-r--r--src/gwin/label.c86
-rw-r--r--src/gwin/label.h32
-rw-r--r--src/gwin/list.c216
-rw-r--r--src/gwin/progressbar.c23
-rw-r--r--src/gwin/radio.c101
-rw-r--r--src/gwin/sys_defs.h18
-rw-r--r--src/gwin/sys_options.h9
12 files changed, 371 insertions, 176 deletions
diff --git a/src/gdisp/image.c b/src/gdisp/image.c
index 2b8395b0..5a743905 100644
--- a/src/gdisp/image.c
+++ b/src/gdisp/image.c
@@ -174,7 +174,7 @@ void gdispImageClose(gdispImage *img) {
}
bool_t gdispImageIsOpen(gdispImage *img) {
- return img->fns != 0;
+ return img->type != GDISP_IMAGE_TYPE_UNKNOWN && img->fns != 0;
}
void gdispImageSetBgColor(gdispImage *img, color_t bgcolor) {
diff --git a/src/gwin/button.c b/src/gwin/button.c
index 72d75225..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)
@@ -109,7 +111,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 +166,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, 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
#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/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/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;
}
diff --git a/src/gwin/label.c b/src/gwin/label.c
index a5064818..8960300b 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)
@@ -44,28 +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;
- }
-
- // 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);
-
- // 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 = {
{
@@ -121,8 +101,10 @@ 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;
+ #endif
widget->w.g.flags |= flags;
gwinSetVisible(&widget->w.g, pInit->g.show);
@@ -141,6 +123,62 @@ 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, const 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
+
+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/label.h b/src/gwin/label.h
index 9d62738d..b7218193 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;
+ const char* attr;
+ #endif
} GLabelObject;
#ifdef __cplusplus
@@ -63,6 +68,33 @@ GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit);
*/
void gwinLabelSetBorder(GHandle gh, bool_t border);
+#if GWIN_LABEL_ATTRIBUTE || defined(__DOXYGEN__)
+ /**
+ * @brief Add an text attribute in front of the normal label text
+ * @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
+ * 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 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
+ * @param[in] attr The attribute to be displayed
+ *
+ * @api
+ */
+ void gwinLabelSetAttribute(GHandle gh, coord_t tab, const char* attr);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gwin/list.c b/src/gwin/list.c
index 50c669f0..788e8828 100644
--- a/src/gwin/list.c
+++ b/src/gwin/list.c
@@ -76,102 +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
-
- // dont 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) {
@@ -209,24 +114,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;
@@ -450,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)))
@@ -687,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
/** @} */
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;
diff --git a/src/gwin/radio.c b/src/gwin/radio.c
index f50ffe9b..8dc3ba6b 100644
--- a/src/gwin/radio.c
+++ b/src/gwin/radio.c
@@ -21,6 +21,11 @@
#include "src/gwin/class_gwin.h"
+#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)
@@ -195,34 +200,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, 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)));
+
+ 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, 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, 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)));
+ 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_defs.h b/src/gwin/sys_defs.h
index 6302f28f..be99be1e 100644
--- a/src/gwin/sys_defs.h
+++ b/src/gwin/sys_defs.h
@@ -345,6 +345,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
*
diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h
index 5fe2d93e..bd720711 100644
--- a/src/gwin/sys_options.h
+++ b/src/gwin/sys_options.h
@@ -113,6 +113,15 @@
* @{
*/
/**
+ * @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
*/