/// <summary> /// Draw the given string using the given font and foreground color at given location. /// </summary> /// <param name="str">the string to draw</param> /// <param name="font">the font to use to draw the string</param> /// <param name="color">the text color to set</param> /// <param name="point">the location to start string draw (top-left)</param> /// <param name="size">used to know the size of the rendered text for transparent text support</param> /// <param name="rtl">is to render the string right-to-left (true - RTL, false - LTR)</param> public override void DrawString(string str, RFont font, RColor color, RPoint point, RSize size, bool rtl) { var textSurface = SDL_ttf.TTF_RenderUTF8_Blended(font.ToTTF_Font(), str, color.ToSDL()); if (textSurface.ShowSDLError("Graphics.DrawString: Unable to TTF_RenderUTF8_Blended!")) { return; } var texture_text = SDL.SDL_CreateTextureFromSurface(_renderer, textSurface); if (texture_text.ShowSDLError("Graphics.DrawString: Unable to CreateTextureFromSurface!")) { SDL.SDL_FreeSurface(textSurface); return; } var dst_rect = textSurface.As <SDL.SDL_Surface>().ToSDL_Rect().UpdatedByRPoint(point); if (SDL.SDL_RenderCopy(_renderer, texture_text, IntPtr.Zero, ref dst_rect) < 0) { Helpers.ShowSDLError("Graphics.DrawString:Unable to SDL_RenderCopy!"); } SDL.SDL_DestroyTexture(texture_text); SDL.SDL_FreeSurface(textSurface); }
public override RSize MeasureString(string str, RFont font) { SDL_ttf.TTF_SizeUTF8(font.ToTTF_Font(), str, out int w, out int h); return(new RSize(w, h)); }