Skip to content

Commit

Permalink
refactor UpdateBackBufferSize() (#1598)
Browse files Browse the repository at this point in the history
* use clientBounds

* move UpdateBackBufferSize()

* inline UpdateBackBufferSize()

* swap statement

* join code
  • Loading branch information
nkast authored May 22, 2024
1 parent 95264d2 commit 67c1ae9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
14 changes: 14 additions & 0 deletions MonoGame.Framework/.WindowsDX11/ConcreteGraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ private void GraphicsDevice_PresentationChanged_UpdateGamePlatform(object sender
((WinFormsGameWindow)this.Game.Window).OnPresentationChanged(pp);
}

internal void UpdateBackBufferSize(Rectangle clientBounds)
{
if (this.GraphicsDevice != null)
{
if (clientBounds.Width != this.PreferredBackBufferWidth
|| clientBounds.Height != this.PreferredBackBufferHeight)
{
// Set the default new back buffer size
this.PreferredBackBufferWidth = clientBounds.Width;
this.PreferredBackBufferHeight = clientBounds.Height;
this.ApplyChanges();
}
}
}

#region IGraphicsDeviceManager strategy

Expand Down
39 changes: 8 additions & 31 deletions MonoGame.Framework/Platform/Windows/WinFormsGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,15 @@ private void OnResize(object sender, EventArgs eventArgs)

if (_concreteGame.Window == this && Form.WindowState != FormWindowState.Minimized)
{
// we may need to restore full screen when coming back from a minimized window
if (_lastFormState == FormWindowState.Minimized)
GraphicsDeviceManager gdm = _concreteGame.GraphicsDeviceManager;
if (gdm != null)
{
GraphicsDeviceManager gdm = _concreteGame.GraphicsDeviceManager;
if (gdm != null)
{
// we may need to restore full screen when coming back from a minimized window
if (_lastFormState == FormWindowState.Minimized)
((IPlatformGraphicsDevice)gdm.GraphicsDevice).Strategy.ToConcrete<ConcreteGraphicsDevice>().SetHardwareFullscreen();
}

((IPlatformGraphicsDeviceManager)gdm).GetStrategy<ConcreteGraphicsDeviceManager>().UpdateBackBufferSize(this.ClientBounds);
}
UpdateBackBufferSize();
}

_lastFormState = Form.WindowState;
Expand All @@ -311,13 +310,13 @@ private void OnResizeEnd(object sender, EventArgs eventArgs)
_wasMoved = true;
if (_concreteGame.Window == this)
{
UpdateBackBufferSize();

// the display that the window is on might have changed, so we need to
// check and possibly update the Adapter of the GraphicsDevice
GraphicsDeviceManager gdm = _concreteGame.GraphicsDeviceManager;
if (gdm != null)
{
((IPlatformGraphicsDeviceManager)gdm).GetStrategy<ConcreteGraphicsDeviceManager>().UpdateBackBufferSize(this.ClientBounds);

if (_concreteGame.GraphicsDevice != null)
((IPlatformGraphicsDevice)gdm.GraphicsDevice).Strategy.ToConcrete<ConcreteGraphicsDevice>().RefreshAdapter();
}
Expand All @@ -326,28 +325,6 @@ private void OnResizeEnd(object sender, EventArgs eventArgs)
OnClientSizeChanged();
}

private void UpdateBackBufferSize()
{
GraphicsDeviceManager gdm = _concreteGame.GraphicsDeviceManager;
if (gdm != null)
{
if (gdm.GraphicsDevice == null)
return;

SysDrawing.Size newSize = Form.ClientSize;
int newWidth = newSize.Width;
int newHeight = newSize.Height;
if (newWidth != gdm.PreferredBackBufferWidth
|| newHeight != gdm.PreferredBackBufferHeight)
{
// Set the default new back buffer size
gdm.PreferredBackBufferWidth = newWidth;
gdm.PreferredBackBufferHeight = newHeight;
gdm.ApplyChanges();
}
}
}

protected override void SetTitle(string title)
{
Form.Text = title;
Expand Down

0 comments on commit 67c1ae9

Please sign in to comment.