loadTexture method

Pointer<SdlTexture> loadTexture(
  1. String text, {
  2. String? fontFile,
  3. int? fontSize,
  4. int? textColor,
  5. int? backgroundColor,
  6. int? style,
  7. int? outline,
})

Implementation

Pointer<SdlTexture> loadTexture(
  String text, {
  String? fontFile,
  int? fontSize,
  int? textColor,
  int? backgroundColor,
  int? style,
  int? outline,
}) {
  fontFile ??= _defaultFontFile;
  fontSize ??= _defaultFontSize;
  textColor ??= _defaultTextColor;
  backgroundColor ??= _defaultBackgroundColor;
  style ??= _defaultStyle;
  outline ??= _defaultOutline;

  Pointer<SdlTexture> result = nullptr;
  var key = _createKey(
      fontFile, fontSize, textColor, backgroundColor, style, outline, text);
  if (list[key] != null) {
    result = list[key]!;
  } else {
    var font = _open(fontFile, fontSize);
    if (font != nullptr) {
      font.setStyle(style);
      font.setOutline(outline);
      Pointer<SdlSurface> surface = nullptr;
      if (backgroundColor != null) {
        surface = font.renderUtf8Shaded(text, textColor, backgroundColor);
      } else {
        surface = font.renderUtf8Blended(text, textColor);
      }
      if (surface != nullptr) {
        var texture = renderer.createTextureFromSurface(surface);
        if (texture != nullptr) {
          result = texture;
          list[key] = texture;
        }
      }
      font.close();
    }
  }
  return result;
}