Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Add Maximize/Minimize/Restore for game window on Windows (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que committed May 27, 2017
1 parent 728fcea commit 9f16839
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
8 changes: 8 additions & 0 deletions Protogame/Core/IGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,13 @@ public interface IGameWindow
#elif PLATFORM_ANDROID || PLATFORM_OUYA
Microsoft.Xna.Framework.AndroidGameWindow PlatformWindow { get; }
#endif

#if PLATFORM_WINDOWS
void Maximize();

void Minimize();

void Restore();
#endif
}
}
63 changes: 26 additions & 37 deletions Protogame/Platform/DefaultGameWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS1591

using Microsoft.Xna.Framework;

#if PLATFORM_WINDOWS || PLATFORM_MACOS || PLATFORM_LINUX || PLATFORM_WEB || PLATFORM_IOS
Expand All @@ -9,43 +11,21 @@ namespace Protogame
/// </summary>
public class DefaultGameWindow : IGameWindow
{
/// <summary>
/// Stores a reference to the underlying XNA game window.
/// </summary>
private readonly GameWindow _gameWindow;

/// <summary>
/// Initializes a new instance of the <see cref="Protogame.DefaultGameWindow"/> class.
/// </summary>
/// <param name="gameWindow">
/// The underlying XNA game window to wrap.
/// </param>
public DefaultGameWindow(GameWindow gameWindow)
{
_gameWindow = gameWindow;
}

/// <summary>
/// Gets the client bounds of the window.
/// </summary>
/// <value>
/// The client bounds of the window.
/// </value>

public Rectangle ClientBounds
{
get
{
return _gameWindow.ClientBounds;
}
}

/// <summary>
/// Gets or sets the title of the window. Ignored on platforms where
/// the title is non-existent (such as mobile platforms).
/// </summary>
/// <value>
/// The title shown on the window.
/// </value>

public string Title
{
get
Expand All @@ -58,14 +38,7 @@ public string Title
_gameWindow.Title = value;
}
}

/// <summary>
/// Gets or sets a value indicating whether the user is allowed to resize the window. Ignored
/// on platforms where the window is of a fixed size.
/// </summary>
/// <value>
/// Whether or not the user is allowed to resize the window.
/// </value>

public bool AllowUserResizing
{
get
Expand All @@ -83,15 +56,31 @@ public bool AllowUserResizing
}
}
}

/// <summary>
/// The underlying MonoGame window object. The type and presence of this property
/// varies per-platform, so it's access should always be within a platform specific block.
/// </summary>

public GameWindow PlatformWindow
{
get { return _gameWindow; }
}

#if PLATFORM_WINDOWS
public void Maximize()
{
var form = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(_gameWindow.Handle);
form.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}

public void Minimize()
{
var form = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(_gameWindow.Handle);
form.WindowState = System.Windows.Forms.FormWindowState.Minimized;
}

public void Restore()
{
var form = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(_gameWindow.Handle);
form.WindowState = System.Windows.Forms.FormWindowState.Normal;
}
#endif
}
}

Expand Down

0 comments on commit 9f16839

Please sign in to comment.