Skip to content

Commit

Permalink
Implement most CSFML 2.6.0 features
Browse files Browse the repository at this point in the history
  • Loading branch information
Marioalexsan committed Feb 17, 2024
1 parent cb9c755 commit 6729e66
Show file tree
Hide file tree
Showing 17 changed files with 1,721 additions and 436 deletions.
20 changes: 19 additions & 1 deletion src/SFML.Audio/Music.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ public class Music : ObjectBase
{
////////////////////////////////////////////////////////////
/// <summary>
/// Constructs a music from an audio file
/// Constructs a music from a file
///
/// This constructor doesn't start playing the music (call
/// <see cref="Play"/> to do so).
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="filename">Path of the music file to open</param>
////////////////////////////////////////////////////////////
Expand All @@ -31,6 +37,12 @@ public class Music : ObjectBase
////////////////////////////////////////////////////////////
/// <summary>
/// Constructs a music from a custom stream
///
/// This constructor doesn't start playing the music (call
/// <see cref="Play"/> to do so).
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="stream">Source stream to read from</param>
////////////////////////////////////////////////////////////
Expand All @@ -49,6 +61,12 @@ public class Music : ObjectBase
////////////////////////////////////////////////////////////
/// <summary>
/// Constructs a music from an audio file in memory
///
/// This constructor doesn't start playing the music (call
/// <see cref="Play"/> to do so).
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="bytes">Byte array containing the file contents</param>
/// <exception cref="LoadingFailedException" />
Expand Down
8 changes: 4 additions & 4 deletions src/SFML.Audio/SoundBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SoundBuffer : ObjectBase
/// Construct a sound buffer from a file
///
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="filename">Path of the sound file to load</param>
Expand All @@ -38,7 +38,7 @@ public class SoundBuffer : ObjectBase
/// Construct a sound buffer from a custom stream.
///
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="stream">Source stream to read from</param>
Expand All @@ -63,7 +63,7 @@ public class SoundBuffer : ObjectBase
/// Construct a sound buffer from a file in memory.
///
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="bytes">Byte array containing the file contents</param>
Expand Down Expand Up @@ -129,7 +129,7 @@ public class SoundBuffer : ObjectBase
/// Save the sound buffer to an audio file.
///
/// Here is a complete list of all the supported audio formats:
/// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam,
/// ogg, wav, flac, mp3, aiff, au, raw, paf, svx, nist, voc, ircam,
/// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64.
/// </summary>
/// <param name="filename">Path of the sound file to write</param>
Expand Down
15 changes: 13 additions & 2 deletions src/SFML.Graphics/BlendMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ public enum Equation
Subtract,

/// <summary>Pixel = Dst * DstFactor - Src * SrcFactor</summary>
ReverseSubtract
ReverseSubtract,

/// <summary>Pixel = min(Dst, Src)</summary>
Min,

/// <summary>Pixel = max(Dst, Src)</summary>
Max
}

/// <summary>Blend source and dest according to dest alpha</summary>
Expand All @@ -77,10 +83,15 @@ public enum Equation
/// <summary>Multiply source and dest</summary>
public static readonly BlendMode Multiply = new BlendMode(Factor.DstColor, Factor.Zero);

/// <summary>Take minimum between source and dest</summary>
public static readonly BlendMode Min = new BlendMode(Factor.One, Factor.One, Equation.Min);

/// <summary>Take maximum between source and dest</summary>
public static readonly BlendMode Max = new BlendMode(Factor.One, Factor.One, Equation.Max);

/// <summary>Overwrite dest with source</summary>
public static readonly BlendMode None = new BlendMode(Factor.One, Factor.Zero);


////////////////////////////////////////////////////////////
/// <summary>
/// Construct the blend mode given the factors and equation
Expand Down
48 changes: 46 additions & 2 deletions src/SFML.Graphics/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,28 @@ public Font(Stream stream) : base(IntPtr.Zero)

