rectangleRgba function

bool rectangleRgba(
  1. Pointer<SdlRenderer> renderer,
  2. double x1,
  3. double y1,
  4. double x2,
  5. double y2,
  6. int r,
  7. int g,
  8. int b,
  9. int a,
)

Implementation

bool rectangleRgba(Pointer<SdlRenderer> renderer, double x1, double y1,
    double x2, double y2, int r, int g, int b, int a) {
  bool result = true;
  double tmp;

  /*
	* Test for special cases of straight lines or single point
	*/
  if (x1 == x2) {
    if (y1 == y2) {
      return pixelRgba(renderer, x1, y1, r, g, b, a);
    } else {
      return vlineRgba(renderer, x1, y1, y2, r, g, b, a);
    }
  } else {
    if (y1 == y2) {
      return hlineRgba(renderer, x1, x2, y1, r, g, b, a);
    }
  }

  /*
	* Swap x1, x2 if required
	*/
  if (x1 > x2) {
    tmp = x1;
    x1 = x2;
    x2 = tmp;
  }

  /*
	* Swap y1, y2 if required
	*/
  if (y1 > y2) {
    tmp = y1;
    y1 = y2;
    y2 = tmp;
  }

  /*
	* Create destination rect
	*/
  var rect = calloc<SdlFRect>();
  rect.ref.x = x1;
  rect.ref.y = y1;
  rect.ref.w = x2 - x1;
  rect.ref.h = y2 - y1;

  /*
	* Draw
	*/
  result = true;
  if (result) {
    result = sdlSetRenderDrawBlendMode(
        renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
  }
  if (result) {
    result = sdlSetRenderDrawColor(renderer, r, g, b, a);
  }
  if (result) {
    result = sdlRenderRect(renderer, rect);
  }
  calloc.free(rect);
  return result;
}