Example #1
0
void graphicsDrawRect(JsGraphics *gfx, short x1, short y1, short x2, short y2) {
  graphicsToDeviceCoordinates(gfx, &x1, &y1);
  graphicsToDeviceCoordinates(gfx, &x2, &y2);
  // rather than writing pixels, we use fillrect - as it is faster
  graphicsFillRectDevice(gfx,x1,y1,x2,y1);
  graphicsFillRectDevice(gfx,x2,y1,x2,y2);
  graphicsFillRectDevice(gfx,x1,y2,x2,y2);
  graphicsFillRectDevice(gfx,x1,y2,x1,y1);
}
Example #2
0
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;
    }
  }
}
Example #3
0
void graphicsDrawLine(JsGraphics *gfx, short x1, short y1, short x2, short y2) {
  graphicsToDeviceCoordinates(gfx, &x1, &y1);
  graphicsToDeviceCoordinates(gfx, &x2, &y2);

  int xl = x2-x1;
  int yl = y2-y1;
  if (xl<0) xl=-xl; else if (xl==0) xl=1;
  if (yl<0) yl=-yl; else if (yl==0) yl=1;
  if (xl > yl) { // longer in X - scan in X
    if (x1>x2) {
      short t;
      t = x1; x1 = x2; x2 = t;
      t = y1; y1 = y2; y2 = t;
    }
    int pos = (y1<<8) + 128; // rounding!
    int step = ((y2-y1)<<8) / xl;
    short x;
    for (x=x1;x<=x2;x++) {
      graphicsSetPixelDevice(gfx, x, (short)(pos>>8), gfx->data.fgColor);
      pos += step;
    }
  } else {
    if (y1>y2) {
Example #4
0
void graphicsFillCircle(JsGraphics *gfx, short x, short y, short rad) {
  graphicsToDeviceCoordinates(gfx, &x, &y);

  int radY = 0;
  int decisionOver2 = 1 - rad;

  while (rad >= radY) {
    graphicsFillRectDevice(gfx, rad + x, radY + y, -rad + x, -radY + y);
    graphicsFillRectDevice(gfx, radY + x, rad + y, -radY + x, -rad + y);
    graphicsFillRectDevice(gfx, -rad + x, radY + y, rad + x, -radY + y);
    graphicsFillRectDevice(gfx, -radY + x, rad + y, radY + x, -rad + y);
    radY++;
    if (decisionOver2 <= 0){
      // Change in decision criterion for radY -> radY+1
      decisionOver2 += 2 * radY + 1;
    }else{
      rad--;
      // Change for radY -> radY+1, rad -> rad-1
      decisionOver2 += 2 * (radY - rad) + 1;
    }
  }
}
Example #5
0
void graphicsFillRect(JsGraphics *gfx, short x1, short y1, short x2, short y2) {
  graphicsToDeviceCoordinates(gfx, &x1, &y1);
  graphicsToDeviceCoordinates(gfx, &x2, &y2);
  graphicsFillRectDevice(gfx, x1, y1, x2, y2);
}
Example #6
0
unsigned int graphicsGetPixel(JsGraphics *gfx, short x, short y) {
  graphicsToDeviceCoordinates(gfx, &x, &y);
  return graphicsGetPixelDevice(gfx, x, y);
}
Example #7
0
void graphicsSetPixel(JsGraphics *gfx, short x, short y, unsigned int col) {
  graphicsToDeviceCoordinates(gfx, &x, &y);
  graphicsSetPixelDevice(gfx, x, y, col);
}