filledPolygonRgbaMt function

int filledPolygonRgbaMt(
  1. Pointer<SdlRenderer> renderer,
  2. Pointer<Int16> vx,
  3. Pointer<Int16> vy,
  4. int n,
  5. int r,
  6. int g,
  7. int b,
  8. int a,
)

Implementation

int filledPolygonRgbaMt(Pointer<SdlRenderer> renderer, Pointer<Int16> vx,
    Pointer<Int16> vy, int n, int r, int g, int b, int a) {
  int result;
  int i;
  int y, xa, xb;
  int miny, maxy;
  int x1, y1;
  int x2, y2;
  int ind1, ind2;
  var gfxPrimitivesPolyInts = <int>[];

  /*
	* Vertex array NULL check
	*/
  if (vx == nullptr) {
    return (-1);
  }
  if (vy == nullptr) {
    return (-1);
  }

  /*
	* Sanity check number of edges
	*/
  if (n < 3) {
    return -1;
  }

  miny = vy[0];
  maxy = vy[0];
  for (i = 1; (i < n); i++) {
    if (vy[i] < miny) {
      miny = vy[i];
    } else if (vy[i] > maxy) {
      maxy = vy[i];
    }
  }

  /*
	* Draw, scanning y
	*/
  result = 0;
  for (y = miny; (y <= maxy); y++) {
    gfxPrimitivesPolyInts.clear();
    for (i = 0; (i < n); i++) {
      if (i == 0) {
        ind1 = n - 1;
        ind2 = 0;
      } else {
        ind1 = i - 1;
        ind2 = i;
      }
      y1 = vy[ind1];
      y2 = vy[ind2];
      if (y1 < y2) {
        x1 = vx[ind1];
        x2 = vx[ind2];
      } else if (y1 > y2) {
        y2 = vy[ind1];
        y1 = vy[ind2];
        x2 = vx[ind1];
        x1 = vx[ind2];
      } else {
        continue;
      }
      if (((y >= y1) && (y < y2)) || ((y == maxy) && (y > y1) && (y <= y2))) {
        gfxPrimitivesPolyInts
            .add(((65536 * (y - y1)) ~/ (y2 - y1)) * (x2 - x1) + (65536 * x1));
      }
    }
    gfxPrimitivesPolyInts.sort((a, b) => b - a);
    /*
		* Set color
		*/
    result = 0;
    result |= sdlSetRenderDrawBlendMode(
        renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
    result |= sdlSetRenderDrawColor(renderer, r, g, b, a);
    for (i = 0; (i < gfxPrimitivesPolyInts.length); i += 2) {
      xa = gfxPrimitivesPolyInts[i] + 1;
      xa = (xa >> 16) + ((xa & 32768) >> 15);
      xb = gfxPrimitivesPolyInts[i + 1] - 1;
      xb = (xb >> 16) + ((xb & 32768) >> 15);
      result |= hline(renderer, xa, xb, y);
    }
  }
  return result;
}