boxRgba function

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

Implementation

int boxRgba(Pointer<SdlRenderer> renderer, int x1, int y1, int x2, int y2,
    int r, int g, int b, int a) {
  int result;
  int 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<SdlRect>();
  rect.ref.x = x1;
  rect.ref.y = y1;
  rect.ref.w = x2 - x1;
  rect.ref.h = y2 - y1;
  // changed 1.5.3
  //rect.ref.w = x2 - x1 + 1;
  //rect.ref.h = y2 - y1 + 1;

  /*
	* Draw
	*/
  result = 0;
  result |= sdlSetRenderDrawBlendMode(
      renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
  result |= sdlSetRenderDrawColor(renderer, r, g, b, a);
  result |= sdlRenderFillRect(renderer, rect);
  calloc.free(rect);
  return result;
}