internal void ReinitDisplayProperties(bool overrideDirty = false)
{
graphicsManager.SynchronizeWithVerticalRetrace = VSync;
if (!dirty && !overrideDirty)
{
return;
}
game.IsMouseVisible = MouseVisible;
window.IsBorderless = Borderless;
graphicsManager.IsFullScreen = Fullscreen;
graphicsManager.PreferredBackBufferWidth = WindowResolution.Width;
graphicsManager.PreferredBackBufferHeight = WindowResolution.Height;
// Center the display based on the native resolution.
var form = (System.Windows.Forms.Form)Control.FromHandle(window.Handle);
var position = new System.Drawing.Point(
(Resolution.Native.Width - WindowResolution.Width) / 2,
(Resolution.Native.Height - WindowResolution.Height) / 2
);
// This offset seems to width and height of the windows border,
// so it accounts for the slight off-centering (unless the window
// is larger than the native display).
if (!Borderless)
{
position.X -= WINDOW_BORDER_OFFSET_X;
position.Y -= WINDOW_BORDER_OFFSET_Y;
}
graphicsManager.ApplyChanges();
/* We have to reposition the form after we apply changes to the graphics manager
* otherwise if the user changes the resolution while in fullscreen, then goes into
* windowed mode, the window would be position relative to the previous resolution
* rather than the new resolution.
*/
form.Location = position;
dirty = false;
}