From 2e91479bd576160b475cc63d1f43cc119d90e187 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 Aug 2013 18:05:48 +1000 Subject: [PATCH] Add image support to GWIN Listboxes. Updated GWIN widgets demo to match. --- demos/modules/gwin/widgets/gfxconf.h | 2 +- demos/modules/gwin/widgets/image_yesno.gif | Bin 0 -> 202 bytes demos/modules/gwin/widgets/image_yesno.h | 21 ++++++ demos/modules/gwin/widgets/main.c | 17 +++-- include/gwin/list.h | 43 ++++++++++-- src/gwin/list.c | 75 ++++++++++++++++++--- 6 files changed, 138 insertions(+), 20 deletions(-) create mode 100644 demos/modules/gwin/widgets/image_yesno.gif create mode 100644 demos/modules/gwin/widgets/image_yesno.h diff --git a/demos/modules/gwin/widgets/gfxconf.h b/demos/modules/gwin/widgets/gfxconf.h index 9ca5580b..2b9d8f8f 100644 --- a/demos/modules/gwin/widgets/gfxconf.h +++ b/demos/modules/gwin/widgets/gfxconf.h @@ -83,7 +83,7 @@ #define GWIN_NEED_RADIO TRUE #define GWIN_NEED_LIST TRUE #define GWIN_NEED_IMAGE_ANIMATION TRUE - +#define GWIN_NEED_LIST_IMAGES TRUE /* Features for the GINPUT sub-system. */ #define GINPUT_NEED_MOUSE TRUE diff --git a/demos/modules/gwin/widgets/image_yesno.gif b/demos/modules/gwin/widgets/image_yesno.gif new file mode 100644 index 0000000000000000000000000000000000000000..5a3d3998c02e02c7856f6289c22a78190ce28275 GIT binary patch literal 202 zcmZ?wbhEHb+a1fq@^W83;gT zFtC(=IO)l}_u#$h%{OjtFH~C58yQ*^sx>FK>yWbRotDJsLidEFWeT2fGv$jvIc)If zt;!kh;N>-Dldqp$@J%9T>pkWO8>tBgWAu;OByPXj{{HA{z0*4g.flags & GWIN_FLG_ENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; iheight = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight) + TEXTGAP; + x = 1; // the scroll area if (gw2obj->cnt > (gw->g.height-2) / iheight) { @@ -99,18 +108,38 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { } 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 = 0; i < gw2obj->top && qi; qi = gfxQueueASyncNext(qi), i++); // Draw until we run out of room or items for (y=1; y+iheight < gw->g.height-1 && qi; qi = gfxQueueASyncNext(qi), y += iheight) { - if (qi2li->flags & GLIST_FLG_SELECTED) { - //gdispFillStringBox(gw->g.x+1, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), gw->pstyle->background, ps->text, justifyLeft); - gdispFillStringBox(gw->g.x+1, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), ps->text, ps->fill, justifyLeft); - } else { - gdispFillStringBox(gw->g.x+1, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), ps->text, gw->pstyle->background, justifyLeft); - } + fill = (qi2li->flags & GLIST_FLG_SELECTED) ? ps->fill : gw->pstyle->background; + #if GWIN_NEED_LIST_IMAGES + if ((gw->g.flags & GLIST_FLG_HASIMAGES)) { + // Clear the image area + gdispFillArea(gw->g.x+1, gw->g.y+y, x-1, iheight, fill); + if (qi2li->pimg && gdispImageIsOpen(qi2li->pimg)) { + // Calculate which image + sy = (qi2li->flags & GLIST_FLG_SELECTED) ? 0 : (iheight-TEXTGAP); + if (!(gw->g.flags & GWIN_FLG_ENABLED)) + sy += 2*(iheight-TEXTGAP); + while (sy > qi2li->pimg->height) + sy -= iheight-TEXTGAP; + // Draw the image + gdispImageSetBgColor(qi2li->pimg, fill); + gdispImageDraw(qi2li->pimg, gw->g.x+1, gw->g.y+y, iheight-TEXTGAP, iheight-TEXTGAP, 0, sy); + } + } + #endif + gdispFillStringBox(gw->g.x+x, gw->g.y+y, iwidth, iheight, qi2li->text, gwinGetDefaultFont(), ps->text, fill, justifyLeft); } // Fill any remaining item space @@ -322,6 +351,9 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { newItem->flags = 0; newItem->param = 0; newItem->text = item_name; + #if GWIN_NEED_LIST_IMAGES + newItem->pimg = 0; + #endif // select the item if it's the first in the list if (gh2obj->cnt == 0 && !(gh->flags & GLIST_FLG_MULTISELECT)) @@ -428,6 +460,7 @@ void gwinListDeleteAll(GHandle gh) { while((qi = gfxQueueASyncGet(&gh2obj->list_head))) gfxFree(qi); + gh->flags &= ~GLIST_FLG_HASIMAGES; gh2obj->cnt = 0; gh2obj->top = 0; _gwidgetRedraw(gh); @@ -503,6 +536,30 @@ int gwinListItemCount(GHandle gh) { return gh2obj->cnt; } +#if GWIN_NEED_LIST_IMAGES + void gwinListItemSetImage(GHandle gh, int item, gdispImage *pimg) { + const gfxQueueASyncItem * qi; + int i; + + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&listVMT) + return; + + // watch out for an invalid item + if (item < 0 || item > (gh2obj->cnt) - 1) + return; + + for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) { + if (i == item) { + qi2li->pimg = pimg; + if (pimg) + gh->flags |= GLIST_FLG_HASIMAGES; + break; + } + } + } +#endif + #endif // GFX_USE_GWIN && GWIN_NEED_LIST /** @} */