filledPolygonRgbaMt function

bool 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

bool filledPolygonRgbaMt(Pointer<SdlRenderer> renderer, Pointer<Int16> vx,
    Pointer<Int16> vy, int n, int r, int g, int b, int a) {
  bool result = true;
  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 false;
  }
  if (vy == nullptr) {
    return false;
  }

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

  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 = true;
  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 = true;
    if (result) {
      result = sdlSetRenderDrawBlendMode(
          renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
    }
    if (result) {
      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);
      if (result) {
        result = hline(renderer, xa.toDouble(), xb.toDouble(), y.toDouble());
      }
    }
  }
  return result;
}