diff --git a/UI/Config/Configuration.cs b/UI/Config/Configuration.cs index 6b968f3..e318a5b 100644 --- a/UI/Config/Configuration.cs +++ b/UI/Config/Configuration.cs @@ -22,8 +22,8 @@ namespace Mesen.GUI.Config public PreferencesConfig Preferences; public DebugInfo Debug; public RecentItems RecentFiles; - public Point? WindowLocation; - public Size? WindowSize; + public Point WindowLocation; + public Size WindowSize; public bool NeedInputReinit = true; public Configuration() diff --git a/UI/Controls/ctrlRecentGames.cs b/UI/Controls/ctrlRecentGames.cs index 8ecc503..ee87092 100644 --- a/UI/Controls/ctrlRecentGames.cs +++ b/UI/Controls/ctrlRecentGames.cs @@ -20,7 +20,6 @@ namespace Mesen.GUI.Controls public partial class ctrlRecentGames : BaseControl { public delegate void RecentGameLoadedHandler(RecentGameInfo gameInfo); - public event RecentGameLoadedHandler OnRecentGameLoaded; public new event MouseEventHandler MouseMove { diff --git a/UI/Emulation/ShortcutHandler.cs b/UI/Emulation/ShortcutHandler.cs index a562dee..c9e0f39 100644 --- a/UI/Emulation/ShortcutHandler.cs +++ b/UI/Emulation/ShortcutHandler.cs @@ -16,6 +16,8 @@ namespace Mesen.GUI.Emulation private Dictionary> _actionEnabledFuncs = new Dictionary>(); private List _speedValues = new List { 1, 3, 6, 12, 25, 50, 75, 100, 150, 200, 250, 300, 350, 400, 450, 500, 750, 1000, 2000, 4000 }; + public bool AutoResizeForm { get; internal set; } + public void BindShortcut(ToolStripMenuItem item, EmulatorShortcut shortcut, Func isActionEnabled = null) { item.Click += (object sender, EventArgs e) => { @@ -158,8 +160,9 @@ namespace Mesen.GUI.Emulation ConfigManager.ApplyChanges(); } - private void SetScale(int scale) + public void SetScale(double scale, bool autoResize = true) { + this.AutoResizeForm = autoResize; ConfigManager.Config.Video.VideoScale = scale; ConfigManager.Config.Video.ApplyConfig(); ConfigManager.ApplyChanges(); diff --git a/UI/Forms/frmMain.cs b/UI/Forms/frmMain.cs index 0463b38..5232d51 100644 --- a/UI/Forms/frmMain.cs +++ b/UI/Forms/frmMain.cs @@ -29,6 +29,17 @@ namespace Mesen.GUI.Forms ResourceHelper.LoadResources(Language.English); } + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + if(!ConfigManager.Config.WindowSize.IsEmpty) { + this.StartPosition = FormStartPosition.Manual; + this.Location = ConfigManager.Config.WindowLocation; + this.Size = ConfigManager.Config.WindowSize; + } + } + protected override void OnShown(EventArgs e) { base.OnShown(e); @@ -52,6 +63,9 @@ namespace Mesen.GUI.Forms ctrlRecentGames.Initialize(); ctrlRecentGames.Visible = true; + + this.Resize += frmMain_Resize; + ResizeRecentGames(); } protected override void OnFormClosing(FormClosingEventArgs e) @@ -63,6 +77,8 @@ namespace Mesen.GUI.Forms _notifListener = null; } + ConfigManager.Config.WindowLocation = this.WindowState == FormWindowState.Normal ? this.Location : this.RestoreBounds.Location; + ConfigManager.Config.WindowSize = this.WindowState == FormWindowState.Normal ? this.Size : this.RestoreBounds.Size; ConfigManager.ApplyChanges(); DebugApi.ResumeExecution(); @@ -85,6 +101,7 @@ namespace Mesen.GUI.Forms this.BeginInvoke((Action)(() => { ctrlRecentGames.Initialize(); ctrlRecentGames.Visible = true; + ResizeRecentGames(); })); break; @@ -176,28 +193,58 @@ namespace Mesen.GUI.Forms private void UpdateViewerSize(ScreenSize screenSize) { - //this.Resize -= frmMain_Resize; - - //if(forceUpdate || (!_customSize && this.WindowState != FormWindowState.Maximized)) { + if(_shortcuts.AutoResizeForm && this.WindowState != FormWindowState.Maximized) { + this.Resize -= frmMain_Resize; Size newSize = new Size(screenSize.Width, screenSize.Height); - - //UpdateScaleMenu(size.Scale); this.ClientSize = new Size(newSize.Width, newSize.Height + pnlRenderer.Top); - //} + this.Resize += frmMain_Resize; + } ctrlRenderer.Size = new Size(screenSize.Width, screenSize.Height); ctrlRenderer.Top = (pnlRenderer.Height - ctrlRenderer.Height) / 2; ctrlRenderer.Left = (pnlRenderer.Width - ctrlRenderer.Width) / 2; + } + + private void SetScaleBasedOnDimensions(Size dimensions) + { + ScreenSize size = EmuApi.GetScreenSize(true); - //this.Resize += frmMain_Resize; + double verticalScale = (double)dimensions.Height / size.Height; + double horizontalScale = (double)dimensions.Width / size.Width; + double scale = Math.Min(verticalScale, horizontalScale); + /*if(_fullscreenMode && ConfigManager.Config.Video.FullscreenForceIntegerScale) { + scale = Math.Floor(scale); + }*/ + + _shortcuts.SetScale(scale, false); } - protected override void OnResize(EventArgs e) + private void SetScaleBasedOnWindowSize() + { + SetScaleBasedOnDimensions(pnlRenderer.ClientSize); + } + + private void SetScaleBasedOnScreenSize() + { + SetScaleBasedOnDimensions(Screen.FromControl(this).Bounds.Size); + } + + private void ResizeRecentGames() { - base.OnResize(e); ctrlRecentGames.Height = this.ClientSize.Height - ctrlRecentGames.Top - 80; } + private void ProcessResize() + { + ResizeRecentGames(); + SetScaleBasedOnWindowSize(); + } + + private void frmMain_Resize(object sender, EventArgs e) + { + ProcessResize(); + } + private void mnuVideoConfig_Click(object sender, EventArgs e) { using(frmVideoConfig frm = new frmVideoConfig()) {