ttfRenderTextShaded function

Pointer<SdlSurface> ttfRenderTextShaded(
  1. Pointer<TtfFont> font,
  2. String? text,
  3. SdlColor fg,
  4. SdlColor bg,
)

Render Latin1 text at high quality to a new 8-bit surface.

This function will allocate a new 8-bit, palettized surface. The surface's 0 pixel will be the specified background color, while other pixels have varying degrees of the foreground color. This function returns the new surface, or NULL if there was an error.

This will not word-wrap the string; you'll get a surface with a single line of text, as long as the string requires. You can use TTF_RenderText_Shaded_Wrapped() instead if you need to wrap the output to multiple lines.

This will not wrap on newline characters.

You almost certainly want TTF_RenderUTF8_Shaded() unless you're sure you have a 1-byte Latin1 encoding. US ASCII characters will work with either function, but most other Unicode characters packed into a const char * will need UTF-8.

You can render at other quality levels with TTF_RenderText_Solid, TTF_RenderText_Blended, and TTF_RenderText_LCD.

\param font the font to render with. \param text text to render, in Latin1 encoding. \param fg the foreground color for the text. \param bg the background color for the text. \returns a new 8-bit, palettized surface, or NULL if there was an error.

\since This function is available since SDL_ttf 2.0.12.

\sa TTF_RenderUTF8_Shaded \sa TTF_RenderUNICODE_Shaded

extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Shaded(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg)

Implementation

Pointer<SdlSurface> ttfRenderTextShaded(
    Pointer<TtfFont> font, String? text, SdlColor fg, SdlColor bg) {
  final ttfRenderTextShadedLookupFunction = libSdl2Ttf.lookupFunction<
      Pointer<SdlSurface> Function(
          Pointer<TtfFont> font, Pointer<Utf8> text, SdlColor fg, SdlColor bg),
      Pointer<SdlSurface> Function(Pointer<TtfFont> font, Pointer<Utf8> text,
          SdlColor fg, SdlColor bg)>('TTF_RenderText_Shaded');
  final textPointer = text != null ? text.toNativeUtf8() : nullptr;
  final result = ttfRenderTextShadedLookupFunction(font, textPointer, fg, bg);
  calloc.free(textPointer);
  return result;
}