Skip to content

Commit

Permalink
Resolve constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
AzuxirenLeadGuy committed Jun 4, 2024
1 parent 18e9448 commit e70fc89
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
25 changes: 15 additions & 10 deletions src/SFML.Graphics/RenderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public class RenderWindow : Window.Window, RenderTarget
/// </summary>
/// <param name="mode">Video mode to use</param>
/// <param name="title">Title of the window</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public RenderWindow(VideoMode mode, string title) :
this(mode, title, Styles.Default, new ContextSettings(0, 0))
public RenderWindow(VideoMode mode, string title, IEventMan manager = null) :
this(mode, title, Styles.Default, new ContextSettings(0, 0), manager)
{
}

Expand All @@ -34,9 +35,10 @@ public RenderWindow(VideoMode mode, string title) :
/// <param name="mode">Video mode to use</param>
/// <param name="title">Title of the window</param>
/// <param name="style">Window style (Resize | Close by default)</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public RenderWindow(VideoMode mode, string title, Styles style) :
this(mode, title, style, new ContextSettings(0, 0))
public RenderWindow(VideoMode mode, string title, Styles style, IEventMan manager = null) :
this(mode, title, style, new ContextSettings(0, 0), manager)
{
}

Expand All @@ -48,9 +50,10 @@ public RenderWindow(VideoMode mode, string title, Styles style) :
/// <param name="title">Title of the window</param>
/// <param name="style">Window style (Resize | Close by default)</param>
/// <param name="settings">Creation parameters</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings) :
base(IntPtr.Zero, 0)
public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings, IEventMan manager = null) :
base(manager, IntPtr.Zero)
{
// Copy the string to a null-terminated UTF-32 byte array
byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0');
Expand All @@ -70,9 +73,10 @@ public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings
/// Create the window from an existing control with default creation settings
/// </summary>
/// <param name="handle">Platform-specific handle of the control</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public RenderWindow(IntPtr handle) :
this(handle, new ContextSettings(0, 0))
public RenderWindow(IntPtr handle, IEventMan manager = null) :
this(handle, new ContextSettings(0, 0), manager)
{
}

Expand All @@ -82,9 +86,10 @@ public RenderWindow(IntPtr handle) :
/// </summary>
/// <param name="handle">Platform-specific handle of the control</param>
/// <param name="settings">Creation parameters</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public RenderWindow(IntPtr handle, ContextSettings settings) :
base(sfRenderWindow_createFromHandle(handle, ref settings), 0)
public RenderWindow(IntPtr handle, ContextSettings settings, IEventMan manager = null) :
base(manager, sfRenderWindow_createFromHandle(handle, ref settings))
{
Initialize();
}
Expand Down
37 changes: 13 additions & 24 deletions src/SFML.Window/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,17 @@ namespace SFML.Window
////////////////////////////////////////////////////////////
public class Window : WindowBase
{
////////////////////////////////////////////////////////////
/// <summary>
/// Create the window with default style and creation settings
/// </summary>
/// <param name="mode">Video mode to use</param>
/// <param name="title">Title of the window</param>
////////////////////////////////////////////////////////////
public Window(VideoMode mode, string title) :
this(mode, title, Styles.Default, new ContextSettings(0, 0))
{
}

////////////////////////////////////////////////////////////
/// <summary>
/// Create the window with default creation settings
/// </summary>
/// <param name="mode">Video mode to use</param>
/// <param name="title">Title of the window</param>
/// <param name="style">Window style (Resize | Close by default)</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public Window(VideoMode mode, string title, Styles style) :
this(mode, title, style, new ContextSettings(0, 0))
public Window(VideoMode mode, string title, Styles style = Styles.Default, IEventMan manager = null) :
this(mode, title, style, new ContextSettings(0, 0), manager)
{
}

Expand All @@ -46,9 +35,10 @@ public Window(VideoMode mode, string title, Styles style) :
/// <param name="title">Title of the window</param>
/// <param name="style">Window style (Resize | Close by default)</param>
/// <param name="settings">Creation parameters</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public Window(VideoMode mode, string title, Styles style, ContextSettings settings) :
base(IntPtr.Zero)
public Window(VideoMode mode, string title, Styles style, ContextSettings settings, IEventMan manager = null) :
base(IntPtr.Zero, manager)
{
// Copy the title to a null-terminated UTF-32 byte array
byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0');
Expand Down Expand Up @@ -79,9 +69,10 @@ public Window(IntPtr handle) :
/// </summary>
/// <param name="Handle">Platform-specific handle of the control</param>
/// <param name="settings">Creation parameters</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public Window(IntPtr Handle, ContextSettings settings) :
base(sfWindow_createFromHandle(Handle, ref settings))
public Window(IntPtr Handle, ContextSettings settings, IEventMan manager = null) :
base(sfWindow_createFromHandle(Handle, ref settings), manager)
{
}

Expand Down Expand Up @@ -379,14 +370,12 @@ public override string ToString()
/// <summary>
/// Constructor for derived classes
/// </summary>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
/// <param name="cPointer">Pointer to the internal object in the C API</param>
/// <param name="dummy">Internal hack :)</param>
////////////////////////////////////////////////////////////
protected Window(IntPtr cPointer, int dummy) :
base(cPointer, 0)
{
// TODO : find a cleaner way of separating this constructor from Window(IntPtr handle)
}
protected Window(IEventMan manager, IntPtr cPointer) :
base(manager, cPointer)
{ }

////////////////////////////////////////////////////////////
/// <summary>
Expand Down
26 changes: 21 additions & 5 deletions src/SFML.Window/WindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public class WindowBase : ObjectBase
/// <param name="mode">Video mode to use</param>
/// <param name="title">Title of the window</param>
/// <param name="style">Window style (Resize | Close by default)</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public WindowBase(VideoMode mode, string title, Styles style) :
public WindowBase(VideoMode mode, string title, Styles style = Styles.Default, IEventMan manager = null) :
base(IntPtr.Zero)
{
// Copy the title to a null-terminated UTF-32 byte array
Expand All @@ -71,17 +72,28 @@ public WindowBase(VideoMode mode, string title, Styles style) :
CPointer = sfWindowBase_createUnicode(mode, (IntPtr)titlePtr, style);
}
}
if (manager == null)
{
manager = new SubscribeManager() { Parent = this };
}
SfmlEventManager = manager;
}

////////////////////////////////////////////////////////////
/// <summary>
/// Create the window from an existing control
/// </summary>
/// <param name="Handle">Platform-specific handle of the control</param>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
////////////////////////////////////////////////////////////
public WindowBase(IntPtr Handle) :
public WindowBase(IntPtr Handle, IEventMan manager = null) :
base(sfWindowBase_createFromHandle(Handle))
{
if (manager == null)
{
manager = new SubscribeManager() { Parent = this };
}
SfmlEventManager = manager;
}

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -346,13 +358,17 @@ public override string ToString()
/// <summary>
/// Constructor for derived classes
/// </summary>
/// <param name="manager">A custom event manager. By default, a SubscribeManager object is created</param>
/// <param name="cPointer">Pointer to the internal object in the C API</param>
/// <param name="dummy">Internal hack :)</param>
////////////////////////////////////////////////////////////
protected WindowBase(IntPtr cPointer, int dummy) :
protected WindowBase(IEventMan manager, IntPtr cPointer) :
base(cPointer)
{
// TODO : find a cleaner way of separating this constructor from WindowBase(IntPtr handle)
if (manager == null)
{
manager = new SubscribeManager() { Parent = this };
}
SfmlEventManager = manager;
}

////////////////////////////////////////////////////////////
Expand Down

0 comments on commit e70fc89

Please sign in to comment.