Merge branch 'master' into fonts

This commit is contained in:
inmarket 2013-08-01 18:07:34 +10:00
commit a2632f0d31
8 changed files with 183 additions and 45 deletions

View File

@ -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) {

View File

@ -80,7 +80,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

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

View File

@ -0,0 +1,21 @@
/**
* This file was generated from "yesno.gif" using...
*
* file2c -bcs image_yesno.gif image_yesno.h
*
*/
static const unsigned char image_yesno[] = {
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0B, 0x00, 0x2C, 0x00, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xC6, 0x00, 0xC6, 0xFF, 0xC6, 0xCE, 0xFF, 0xCE, 0xFF, 0x08, 0x18, 0xFF, 0xCE, 0xDE, 0xFF,
0xDE, 0xDE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x21, 0xF9, 0x04,
0x03, 0x00, 0x00, 0x0F, 0x00, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x2C, 0x00, 0x00, 0x04,
0x77, 0xF0, 0xC9, 0x49, 0x03, 0xBD, 0xC1, 0xDE, 0x97, 0x83, 0xD8, 0xD9, 0xB7, 0x71, 0x22, 0xA8,
0x8D, 0x59, 0x55, 0x7A, 0x55, 0x2A, 0x9C, 0x6D, 0x8A, 0xC2, 0x23, 0x45, 0xDC, 0x84, 0x61, 0xE7,
0x12, 0xDE, 0x13, 0x1B, 0x1C, 0x70, 0xE4, 0x0B, 0x02, 0x6F, 0x17, 0xE4, 0xC3, 0x30, 0xFC, 0xED,
0x24, 0xCC, 0x0B, 0x53, 0xA7, 0x7C, 0x36, 0x93, 0xD7, 0xCD, 0xA0, 0xF6, 0x18, 0x6C, 0xB5, 0xDE,
0x03, 0x58, 0x3C, 0x1A, 0x90, 0xC1, 0x5C, 0x2F, 0xC5, 0x3C, 0x61, 0xB7, 0xD5, 0x87, 0xEF, 0xC5,
0xAB, 0x2E, 0xCB, 0xB9, 0x93, 0x82, 0xBE, 0x70, 0x7E, 0xE8, 0xC9, 0x7B, 0x12, 0x7A, 0x1B, 0x7B,
0x05, 0x35, 0x81, 0x84, 0x86, 0x83, 0x14, 0x8B, 0x07, 0x86, 0x79, 0x8F, 0x82, 0x8F, 0x8E, 0x17,
0x8E, 0x62, 0x8B, 0x8C, 0x8A, 0x87, 0x05, 0x11, 0x00, 0x3B,
};

View File

@ -30,6 +30,7 @@
// include our chibios logo in a .gif format
#include "image_chibios.h"
#include "image_yesno.h"
/**
* This demo demonstrates many of the GWIN widgets.
@ -76,8 +77,9 @@ static GHandle ghCheckbox1, ghCheckbox2, ghCheckDisableAll;
static GHandle ghLabel1;
static GHandle ghRadio1, ghRadio2;
static GHandle ghRadioBlack, ghRadioWhite, ghRadioYellow;
static GHandle ghList1;
static GHandle ghList1, ghList2, ghList3;
static GHandle ghImage1;
static gdispImage imgYesNo;
/* Some useful macros */
#define ScrWidth gdispGetWidth()
@ -163,21 +165,29 @@ 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);
wi.g.x = 0+2*(LIST_WIDTH+1); wi.text = "L3"; ghList3 = gwinListCreate(NULL, &wi, FALSE);
gwinListAddItem(ghList3, "Item 0", FALSE); gwinListAddItem(ghList3, "Item 1", FALSE);
gwinListAddItem(ghList3, "Item 2", FALSE); gwinListAddItem(ghList3, "Item 3", FALSE);
gdispImageSetMemoryReader(&imgYesNo, image_yesno);
gdispImageOpen(&imgYesNo);
gwinListItemSetImage(ghList3, 1, &imgYesNo);
gwinListItemSetImage(ghList3, 3, &imgYesNo);
// Image
wi.g.x = ScrWidth-210; wi.g.y = TAB_HEIGHT + 10; wi.g.width = 200; wi.g.height = 200;
@ -206,7 +216,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(ghList3, FALSE);
gwinSetVisible(ghImage1, FALSE);
/* Turn on widgets depending on the tab selected */
@ -224,7 +234,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); gwinSetVisible(ghList3, TRUE);
} else if (tab == ghTabImages) {
gwinSetVisible(ghImage1, TRUE);
}
@ -241,6 +251,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(ghList3, ena);
gwinSetEnabled(ghRadioWhite, ena); gwinSetEnabled(ghRadioBlack, ena); gwinSetEnabled(ghRadioYellow, ena);
gwinSetEnabled(ghImage1, ena);
}
@ -309,7 +320,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:

