void graphicsDrawCircle(JsGraphics *gfx, short posX, short posY, short rad) { graphicsToDeviceCoordinates(gfx, &posX, &posY); int radY = 0, radX = rad; // Decision criterion divided by 2 evaluated at radX=radX, radY=0 int decisionOver2 = 1 - radX; while (radX >= radY) { graphicsSetPixelDevice(gfx, radX + posX, radY + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, radY + posX, radX + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, -radX + posX, radY + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, -radY + posX, radX + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, -radX + posX, -radY + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, -radY + posX, -radX + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, radX + posX, -radY + posY, gfx->data.fgColor); graphicsSetPixelDevice(gfx, radY + posX, -radX + posY, gfx->data.fgColor); radY++; if (decisionOver2 <= 0) { // Change in decision criterion for radY -> radY+1 decisionOver2 += 2 * radY + 1; } else { radX--; // Change for radY -> radY+1, radX -> radX-1 decisionOver2 += 2 * (radY - radX) + 1; } } }
static void graphicsFillRectDevice(JsGraphics *gfx, short x1, short y1, short x2, short y2) { if (x1>x2) { short t = x1; x1 = x2; x2 = t; } if (y1>y2) { short t = y1; y1 = y2; y2 = t; } if (x1<0) x1=0; if (y1<0) y1=0; if (x2>=gfx->data.width) x2 = (short)(gfx->data.width - 1); if (y2>=gfx->data.height) y2 = (short)(gfx->data.height - 1); if (x2<x1 || y2<y1) return; // nope if (x1 < gfx->data.modMinX) gfx->data.modMinX=x1; if (x2 > gfx->data.modMaxX) gfx->data.modMaxX=x2; if (y1 < gfx->data.modMinY) gfx->data.modMinY=y1; if (y2 > gfx->data.modMaxY) gfx->data.modMaxY=y2; if (x1==x2 && y1==y2) { graphicsSetPixelDevice(gfx,x1,y1,gfx->data.fgColor); return; } return gfx->fillRect(gfx, x1, y1, x2, y2); }
void graphicsFallbackFillRect(JsGraphics *gfx, short x1, short y1, short x2, short y2) { short x,y; for (y=y1;y<=y2;y++) for (x=x1;x<=x2;x++) graphicsSetPixelDevice(gfx,x,y, gfx->data.fgColor); }
void graphicsSetPixel(JsGraphics *gfx, short x, short y, unsigned int col) { graphicsToDeviceCoordinates(gfx, &x, &y); graphicsSetPixelDevice(gfx, x, y, col); }