bool_t gwinImageOpenGFile(GHandle gh, GFILE *f) { // is it a valid handle? if (gh->vmt != (gwinVMT *)&imageVMT) return FALSE; if (gdispImageIsOpen(&gw->image)) gdispImageClose(&gw->image); if ((gdispImageOpenGFile(&gw->image, f) & GDISP_IMAGE_ERR_UNRECOVERABLE)) return FALSE; _gwinUpdate(gh); return TRUE; }
bool_t gwinImageOpenStream(GHandle gh, void *streamPtr) { if (gdispImageIsOpen(&widget(gh)->image)) gdispImageClose(&widget(gh)->image); if (!gdispImageSetBaseFileStreamReader(&widget(gh)->image, streamPtr)) return FALSE; if (gdispImageOpen(&widget(gh)->image) != GDISP_IMAGE_ERR_OK) return FALSE; if ((gh->flags & GWIN_FLG_VISIBLE)) { // Setting the clip here shouldn't be necessary if the redraw doesn't overdraw // but we put it in for safety anyway #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif _redraw(gh); } return TRUE; }
static void ImageRedraw(GHandle gh) { coord_t x, y, w, h, dx, dy; color_t bg; #if GWIN_NEED_IMAGE_ANIMATION delaytime_t delay; #endif // The default display area dx = 0; dy = 0; x = gh->x; y = gh->y; w = gh->width; h = gh->height; bg = gwinGetDefaultBgColor(); // If the image isn't open just clear the area if (!gdispImageIsOpen(&gw->image)) { gdispGFillArea(gh->display, x, y, w, h, bg); return; } // Center horizontally if the area is larger than the image if (gw->image.width < w) { w = gw->image.width; dx = (gh->width-w)/2; x += dx; if (dx) gdispGFillArea(gh->display, gh->x, y, dx, h, bg); gdispGFillArea(gh->display, x+w, y, gh->width-dx-w, h, bg); dx = 0; } // Center image horizontally if the area is smaller than the image else if (gw->image.width > w) { dx = (gw->image.width - w)/2; } // Center vertically if the area is larger than the image if (gw->image.height < h) { h = gw->image.height; dy = (gh->height-h)/2; y += dy; if (dy) gdispGFillArea(gh->display, x, gh->y, w, dy, bg); gdispGFillArea(gh->display, x, y+h, w, gh->height-dy-h, bg); dy = 0; } // Center image vertically if the area is smaller than the image else if (gw->image.height > h) { dy = (gw->image.height - h)/2; } // Reset the background color in case it has changed gdispImageSetBgColor(&gw->image, bg); // Display the image gdispGImageDraw(gh->display, &gw->image, x, y, w, h, dx, dy); #if GWIN_NEED_IMAGE_ANIMATION // read the delay for the next frame delay = gdispImageNext(&gw->image); // Wait for that delay if required switch(delay) { case TIME_INFINITE: // Everything is done break; case TIME_IMMEDIATE: // We can't allow a continuous loop here as it would lock the system up so we delay for the minimum period delay = 1; // Fall through default: // Start the timer to draw the next frame of the animation gtimerStart(&gw->timer, ImageTimer, (void*)gh, FALSE, delay); break; } #endif }
static void ImageDestroy(GWindowObject *gh) { if (gdispImageIsOpen(&gw->image)) gdispImageClose(&gw->image); }
static void _destroy(GWindowObject *gh) { if (gdispImageIsOpen(&widget(gh)->image)) gdispImageClose(&widget(gh)->image); }
void gwinListDefaultDraw(GWidgetObject* gw, void* param) { 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 #if GDISP_NEED_CONVEX_POLYGON 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 (void)param; // 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_SYSENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; iheight = gdispGetFontMetric(gw->g.font, fontHeight) + LST_VERT_PAD; 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 - (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+((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+((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; #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. #if GDISP_NEED_CLIP gdispGSetClip(gw->g.display, gw->g.x+1, gw->g.y+1, gw->g.width-2, gw->g.height-2); #endif // 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-LST_VERT_PAD); if (!(gw->g.flags & GWIN_FLG_SYSENABLED)) sy += 2*(iheight-LST_VERT_PAD); while (sy > qi2li->pimg->height) 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-LST_VERT_PAD, iheight-LST_VERT_PAD, 0, sy); } } #endif 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 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); }