////////////////////////////////////////////////////////////
/// <summary>
/// Get the kerning offset between two glyphs
/// Get the kerning value corresponding to a given pair of
/// characters in a font
/// </summary>
/// <param name="first">Unicode code point of the first character</param>
/// <param name="second">Unicode code point of the second character</param>
/// <param name="characterSize">Character size</param>
/// <param name="characterSize">Character size, in pixels</param>
/// <returns>Kerning offset, in pixels</returns>
////////////////////////////////////////////////////////////
public float GetKerning(uint first, uint second, uint characterSize) => sfFont_getKerning(CPointer, first, second, characterSize);

////////////////////////////////////////////////////////////
/// <summary>
/// Get the bold kerning value corresponding to a given pair
/// of characters in a font
/// </summary>
/// <param name="first">Unicode code point of the first character</param>
/// <param name="second">Unicode code point of the second character</param>
/// <param name="characterSize">Character size, in pixels</param>
/// <returns>Kerning offset, in pixels</returns>
////////////////////////////////////////////////////////////
public float GetBoldKerning(uint first, uint second, uint characterSize) => sfFont_getBoldKerning(CPointer, first, second, characterSize);

////////////////////////////////////////////////////////////
/// <summary>
/// Get spacing between two consecutive lines
Expand Down Expand Up @@ -130,6 +143,28 @@ public Texture GetTexture(uint characterSize)
return myTextures[characterSize];
}

////////////////////////////////////////////////////////////
/// <summary>
/// Enable or disable the smooth filter
///
/// When the filter is activated, the font appears smoother
/// so that pixels are less noticeable. However if you want
/// the font to look exactly the same as its source file,
/// you should disable it.
/// The smooth filter is enabled by default.
/// </summary>
/// <param name="smooth">True to enable smoothing, false to disable it</param>
////////////////////////////////////////////////////////////
public void SetSmooth(bool smooth) => sfFont_setSmooth(CPointer, smooth);

////////////////////////////////////////////////////////////
/// <summary>
/// Tell whether the smooth filter is enabled or disabled
/// </summary>
/// <returns>True if smoothing is enabled, false if it is disabled</returns>
////////////////////////////////////////////////////////////
public bool IsSmooth() => sfFont_isSmooth(CPointer);

