void gdispDrawPoly(coord_t tx, coord_t ty, const point *pntarray, unsigned cnt, color_t color) { const point *epnt, *p; epnt = &pntarray[cnt-1]; for(p = pntarray; p < epnt; p++) gdispDrawLine(tx+p->x, ty+p->y, tx+p[1].x, ty+p[1].y, color); gdispDrawLine(tx+p->x, ty+p->y, tx+pntarray->x, ty+pntarray->y, color); }
void gdispDrawRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t radius, color_t color) { if (2*radius > cx || 2*radius > cy) { gdispDrawBox(x, y, cx, cy, color); return; } gdispDrawArc(x+radius, y+radius, radius, 90, 180, color); gdispDrawLine(x+radius+1, y, x+cx-2-radius, y, color); gdispDrawArc(x+cx-1-radius, y+radius, radius, 0, 90, color); gdispDrawLine(x+cx-1, y+radius+1, x+cx-1, y+cy-2-radius, color); gdispDrawArc(x+cx-1-radius, y+cy-1-radius, radius, 270, 360, color); gdispDrawLine(x+radius+1, y+cy-1, x+cx-2-radius, y+cy-1, color); gdispDrawArc(x+radius, y+cy-1-radius, radius, 180, 270, color); gdispDrawLine(x, y+radius+1, x, y+cy-2-radius, color); }
int main(void) { coord_t width, height; coord_t i, j; halInit(); chSysInit(); /* Initialize and clear the display */ gdispInit(); gdispClear(Black); // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); // Code Here gdispDrawBox(10, 10, width/2, height/2, Yellow); gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue); gdispDrawLine(5, 30, width-50, height-40, Red); for(i = 5, j = 0; i < width && j < height; i += 7, j += i/20) gdispDrawPixel (i, j, White); while(TRUE) { chThdSleepMilliseconds(500); } }
void gwinFrameDraw_Transparent(GWidgetObject *gw, void *param) { const GColorSet *pcol; coord_t pos; color_t contrast; color_t btn; (void)param; if (gw->g.vmt != (gwinVMT *)&frameVMT) return; pcol = (gw->g.flags & GWIN_FLG_SYSENABLED) ? &gw->pstyle->enabled : &gw->pstyle->disabled; contrast = gdispContrastColor(pcol->edge); btn = gdispBlendColor(pcol->edge, contrast, 128); // Render the frame gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, FRM_BORDER_T, gw->text, gw->g.font, contrast, pcol->edge, justifyCenter); gdispGFillArea(gw->g.display, gw->g.x, gw->g.y+FRM_BORDER_T, FRM_BORDER_L, gw->g.height-(FRM_BORDER_T+FRM_BORDER_B), pcol->edge); gdispGFillArea(gw->g.display, gw->g.x+gw->g.width-FRM_BORDER_R, gw->g.y+FRM_BORDER_T, FRM_BORDER_R, gw->g.height-(FRM_BORDER_T+FRM_BORDER_B), pcol->edge); gdispGFillArea(gw->g.display, gw->g.x, gw->g.y+gw->g.height-FRM_BORDER_B, gw->g.width, FRM_BORDER_B, pcol->edge); // Add the buttons pos = gw->g.x+gw->g.width - (FRM_BORDER_R+FRM_BUTTON_X); if ((gw->g.flags & GWIN_FRAME_CLOSE_BTN)) { if ((gw->g.flags & GWIN_FRAME_CLOSE_PRESSED)) gdispFillArea(pos, gw->g.y+FRM_BUTTON_T, FRM_BUTTON_X, FRM_BUTTON_Y, btn); gdispDrawLine(pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I), pos+(FRM_BUTTON_X-FRM_BUTTON_I-1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), contrast); gdispDrawLine(pos+(FRM_BUTTON_X-FRM_BUTTON_I-1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I), pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), contrast); pos -= FRM_BUTTON_X; } if ((gw->g.flags & GWIN_FRAME_MINMAX_BTN)) { if ((gw->g.flags & GWIN_FRAME_MAX_PRESSED)) gdispFillArea(pos, gw->g.y+FRM_BUTTON_T, FRM_BUTTON_X, FRM_BUTTON_Y, btn); // the symbol gdispDrawBox(pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I), FRM_BUTTON_X-2*FRM_BUTTON_I, FRM_BUTTON_Y-2*FRM_BUTTON_I, contrast); gdispDrawLine(pos+(FRM_BUTTON_I+1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+1), pos+(FRM_BUTTON_X-FRM_BUTTON_I-2), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+1), contrast); gdispDrawLine(pos+(FRM_BUTTON_I+1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+2), pos+(FRM_BUTTON_X-FRM_BUTTON_I-2), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_I+2), contrast); pos -= FRM_BUTTON_X; if ((gw->g.flags & GWIN_FRAME_MIN_PRESSED)) gdispFillArea(pos, gw->g.y+FRM_BUTTON_T, FRM_BUTTON_X, FRM_BUTTON_Y, btn); gdispDrawLine(pos+FRM_BUTTON_I, gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), pos+(FRM_BUTTON_X-FRM_BUTTON_I-1), gw->g.y+(FRM_BUTTON_T+FRM_BUTTON_Y-FRM_BUTTON_I-1), contrast); pos -= FRM_BUTTON_X; } // Don't touch the client area }
void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { /* No mutex required as we only call high level functions which have their own mutex */ coord_t x1, y1; x1 = x+cx-1; y1 = y+cy-1; if (cx > 2) { if (cy >= 1) { gdispDrawLine(x, y, x1, y, color); if (cy >= 2) { gdispDrawLine(x, y1, x1, y1, color); if (cy > 2) { gdispDrawLine(x, y+1, x, y1-1, color); gdispDrawLine(x1, y+1, x1, y1-1, color); } } } } else if (cx == 2) { gdispDrawLine(x, y, x, y1, color); gdispDrawLine(x1, y, x1, y1, color); } else if (cx == 1) { gdispDrawLine(x, y, x, y1, color); } }
void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1) { if (!((gh->flags & GWIN_FLG_VISIBLE))) return; #if GDISP_NEED_CLIP gdispSetClip(gh->x, gh->y, gh->width, gh->height); #endif gdispDrawLine(gh->x+x0, gh->y+y0, gh->x+x1, gh->y+y1, gh->color); }
/// \method line(x1, y1, x2, y2, colour) /// /// Draw a line from (x1,y1) to (x2,y2) using the given colour. /// STATIC mp_obj_t pyb_ugfx_line(mp_uint_t n_args, const mp_obj_t *args) { // extract arguments //pyb_ugfx_obj_t *self = args[0]; int x0 = mp_obj_get_int(args[1]); int y0 = mp_obj_get_int(args[2]); int x1 = mp_obj_get_int(args[3]); int y1 = mp_obj_get_int(args[4]); int col = mp_obj_get_int(args[5]); gdispDrawLine(x0, y0, x1, y1, col); return mp_const_none; }
void gdispFillConvexPoly(coord_t tx, coord_t ty, const point *pntarray, unsigned cnt, color_t color) { const point *lpnt, *rpnt, *epnts; fpcoord_t lx, rx, lk, rk; coord_t y, ymax, lxc, rxc; epnts = &pntarray[cnt-1]; /* Find a top point */ rpnt = pntarray; for(lpnt=pntarray+1; lpnt <= epnts; lpnt++) { if (lpnt->y < rpnt->y) rpnt = lpnt; } lx = rx = rpnt->x<<16; y = rpnt->y; /* Work out the slopes of the two attached line segs */ lpnt = rpnt <= pntarray ? epnts : rpnt-1; while (lpnt->y == y) { lx = lpnt->x<<16; lpnt = lpnt <= pntarray ? epnts : lpnt-1; if (!cnt--) return; } rpnt = rpnt >= epnts ? pntarray : rpnt+1; while (rpnt->y == y) { rx = rpnt->x<<16; rpnt = rpnt >= epnts ? pntarray : rpnt+1; if (!cnt--) return; } lk = (((fpcoord_t)(lpnt->x)<<16) - lx) / (lpnt->y - y); rk = (((fpcoord_t)(rpnt->x)<<16) - rx) / (rpnt->y - y); while(1) { /* Determine our boundary */ ymax = rpnt->y < lpnt->y ? rpnt->y : lpnt->y; /* Scan down the line segments until we hit a boundary */ for(; y < ymax; y++) { lxc = lx>>16; rxc = rx>>16; /* * Doesn't print the right hand point in order to allow polygon joining. * Also ensures that we draw from left to right with the minimum number * of pixels. */ if (lxc < rxc) { if (rxc - lxc == 1) gdispDrawPixel(tx+lxc, ty+y, color); else gdispDrawLine(tx+lxc, ty+y, tx+rxc-1, ty+y, color); } else if (lxc > rxc) { if (lxc - rxc == 1) gdispDrawPixel(tx+rxc, ty+y, color); else gdispDrawLine(tx+rxc, ty+y, tx+lxc-1, ty+y, color); } lx += lk; rx += rk; } if (!cnt--) return; /* Replace the appropriate point */ if (ymax == lpnt->y) { lpnt = lpnt <= pntarray ? epnts : lpnt-1; while (lpnt->y == y) { lx = lpnt->x<<16; lpnt = lpnt <= pntarray ? epnts : lpnt-1; if (!cnt--) return; } lk = (((fpcoord_t)(lpnt->x)<<16) - lx) / (lpnt->y - y); } else { rpnt = rpnt >= epnts ? pntarray : rpnt+1; while (rpnt->y == y) { rx = rpnt->x<<16; rpnt = rpnt >= epnts ? pntarray : rpnt+1; if (!cnt--) return; } rk = (((fpcoord_t)(rpnt->x)<<16) - rx) / (rpnt->y - y); } } }
static inline void _tsDrawCross(const MousePoint *pp) { gdispDrawLine(pp->x-15, pp->y, pp->x-2, pp->y, White); gdispDrawLine(pp->x+2, pp->y, pp->x+15, pp->y, White); gdispDrawLine(pp->x, pp->y-15, pp->x, pp->y-2, White); gdispDrawLine(pp->x, pp->y+2, pp->x, pp->y+15, White); gdispDrawLine(pp->x-15, pp->y+15, pp->x-7, pp->y+15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x-15, pp->y+7, pp->x-15, pp->y+15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x-15, pp->y-15, pp->x-7, pp->y-15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x-15, pp->y-7, pp->x-15, pp->y-15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x+7, pp->y+15, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x+15, pp->y+7, pp->x+15, pp->y+15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x+7, pp->y-15, pp->x+15, pp->y-15, RGB2COLOR(184,158,131)); gdispDrawLine(pp->x+15, pp->y-15, pp->x+15, pp->y-7, RGB2COLOR(184,158,131)); }
static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t y1, const GGraphLineStyle *style) { coord_t dy, dx; coord_t addx, addy; coord_t P, diff, i; coord_t run_on, run_off, run; if (style->type == GGRAPH_LINE_NONE) return; // Convert to device space. Note the y-axis is inverted. x0 += gg->g.x + gg->xorigin; y0 = gg->g.y + gg->g.height - 1 - gg->yorigin - y0; x1 += gg->g.x + gg->xorigin; y1 = gg->g.y + gg->g.height - 1 - gg->yorigin - y1; if (style->size <= 0) { // Use the driver to draw a solid line gdispDrawLine(x0, y0, x1, y1, style->color); return; } switch (style->type) { case GGRAPH_LINE_DOT: run_on = 1; run_off = -style->size; break; case GGRAPH_LINE_DASH: run_on = style->size; run_off = -style->size; break; case GGRAPH_LINE_SOLID: default: // Use the driver to draw a solid line gdispDrawLine(x0, y0, x1, y1, style->color); return; } // Use Bresenham's algorithm modified to draw a stylized line run = 0; if (x1 >= x0) { dx = x1 - x0; addx = 1; } else { dx = x0 - x1; addx = -1; } if (y1 >= y0) { dy = y1 - y0; addy = 1; } else { dy = y0 - y1; addy = -1; } if (dx >= dy) { dy *= 2; P = dy - dx; diff = P - dx; for(i=0; i<=dx; ++i) { if (run++ >= 0) { if (run >= run_on) run = run_off; gdispDrawPixel(x0, y0, style->color); } if (P < 0) { P += dy; x0 += addx; } else { P += diff; x0 += addx; y0 += addy; } } } else { dx *= 2; P = dx - dy; diff = P - dy; for(i=0; i<=dy; ++i) { if (run++ >= 0) { if (run >= run_on) run = run_off; gdispDrawPixel(x0, y0, style->color); } if (P < 0) { P += dx; y0 += addy; } else { P += diff; x0 += addx; y0 += addy; } } } }