From 312e759124098da0d6e2223698d39cb21bf9d5ae Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 Aug 2013 15:58:46 +1000 Subject: [PATCH 1/3] Add GWIN List multi-select support --- demos/modules/gwin/list/main.c | 2 +- demos/modules/gwin/widgets/main.c | 41 +++++++++++++++++-------------- include/gwin/list.h | 3 ++- src/gwin/list.c | 25 ++++++++++++++----- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/demos/modules/gwin/list/main.c b/demos/modules/gwin/list/main.c index a3a17250..21afa544 100644 --- a/demos/modules/gwin/list/main.c +++ b/demos/modules/gwin/list/main.c @@ -20,7 +20,7 @@ static void createWidgets(void) { wi.text = "List Name"; // Create the actual list - ghList1 = gwinListCreate(NULL, &wi); + ghList1 = gwinListCreate(NULL, &wi, FALSE); } int main(void) { diff --git a/demos/modules/gwin/widgets/main.c b/demos/modules/gwin/widgets/main.c index f2323b5c..59b0b917 100644 --- a/demos/modules/gwin/widgets/main.c +++ b/demos/modules/gwin/widgets/main.c @@ -76,7 +76,7 @@ static GHandle ghCheckbox1, ghCheckbox2, ghCheckDisableAll; static GHandle ghLabel1; static GHandle ghRadio1, ghRadio2; static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow; -static GHandle ghList1; +static GHandle ghList1, ghList2; static GHandle ghImage1; /* Some useful macros */ @@ -163,21 +163,22 @@ static void createWidgets(void) { // Lists wi.g.show = FALSE; wi.customDraw = 0; wi.g.width = LIST_WIDTH; wi.g.height = LIST_HEIGHT; wi.g.y = TAB_HEIGHT+5; - wi.g.x = 0+0*(LIST_WIDTH+1); wi.text = "L1"; ghList1 = gwinListCreate(NULL, &wi); - gwinListAddItem(ghList1, "Item 0", FALSE); - gwinListAddItem(ghList1, "Item 1", FALSE); - gwinListAddItem(ghList1, "Item 2", FALSE); - gwinListAddItem(ghList1, "Item 3", FALSE); - gwinListAddItem(ghList1, "Item 4", FALSE); - gwinListAddItem(ghList1, "Item 5", FALSE); - gwinListAddItem(ghList1, "Item 6", FALSE); - gwinListAddItem(ghList1, "Item 7", FALSE); - gwinListAddItem(ghList1, "Item 8", FALSE); - gwinListAddItem(ghList1, "Item 9", FALSE); - gwinListAddItem(ghList1, "Item 10", FALSE); - gwinListAddItem(ghList1, "Item 11", FALSE); - gwinListAddItem(ghList1, "Item 12", FALSE); - gwinListAddItem(ghList1, "Item 13", FALSE); + wi.g.x = 0+0*(LIST_WIDTH+1); wi.text = "L1"; ghList1 = gwinListCreate(NULL, &wi, FALSE); + gwinListAddItem(ghList1, "Item 0", FALSE); gwinListAddItem(ghList1, "Item 1", FALSE); + gwinListAddItem(ghList1, "Item 2", FALSE); gwinListAddItem(ghList1, "Item 3", FALSE); + gwinListAddItem(ghList1, "Item 4", FALSE); gwinListAddItem(ghList1, "Item 5", FALSE); + gwinListAddItem(ghList1, "Item 6", FALSE); gwinListAddItem(ghList1, "Item 7", FALSE); + gwinListAddItem(ghList1, "Item 8", FALSE); gwinListAddItem(ghList1, "Item 9", FALSE); + gwinListAddItem(ghList1, "Item 10", FALSE); gwinListAddItem(ghList1, "Item 11", FALSE); + gwinListAddItem(ghList1, "Item 12", FALSE); gwinListAddItem(ghList1, "Item 13", FALSE); + wi.g.x = 0+1*(LIST_WIDTH+1); wi.text = "L2"; ghList2 = gwinListCreate(NULL, &wi, TRUE); + gwinListAddItem(ghList2, "Item 0", FALSE); gwinListAddItem(ghList2, "Item 1", FALSE); + gwinListAddItem(ghList2, "Item 2", FALSE); gwinListAddItem(ghList2, "Item 3", FALSE); + gwinListAddItem(ghList2, "Item 4", FALSE); gwinListAddItem(ghList2, "Item 5", FALSE); + gwinListAddItem(ghList2, "Item 6", FALSE); gwinListAddItem(ghList2, "Item 7", FALSE); + gwinListAddItem(ghList2, "Item 8", FALSE); gwinListAddItem(ghList2, "Item 9", FALSE); + gwinListAddItem(ghList2, "Item 10", FALSE); gwinListAddItem(ghList2, "Item 11", FALSE); + gwinListAddItem(ghList2, "Item 12", FALSE); gwinListAddItem(ghList2, "Item 13", FALSE); // Image wi.g.x = ScrWidth-210; wi.g.y = TAB_HEIGHT + 10; wi.g.width = 200; wi.g.height = 200; @@ -206,7 +207,7 @@ static void setTab(GHandle tab) { gwinSetVisible(ghLabel1, FALSE); gwinSetVisible(ghRadio1, FALSE); gwinSetVisible(ghRadio2, FALSE); gwinSetVisible(ghRadioWhite, FALSE);gwinSetVisible(ghRadioBlack, FALSE);gwinSetVisible(ghRadioYellow, FALSE); - gwinSetVisible(ghList1, FALSE); + gwinSetVisible(ghList1, FALSE); gwinSetVisible(ghList2, FALSE); gwinSetVisible(ghImage1, FALSE); /* Turn on widgets depending on the tab selected */ @@ -224,7 +225,7 @@ static void setTab(GHandle tab) { gwinSetVisible(ghRadio1, TRUE); gwinSetVisible(ghRadio2, TRUE); gwinSetVisible(ghRadioWhite, TRUE); gwinSetVisible(ghRadioBlack, TRUE); gwinSetVisible(ghRadioYellow, TRUE); } else if (tab == ghTabLists) { - gwinSetVisible(ghList1, TRUE); + gwinSetVisible(ghList1, TRUE); gwinSetVisible(ghList2, TRUE); } else if (tab == ghTabImages) { gwinSetVisible(ghImage1, TRUE); } @@ -241,6 +242,7 @@ static void setEnabled(bool_t ena) { gwinSetEnabled(ghCheckbox1, ena); gwinSetEnabled(ghCheckbox2, ena); //gwinSetEnabled(ghCheckDisableAll, TRUE); gwinSetEnabled(ghLabel1, ena); gwinSetEnabled(ghRadio1, ena); gwinSetEnabled(ghRadio2, ena); + gwinSetEnabled(ghList1, ena); gwinSetEnabled(ghList2, ena); gwinSetEnabled(ghRadioWhite, ena); gwinSetEnabled(ghRadioBlack, ena); gwinSetEnabled(ghRadioYellow, ena); gwinSetEnabled(ghImage1, ena); } @@ -309,7 +311,8 @@ int main(void) { break; case GEVENT_GWIN_LIST: - gwinPrintf(ghConsole, "List %s Item %d\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item); + gwinPrintf(ghConsole, "List %s Item %d %s\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item, + gwinListItemIsSelected(((GEventGWinList *)pe)->list, ((GEventGWinList *)pe)->item) ? "Selected" : "Unselected"); break; case GEVENT_GWIN_RADIO: diff --git a/include/gwin/list.h b/include/gwin/list.h index 99f5f532..fa4c43c5 100644 --- a/include/gwin/list.h +++ b/include/gwin/list.h @@ -79,12 +79,13 @@ extern "C" { * * @param[in] widget The GListObject structure to initialize. If this is NULL, the structure is dynamically allocated. * @param[in] pInit The initialization parameters to use + * @param[in] multiselect If TRUE the list is multi-select instead of single-select. * * @return NULL if there is no resulting drawing area, otherwise a window handle. * * @api */ -GHandle gwinListCreate(GListObject *widget, GWidgetInit *pInit); +GHandle gwinListCreate(GListObject *widget, GWidgetInit *pInit, bool_t multiselect); /** * @brief Add an item to the list diff --git a/src/gwin/list.c b/src/gwin/list.c index a938150f..f3f154a9 100644 --- a/src/gwin/list.c +++ b/src/gwin/list.c @@ -172,10 +172,17 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { return; for(qi = gfxQueueASyncPeek(&gw2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) { - if (item == i) - qi2li->flags |= GLIST_FLG_SELECTED; - else - qi2li->flags &=~ GLIST_FLG_SELECTED; + if ((gw->g.flags & GLIST_FLG_MULTISELECT)) { + if (item == i) { + qi2li->flags ^= GLIST_FLG_SELECTED; + break; + } + } else { + if (item == i) + qi2li->flags |= GLIST_FLG_SELECTED; + else + qi2li->flags &=~ GLIST_FLG_SELECTED; + } } _gwidgetRedraw(&gw->g); @@ -281,7 +288,7 @@ static const gwidgetVMT listVMT = { #endif }; -GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit) { +GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit, bool_t multiselect) { if (!(gobj = (GListObject *)_gwidgetCreate(&gobj->w, pInit, &listVMT))) return 0; @@ -289,6 +296,8 @@ GHandle gwinListCreate(GListObject* gobj, GWidgetInit* pInit) { gfxQueueASyncInit(&gobj->list_head); gobj->cnt = 0; gobj->top = 0; + if (multiselect) + gobj->w.g.flags |= GLIST_FLG_MULTISELECT; gwinSetVisible(&gobj->w.g, pInit->g.show); @@ -315,7 +324,7 @@ int gwinListAddItem(GHandle gh, const char* item_name, bool_t useAlloc) { newItem->text = item_name; // select the item if it's the first in the list - if (gh2obj->cnt == 0) + if (gh2obj->cnt == 0 && !(gh->flags & GLIST_FLG_MULTISELECT)) newItem->flags |= GLIST_FLG_SELECTED; // add the new item to the list @@ -377,6 +386,10 @@ int gwinListGetSelected(GHandle gh) { if (gh->vmt != (gwinVMT *)&listVMT) return -1; + // Multi-select always returns -1. Use gwinListItemIsSelected() instead + if ((gh->flags & GLIST_FLG_MULTISELECT)) + return -1; + for(qi = gfxQueueASyncPeek(&gh2obj->list_head), i = 0; qi; qi = gfxQueueASyncNext(qi), i++) { if (qi2li->flags & GLIST_FLG_SELECTED) return i; From 171276e85f14cae3702b98d026881f348c00b2e0 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 Aug 2013 18:05:05 +1000 Subject: [PATCH 2/3] Release notes update --- releases.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/releases.txt b/releases.txt index 3007c8f8..96f7fa75 100644 --- a/releases.txt +++ b/releases.txt @@ -4,10 +4,14 @@ current release: 1.8 +*** changes after 1.8 *** +FEATURE: GWIN list boxes. +FIX: POSIX port removed, now dedicated OS-X and Linux ports +FIX: Several bugfixes *** changes after 1.7 *** FEATURE: Rename of the project from ChibiOS/GFX to uGFX -FEATURE: Moved from github.com to bitbucket.org +FEATURE: Moved from github.com to bitbucket.org FEATURE: New website with a lot more of documentation FEATURE: Introduced dedicated discussion forum FEATURE: Complete rework of the widget manager (GWIN) @@ -15,7 +19,6 @@ FEATURE: Added a lot of new widgets FEATURE: Added gfxRealloc() to the GOS module FIX: gfxHalt() fix for the Win32 port FIX: Cleaned up board file mess -FIX: POSIX port removed, now dedicated OS-X and Linux ports *** changes after 1.6 *** From 2e91479bd576160b475cc63d1f43cc119d90e187 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 1 Aug 2013 18:05:48 +1000 Subject: [PATCH 3/3] 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 /** @} */