UI: Auto-scale display when resizing window
This commit is contained in:
parent
0836db643f
commit
a8d388043e
4 changed files with 62 additions and 13 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -16,6 +16,8 @@ namespace Mesen.GUI.Emulation
|
|||
private Dictionary<EmulatorShortcut, Func<bool>> _actionEnabledFuncs = new Dictionary<EmulatorShortcut, Func<bool>>();
|
||||
private List<uint> _speedValues = new List<uint> { 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<bool> 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();
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue