diff --git a/PushNuGetLocal.ps1 b/PushNuGetLocal.ps1
new file mode 100644
index 00000000..633b32f6
--- /dev/null
+++ b/PushNuGetLocal.ps1
@@ -0,0 +1,28 @@
+Param(
+ [Parameter(Mandatory, Position = 0)]
+ [string]$LocalSource
+)
+
+dotnet build -c Release
+if ($LASTEXITCODE -ne 0) {
+ Write-Error "Build failed"
+ exit 1
+}
+
+$count = 0
+$packages = (Get-ChildItem src/*/bin/Release/*.nupkg)
+foreach ($package in $packages) {
+ Write-Progress "Pushing packages" -CurrentOperation "Pushing $($package.Name)" -PercentComplete (($count * 100.0) / $packages.Length)
+
+ nuget add $package.FullName -Source $LocalSource
+
+ if ($LASTEXITCODE -ne 0) {
+ Write-Error "Unable to push $($package.Name)"
+ exit 1
+ }
+
+ $count++
+}
+
+Write-Progress "Done" -Completed
+Write-Output "Successfully pushed $count packages"
diff --git a/SFML.Module.props b/SFML.Module.props
index 665c81b4..df8e13db 100644
--- a/SFML.Module.props
+++ b/SFML.Module.props
@@ -20,7 +20,7 @@
-
+
diff --git a/SFML.NuGet.props b/SFML.NuGet.props
index cf8216f2..b119012f 100644
--- a/SFML.NuGet.props
+++ b/SFML.NuGet.props
@@ -5,7 +5,7 @@
true
- 3.0.0
+ 3.1.0
Laurent Gomila
sfml sfml.net
Copyright © Laurent Gomila
diff --git a/examples/opengl/OpenGL.cs b/examples/opengl/OpenGL.cs
index 5dbe314f..0645139e 100644
--- a/examples/opengl/OpenGL.cs
+++ b/examples/opengl/OpenGL.cs
@@ -49,6 +49,35 @@ private static void Main()
FillColor = new SFML.Graphics.Color(255, 255, 255, 170)
};
+ var test = text.Font.GetInfo();
+ Console.WriteLine(test);
+ Console.WriteLine(text.Font.GetAscent(32));
+ Console.WriteLine(text.Font.GetDescent(32));
+ var glyphs = text.GetShapedGlyphs();
+ foreach (var glyph in glyphs)
+ {
+ Console.WriteLine($"{glyph} would be nice if it works");
+ }
+
+ foreach (var vert in text.GetVertexData())
+ {
+ Console.WriteLine(vert);
+ }
+
+ foreach (var vert in text.GetOutlineVertexData())
+ {
+ Console.WriteLine(vert);
+ }
+
+ text.SetGlyphPreProcessor((ref Text.ShapedGlyph glyph, ref uint style, ref Color color, ref Color outlineColor, ref float thickness,
+ object data) =>
+ {
+ Console.WriteLine("huuuu");
+ color = new Color((uint)Random.Shared.Next());
+ thickness += 0.01f;
+ }, null);
+ text.DisplayedString = "A test, huh!";
+
// Make the window the active target for OpenGL calls
_ = window.SetActive();
diff --git a/examples/sound/Sound.cs b/examples/sound/Sound.cs
index 613fe6e5..d78debaf 100644
--- a/examples/sound/Sound.cs
+++ b/examples/sound/Sound.cs
@@ -11,6 +11,31 @@ internal static class Program
///
private static void Main()
{
+ PlaybackDevice.SetNotificationCallback((notification, _) =>
+ {
+ Console.WriteLine(notification);
+ });
+
+ var buffer = new SoundBuffer("resources/canary.wav");
+ // Create a sound instance and play it
+ var sound = new Sound(buffer);
+ sound.Play();
+ Console.WriteLine(PlaybackDevice.GetDefaultDevice());
+ foreach (var device in PlaybackDevice.GetAvailableDevices())
+ {
+ Console.WriteLine($"{device}, set: {PlaybackDevice.SetDevice(device)}, Freq: {PlaybackDevice.GetDeviceSampleRate()}, Default: {PlaybackDevice.IsDefaultDevice()}");
+ }
+
+ Console.WriteLine(PlaybackDevice.GetDevice());
+ Console.WriteLine(PlaybackDevice.SetDeviceToDefault());
+ Console.WriteLine(PlaybackDevice.GetDevice());
+ Console.WriteLine(PlaybackDevice.SetDeviceToNull());
+ Console.WriteLine(PlaybackDevice.GetDevice());
+
+ sound.Stop();
+
+ PlaybackDevice.SetNotificationCallback(null);
+
// Play a sound
PlaySound();
Console.Clear();
diff --git a/examples/window/Program.cs b/examples/window/Program.cs
index 09490a86..1c5a4738 100644
--- a/examples/window/Program.cs
+++ b/examples/window/Program.cs
@@ -1,4 +1,5 @@
using System;
+using Version = SFML.System.Version;
namespace window;
@@ -6,6 +7,13 @@ internal static class Program
{
private static void Main()
{
+ var version = Version.GetVersion();
+ Console.WriteLine(version.Major);
+ Console.WriteLine(version.Minor);
+ Console.WriteLine(version.Patch);
+ Console.WriteLine(version.IsRelease);
+ Console.WriteLine(version.String);
+
Console.WriteLine("Press ESC key to close window");
var window = new SimpleWindow();
window.Run();
@@ -28,6 +36,9 @@ public void Run()
FillColor = SFML.Graphics.Color.Blue
};
+ circle.MiterLimit = 2;
+ Console.WriteLine(circle.MiterLimit);
+
// Start the game loop
while (window.IsOpen)
{
diff --git a/src/SFML.Audio/PlaybackDevice.cs b/src/SFML.Audio/PlaybackDevice.cs
new file mode 100644
index 00000000..3f71a9de
--- /dev/null
+++ b/src/SFML.Audio/PlaybackDevice.cs
@@ -0,0 +1,209 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using SFML.System;
+
+namespace SFML.Audio;
+
+////////////////////////////////////////////////////////////
+///
+/// Queries state over sound stuff
+///
+////////////////////////////////////////////////////////////
+public static class PlaybackDevice
+{
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Enumeration of the playback device notifications.
+ ///
+ ////////////////////////////////////////////////////////////
+ public enum Notification
+ {
+ /// Playback device has been started.
+ Started,
+
+ /// Playback device has been stopped.
+ Stopped,
+
+ /// Playback device has been rerouted (Generated on platforms that support automatic stream routing).
+ Rerouted,
+
+ /// Playback device interruption has begun (Generated on Apple mobile platforms).
+ InterruptionBegan,
+
+ /// Playback device interruption has ended (Generated on Apple mobile platforms).
+ InterruptionEnded,
+
+ /// Playback device has been unlocked (Generated by Emscripten/WebAudio).
+ Unlocked
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Callable that is called to notify of changes to the playback device state.
+ ///
+ ////////////////////////////////////////////////////////////
+ public delegate void NotificationCallback(Notification notification, object userData);
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get a list of the names of all available audio playback devices
+ ///
+ /// An array of strings containing the device names or empty if no devices are available
+ ////////////////////////////////////////////////////////////
+ public static string[] GetAvailableDevices()
+ {
+ unsafe
+ {
+ var length = new UIntPtr(0);
+ var buffer = sfPlaybackDevice_getAvailableDevices(ref length);
+ var devices = new string[length.ToUInt64()];
+ for (ulong i = 0; i < length.ToUInt64(); i++)
+ {
+ devices[i] = Marshal.PtrToStringAnsi(*buffer);
+ buffer++;
+ }
+ return devices;
+ }
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the name of the default audio playback device
+ ///
+ /// The name of the default audio playback device or NULL if there is none
+ ////////////////////////////////////////////////////////////
+ public static string GetDefaultDevice()
+ {
+ var device = sfPlaybackDevice_getDefaultDevice();
+ return device == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(device);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Set the audio playback device
+ ///
+ ///
+ /// True, if it was able to set the requested device
+ ////////////////////////////////////////////////////////////
+ public static bool SetDevice(string device) => sfPlaybackDevice_setDevice(device);
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Set the audio playback device to the default
+ ///
+ /// True, if it was able to set the audio playback device to the default device
+ ////////////////////////////////////////////////////////////
+ public static bool SetDeviceToDefault() => sfPlaybackDevice_setDeviceToDefault();
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Set the audio playback device to the null device
+ ///
+ /// True, if it was able to set the audio playback device to the null device
+ ////////////////////////////////////////////////////////////
+ public static bool SetDeviceToNull() => sfPlaybackDevice_setDeviceToNull();
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the name of the current audio playback device
+ ///
+ /// The name of the current audio playback device or null if there is none
+ ////////////////////////////////////////////////////////////
+ public static string GetDevice()
+ {
+ var device = sfPlaybackDevice_getDevice();
+ return device == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(device);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Gets the sample rate of the current audio playback device
+ ///
+ /// The sample rate of the current audio playback device or 0 if there is none
+ ////////////////////////////////////////////////////////////
+ public static uint GetDeviceSampleRate() => sfPlaybackDevice_getDeviceSampleRate();
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Check if the current playback device is the default device
+ ///
+ ///
+ /// True, if the current playback device is the default device.
+ /// Also false, if there is no current playback device.
+ ///
+ ////////////////////////////////////////////////////////////
+ public static bool IsDefaultDevice() => sfPlaybackDevice_isDefaultDevice();
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Set a callback that should be called to notify of changes to the playback device state
+ ///
+ /// Warning: Do not attempt to alter the device state from
+ /// within this callback. This includes changing the device
+ /// and even creating/destroying sound objects since that
+ /// could indirectly cause the playback device to be
+ /// created/destroyed. Also do not attempt to set the
+ /// notification callback from within this callback. Doing
+ /// so will result in a deadlock.
+ ///
+ /// When receiving a notification via this callback, store
+ /// the information somewhere and react on it from another
+ /// thread e.g. the main thread within the application.
+ ///
+ /// The callback to be called, pass null to remove the current callback
+ /// User data that will be passed to the callback
+ ////////////////////////////////////////////////////////////
+ public static void SetNotificationCallback(NotificationCallback callback, object userData = null)
+ {
+ if (callback is null)
+ {
+ sfPlaybackDevice_setNotificationCallback(IntPtr.Zero, IntPtr.Zero);
+ return;
+ }
+
+ _internalDeviceNotificationCallback = (notification, _) => callback(notification, userData);
+ sfPlaybackDevice_setNotificationCallback(Marshal.GetFunctionPointerForDelegate(_internalDeviceNotificationCallback), IntPtr.Zero);
+ }
+
+
+ private static InternalDeviceNotificationCallback _internalDeviceNotificationCallback;
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ private delegate void InternalDeviceNotificationCallback(Notification notification, IntPtr userData);
+
+ #region Imports
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern unsafe IntPtr* sfPlaybackDevice_getAvailableDevices(ref UIntPtr count);
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern IntPtr sfPlaybackDevice_getDefaultDevice();
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ [return: MarshalAs(UnmanagedType.I1)]
+ private static extern bool sfPlaybackDevice_setDevice(string device);
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ [return: MarshalAs(UnmanagedType.I1)]
+ private static extern bool sfPlaybackDevice_setDeviceToDefault();
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ [return: MarshalAs(UnmanagedType.I1)]
+ private static extern bool sfPlaybackDevice_setDeviceToNull();
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern IntPtr sfPlaybackDevice_getDevice();
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern uint sfPlaybackDevice_getDeviceSampleRate();
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ [return: MarshalAs(UnmanagedType.I1)]
+ private static extern bool sfPlaybackDevice_isDefaultDevice();
+
+ [DllImport(CSFML.Audio, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern void sfPlaybackDevice_setNotificationCallback(IntPtr callback, IntPtr userData);
+
+ #endregion
+}
\ No newline at end of file
diff --git a/src/SFML.Graphics/Font.cs b/src/SFML.Graphics/Font.cs
index 7803b02d..aa49110f 100644
--- a/src/SFML.Graphics/Font.cs
+++ b/src/SFML.Graphics/Font.cs
@@ -144,6 +144,24 @@ public Font(Font copy) : base(sfFont_copy(copy.CPointer)) { }
////////////////////////////////////////////////////////////
public float GetLineSpacing(uint characterSize) => sfFont_getLineSpacing(CPointer, characterSize);
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the ascent of a font
+ ///
+ /// Reference character size
+ /// Ascent, in pixels
+ ////////////////////////////////////////////////////////////
+ public float GetAscent(uint characterSize) => sfFont_getAscent(CPointer, characterSize);
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the descent of a font
+ ///
+ /// Reference character size
+ /// Descent, in pixels
+ ////////////////////////////////////////////////////////////
+ public float GetDescent(uint characterSize) => sfFont_getDescent(CPointer, characterSize);
+
////////////////////////////////////////////////////////////
///
/// Get the position of the underline
@@ -208,7 +226,10 @@ public Info GetInfo()
var data = sfFont_getInfo(CPointer);
var info = new Info
{
- Family = Marshal.PtrToStringAnsi(data.Family)
+ Family = Marshal.PtrToStringAnsi(data.Family),
+ HasKerning = data.HasKerning,
+ HasVerticalMetrics = data.HasVerticalMetrics,
+ Id = data.Id
};
return info;
@@ -265,8 +286,17 @@ protected override void Destroy(bool disposing)
////////////////////////////////////////////////////////////
public struct Info
{
+ /// A unique id that indentifies the font
+ public ulong Id;
+
/// The font family
public string Family;
+
+ /// Has Kerning Information
+ public bool HasKerning;
+
+ /// Has native vertical metrics
+ public bool HasVerticalMetrics;
}
////////////////////////////////////////////////////////////
@@ -276,9 +306,14 @@ public struct Info
///
////////////////////////////////////////////////////////////
[StructLayout(LayoutKind.Sequential)]
- internal struct InfoMarshalData
+ private struct InfoMarshalData
{
+ public ulong Id;
public IntPtr Family;
+ [MarshalAs(UnmanagedType.I1)]
+ public bool HasKerning;
+ [MarshalAs(UnmanagedType.I1)]
+ public bool HasVerticalMetrics;
}
private readonly Dictionary _textures = [];
@@ -335,5 +370,11 @@ internal struct InfoMarshalData
[DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern InfoMarshalData sfFont_getInfo(IntPtr cPointer);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern float sfFont_getAscent(IntPtr cPointer, uint characterSize);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern float sfFont_getDescent(IntPtr cPointer, uint characterSize);
#endregion
}
diff --git a/src/SFML.Graphics/Shape.cs b/src/SFML.Graphics/Shape.cs
index 05907c59..61498854 100644
--- a/src/SFML.Graphics/Shape.cs
+++ b/src/SFML.Graphics/Shape.cs
@@ -67,6 +67,17 @@ public float OutlineThickness
set => sfShape_setOutlineThickness(CPointer, value);
}
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Set the limit on the ratio between miter length and outline thickness of a shape
+ ///
+ ////////////////////////////////////////////////////////////
+ public float MiterLimit
+ {
+ get => sfShape_getMiterLimit(CPointer);
+ set => sfShape_setMiterLimit(CPointer, value);
+ }
+
////////////////////////////////////////////////////////////
///
/// Get the total number of points of the shape
@@ -285,5 +296,11 @@ public Shape(Shape copy) :
[DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfRenderTexture_drawShape(IntPtr cPointer, IntPtr shape, ref RenderStates.MarshalData states);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern float sfShape_getMiterLimit(IntPtr cPointer);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern void sfShape_setMiterLimit(IntPtr cPointer, float miterLimit);
#endregion
}
diff --git a/src/SFML.Graphics/Text.cs b/src/SFML.Graphics/Text.cs
index 6d4608fa..d5cde3cb 100644
--- a/src/SFML.Graphics/Text.cs
+++ b/src/SFML.Graphics/Text.cs
@@ -40,6 +40,141 @@ public enum Styles
StrikeThrough = 1 << 3
}
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Line alignment of a multi-line text
+ ///
+ ////////////////////////////////////////////////////////////
+ public enum Alignment
+ {
+ /// Automatically align lines by script direction, left-align left-to-right text and right-align right-to-left text
+ Default,
+
+ /// Force align all lines to the left, regardless of script direction
+ Left,
+
+ /// Force align all lines centrally
+ Center,
+
+ /// Force align lines to the right, regardless of script direction
+ Right
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Line alignment of a multi-line text
+ ///
+ ////////////////////////////////////////////////////////////
+ public enum TextClusterGrouping
+ {
+ /// Group clusters by grapheme
+ Grapheme,
+
+ /// Group clusters by character
+ Character,
+
+ /// Do not group clusters
+ None
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Direction of the text a glyph belongs to
+ ///
+ ////////////////////////////////////////////////////////////
+ public enum Direction
+ {
+ /// Unspecified
+ Unspecified,
+
+ /// Left-to-right
+ LeftToRight,
+
+ /// Right-to-left
+ RightToLeft,
+
+ /// Top-to-bottom
+ TopToBottom,
+
+ /// Bottom-to-top
+ BottomToTop
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Text Orientation
+ ///
+ ////////////////////////////////////////////////////////////
+ public enum Orientation
+ {
+ /// Default (left-to-right or right-to-left depending on detected script)
+ Default,
+
+ /// Top-to-bottom
+ TopToBottom,
+
+ /// Bottom-to-top
+ BottomToTop
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Glyph that has been positioned by the shaper
+ ///
+ ////////////////////////////////////////////////////////////
+ public struct ShapedGlyph
+ {
+ /// The glyph
+ public Glyph Glyph;
+
+ /// Position of the glyph within a text
+ public Vector2f Position;
+
+ /// Cluster ID
+ public uint Cluster;
+
+ /// Text direction
+ public Direction TextDirection;
+
+ /// The baseline position of the line this glyph is a part of
+ public float Baseline;
+
+ /// Starting offset of the vertex data belonging to this glyph
+ public uint VertexOffset;
+
+ /// Count of vertices belonging to this glyph
+ public uint VertexCount;
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Callback that is provided with glyph data for pre-processing
+ ///
+ /// The callback is called once per glyph whenever the text
+ /// geometry is regenerated, in the order in which the glyph
+ /// geometry is generated. The style, fill color, outline color
+ /// and outline thickness of the glyph can be modified through
+ /// the given pointers.
+ ///
+ /// To map glyphs back to the input string, use the cluster
+ /// value of the shaped glyph. See sf::Text::GlyphPreProcessor
+ /// in the SFML documentation for a detailed explanation.
+ ///
+ /// Changing the style or outline thickness might lead to
+ /// slight inconsistencies of the text bounds, changing the
+ /// fill or outline color is always safe. It is not safe to
+ /// query the text bounds from within the callback.
+ ///
+ /// The shaped glyph to pre-process
+ /// Style of the glyph (see sfTextStyle enum)
+ /// Fill color of the glyph
+ /// Outline color of the glyph
+ /// Outline thickness of the glyph
+ /// User data passed to sfText_setGlyphPreProcessor
+ ////////////////////////////////////////////////////////////
+ public delegate void GlyphPreProcessorCallback(ref ShapedGlyph shapedGlyph, ref uint style, ref Color fillColor, ref Color outlineColor,
+ ref float outlineThickness, object userData);
+
////////////////////////////////////////////////////////////
///
/// Construct the text from a
@@ -248,6 +383,43 @@ public Styles Style
set => sfText_setStyle(CPointer, value);
}
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Line alignment for a multi-line text
+ ///
+ ////////////////////////////////////////////////////////////
+ public Alignment LineAlignment
+ {
+ get => sfText_getLineAlignment(CPointer);
+ set => sfText_setLineAlignment(CPointer, value);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Text orientation
+ ///
+ /// Vertical text orientations require the font to provide
+ /// vertical metrics, see
+ ///
+ ////////////////////////////////////////////////////////////
+ public Orientation TextOrientation
+ {
+ get => sfText_getTextOrientation(CPointer);
+ set => sfText_setTextOrientation(CPointer, value);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Cluster grouping algorithm in use
+ ///
+ ////////////////////////////////////////////////////////////
+ public TextClusterGrouping ClusterGrouping
+ {
+ get => sfText_getClusterGrouping(CPointer);
+ set => sfText_setClusterGrouping(CPointer, value);
+ }
+
+
////////////////////////////////////////////////////////////
///
/// Return the visual position of the Index-th character of the text,
@@ -259,8 +431,106 @@ public Styles Style
/// Index of the character
/// Position of the Index-th character (end of text if Index is out of range)
////////////////////////////////////////////////////////////
+ [Obsolete("Use GetShapedGlyphs instead")]
public Vector2f FindCharacterPos(uint index) => sfText_findCharacterPos(CPointer, (UIntPtr)index);
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the shaped glyphs that make up a text
+ ///
+ /// Array of shaped glyphs
+ ////////////////////////////////////////////////////////////
+ public ShapedGlyph[] GetShapedGlyphs()
+ {
+ unsafe
+ {
+ var length = new UIntPtr(0);
+ var rawGlyphs = sfText_getShapedGlyphs(CPointer, ref length);
+ var glyphs = new ShapedGlyph[length.ToUInt64()];
+ for (ulong i = 0; i < length.ToUInt64(); i++)
+ {
+ glyphs[i] = new ShapedGlyph
+ {
+ Baseline = rawGlyphs[i].Baseline,
+ Cluster = rawGlyphs[i].Cluster,
+ Glyph = rawGlyphs[i].Glyph,
+ Position = rawGlyphs[i].Position,
+ TextDirection = rawGlyphs[i].TextDirection,
+ VertexCount = rawGlyphs[i].VertexCount.ToUInt32(),
+ VertexOffset = rawGlyphs[i].VertexOffset.ToUInt32()
+ };
+ }
+ return glyphs;
+ }
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Set the glyph pre-processor to be called per glyph
+ ///
+ /// The glyph pre-processor is called with glyph data to be
+ /// pre-processed whenever the text geometry is regenerated.
+ ///
+ /// The glyph pre-processor to be called per glyph, pass null to disable pre-processing
+ /// User data that will be passed to the glyph pre-processor
+ ////////////////////////////////////////////////////////////
+ public void SetGlyphPreProcessor(GlyphPreProcessorCallback callback, object userData)
+ {
+ if (callback is null)
+ {
+ sfText_setGlyphPreProcessor(CPointer, IntPtr.Zero, IntPtr.Zero);
+ return;
+ }
+ _internalGlyphPreProcessorCallback = (ref ShapedGlyph glyph, ref uint style, ref Color color, ref Color outlineColor, ref float thickness,
+ IntPtr _) =>
+ {
+ callback(ref glyph, ref style, ref color, ref outlineColor, ref thickness, userData);
+ };
+ sfText_setGlyphPreProcessor(CPointer, Marshal.GetFunctionPointerForDelegate(_internalGlyphPreProcessorCallback), IntPtr.Zero);
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the vertex data of the text
+ ///
+ ///
+ ////////////////////////////////////////////////////////////
+ public Vertex[] GetVertexData()
+ {
+ unsafe
+ {
+ var length = new UIntPtr(0);
+ var rawVerts = sfText_getVertexData(CPointer, ref length);
+ var vertices = new Vertex[length.ToUInt64()];
+ for (ulong i = 0; i < length.ToUInt64(); i++)
+ {
+ vertices[i] = rawVerts[i];
+ }
+ return vertices;
+ }
+ }
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the outline vertex data of the text
+ ///
+ ///
+ ////////////////////////////////////////////////////////////
+ public Vertex[] GetOutlineVertexData()
+ {
+ unsafe
+ {
+ var length = new UIntPtr(0);
+ var rawVerts = sfText_getOutlineVertexData(CPointer, ref length);
+ var vertices = new Vertex[length.ToUInt64()];
+ for (ulong i = 0; i < length.ToUInt64(); i++)
+ {
+ vertices[i] = rawVerts[i];
+ }
+ return vertices;
+ }
+ }
+
////////////////////////////////////////////////////////////
///
/// Get the local bounding of the text.
@@ -342,7 +612,26 @@ public void Draw(IRenderTarget target, RenderStates states)
////////////////////////////////////////////////////////////
protected override void Destroy(bool disposing) => sfText_destroy(CPointer);
+ [StructLayout(LayoutKind.Sequential)]
+ private struct ShapedGlyphMarshal
+ {
+ public Glyph Glyph;
+ public Vector2f Position;
+ public uint Cluster;
+ public Direction TextDirection;
+ public float Baseline;
+ public UIntPtr VertexOffset;
+ public UIntPtr VertexCount;
+ }
+
+
private Font _font;
+ private InternalGlyphPreProcessorCallback _internalGlyphPreProcessorCallback;
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ private delegate void InternalGlyphPreProcessorCallback(ref ShapedGlyph shapedGlyph, ref uint style, ref Color fillColor, ref Color outlineColor,
+ ref float outlineThickness, IntPtr userData);
+
#region Imports
[DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@@ -416,5 +705,35 @@ public void Draw(IRenderTarget target, RenderStates states)
[DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern FloatRect sfText_getLocalBounds(IntPtr cPointer);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern Alignment sfText_getLineAlignment(IntPtr cPointer);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern Orientation sfText_getTextOrientation(IntPtr cPointer);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern void sfText_setLineAlignment(IntPtr cPointer, Alignment lineAlignment);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern void sfText_setTextOrientation(IntPtr cPointer, Orientation textOrientation);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern unsafe ShapedGlyphMarshal* sfText_getShapedGlyphs(IntPtr cPointer, ref UIntPtr count);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern TextClusterGrouping sfText_getClusterGrouping(IntPtr cPointer);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern void sfText_setClusterGrouping(IntPtr cPointer, TextClusterGrouping clusterGrouping);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern void sfText_setGlyphPreProcessor(IntPtr cPointer, IntPtr callback, IntPtr userData);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern unsafe Vertex* sfText_getVertexData(IntPtr cPointer, ref UIntPtr count);
+
+ [DllImport(CSFML.Graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern unsafe Vertex* sfText_getOutlineVertexData(IntPtr cPointer, ref UIntPtr count);
#endregion
}
diff --git a/src/SFML.System/Version.cs b/src/SFML.System/Version.cs
new file mode 100644
index 00000000..6c8bdcc5
--- /dev/null
+++ b/src/SFML.System/Version.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace SFML.System;
+
+////////////////////////////////////////////////////////////
+///
+/// Version information of the SFML library
+///
+////////////////////////////////////////////////////////////
+[StructLayout(LayoutKind.Sequential)]
+public readonly struct Version
+{
+ ////////////////////////////////////////////////////////////
+ ///
+ /// SFML Major Version
+ ///
+ ////////////////////////////////////////////////////////////
+ public readonly sbyte Major;
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// SFML Minor Version
+ ///
+ ////////////////////////////////////////////////////////////
+ public readonly sbyte Minor;
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// SFML Patch Version
+ ///
+ ////////////////////////////////////////////////////////////
+ public readonly sbyte Patch;
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// true if this is a release version, false if this is a development version
+ ///
+ ////////////////////////////////////////////////////////////
+ [MarshalAs(UnmanagedType.I1)]
+ public readonly bool IsRelease;
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// String representation of the SFML version, e.g. 3.1.0 or 3.1.0-dev
+ ///
+ ////////////////////////////////////////////////////////////
+ public string String => Marshal.PtrToStringAnsi(_versionPointer);
+
+ ////////////////////////////////////////////////////////////
+ ///
+ /// Get the version of the SFML library loaded at runtime
+ ///
+ /// Version information of the SFML library
+ ////////////////////////////////////////////////////////////
+ public static Version GetVersion() => sfGetVersion();
+
+ private readonly IntPtr _versionPointer;
+
+ #region Imports
+ [DllImport(CSFML.System, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+ private static extern Version sfGetVersion();
+ #endregion
+}
\ No newline at end of file
diff --git a/src/SFML.Window/Touch.cs b/src/SFML.Window/Touch.cs
index 13d6fe61..560a9817 100644
--- a/src/SFML.Window/Touch.cs
+++ b/src/SFML.Window/Touch.cs
@@ -10,6 +10,7 @@ namespace SFML.Window;
/// Give access to the real-time state of the touches
///
////////////////////////////////////////////////////////////
+[Obsolete("Use Touch Events instead")]
public static class Touch
{
////////////////////////////////////////////////////////////