diff options
author | inmarket <andrewh@inmarket.com.au> | 2015-06-08 14:14:40 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2015-06-08 14:14:40 +1000 |
commit | ccde54722f2c284fb0e7fc273d65c57a3be71db1 (patch) | |
tree | fffa49870c73d7e9d5caaf5c6d1d47cf0e5c90d3 /src/gwin/gwin_list.c | |
parent | e850c344b818f21a2ec286f9c4a149a9cd4ac34b (diff) | |
download | uGFX-ccde54722f2c284fb0e7fc273d65c57a3be71db1.tar.gz uGFX-ccde54722f2c284fb0e7fc273d65c57a3be71db1.tar.bz2 uGFX-ccde54722f2c284fb0e7fc273d65c57a3be71db1.zip |
Added ability to compile ugfx as a single file (excluding driver and board files).
Simply compile src/gfx_mk.c
Diffstat (limited to 'src/gwin/gwin_list.c')
-rw-r--r-- | src/gwin/gwin_list.c | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/src/gwin/gwin_list.c b/src/gwin/gwin_list.c index 2e3cb8e5..7ca300a9 100644 --- a/src/gwin/gwin_list.c +++ b/src/gwin/gwin_list.c @@ -19,10 +19,10 @@ #include <stdlib.h> // user for the default drawing routine -#define SCROLLWIDTH 16 // the border from the scroll buttons to the frame -#define ARROW 10 // arrow side length -#define HORIZONTAL_PADDING 5 // extra horizontal padding for text -#define VERTICAL_PADDING 2 // extra vertical padding for text +#define LST_SCROLLWIDTH 16 // the border from the scroll buttons to the frame +#define LST_ARROW_SZ 10 // arrow side length +#define LST_HORIZ_PAD 5 // extra horizontal padding for text +#define LST_VERT_PAD 2 // extra vertical padding for text // Macro's to assist in data type conversions #define gh2obj ((GListObject *)gh) @@ -77,13 +77,13 @@ static void sendListEvent(GWidgetObject *gw, int item) { static void gwinListDefaultDraw(GWidgetObject* gw, void* param); #if GINPUT_NEED_MOUSE - static void MouseSelect(GWidgetObject* gw, coord_t x, coord_t y) { + static void ListMouseSelect(GWidgetObject* gw, coord_t x, coord_t y) { const gfxQueueASyncItem* qi; int item, i; coord_t iheight; (void) x; - iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; + iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; // Handle click over the list area item = (gw2obj->top + y) / iheight; @@ -111,7 +111,7 @@ 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) { + static void ListMouseDown(GWidgetObject* gw, coord_t x, coord_t y) { coord_t iheight, pgsz; // Save our mouse start position @@ -119,24 +119,24 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param); gw2obj->start_mouse_y = y; gw2obj->last_mouse_y = y; - // For smooth scrolling, scrolling is done in the MouseMove and selection is done on MouseUp + // For smooth scrolling, scrolling is done in the ListMouseMove and selection is done on ListMouseUp if (gw->g.flags & GLIST_FLG_SCROLLSMOOTH) return; // Some initial stuff - iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; + iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; pgsz = gw->g.height-2; // Handle click over the scroll bar - if (x >= gw->g.width-(SCROLLWIDTH+2) && (gw2obj->cnt > pgsz/iheight || (gw->g.flags & GLIST_FLG_SCROLLALWAYS))) { - if (y < 2*ARROW) { + if (x >= gw->g.width-(LST_SCROLLWIDTH+2) && (gw2obj->cnt > pgsz/iheight || (gw->g.flags & GLIST_FLG_SCROLLALWAYS))) { + if (y < 2*LST_ARROW_SZ) { if (gw2obj->top > 0) { gw2obj->top -= iheight; if (gw2obj->top < 0) gw2obj->top = 0; _gwinUpdate(&gw->g); } - } else if (y >= gw->g.height - 2*ARROW) { + } else if (y >= gw->g.height - 2*LST_ARROW_SZ) { if (gw2obj->top < gw2obj->cnt * iheight - pgsz) { gw2obj->top += iheight; if (gw2obj->top > gw2obj->cnt * iheight - pgsz) @@ -163,10 +163,10 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param); return; } - MouseSelect(gw, x, y); + ListMouseSelect(gw, x, y); } - static void MouseUp(GWidgetObject* gw, coord_t x, coord_t y) { + static void ListMouseUp(GWidgetObject* gw, coord_t x, coord_t y) { // Only act when we are a smooth scrolling list if (!(gw->g.flags & GLIST_FLG_SCROLLSMOOTH)) return; @@ -175,10 +175,10 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param); if (abs(gw2obj->start_mouse_x - x) > 4 || abs(gw2obj->start_mouse_y - y) > 4) return; - MouseSelect(gw, x, y); + ListMouseSelect(gw, x, y); } - static void MouseMove(GWidgetObject* gw, coord_t x, coord_t y) { + static void ListMouseMove(GWidgetObject* gw, coord_t x, coord_t y) { int iheight, oldtop; (void) x; @@ -186,7 +186,7 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param); if (gw2obj->last_mouse_y != y) { oldtop = gw2obj->top; - iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; + iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; gw2obj->top -= y - gw2obj->last_mouse_y; if (gw2obj->top >= gw2obj->cnt * iheight - (gw->g.height-2)) @@ -202,7 +202,7 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param); #if GINPUT_NEED_TOGGLE // a toggle-on has occurred - static void ToggleOn(GWidgetObject *gw, uint16_t role) { + static void ListToggleOn(GWidgetObject *gw, uint16_t role) { const gfxQueueASyncItem * qi; const gfxQueueASyncItem * qix; int i; @@ -242,19 +242,19 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param); } } - static void ToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) { + static void ListToggleAssign(GWidgetObject *gw, uint16_t role, uint16_t instance) { if (role) gw2obj->t_up = instance; else gw2obj->t_dn = instance; } - static uint16_t ToggleGet(GWidgetObject *gw, uint16_t role) { + static uint16_t ListToggleGet(GWidgetObject *gw, uint16_t role) { return role ? gw2obj->t_up : gw2obj->t_dn; } #endif -static void _destroy(GHandle gh) { +static void ListDestroy(GHandle gh) { const gfxQueueASyncItem* qi; while((qi = gfxQueueASyncGet(&gh2obj->list_head))) @@ -267,25 +267,25 @@ static const gwidgetVMT listVMT = { { "List", // The class name sizeof(GListObject), // The object size - _destroy, // The destroy routine + ListDestroy, // The destroy routine _gwidgetRedraw, // The redraw routine 0, // The after-clear routine }, gwinListDefaultDraw, // default drawing routine #if GINPUT_NEED_MOUSE { - MouseDown, - MouseUp, - MouseMove, + ListMouseDown, + ListMouseUp, + ListMouseMove, }, #endif #if GINPUT_NEED_TOGGLE { 2, // two toggle roles - ToggleAssign, // Assign toggles - ToggleGet, // get toggles + ListToggleAssign, // Assign toggles + ListToggleGet, // Get toggles 0, - ToggleOn, // process toggle on event + ListToggleOn, // Process toggle on event }, #endif #if GINPUT_NEED_DIAL @@ -616,7 +616,7 @@ void gwinListViewItem(GHandle gh, int item) { return; // Work out a possible new top for the list - iheight = gdispGetFontMetric(gh->font, fontHeight) + VERTICAL_PADDING; + iheight = gdispGetFontMetric(gh->font, fontHeight) + LST_VERT_PAD; gh2obj->top = iheight * item; // Adjust the list @@ -656,8 +656,8 @@ 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} }; + static const point upArrow[] = { {0, LST_ARROW_SZ}, {LST_ARROW_SZ, LST_ARROW_SZ}, {LST_ARROW_SZ/2, 0} }; + static const point downArrow[] = { {0, 0}, {LST_ARROW_SZ, 0}, {LST_ARROW_SZ/2, LST_ARROW_SZ} }; #endif const gfxQueueASyncItem* qi; @@ -678,7 +678,7 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { return; ps = (gw->g.flags & GWIN_FLG_SYSENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; - iheight = gdispGetFontMetric(gw->g.font, fontHeight) + VERTICAL_PADDING; + iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; x = 1; // the scroll area @@ -693,16 +693,16 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { } } } 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)); + iwidth = gw->g.width - (LST_SCROLLWIDTH+3); + gdispGFillArea(gw->g.display, gw->g.x+iwidth+2, gw->g.y+1, LST_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); + gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+(LST_ARROW_SZ/2+1), upArrow, 3, ps->fill); + gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+gw->g.height-(LST_ARROW_SZ+LST_ARROW_SZ/2+1), downArrow, 3, ps->fill); #else #warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLYGON 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); + gdispGFillArea(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+(LST_ARROW_SZ/2+1), LST_ARROW_SZ, LST_ARROW_SZ, ps->fill); + gdispGFillArea(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+gw->g.height-(LST_ARROW_SZ+LST_ARROW_SZ/2+1), LST_ARROW_SZ, LST_ARROW_SZ, ps->fill); #endif } else iwidth = gw->g.width - 2; @@ -733,18 +733,18 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { // Clear the image area if (qi2li->pimg && gdispImageIsOpen(qi2li->pimg)) { // Calculate which image - sy = (qi2li->flags & GLIST_FLG_SELECTED) ? 0 : (iheight-VERTICAL_PADDING); + sy = (qi2li->flags & GLIST_FLG_SELECTED) ? 0 : (iheight-LST_VERT_PAD); if (!(gw->g.flags & GWIN_FLG_SYSENABLED)) - sy += 2*(iheight-VERTICAL_PADDING); + sy += 2*(iheight-LST_VERT_PAD); while (sy > qi2li->pimg->height) - sy -= iheight-VERTICAL_PADDING; + sy -= iheight-LST_VERT_PAD; // 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); + gdispGImageDraw(gw->g.display, qi2li->pimg, gw->g.x+1, gw->g.y+y, iheight-LST_VERT_PAD, iheight-LST_VERT_PAD, 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); + gdispGFillStringBox(gw->g.display, gw->g.x+x+LST_HORIZ_PAD, gw->g.y+y, iwidth-LST_HORIZ_PAD, iheight, qi2li->text, gw->g.font, ps->text, fill, justifyLeft); } // Fill any remaining item space @@ -752,4 +752,9 @@ static void gwinListDefaultDraw(GWidgetObject* gw, void* param) { gdispGFillArea(gw->g.display, gw->g.x+1, gw->g.y+y, iwidth, gw->g.height-1-y, gw->pstyle->background); } +#undef gh2obj +#undef gw2obj +#undef qi2li +#undef qix2li +#undef ple #endif // GFX_USE_GWIN && GWIN_NEED_LIST |