characterRgba function

bool characterRgba(
  1. Pointer<SdlRenderer> renderer,
  2. double x,
  3. double y,
  4. int c,
  5. int r,
  6. int g,
  7. int b,
  8. int a,
)

Implementation

bool characterRgba(
  Pointer<SdlRenderer> renderer,
  double x,
  double y,
  int c,
  int r,
  int g,
  int b,
  int a,
) {
  final srect = calloc<SdlFRect>();
  final drect = calloc<SdlFRect>();
  var result = true;
  int ix;
  int iy;
  int patt;
  Pointer<Uint32> pixels;
  int linepos;
  Pointer<SdlSurface> character;
  Pointer<SdlSurface> rotatedCharacter;
  int ci;
  /* Character index in cache */
  ci = c;
  /*
	* Create new charWidth x charHeight bitmap surface if not already present.
	* Might get rotated later.
	*/
  if (gfxPrimitivesFont[ci] == nullptr) {
    /*
		* Redraw character into surface
		*/
    character = sdlCreateSurface(
      charWidth,
      charHeight,
      SDL_PIXELFORMAT_RGBA8888,
    );
    if (character == nullptr) {
      return false;
    }
    final charpos = ci * charSize;
    pixels = character.ref.pixels.cast<Uint32>();
    /*
		* Drawing loop
		*/
    patt = 0;
    linepos = 0;
    for (iy = 0; iy < charHeight; iy++) {
      patt = currentFontdata[charpos + iy];
      for (ix = 0; ix < charWidth; ix++) {
        final pixel = pixels + linepos;
        if (patt & 0x80 != 0) {
          pixel.value = 0xffffffff;
        } else {
          pixel.value = 0;
        }
        linepos++;
        patt = patt << 1;
      }
    }
    /* Maybe rotate and replace cached image */
    if (charRotation > 0) {
      rotatedCharacter = rotateSurface90Degrees(character, charRotation);
      sdlDestroySurface(character);
      character = rotatedCharacter;
    }
    /* Convert temp surface into texture */
    gfxPrimitivesFont[ci] = sdlCreateTextureFromSurface(renderer, character);
    sdlDestroySurface(character);
    /*
		* Check pointer
		*/
    if (gfxPrimitivesFont[ci] == nullptr) {
      return false;
    }
  }
  /*
	* Set color
	*/
  result = true;
  if (result) {
    result = sdlSetTextureColorMod(gfxPrimitivesFont[ci], r, g, b);
  }
  if (result) {
    result = sdlSetTextureAlphaMod(gfxPrimitivesFont[ci], a);
  }
  /*
	* Setup source rectangle
	*/
  srect.ref.x = 0;
  srect.ref.y = 0;
  srect.ref.w = charWidthLocal.toDouble();
  srect.ref.h = charHeightLocal.toDouble();
  /*
	* Setup destination rectangle
	*/
  drect.ref.x = x;
  drect.ref.y = y;
  drect.ref.w = charWidthLocal.toDouble();
  drect.ref.h = charHeightLocal.toDouble();
  /*
	* Draw texture onto destination
	*/
  if (result) {
    result = sdlRenderTexture(renderer, gfxPrimitivesFont[ci], srect, drect);
  }
  calloc
    ..free(srect)
    ..free(drect);
  return result;
}