////////////////////////////////////////////////////////////
/// <summary>
/// Get the font information
Expand Down Expand Up @@ -244,6 +279,9 @@ internal struct InfoMarshalData
[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern float sfFont_getKerning(IntPtr CPointer, uint first, uint second, uint characterSize);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern float sfFont_getBoldKerning(IntPtr CPointer, uint first, uint second, uint characterSize);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern float sfFont_getLineSpacing(IntPtr CPointer, uint characterSize);

Expand All @@ -256,6 +294,12 @@ internal struct InfoMarshalData
[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern IntPtr sfFont_getTexture(IntPtr CPointer, uint characterSize);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfFont_setSmooth(IntPtr CPointer, bool smooth);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern bool sfFont_isSmooth(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern InfoMarshalData sfFont_getInfo(IntPtr CPointer);
#endregion
Expand Down
27 changes: 27 additions & 0 deletions src/SFML.Graphics/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ public Image(string filename) : base(sfImage_createFromFile(filename))
////////////////////////////////////////////////////////////
public bool SaveToFile(string filename) => sfImage_saveToFile(CPointer, filename);

////////////////////////////////////////////////////////////
/// <summary>
/// Save the image to a buffer in memory
///
/// The format of the image must be specified.
/// The supported image formats are bmp, png, tga and jpg.
/// This function fails if the image is empty, or if
/// the format was invalid.
/// </summary>
/// <param name="output">Byte array filled with encoded data</param>
/// <param name="format">Encoding format to use</param>
/// <returns>True if saving was successful</returns>
////////////////////////////////////////////////////////////
public bool SaveToMemory(out byte[] output, string format)
{
using (SFML.System.Buffer buffer = new SFML.System.Buffer())
{
bool success = sfImage_saveToMemory(CPointer, buffer.CPointer, format);

output = success ? buffer.GetData() : Array.Empty<byte>();
return success;
}
}

////////////////////////////////////////////////////////////
/// <summary>
/// Create a transparency mask from a specified colorkey
Expand Down Expand Up @@ -376,6 +400,9 @@ protected override void Destroy(bool disposing)
[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern bool sfImage_saveToFile(IntPtr CPointer, string Filename);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern bool sfImage_saveToMemory(IntPtr CPointer, IntPtr bufferOutput, string format);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfImage_createMaskFromColor(IntPtr CPointer, Color Col, byte Alpha);

Expand Down
32 changes: 32 additions & 0 deletions src/SFML.Graphics/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ public bool Intersects(IntRect rect, out IntRect overlap)
}
}

////////////////////////////////////////////////////////////
/// <summary>
/// Get the position of the rectangle's top-left corner
/// </summary>
/// <returns>Position of rectangle</returns>
////////////////////////////////////////////////////////////
public Vector2i Position => new Vector2i(Left, Top);

////////////////////////////////////////////////////////////
/// <summary>
/// Get the size of the rectangle
/// </summary>
/// <returns>Size of rectangle</returns>
////////////////////////////////////////////////////////////
public Vector2i Size => new Vector2i(Width, Height);

////////////////////////////////////////////////////////////
/// <summary>
/// Provide a string describing the object
Expand Down Expand Up @@ -337,6 +353,22 @@ public bool Intersects(FloatRect rect, out FloatRect overlap)
}
}

////////////////////////////////////////////////////////////
/// <summary>
/// Get the position of the rectangle's top-left corner
/// </summary>
/// <returns>Position of rectangle</returns>
////////////////////////////////////////////////////////////
public Vector2f Position => new Vector2f(Left, Top);

////////////////////////////////////////////////////////////
/// <summary>
/// Get the size of the rectangle
/// </summary>
/// <returns>Size of rectangle</returns>
////////////////////////////////////////////////////////////
public Vector2f Size => new Vector2f(Width, Height);

////////////////////////////////////////////////////////////
/// <summary>
/// Provide a string describing the object
Expand Down
13 changes: 13 additions & 0 deletions src/SFML.Graphics/RenderTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public Vector2u Size
get { return sfRenderTexture_getSize(CPointer); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Tell if the render texture will use sRGB encoding when drawing on it
/// </summary>
////////////////////////////////////////////////////////////
public bool IsSrgb
{
get { return sfRenderTexture_isSrgb(CPointer); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Default view of the render texture
Expand Down Expand Up @@ -540,6 +550,9 @@ protected override void Destroy(bool disposing)
[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern Vector2u sfRenderTexture_getSize(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern bool sfRenderTexture_isSrgb(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern bool sfRenderTexture_setActive(IntPtr CPointer, bool Active);

Expand Down
13 changes: 13 additions & 0 deletions src/SFML.Graphics/RenderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public override Vector2u Size
set { sfRenderWindow_setSize(CPointer, value); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Tell if the render window will use sRGB encoding when drawing on it
/// </summary>
////////////////////////////////////////////////////////////
public bool IsSrgb
{
get { return sfRenderWindow_isSrgb(CPointer); }
}

////////////////////////////////////////////////////////////
/// <summary>
/// Change the title of the window
Expand Down Expand Up @@ -830,6 +840,9 @@ private void Initialize()
[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern Vector2u sfRenderWindow_getSize(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern bool sfRenderWindow_isSrgb(IntPtr CPointer);

[DllImport(CSFML.graphics, CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
private static extern void sfRenderWindow_setSize(IntPtr CPointer, Vector2u size);

Expand Down
Loading

0 comments on commit 6729e66

Please sign in to comment.