mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 21:18:24 +01:00
3013 lines
126 KiB
C#
3013 lines
126 KiB
C#
// <auto-generated/>
|
|
// Generated by Brutal.Sdl.Generate; do not edit by hand.
|
|
#nullable enable
|
|
|
|
namespace Brutal.SdlApi.Ttf
|
|
{
|
|
public static unsafe partial class SdlTtf
|
|
{
|
|
/// <summary>
|
|
/// This function gets the version of the dynamically linked SDL_ttf library.
|
|
/// </summary>
|
|
/// <returns>SDL_ttf version.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static int Version() => PInvoke.Version();
|
|
|
|
/// <summary>
|
|
/// Query the version of the FreeType library in use.
|
|
/// </summary>
|
|
/// <param name="major">to be filled in with the major version number. Can be NULL.</param>
|
|
/// <param name="minor">to be filled in with the minor version number. Can be NULL.</param>
|
|
/// <param name="patch">to be filled in with the param version number. Can be NULL.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// TTF_Init() should be called before calling this function.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.Init"/>
|
|
public static void GetFreeTypeVersion(out int major, out int minor, out int patch)
|
|
{
|
|
major = default;
|
|
minor = default;
|
|
patch = default;
|
|
fixed (int* majorPtr = &major)
|
|
{
|
|
fixed (int* minorPtr = &minor)
|
|
{
|
|
fixed (int* patchPtr = &patch)
|
|
{
|
|
PInvoke.GetFreeTypeVersion(majorPtr, minorPtr, patchPtr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query the version of the HarfBuzz library in use.
|
|
/// </summary>
|
|
/// <param name="major">to be filled in with the major version number. Can be NULL.</param>
|
|
/// <param name="minor">to be filled in with the minor version number. Can be NULL.</param>
|
|
/// <param name="patch">to be filled in with the param version number. Can be NULL.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If HarfBuzz is not available, the version reported is 0.0.0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static void GetHarfBuzzVersion(out int major, out int minor, out int patch)
|
|
{
|
|
major = default;
|
|
minor = default;
|
|
patch = default;
|
|
fixed (int* majorPtr = &major)
|
|
{
|
|
fixed (int* minorPtr = &minor)
|
|
{
|
|
fixed (int* patchPtr = &patch)
|
|
{
|
|
PInvoke.GetHarfBuzzVersion(majorPtr, minorPtr, patchPtr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_Init</c>. Throws instead of returning false on failure.
|
|
/// </summary>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static void Init()
|
|
{
|
|
if (PInvoke.Init() == 0)
|
|
{
|
|
throw SdlException.FromError("TTF_Init failed");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_OpenFont</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="file">path to font file.</param>
|
|
/// <param name="ptsize">point size to use for the newly-opened font.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfFont OpenFont(string file, float ptsize)
|
|
{
|
|
TtfFont result = PInvoke.OpenFont(file, ptsize);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("TTF_OpenFont failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_OpenFontIO</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="src">an SDL_IOStream to provide a font file's data.</param>
|
|
/// <param name="closeio">
|
|
/// true to close <c>src</c> when the font is closed, false to leave
|
|
/// it open.
|
|
/// </param>
|
|
/// <param name="ptsize">point size to use for the newly-opened font.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfFont OpenFontIO(nint src, bool closeio, float ptsize)
|
|
{
|
|
TtfFont result = PInvoke.OpenFontIO(src, closeio ? (byte)1 : (byte)0, ptsize);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("TTF_OpenFontIO failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_OpenFontWithProperties</c>. Throws instead of returning a null handle on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="props">the properties to use.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfFont OpenFontWithProperties(uint props)
|
|
{
|
|
TtfFont result = PInvoke.OpenFontWithProperties(props);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("TTF_OpenFontWithProperties failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CopyFont</c>. Throws instead of returning a null handle on failure.
|
|
/// </summary>
|
|
/// <param name="existing_font">the font to copy.</param>
|
|
/// <returns>The created handle (never a null handle).</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfFont CopyFont(TtfFont existing_font)
|
|
{
|
|
TtfFont result = PInvoke.CopyFont(existing_font);
|
|
if (result.IsNull())
|
|
{
|
|
throw SdlException.FromError("TTF_CopyFont failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The following read-write properties are provided by SDL:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER</c>: The FT_Stroker_LineCap value
|
|
/// used when setting the font outline, defaults to
|
|
/// <c>FT_STROKER_LINECAP_ROUND</c>.
|
|
/// - <c>TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER</c>: The FT_Stroker_LineJoin value
|
|
/// used when setting the font outline, defaults to
|
|
/// <c>FT_STROKER_LINEJOIN_ROUND</c>.
|
|
/// - <c>TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER</c>: The FT_Fixed miter limit used
|
|
/// when setting the font outline, defaults to 0.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static uint GetFontProperties(TtfFont font) => PInvoke.GetFontProperties(font);
|
|
|
|
/// <summary>
|
|
/// Get the font generation.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>
|
|
/// the font generation or 0 on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The generation is incremented each time font properties change that require
|
|
/// rebuilding glyphs, such as style, size, etc.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static uint GetFontGeneration(TtfFont font) => PInvoke.GetFontGeneration(font);
|
|
|
|
/// <summary>
|
|
/// Add a fallback font.
|
|
/// </summary>
|
|
/// <param name="font">the font to modify.</param>
|
|
/// <param name="fallback">the font to add as a fallback.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Add a font that will be used for glyphs that are not in the current font.
|
|
/// The fallback font should have the same size and style as the current font.
|
|
/// </para>
|
|
/// <para>
|
|
/// If there are multiple fallback fonts, they are used in the order added.
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created
|
|
/// both fonts.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.ClearFallbackFonts"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.RemoveFallbackFont"/>
|
|
public static bool AddFallbackFont(TtfFont font, TtfFont fallback) =>
|
|
PInvoke.AddFallbackFont(font, fallback) != 0;
|
|
|
|
/// <summary>
|
|
/// Remove a fallback font.
|
|
/// </summary>
|
|
/// <param name="font">the font to modify.</param>
|
|
/// <param name="fallback">the font to remove as a fallback.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created
|
|
/// both fonts.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.AddFallbackFont"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.ClearFallbackFonts"/>
|
|
public static void RemoveFallbackFont(TtfFont font, TtfFont fallback) =>
|
|
PInvoke.RemoveFallbackFont(font, fallback);
|
|
|
|
/// <summary>
|
|
/// Remove all fallback fonts.
|
|
/// </summary>
|
|
/// <param name="font">the font to modify.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.AddFallbackFont"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.RemoveFallbackFont"/>
|
|
public static void ClearFallbackFonts(TtfFont font) => PInvoke.ClearFallbackFonts(font);
|
|
|
|
/// <summary>
|
|
/// Set a font's size dynamically.
|
|
/// </summary>
|
|
/// <param name="font">the font to resize.</param>
|
|
/// <param name="ptsize">the new point size.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font, and clears
|
|
/// already-generated glyphs, if any, from the cache.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontSize"/>
|
|
public static bool SetFontSize(TtfFont font, float ptsize) => PInvoke.SetFontSize(font, ptsize) != 0;
|
|
|
|
/// <summary>
|
|
/// Set font size dynamically with target resolutions, in dots per inch.
|
|
/// </summary>
|
|
/// <param name="font">the font to resize.</param>
|
|
/// <param name="ptsize">the new point size.</param>
|
|
/// <param name="hdpi">the target horizontal DPI.</param>
|
|
/// <param name="vdpi">the target vertical DPI.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font, and clears
|
|
/// already-generated glyphs, if any, from the cache.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontSize"/>
|
|
public static bool SetFontSizeDPI(TtfFont font, float ptsize, int hdpi, int vdpi) =>
|
|
PInvoke.SetFontSizeDPI(font, ptsize, hdpi, vdpi) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the size of a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>
|
|
/// the size of the font, or 0.0f on failure; call SDL_GetError() for
|
|
/// more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontSize"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontSizeDPI"/>
|
|
public static float GetFontSize(TtfFont font) => PInvoke.GetFontSize(font);
|
|
|
|
/// <summary>
|
|
/// Get font target resolutions, in dots per inch.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="hdpi">a pointer filled in with the target horizontal DPI.</param>
|
|
/// <param name="vdpi">a pointer filled in with the target vertical DPI.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontSizeDPI"/>
|
|
public static bool GetFontDPI(TtfFont font, out int hdpi, out int vdpi)
|
|
{
|
|
hdpi = default;
|
|
vdpi = default;
|
|
fixed (int* hdpiPtr = &hdpi)
|
|
{
|
|
fixed (int* vdpiPtr = &vdpi)
|
|
{
|
|
return PInvoke.GetFontDPI(font, hdpiPtr, vdpiPtr) != 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set a font's current style.
|
|
/// </summary>
|
|
/// <param name="font">the font to set a new style on.</param>
|
|
/// <param name="style">the new style values to set, OR'd together.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font, and clears
|
|
/// already-generated glyphs, if any, from the cache.
|
|
/// </para>
|
|
/// <para>
|
|
/// The font styles are a set of bit flags, OR'd together:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>TTF_STYLE_NORMAL</c> (is zero)
|
|
/// - <c>TTF_STYLE_BOLD</c>
|
|
/// - <c>TTF_STYLE_ITALIC</c>
|
|
/// - <c>TTF_STYLE_UNDERLINE</c>
|
|
/// - <c>TTF_STYLE_STRIKETHROUGH</c>
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontStyle"/>
|
|
public static void SetFontStyle(TtfFont font, TtfFontStyleFlags style) => PInvoke.SetFontStyle(font, style);
|
|
|
|
/// <summary>
|
|
/// Query a font's current style.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the current font style, as a set of bit flags.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The font styles are a set of bit flags, OR'd together:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>TTF_STYLE_NORMAL</c> (is zero)
|
|
/// - <c>TTF_STYLE_BOLD</c>
|
|
/// - <c>TTF_STYLE_ITALIC</c>
|
|
/// - <c>TTF_STYLE_UNDERLINE</c>
|
|
/// - <c>TTF_STYLE_STRIKETHROUGH</c>
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontStyle"/>
|
|
public static TtfFontStyleFlags GetFontStyle(TtfFont font) => PInvoke.GetFontStyle(font);
|
|
|
|
/// <summary>
|
|
/// Set a font's current outline.
|
|
/// </summary>
|
|
/// <param name="font">the font to set a new outline on.</param>
|
|
/// <param name="outline">positive outline value, 0 to default.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This uses the font properties <c>TTF_PROP_FONT_OUTLINE_LINE_CAP_NUMBER</c>,
|
|
/// <c>TTF_PROP_FONT_OUTLINE_LINE_JOIN_NUMBER</c>, and
|
|
/// <c>TTF_PROP_FONT_OUTLINE_MITER_LIMIT_NUMBER</c> when setting the font outline.
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font, and clears
|
|
/// already-generated glyphs, if any, from the cache.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontOutline"/>
|
|
public static bool SetFontOutline(TtfFont font, int outline) => PInvoke.SetFontOutline(font, outline) != 0;
|
|
|
|
/// <summary>
|
|
/// Query a font's current outline.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's current outline value.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontOutline"/>
|
|
public static int GetFontOutline(TtfFont font) => PInvoke.GetFontOutline(font);
|
|
|
|
/// <summary>
|
|
/// Set a font's current hinter setting.
|
|
/// </summary>
|
|
/// <param name="font">the font to set a new hinter setting on.</param>
|
|
/// <param name="hinting">the new hinter setting.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font, and clears
|
|
/// already-generated glyphs, if any, from the cache.
|
|
/// </para>
|
|
/// <para>
|
|
/// The hinter setting is a single value:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>TTF_HINTING_NORMAL</c>
|
|
/// - <c>TTF_HINTING_LIGHT</c>
|
|
/// - <c>TTF_HINTING_MONO</c>
|
|
/// - <c>TTF_HINTING_NONE</c>
|
|
/// - <c>TTF_HINTING_LIGHT_SUBPIXEL</c> (available in SDL_ttf 3.0.0 and later)
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontHinting"/>
|
|
public static void SetFontHinting(TtfFont font, TtfHintingFlags hinting) =>
|
|
PInvoke.SetFontHinting(font, hinting);
|
|
|
|
/// <summary>
|
|
/// Query the number of faces of a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the number of FreeType font faces.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static int GetNumFontFaces(TtfFont font) => PInvoke.GetNumFontFaces(font);
|
|
|
|
/// <summary>
|
|
/// Query a font's current FreeType hinter setting.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>
|
|
/// the font's current hinter value, or TTF_HINTING_INVALID if the
|
|
/// font is invalid.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The hinter setting is a single value:
|
|
/// </para>
|
|
/// <para>
|
|
/// - <c>TTF_HINTING_NORMAL</c>
|
|
/// - <c>TTF_HINTING_LIGHT</c>
|
|
/// - <c>TTF_HINTING_MONO</c>
|
|
/// - <c>TTF_HINTING_NONE</c>
|
|
/// - <c>TTF_HINTING_LIGHT_SUBPIXEL</c> (available in SDL_ttf 3.0.0 and later)
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontHinting"/>
|
|
public static TtfHintingFlags GetFontHinting(TtfFont font) => PInvoke.GetFontHinting(font);
|
|
|
|
/// <summary>
|
|
/// Enable Signed Distance Field rendering for a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to set SDF support on.</param>
|
|
/// <param name="enabled">true to enable SDF, false to disable.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// SDF is a technique that helps fonts look sharp even when scaling and
|
|
/// rotating, and requires special shader support for display.
|
|
/// </para>
|
|
/// <para>
|
|
/// This works with Blended APIs, and generates the raw signed distance values
|
|
/// in the alpha channel of the resulting texture.
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font, and clears
|
|
/// already-generated glyphs, if any, from the cache.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontSDF"/>
|
|
public static bool SetFontSDF(TtfFont font, bool enabled) =>
|
|
PInvoke.SetFontSDF(font, enabled ? (byte)1 : (byte)0) != 0;
|
|
|
|
/// <summary>
|
|
/// Query whether Signed Distance Field rendering is enabled for a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>true if enabled, false otherwise.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontSDF"/>
|
|
public static bool GetFontSDF(TtfFont font) => PInvoke.GetFontSDF(font) != 0;
|
|
|
|
/// <summary>
|
|
/// Query a font's weight, in terms of the lightness/heaviness of the strokes.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's current weight.</returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.4.0.
|
|
/// </since>
|
|
public static int GetFontWeight(TtfFont font) => PInvoke.GetFontWeight(font);
|
|
|
|
/// <summary>
|
|
/// Set a font's current wrap alignment option.
|
|
/// </summary>
|
|
/// <param name="font">the font to set a new wrap alignment option on.</param>
|
|
/// <param name="align">the new wrap alignment option.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontWrapAlignment"/>
|
|
public static void SetFontWrapAlignment(TtfFont font, TtfHorizontalAlignment align) =>
|
|
PInvoke.SetFontWrapAlignment(font, align);
|
|
|
|
/// <summary>
|
|
/// Query a font's current wrap alignment option.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's current wrap alignment option.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontWrapAlignment"/>
|
|
public static TtfHorizontalAlignment GetFontWrapAlignment(TtfFont font) => PInvoke.GetFontWrapAlignment(font);
|
|
|
|
/// <summary>
|
|
/// Query the total height of a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's height.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This is usually equal to point size.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static int GetFontHeight(TtfFont font) => PInvoke.GetFontHeight(font);
|
|
|
|
/// <summary>
|
|
/// Query the offset from the baseline to the top of a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's ascent.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This is a positive value, relative to the baseline.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static int GetFontAscent(TtfFont font) => PInvoke.GetFontAscent(font);
|
|
|
|
/// <summary>
|
|
/// Query the offset from the baseline to the bottom of a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's descent.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This is a negative value, relative to the baseline.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static int GetFontDescent(TtfFont font) => PInvoke.GetFontDescent(font);
|
|
|
|
/// <summary>
|
|
/// Set the spacing between lines of text for a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to modify.</param>
|
|
/// <param name="lineskip">the new line spacing for the font.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontLineSkip"/>
|
|
public static void SetFontLineSkip(TtfFont font, int lineskip) => PInvoke.SetFontLineSkip(font, lineskip);
|
|
|
|
/// <summary>
|
|
/// Query the spacing between lines of text for a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's recommended spacing.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontLineSkip"/>
|
|
public static int GetFontLineSkip(TtfFont font) => PInvoke.GetFontLineSkip(font);
|
|
|
|
/// <summary>
|
|
/// Set if kerning is enabled for a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to set kerning on.</param>
|
|
/// <param name="enabled">true to enable kerning, false to disable.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Newly-opened fonts default to allowing kerning. This is generally a good
|
|
/// policy unless you have a strong reason to disable it, as it tends to
|
|
/// produce better rendering (with kerning disabled, some fonts might render
|
|
/// the word <c>kerning</c> as something that looks like <c>keming</c> for example).
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetFontKerning"/>
|
|
public static void SetFontKerning(TtfFont font, bool enabled) =>
|
|
PInvoke.SetFontKerning(font, enabled ? (byte)1 : (byte)0);
|
|
|
|
/// <summary>
|
|
/// Query whether or not kerning is enabled for a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>true if kerning is enabled, false otherwise.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontKerning"/>
|
|
public static bool GetFontKerning(TtfFont font) => PInvoke.GetFontKerning(font) != 0;
|
|
|
|
/// <summary>
|
|
/// Query whether a font is fixed-width.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>true if the font is fixed-width, false otherwise.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// A "fixed-width" font means all glyphs are the same width across; a
|
|
/// lowercase 'i' will be the same size across as a capital 'W', for example.
|
|
/// This is common for terminals and text editors, and other apps that treat
|
|
/// text as a grid. Most other things (WYSIWYG word processors, web pages, etc)
|
|
/// are more likely to not be fixed-width in most cases.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool FontIsFixedWidth(TtfFont font) => PInvoke.FontIsFixedWidth(font) != 0;
|
|
|
|
/// <summary>
|
|
/// Query whether a font is scalable or not.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>true if the font is scalable, false otherwise.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Scalability lets us distinguish between outline and bitmap fonts.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetFontSDF"/>
|
|
public static bool FontIsScalable(TtfFont font) => PInvoke.FontIsScalable(font) != 0;
|
|
|
|
/// <summary>
|
|
/// Query a font's family name.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's family name.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This string is dictated by the contents of the font file.
|
|
/// </para>
|
|
/// <para>
|
|
/// Note that the returned string is to internal storage, and should not be
|
|
/// modified or free'd by the caller. The string becomes invalid, with the rest
|
|
/// of the font, when <c>font</c> is handed to TTF_CloseFont().
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static string? GetFontFamilyName(TtfFont font) => PInvoke.GetFontFamilyName(font);
|
|
|
|
/// <summary>
|
|
/// Query a font's style name.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the font's style name.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This string is dictated by the contents of the font file.
|
|
/// </para>
|
|
/// <para>
|
|
/// Note that the returned string is to internal storage, and should not be
|
|
/// modified or free'd by the caller. The string becomes invalid, with the rest
|
|
/// of the font, when <c>font</c> is handed to TTF_CloseFont().
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static string? GetFontStyleName(TtfFont font) => PInvoke.GetFontStyleName(font);
|
|
|
|
/// <summary>
|
|
/// Set the direction to be used for text shaping by a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to modify.</param>
|
|
/// <param name="direction">the new direction for text to flow.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function only supports left-to-right text shaping if SDL_ttf was not
|
|
/// built with HarfBuzz support.
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool SetFontDirection(TtfFont font, TtfDirection direction) =>
|
|
PInvoke.SetFontDirection(font, direction) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the direction to be used for text shaping by a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>the direction to be used for text shaping.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This defaults to TTF_DIRECTION_INVALID if it hasn't been set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static TtfDirection GetFontDirection(TtfFont font) => PInvoke.GetFontDirection(font);
|
|
|
|
/// <summary>
|
|
/// Convert from a 4 character string to a 32-bit tag.
|
|
/// </summary>
|
|
/// <param name="string">the 4 character string to convert.</param>
|
|
/// <returns>the 32-bit representation of the string.</returns>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.TagToString"/>
|
|
public static uint StringToTag(string @string) => PInvoke.StringToTag(@string);
|
|
|
|
/// <summary>
|
|
/// Convert from a 32-bit tag to a 4 character string.
|
|
/// </summary>
|
|
/// <param name="tag">the 32-bit tag to convert.</param>
|
|
/// <param name="string">
|
|
/// a pointer filled in with the 4 character representation of
|
|
/// the tag.
|
|
/// </param>
|
|
/// <param name="size">
|
|
/// the size of the buffer pointed at by string, should be at least
|
|
/// 4.
|
|
/// </param>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.TagToString"/>
|
|
public static void TagToString(uint tag, byte* @string, nuint size) => PInvoke.TagToString(tag, @string, size);
|
|
|
|
/// <summary>
|
|
/// Set the script to be used for text shaping by a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to modify.</param>
|
|
/// <param name="script">
|
|
/// an
|
|
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
|
|
/// .
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This returns false if SDL_ttf isn't built with HarfBuzz support.
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.StringToTag"/>
|
|
public static bool SetFontScript(TtfFont font, uint script) => PInvoke.SetFontScript(font, script) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the script used for text shaping a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <returns>
|
|
/// an
|
|
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
|
|
/// or 0 if a script hasn't been set.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.TagToString"/>
|
|
public static uint GetFontScript(TtfFont font) => PInvoke.GetFontScript(font);
|
|
|
|
/// <summary>
|
|
/// Get the script used by a 32-bit codepoint.
|
|
/// </summary>
|
|
/// <param name="ch">the character code to check.</param>
|
|
/// <returns>
|
|
/// an
|
|
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
|
|
/// on success, or 0 on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function is thread-safe.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.TagToString"/>
|
|
public static uint GetGlyphScript(uint ch) => PInvoke.GetGlyphScript(ch);
|
|
|
|
/// <summary>
|
|
/// Set language to be used for text shaping by a font.
|
|
/// </summary>
|
|
/// <param name="font">the font to specify a language for.</param>
|
|
/// <param name="language_bcp47">
|
|
/// a null-terminated string containing the desired
|
|
/// language's BCP47 code. Or null to reset the value.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If SDL_ttf was not built with HarfBuzz support, this function returns
|
|
/// false.
|
|
/// </para>
|
|
/// <para>
|
|
/// This updates any TTF_Text objects using this font.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool SetFontLanguage(TtfFont font, string language_bcp47) =>
|
|
PInvoke.SetFontLanguage(font, language_bcp47) != 0;
|
|
|
|
/// <summary>
|
|
/// Check whether a glyph is provided by the font for a UNICODE codepoint.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="ch">the codepoint to check.</param>
|
|
/// <returns>true if font provides a glyph for this character, false if not.</returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool FontHasGlyph(TtfFont font, uint ch) => PInvoke.FontHasGlyph(font, ch) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the pixel image for a UNICODE codepoint.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="ch">the codepoint to check.</param>
|
|
/// <param name="image_type">
|
|
/// a pointer filled in with the glyph image type, may be
|
|
/// NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// an SDL_Surface containing the glyph, or NULL on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static SdlSurface* GetGlyphImage(TtfFont font, uint ch, out TtfImageType image_type)
|
|
{
|
|
image_type = default;
|
|
fixed (TtfImageType* image_typePtr = &image_type)
|
|
{
|
|
return PInvoke.GetGlyphImage(font, ch, image_typePtr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the pixel image for a character index.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="glyph_index">the index of the glyph to return.</param>
|
|
/// <param name="image_type">
|
|
/// a pointer filled in with the glyph image type, may be
|
|
/// NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// an SDL_Surface containing the glyph, or NULL on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This is useful for text engine implementations, which can call this with
|
|
/// the <c>glyph_index</c> in a TTF_CopyOperation
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static SdlSurface* GetGlyphImageForIndex(TtfFont font, uint glyph_index, out TtfImageType image_type)
|
|
{
|
|
image_type = default;
|
|
fixed (TtfImageType* image_typePtr = &image_type)
|
|
{
|
|
return PInvoke.GetGlyphImageForIndex(font, glyph_index, image_typePtr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query the metrics (dimensions) of a font's glyph for a UNICODE codepoint.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="ch">the codepoint to check.</param>
|
|
/// <param name="minx">
|
|
/// a pointer filled in with the minimum x coordinate of the glyph
|
|
/// from the left edge of its bounding box. This value may be
|
|
/// negative.
|
|
/// </param>
|
|
/// <param name="maxx">
|
|
/// a pointer filled in with the maximum x coordinate of the glyph
|
|
/// from the left edge of its bounding box.
|
|
/// </param>
|
|
/// <param name="miny">
|
|
/// a pointer filled in with the minimum y coordinate of the glyph
|
|
/// from the bottom edge of its bounding box. This value may be
|
|
/// negative.
|
|
/// </param>
|
|
/// <param name="maxy">
|
|
/// a pointer filled in with the maximum y coordinate of the glyph
|
|
/// from the bottom edge of its bounding box.
|
|
/// </param>
|
|
/// <param name="advance">
|
|
/// a pointer filled in with the distance to the next glyph from
|
|
/// the left edge of this glyph's bounding box.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// To understand what these metrics mean, here is a useful link:
|
|
/// </para>
|
|
/// <para>
|
|
/// https://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetGlyphMetrics(
|
|
TtfFont font,
|
|
uint ch,
|
|
out int minx,
|
|
out int maxx,
|
|
out int miny,
|
|
out int maxy,
|
|
out int advance
|
|
)
|
|
{
|
|
minx = default;
|
|
maxx = default;
|
|
miny = default;
|
|
maxy = default;
|
|
advance = default;
|
|
fixed (int* minxPtr = &minx)
|
|
{
|
|
fixed (int* maxxPtr = &maxx)
|
|
{
|
|
fixed (int* minyPtr = &miny)
|
|
{
|
|
fixed (int* maxyPtr = &maxy)
|
|
{
|
|
fixed (int* advancePtr = &advance)
|
|
{
|
|
return PInvoke.GetGlyphMetrics(font, ch, minxPtr, maxxPtr, minyPtr, maxyPtr, advancePtr)
|
|
!= 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Query the kerning size between the glyphs of two UNICODE codepoints.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="previous_ch">the previous codepoint.</param>
|
|
/// <param name="ch">the current codepoint.</param>
|
|
/// <param name="kerning">
|
|
/// a pointer filled in with the kerning size between the two
|
|
/// glyphs, in pixels, may be NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetGlyphKerning(TtfFont font, uint previous_ch, uint ch, out int kerning)
|
|
{
|
|
kerning = default;
|
|
fixed (int* kerningPtr = &kerning)
|
|
{
|
|
return PInvoke.GetGlyphKerning(font, previous_ch, ch, kerningPtr) != 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calculate the dimensions of a rendered string of UTF-8 text.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="text">text to calculate, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="w">will be filled with width, in pixels, on return.</param>
|
|
/// <param name="h">will be filled with height, in pixels, on return.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This will report the width and height, in pixels, of the space that the
|
|
/// specified string will take to fully render.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetStringSize(TtfFont font, string text, nuint length, int* w, int* h) =>
|
|
PInvoke.GetStringSize(font, text, length, w, h) != 0;
|
|
|
|
/// <summary>
|
|
/// Calculate the dimensions of a rendered string of UTF-8 text.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="text">text to calculate, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="wrap_width">the maximum width or 0 to wrap on newline characters.</param>
|
|
/// <param name="w">will be filled with width, in pixels, on return.</param>
|
|
/// <param name="h">will be filled with height, in pixels, on return.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This will report the width and height, in pixels, of the space that the
|
|
/// specified string will take to fully render.
|
|
/// </para>
|
|
/// <para>
|
|
/// Text is wrapped to multiple lines on line endings and on word boundaries if
|
|
/// it extends beyond <c>wrap_width</c> in pixels.
|
|
/// </para>
|
|
/// <para>
|
|
/// If wrap_width is 0, this function will only wrap on newline characters.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetStringSizeWrapped(
|
|
TtfFont font,
|
|
string text,
|
|
nuint length,
|
|
int wrap_width,
|
|
int* w,
|
|
int* h
|
|
) => PInvoke.GetStringSizeWrapped(font, text, length, wrap_width, w, h) != 0;
|
|
|
|
/// <summary>
|
|
/// Calculate how much of a UTF-8 string will fit in a given width.
|
|
/// </summary>
|
|
/// <param name="font">the font to query.</param>
|
|
/// <param name="text">text to calculate, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="max_width">
|
|
/// maximum width, in pixels, available for the string, or 0
|
|
/// for unbounded width.
|
|
/// </param>
|
|
/// <param name="measured_width">
|
|
/// a pointer filled in with the width, in pixels, of the
|
|
/// string that will fit, may be NULL.
|
|
/// </param>
|
|
/// <param name="measured_length">
|
|
/// a pointer filled in with the length, in bytes, of
|
|
/// the string that will fit, may be NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This reports the number of characters that can be rendered before reaching
|
|
/// <c>max_width</c>.
|
|
/// </para>
|
|
/// <para>
|
|
/// This does not need to render the string to do this calculation.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool MeasureString(
|
|
TtfFont font,
|
|
string text,
|
|
nuint length,
|
|
int max_width,
|
|
int* measured_width,
|
|
nuint* measured_length
|
|
) => PInvoke.MeasureString(font, text, length, max_width, measured_width, measured_length) != 0;
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_Solid</c>. Throws instead of returning a null pointer on failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextSolid(TtfFont font, string text, nuint length, SdlColor fg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextSolid(font, text, length, fg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_Solid failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_Solid_Wrapped</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="wrapLength">
|
|
/// the maximum width of the text surface or 0 to wrap on
|
|
/// newline characters.
|
|
/// </param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextSolidWrapped(
|
|
TtfFont font,
|
|
string text,
|
|
nuint length,
|
|
SdlColor fg,
|
|
int wrapLength
|
|
)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextSolidWrapped(font, text, length, fg, wrapLength);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_Solid_Wrapped failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderGlyph_Solid</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="ch">the character to render.</param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderGlyphSolid(TtfFont font, uint ch, SdlColor fg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderGlyphSolid(font, ch, fg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderGlyph_Solid failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_Shaded</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="bg">the background color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextShaded(TtfFont font, string text, nuint length, SdlColor fg, SdlColor bg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextShaded(font, text, length, fg, bg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_Shaded failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_Shaded_Wrapped</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="bg">the background color for the text.</param>
|
|
/// <param name="wrap_width">
|
|
/// the maximum width of the text surface or 0 to wrap on
|
|
/// newline characters.
|
|
/// </param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextShadedWrapped(
|
|
TtfFont font,
|
|
string text,
|
|
nuint length,
|
|
SdlColor fg,
|
|
SdlColor bg,
|
|
int wrap_width
|
|
)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextShadedWrapped(font, text, length, fg, bg, wrap_width);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_Shaded_Wrapped failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderGlyph_Shaded</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="ch">the codepoint to render.</param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="bg">the background color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderGlyphShaded(TtfFont font, uint ch, SdlColor fg, SdlColor bg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderGlyphShaded(font, ch, fg, bg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderGlyph_Shaded failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_Blended</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextBlended(TtfFont font, string text, nuint length, SdlColor fg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextBlended(font, text, length, fg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_Blended failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_Blended_Wrapped</c>. Throws instead of returning a null pointer
|
|
/// on failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="wrap_width">
|
|
/// the maximum width of the text surface or 0 to wrap on
|
|
/// newline characters.
|
|
/// </param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextBlendedWrapped(
|
|
TtfFont font,
|
|
string text,
|
|
nuint length,
|
|
SdlColor fg,
|
|
int wrap_width
|
|
)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextBlendedWrapped(font, text, length, fg, wrap_width);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_Blended_Wrapped failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderGlyph_Blended</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="ch">the codepoint to render.</param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderGlyphBlended(TtfFont font, uint ch, SdlColor fg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderGlyphBlended(font, ch, fg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderGlyph_Blended failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_LCD</c>. Throws instead of returning a null pointer on failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="bg">the background color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextLCD(TtfFont font, string text, nuint length, SdlColor fg, SdlColor bg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextLCD(font, text, length, fg, bg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_LCD failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderText_LCD_Wrapped</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">text to render, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="bg">the background color for the text.</param>
|
|
/// <param name="wrap_width">
|
|
/// the maximum width of the text surface or 0 to wrap on
|
|
/// newline characters.
|
|
/// </param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderTextLCDWrapped(
|
|
TtfFont font,
|
|
string text,
|
|
nuint length,
|
|
SdlColor fg,
|
|
SdlColor bg,
|
|
int wrap_width
|
|
)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderTextLCDWrapped(font, text, length, fg, bg, wrap_width);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderText_LCD_Wrapped failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_RenderGlyph_LCD</c>. Throws instead of returning a null pointer on failure.
|
|
/// </summary>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="ch">the codepoint to render.</param>
|
|
/// <param name="fg">the foreground color for the text.</param>
|
|
/// <param name="bg">the background color for the text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static SdlSurface* RenderGlyphLCD(TtfFont font, uint ch, SdlColor fg, SdlColor bg)
|
|
{
|
|
SdlSurface* result = PInvoke.RenderGlyphLCD(font, ch, fg, bg);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_RenderGlyph_LCD failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CreateSurfaceTextEngine</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfTextEngine* CreateSurfaceTextEngine()
|
|
{
|
|
TtfTextEngine* result = PInvoke.CreateSurfaceTextEngine();
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_CreateSurfaceTextEngine failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Draw text to an SDL surface.
|
|
/// </summary>
|
|
/// <param name="text">the text to draw.</param>
|
|
/// <param name="x">
|
|
/// the x coordinate in pixels, positive from the left edge towards
|
|
/// the right.
|
|
/// </param>
|
|
/// <param name="y">
|
|
/// the y coordinate in pixels, positive from the top edge towards the
|
|
/// bottom.
|
|
/// </param>
|
|
/// <param name="surface">the surface to draw on.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// <c>text</c> must have been created using a TTF_TextEngine from
|
|
/// TTF_CreateSurfaceTextEngine().
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateSurfaceTextEngine"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateText"/>
|
|
public static bool DrawSurfaceText(TtfText* text, int x, int y, SdlSurface* surface) =>
|
|
PInvoke.DrawSurfaceText(text, x, y, surface) != 0;
|
|
|
|
/// <summary>
|
|
/// Destroy a text engine created for drawing text on SDL surfaces.
|
|
/// </summary>
|
|
/// <param name="engine">
|
|
/// a TTF_TextEngine object created with
|
|
/// TTF_CreateSurfaceTextEngine().
|
|
/// </param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// All text created by this engine should be destroyed before calling this
|
|
/// function.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// engine.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateSurfaceTextEngine"/>
|
|
public static void DestroySurfaceTextEngine(TtfTextEngine* engine) => PInvoke.DestroySurfaceTextEngine(engine);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CreateRendererTextEngine</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="renderer">the renderer to use for creating textures and drawing text.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfTextEngine* CreateRendererTextEngine(SdlRenderer renderer)
|
|
{
|
|
TtfTextEngine* result = PInvoke.CreateRendererTextEngine(renderer);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_CreateRendererTextEngine failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CreateRendererTextEngineWithProperties</c>. Throws instead of returning a
|
|
/// null pointer on failure.
|
|
/// </summary>
|
|
/// <param name="props">the properties to use.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfTextEngine* CreateRendererTextEngineWithProperties(uint props)
|
|
{
|
|
TtfTextEngine* result = PInvoke.CreateRendererTextEngineWithProperties(props);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_CreateRendererTextEngineWithProperties failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Draw text to an SDL renderer.
|
|
/// </summary>
|
|
/// <param name="text">the text to draw.</param>
|
|
/// <param name="x">
|
|
/// the x coordinate in pixels, positive from the left edge towards
|
|
/// the right.
|
|
/// </param>
|
|
/// <param name="y">
|
|
/// the y coordinate in pixels, positive from the top edge towards the
|
|
/// bottom.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// <c>text</c> must have been created using a TTF_TextEngine from
|
|
/// TTF_CreateRendererTextEngine(), and will draw using the renderer passed to
|
|
/// that function.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateRendererTextEngine"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateText"/>
|
|
public static bool DrawRendererText(TtfText* text, float x, float y) =>
|
|
PInvoke.DrawRendererText(text, x, y) != 0;
|
|
|
|
/// <summary>
|
|
/// Destroy a text engine created for drawing text on an SDL renderer.
|
|
/// </summary>
|
|
/// <param name="engine">
|
|
/// a TTF_TextEngine object created with
|
|
/// TTF_CreateRendererTextEngine().
|
|
/// </param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// All text created by this engine should be destroyed before calling this
|
|
/// function.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// engine.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateRendererTextEngine"/>
|
|
public static void DestroyRendererTextEngine(TtfTextEngine* engine) =>
|
|
PInvoke.DestroyRendererTextEngine(engine);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CreateGPUTextEngine</c>. Throws instead of returning a null pointer on
|
|
/// failure.
|
|
/// </summary>
|
|
/// <param name="device">
|
|
/// the SDL_GPUDevice to use for creating textures and drawing
|
|
/// text.
|
|
/// </param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfTextEngine* CreateGpuTextEngine(SdlGpuDevice device)
|
|
{
|
|
TtfTextEngine* result = PInvoke.CreateGpuTextEngine(device);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_CreateGPUTextEngine failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CreateGPUTextEngineWithProperties</c>. Throws instead of returning a null
|
|
/// pointer on failure.
|
|
/// </summary>
|
|
/// <param name="props">the properties to use.</param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfTextEngine* CreateGpuTextEngineWithProperties(uint props)
|
|
{
|
|
TtfTextEngine* result = PInvoke.CreateGpuTextEngineWithProperties(props);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_CreateGPUTextEngineWithProperties failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Destroy a text engine created for drawing text with the SDL GPU API.
|
|
/// </summary>
|
|
/// <param name="engine">
|
|
/// a TTF_TextEngine object created with
|
|
/// TTF_CreateGPUTextEngine().
|
|
/// </param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// All text created by this engine should be destroyed before calling this
|
|
/// function.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// engine.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateGpuTextEngine"/>
|
|
public static void DestroyGpuTextEngine(TtfTextEngine* engine) => PInvoke.DestroyGpuTextEngine(engine);
|
|
|
|
/// <summary>
|
|
/// Sets the winding order of the vertices returned by TTF_GetGPUTextDrawData
|
|
/// for a particular GPU text engine.
|
|
/// </summary>
|
|
/// <param name="engine">
|
|
/// a TTF_TextEngine object created with
|
|
/// TTF_CreateGPUTextEngine().
|
|
/// </param>
|
|
/// <param name="winding">the new winding order option.</param>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// engine.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetGpuTextEngineWinding"/>
|
|
public static void SetGpuTextEngineWinding(TtfTextEngine* engine, TtfGpuTextEngineWinding winding) =>
|
|
PInvoke.SetGpuTextEngineWinding(engine, winding);
|
|
|
|
/// <summary>
|
|
/// Get the winding order of the vertices returned by TTF_GetGPUTextDrawData
|
|
/// for a particular GPU text engine
|
|
/// </summary>
|
|
/// <param name="engine">
|
|
/// a TTF_TextEngine object created with
|
|
/// TTF_CreateGPUTextEngine().
|
|
/// </param>
|
|
/// <returns>
|
|
/// the winding order used by the GPU text engine or
|
|
/// TTF_GPU_TEXTENGINE_WINDING_INVALID in case of error.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// engine.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetGpuTextEngineWinding"/>
|
|
public static TtfGpuTextEngineWinding GetGpuTextEngineWinding(TtfTextEngine* engine) =>
|
|
PInvoke.GetGpuTextEngineWinding(engine);
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_CreateText</c>. Throws instead of returning a null pointer on failure.
|
|
/// </summary>
|
|
/// <param name="engine">
|
|
/// the text engine to use when creating the text object, may be
|
|
/// NULL.
|
|
/// </param>
|
|
/// <param name="font">the font to render with.</param>
|
|
/// <param name="text">the text to use, in UTF-8 encoding.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <returns>The created resource (never null); the caller owns it and is responsible for freeing it.</returns>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
public static TtfText* CreateText(TtfTextEngine* engine, TtfFont font, string text, nuint length)
|
|
{
|
|
TtfText* result = PInvoke.CreateText(engine, font, text, length);
|
|
if (result == null)
|
|
{
|
|
throw SdlException.FromError("TTF_CreateText failed");
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the properties associated with a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <returns>
|
|
/// a valid property ID on success or 0 on failure; call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static uint GetTextProperties(TtfText* text) => PInvoke.GetTextProperties(text);
|
|
|
|
/// <summary>
|
|
/// Set the text engine used by a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="engine">the text engine to use for drawing.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextEngine"/>
|
|
public static bool SetTextEngine(TtfText* text, TtfTextEngine* engine) =>
|
|
PInvoke.SetTextEngine(text, engine) != 0;
|
|
|
|
/// <summary>
|
|
/// Set the font used by a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="font">the font to use, may be NULL.</param>
|
|
/// <returns>
|
|
/// false if the text pointer is null; otherwise, true. call
|
|
/// SDL_GetError() for more information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// When a text object has a font, any changes to the font will automatically
|
|
/// regenerate the text. If you set the font to NULL, the text will continue to
|
|
/// render but changes to the font will no longer affect the text.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextFont"/>
|
|
public static bool SetTextFont(TtfText* text, TtfFont font) => PInvoke.SetTextFont(text, font) != 0;
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_GetTextFont</c>.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <remarks>
|
|
/// <b>Borrowed handle:</b> the returned handle is owned by SDL (or by another object) and must not be
|
|
/// disposed. Do not call <see cref="System.IDisposable.Dispose"/> on it; doing so would free a resource this
|
|
/// call does not own. A null handle is returned on failure.
|
|
/// </remarks>
|
|
public static TtfFont GetTextFont(TtfText* text) => PInvoke.GetTextFont(text);
|
|
|
|
/// <summary>
|
|
/// Set the direction to be used for text shaping a text object.
|
|
/// </summary>
|
|
/// <param name="text">the text to modify.</param>
|
|
/// <param name="direction">the new direction for text to flow.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function only supports left-to-right text shaping if SDL_ttf was not
|
|
/// built with HarfBuzz support.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool SetTextDirection(TtfText* text, TtfDirection direction) =>
|
|
PInvoke.SetTextDirection(text, direction) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the direction to be used for text shaping a text object.
|
|
/// </summary>
|
|
/// <param name="text">the text to query.</param>
|
|
/// <returns>the direction to be used for text shaping.</returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This defaults to the direction of the font used by the text object.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static TtfDirection GetTextDirection(TtfText* text) => PInvoke.GetTextDirection(text);
|
|
|
|
/// <summary>
|
|
/// Set the script to be used for text shaping a text object.
|
|
/// </summary>
|
|
/// <param name="text">the text to modify.</param>
|
|
/// <param name="script">
|
|
/// an
|
|
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
|
|
/// .
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This returns false if SDL_ttf isn't built with HarfBuzz support.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.StringToTag"/>
|
|
public static bool SetTextScript(TtfText* text, uint script) => PInvoke.SetTextScript(text, script) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the script used for text shaping a text object.
|
|
/// </summary>
|
|
/// <param name="text">the text to query.</param>
|
|
/// <returns>
|
|
/// an
|
|
/// [ISO 15924 code](https://unicode.org/iso15924/iso15924-codes.html)
|
|
/// or 0 if a script hasn't been set on either the text object or the
|
|
/// font.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This defaults to the script of the font used by the text object.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.TagToString"/>
|
|
public static uint GetTextScript(TtfText* text) => PInvoke.GetTextScript(text);
|
|
|
|
/// <summary>
|
|
/// Set the color of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="r">the red color value in the range of 0-255.</param>
|
|
/// <param name="g">the green color value in the range of 0-255.</param>
|
|
/// <param name="b">the blue color value in the range of 0-255.</param>
|
|
/// <param name="a">the alpha value in the range of 0-255.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The default text color is white (255, 255, 255, 255).
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextColor"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextColorFloat"/>
|
|
public static bool SetTextColor(TtfText* text, byte r, byte g, byte b, byte a) =>
|
|
PInvoke.SetTextColor(text, r, g, b, a) != 0;
|
|
|
|
/// <summary>
|
|
/// Set the color of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="r">the red color value, normally in the range of 0-1.</param>
|
|
/// <param name="g">the green color value, normally in the range of 0-1.</param>
|
|
/// <param name="b">the blue color value, normally in the range of 0-1.</param>
|
|
/// <param name="a">the alpha value in the range of 0-1.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The default text color is white (1.0f, 1.0f, 1.0f, 1.0f).
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextColorFloat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextColor"/>
|
|
public static bool SetTextColorFloat(TtfText* text, float r, float g, float b, float a) =>
|
|
PInvoke.SetTextColorFloat(text, r, g, b, a) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the color of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="r">
|
|
/// a pointer filled in with the red color value in the range of
|
|
/// 0-255, may be NULL.
|
|
/// </param>
|
|
/// <param name="g">
|
|
/// a pointer filled in with the green color value in the range of
|
|
/// 0-255, may be NULL.
|
|
/// </param>
|
|
/// <param name="b">
|
|
/// a pointer filled in with the blue color value in the range of
|
|
/// 0-255, may be NULL.
|
|
/// </param>
|
|
/// <param name="a">
|
|
/// a pointer filled in with the alpha value in the range of 0-255,
|
|
/// may be NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextColorFloat"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextColor"/>
|
|
public static bool GetTextColor(TtfText* text, out byte r, out byte g, out byte b, out byte a)
|
|
{
|
|
r = default;
|
|
g = default;
|
|
b = default;
|
|
a = default;
|
|
fixed (byte* rPtr = &r)
|
|
{
|
|
fixed (byte* gPtr = &g)
|
|
{
|
|
fixed (byte* bPtr = &b)
|
|
{
|
|
fixed (byte* aPtr = &a)
|
|
{
|
|
return PInvoke.GetTextColor(text, rPtr, gPtr, bPtr, aPtr) != 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the color of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="r">
|
|
/// a pointer filled in with the red color value, normally in the
|
|
/// range of 0-1, may be NULL.
|
|
/// </param>
|
|
/// <param name="g">
|
|
/// a pointer filled in with the green color value, normally in the
|
|
/// range of 0-1, may be NULL.
|
|
/// </param>
|
|
/// <param name="b">
|
|
/// a pointer filled in with the blue color value, normally in the
|
|
/// range of 0-1, may be NULL.
|
|
/// </param>
|
|
/// <param name="a">
|
|
/// a pointer filled in with the alpha value in the range of 0-1, may
|
|
/// be NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextColor"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextColorFloat"/>
|
|
public static bool GetTextColorFloat(TtfText* text, out float r, out float g, out float b, out float a)
|
|
{
|
|
r = default;
|
|
g = default;
|
|
b = default;
|
|
a = default;
|
|
fixed (float* rPtr = &r)
|
|
{
|
|
fixed (float* gPtr = &g)
|
|
{
|
|
fixed (float* bPtr = &b)
|
|
{
|
|
fixed (float* aPtr = &a)
|
|
{
|
|
return PInvoke.GetTextColorFloat(text, rPtr, gPtr, bPtr, aPtr) != 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the position of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="x">the x offset of the upper left corner of this text in pixels.</param>
|
|
/// <param name="y">the y offset of the upper left corner of this text in pixels.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This can be used to position multiple text objects within a single wrapping
|
|
/// text area.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextPosition"/>
|
|
public static bool SetTextPosition(TtfText* text, int x, int y) => PInvoke.SetTextPosition(text, x, y) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the position of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="x">
|
|
/// a pointer filled in with the x offset of the upper left corner of
|
|
/// this text in pixels, may be NULL.
|
|
/// </param>
|
|
/// <param name="y">
|
|
/// a pointer filled in with the y offset of the upper left corner of
|
|
/// this text in pixels, may be NULL.
|
|
/// </param>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextPosition"/>
|
|
public static bool GetTextPosition(TtfText* text, out int x, out int y)
|
|
{
|
|
x = default;
|
|
y = default;
|
|
fixed (int* xPtr = &x)
|
|
{
|
|
fixed (int* yPtr = &y)
|
|
{
|
|
return PInvoke.GetTextPosition(text, xPtr, yPtr) != 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set whether wrapping is enabled on a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="wrap_width">
|
|
/// the maximum width in pixels, 0 to wrap on newline
|
|
/// characters.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.GetTextWrapWidth"/>
|
|
public static bool SetTextWrapWidth(TtfText* text, int wrap_width) =>
|
|
PInvoke.SetTextWrapWidth(text, wrap_width) != 0;
|
|
|
|
/// <summary>
|
|
/// Get whether wrapping is enabled on a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="wrap_width">
|
|
/// a pointer filled in with the maximum width in pixels or 0
|
|
/// if the text is being wrapped on newline characters.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextWrapWidth"/>
|
|
public static bool GetTextWrapWidth(TtfText* text, out int wrap_width)
|
|
{
|
|
wrap_width = default;
|
|
fixed (int* wrap_widthPtr = &wrap_width)
|
|
{
|
|
return PInvoke.GetTextWrapWidth(text, wrap_widthPtr) != 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set whether whitespace should be visible when wrapping a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="visible">
|
|
/// true to show whitespace when wrapping text, false to hide
|
|
/// it.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If the whitespace is visible, it will take up space for purposes of
|
|
/// alignment and wrapping. This is good for editing, but looks better when
|
|
/// centered or aligned if whitespace around line wrapping is hidden. This
|
|
/// defaults false.
|
|
/// </para>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.TextWrapWhitespaceVisible"/>
|
|
public static bool SetTextWrapWhitespaceVisible(TtfText* text, bool visible) =>
|
|
PInvoke.SetTextWrapWhitespaceVisible(text, visible ? (byte)1 : (byte)0) != 0;
|
|
|
|
/// <summary>
|
|
/// Return whether whitespace is shown when wrapping a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <returns>
|
|
/// true if whitespace is shown when wrapping text, or false
|
|
/// otherwise.
|
|
/// </returns>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextWrapWhitespaceVisible"/>
|
|
public static bool TextWrapWhitespaceVisible(TtfText* text) => PInvoke.TextWrapWhitespaceVisible(text) != 0;
|
|
|
|
/// <summary>
|
|
/// Set the UTF-8 text used by a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="string">the UTF-8 text to use, may be NULL.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.AppendTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.DeleteTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.InsertTextString"/>
|
|
public static bool SetTextString(TtfText* text, string @string, nuint length) =>
|
|
PInvoke.SetTextString(text, @string, length) != 0;
|
|
|
|
/// <summary>
|
|
/// Insert UTF-8 text into a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="offset">
|
|
/// the offset, in bytes, from the beginning of the string if >=
|
|
/// 0, the offset from the end of the string if < 0. Note that
|
|
/// this does not do UTF-8 validation, so you should only insert
|
|
/// at UTF-8 sequence boundaries.
|
|
/// </param>
|
|
/// <param name="string">the UTF-8 text to insert.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.AppendTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.DeleteTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextString"/>
|
|
public static bool InsertTextString(TtfText* text, int offset, string @string, nuint length) =>
|
|
PInvoke.InsertTextString(text, offset, @string, length) != 0;
|
|
|
|
/// <summary>
|
|
/// Append UTF-8 text to a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="string">the UTF-8 text to insert.</param>
|
|
/// <param name="length">
|
|
/// the length of the text, in bytes, or 0 for null terminated
|
|
/// text.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.DeleteTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.InsertTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextString"/>
|
|
public static bool AppendTextString(TtfText* text, string @string, nuint length) =>
|
|
PInvoke.AppendTextString(text, @string, length) != 0;
|
|
|
|
/// <summary>
|
|
/// Delete UTF-8 text from a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to modify.</param>
|
|
/// <param name="offset">
|
|
/// the offset, in bytes, from the beginning of the string if >=
|
|
/// 0, the offset from the end of the string if < 0. Note that
|
|
/// this does not do UTF-8 validation, so you should only delete
|
|
/// at UTF-8 sequence boundaries.
|
|
/// </param>
|
|
/// <param name="length">
|
|
/// the length of text to delete, in bytes, or -1 for the
|
|
/// remainder of the string.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This function may cause the internal text representation to be rebuilt.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.AppendTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.InsertTextString"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.SetTextString"/>
|
|
public static bool DeleteTextString(TtfText* text, int offset, int length) =>
|
|
PInvoke.DeleteTextString(text, offset, length) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the size of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="w">
|
|
/// a pointer filled in with the width of the text, in pixels, may be
|
|
/// NULL.
|
|
/// </param>
|
|
/// <param name="h">
|
|
/// a pointer filled in with the height of the text, in pixels, may be
|
|
/// NULL.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// The size of the text may change when the font or font style and size
|
|
/// change.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetTextSize(TtfText* text, out int w, out int h)
|
|
{
|
|
w = default;
|
|
h = default;
|
|
fixed (int* wPtr = &w)
|
|
{
|
|
fixed (int* hPtr = &h)
|
|
{
|
|
return PInvoke.GetTextSize(text, wPtr, hPtr) != 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the substring of a text object that surrounds a text offset.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="offset">a byte offset into the text string.</param>
|
|
/// <param name="substring">
|
|
/// a pointer filled in with the substring containing the
|
|
/// offset.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If <c>offset</c> is less than 0, this will return a zero length substring at the
|
|
/// beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If
|
|
/// <c>offset</c> is greater than or equal to the length of the text string, this
|
|
/// will return a zero length substring at the end of the text with the
|
|
/// TTF_SUBSTRING_TEXT_END flag set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetTextSubString(TtfText* text, int offset, TtfSubString* substring) =>
|
|
PInvoke.GetTextSubString(text, offset, substring) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the substring of a text object that contains the given line.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="line">a zero-based line index, in the range [0 .. text->num_lines-1].</param>
|
|
/// <param name="substring">
|
|
/// a pointer filled in with the substring containing the
|
|
/// offset.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If <c>line</c> is less than 0, this will return a zero length substring at the
|
|
/// beginning of the text with the TTF_SUBSTRING_TEXT_START flag set. If <c>line</c>
|
|
/// is greater than or equal to <c>text->num_lines</c> this will return a zero
|
|
/// length substring at the end of the text with the TTF_SUBSTRING_TEXT_END
|
|
/// flag set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetTextSubStringForLine(TtfText* text, int line, TtfSubString* substring) =>
|
|
PInvoke.GetTextSubStringForLine(text, line, substring) != 0;
|
|
|
|
/// <summary>
|
|
/// Ergonomic wrapper over <c>TTF_GetTextSubStringsForRange</c>.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="offset">a byte offset into the text string.</param>
|
|
/// <param name="length">
|
|
/// the length of the range being queried, in bytes, or -1 for
|
|
/// the remainder of the string.
|
|
/// </param>
|
|
/// <exception cref="SdlException">The SDL call failed; the message carries the <c>SDL_GetError</c>
|
|
/// text.</exception>
|
|
/// <remarks>
|
|
/// SDL returns a freshly <c>SDL_malloc</c>'d buffer for this call; the returned array is a managed copy, and
|
|
/// the native buffer is freed with <c>SDL_free</c> before this method returns.
|
|
/// </remarks>
|
|
public static TtfSubString[] GetTextSubStringsForRange(TtfText* text, int offset, int length)
|
|
{
|
|
int count;
|
|
var ptr = PInvoke.GetTextSubStringsForRange(text, offset, length, &count);
|
|
if (ptr is null)
|
|
throw SdlException.FromError("TTF_GetTextSubStringsForRange failed");
|
|
try
|
|
{
|
|
var result = new TtfSubString[count];
|
|
for (var i = 0; i < count; i++)
|
|
result[i] = *ptr[i];
|
|
return result;
|
|
}
|
|
finally
|
|
{
|
|
Sdl.PInvoke.Free(ptr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the portion of a text string that is closest to a point.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="x">
|
|
/// the x coordinate relative to the left side of the text, may be
|
|
/// outside the bounds of the text area.
|
|
/// </param>
|
|
/// <param name="y">
|
|
/// the y coordinate relative to the top side of the text, may be
|
|
/// outside the bounds of the text area.
|
|
/// </param>
|
|
/// <param name="substring">
|
|
/// a pointer filled in with the closest substring of text to
|
|
/// the given point.
|
|
/// </param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This will return the closest substring of text to the given point.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetTextSubStringForPoint(TtfText* text, int x, int y, TtfSubString* substring) =>
|
|
PInvoke.GetTextSubStringForPoint(text, x, y, substring) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the previous substring in a text object
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="substring">the TTF_SubString to query.</param>
|
|
/// <param name="previous"></param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If called at the start of the text, this will return a zero length
|
|
/// substring with the TTF_SUBSTRING_TEXT_START flag set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetPreviousTextSubString(TtfText* text, TtfSubString* substring, TtfSubString* previous) =>
|
|
PInvoke.GetPreviousTextSubString(text, substring, previous) != 0;
|
|
|
|
/// <summary>
|
|
/// Get the next substring in a text object
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to query.</param>
|
|
/// <param name="substring">the TTF_SubString to query.</param>
|
|
/// <param name="next">a pointer filled in with the next substring.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// If called at the end of the text, this will return a zero length substring
|
|
/// with the TTF_SUBSTRING_TEXT_END flag set.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool GetNextTextSubString(TtfText* text, TtfSubString* substring, TtfSubString* next) =>
|
|
PInvoke.GetNextTextSubString(text, substring, next) != 0;
|
|
|
|
/// <summary>
|
|
/// Update the layout of a text object.
|
|
/// </summary>
|
|
/// <param name="text">the TTF_Text to update.</param>
|
|
/// <returns>
|
|
/// true on success or false on failure; call SDL_GetError() for more
|
|
/// information.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This is automatically done when the layout is requested or the text is
|
|
/// rendered, but you can call this if you need more control over the timing of
|
|
/// when the layout and text engine representation are updated.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static bool UpdateText(TtfText* text) => PInvoke.UpdateText(text) != 0;
|
|
|
|
/// <summary>
|
|
/// Destroy a text object created by a text engine.
|
|
/// </summary>
|
|
/// <param name="text">the text to destroy.</param>
|
|
/// <threadsafety>
|
|
/// This function should be called on the thread that created the
|
|
/// text.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.CreateText"/>
|
|
public static void DestroyText(TtfText* text) => PInvoke.DestroyText(text);
|
|
|
|
/// <summary>
|
|
/// Dispose of a previously-created font.
|
|
/// </summary>
|
|
/// <param name="font">the font to dispose of.</param>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// Call this when done with a font. This function will free any resources
|
|
/// associated with it. It is safe to call this function on NULL, for example
|
|
/// on the result of a failed call to TTF_OpenFont().
|
|
/// </para>
|
|
/// <para>
|
|
/// The font is not valid after being passed to this function. String pointers
|
|
/// from functions that return information on this font, such as
|
|
/// TTF_GetFontFamilyName() and TTF_GetFontStyleName(), are no longer valid
|
|
/// after this call, as well.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// This function should not be called while any other thread is
|
|
/// using the font.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.OpenFont"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.OpenFontIO"/>
|
|
public static void CloseFont(TtfFont font) => PInvoke.CloseFont(font);
|
|
|
|
/// <summary>
|
|
/// Deinitialize SDL_ttf.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// You must call this when done with the library, to free internal resources.
|
|
/// It is safe to call this when the library isn't initialized, as it will just
|
|
/// return immediately.
|
|
/// </para>
|
|
/// <para>
|
|
/// Once you have as many quit calls as you have had successful calls to
|
|
/// TTF_Init, the library will actually deinitialize.
|
|
/// </para>
|
|
/// <para>
|
|
/// Please note that this does not automatically close any fonts that are still
|
|
/// open at the time of deinitialization, and it is possibly not safe to close
|
|
/// them afterwards, as parts of the library will no longer be initialized to
|
|
/// deal with it. A well-written program should call TTF_CloseFont() on any
|
|
/// open fonts before calling this function!
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
public static void Quit() => PInvoke.Quit();
|
|
|
|
/// <summary>
|
|
/// Check if SDL_ttf is initialized.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// the current number of initialization calls, that need to
|
|
/// eventually be paired with this many calls to TTF_Quit().
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// This reports the number of times the library has been initialized by a call
|
|
/// to TTF_Init(), without a paired deinitialization request from TTF_Quit().
|
|
/// </para>
|
|
/// <para>
|
|
/// In short: if it's greater than zero, the library is currently initialized
|
|
/// and ready to work. If zero, it is not initialized.
|
|
/// </para>
|
|
/// <para>
|
|
/// Despite the return value being a signed integer, this function should not
|
|
/// return a negative number.
|
|
/// </para>
|
|
/// </remarks>
|
|
/// <threadsafety>
|
|
/// It is safe to call this function from any thread.
|
|
/// </threadsafety>
|
|
/// <since>
|
|
/// This function is available since SDL_ttf 3.0.0.
|
|
/// </since>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.Init"/>
|
|
/// <seealso cref="Brutal.SdlApi.Ttf.SdlTtf.PInvoke.Quit"/>
|
|
public static int WasInit() => PInvoke.WasInit();
|
|
}
|
|
}
|