View File

@ -70,21 +70,20 @@ extern "C" {
* @note A list remembers its normal drawing state. If there is a window manager then it is automatically
* redrawn if the window is moved or its visibility state is changed.
* @note The list contains no elements after creation.
* @note A slider supports mouse, toggle and dial input.
* @note A slider supports mouse, toggle. Note: toggle only works correctly for single-select lists.
* @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than
* one toggle to a role, it will forget the previous toggle. Two roles are supported:
* Role 0 = toggle for down, role 1 = toggle for up
* @note When assigning a dial, only one dial is supported. If you try to assign more than one dial, it
* will forget the previous dial. Only dial role 0 is supported.
* Role 0 = toggle for down, role 1 = toggle for up
*
* @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
@ -156,7 +155,7 @@ uint16_t gwinListItemGetParam(GHandle gh, int item);
*
* @api
*/
void ListDeleteAll(GHandle gh);
void gwinListDeleteAll(GHandle gh);
/**
* @brief Delete an item from the list
@ -196,12 +195,45 @@ bool_t gwinListItemIsSelected(GHandle gh, int item);
*
* @param[in] gh The widget handle (must be a list handle)
*
* @return The ID of the list item
* @return The ID of the selected list item for a single-select list.
*
* @note It always returns -1 (nothing selected) for a multi-select list.
* Instead use @p gwinListItemIsSelected() to get the selection status
* for a multi-select list.
*
* @api
*/
int gwinListGetSelected(GHandle gh);
#if GWIN_NEED_LIST_IMAGES
/**
* @brief Set the image for a list item
*
* @param[in] gh The widget handle (must be a list handle)
* @param[in] item The item ID
* @param[in] pimg The image to be displayed or NULL to turn off the image for this list item.
*
* @note The image should be up to 4 x (the font height) and a width of (the font height).
* The 1st (top) part of the image is displayed for a selected item.
* The 2nd part of the image is displayed for an unselected item.
* The 3rd part of the image is displayed for a disabled selected item.
* The 4th part of the image is displayed for a disabled unselected item.
* If the image is less than 4 times the font height then the image use is collapsed
* into the available height. For example, an image that equals the font height will use
* the same image for all four states.
* @note The image is only displayed while it is open. It is up to the application to open
* the image.
* @note The same image can be used on more than one list item.
* @note Images are aligned with the top (not the baseline) of the list item.
* @note When any item in the list has an image attached, space is allocated to display
* the images even if the image is closed or has been removed by calling @p gwinListItemSetImage()
* with a NULL image or by calling @p gwinListItemDelete(). The only way to turn-off the image area
* for this list is to call gwinListDeleteAll().
*
*/
void gwinListItemSetImage(GHandle gh, int item, gdispImage *pimg);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -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 ***

View File

@ -27,15 +27,19 @@
#define ARROW 10 // arrow side length
#define TEXTGAP 1 // extra vertical padding for text
// Macro's to assist in data type conversions
#define gh2obj ((GListObject *)gh)
#define gw2obj ((GListObject *)gw)
#define qi2li ((ListItem *)qi)
#define qix2li ((ListItem *)qix)
#define ple ((GEventGWinList *)pe)
// Flags for the GListObject
#define GLIST_FLG_MULTISELECT (GWIN_FIRST_CONTROL_FLAG << 0)
#define GLIST_FLG_HASIMAGES (GWIN_FIRST_CONTROL_FLAG << 1)
#define GLIST_FLG_SELECTED (GWIN_FIRST_CONTROL_FLAG << 2)
// Flags on a ListItem.
#define GLIST_FLG_SELECTED 0x0001
typedef struct ListItem {
gfxQueueASyncItem q_item; // This must be the first member in the struct
@ -43,7 +47,7 @@ typedef struct ListItem {
uint16_t flags;
uint16_t param; // A parameter the user can specify himself
const char* text;
#if GWIN_LIST_IMAGES
#if GWIN_NEED_LIST_IMAGES
gdispImage* pimg;
#endif
} ListItem;
@ -77,11 +81,16 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) {
const gfxQueueASyncItem* qi;
int i;
coord_t y, iheight, iwidth;
coord_t x, y, iheight, iwidth;
color_t fill;
const GColorSet * ps;
#if GWIN_NEED_LIST_IMAGES
coord_t sy;
#endif
ps = (gw->g.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
@ -172,10 +201,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 +317,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 +325,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);
@ -313,9 +351,12 @@ 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)
if (gh2obj->cnt == 0 && !(gh->flags & GLIST_FLG_MULTISELECT))
newItem->flags |= GLIST_FLG_SELECTED;
// add the new item to the list
@ -377,6 +418,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;
@ -415,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);
@ -490,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
/** @} */