mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
UI: Fixed window size rounding issues when setting video scale
This commit is contained in:
parent
e18db92692
commit
7b84a75fac
3 changed files with 25 additions and 29 deletions
|
@ -111,7 +111,11 @@ namespace Mesen.ViewModels
|
|||
GetScaleMenuItem(wnd, 3),
|
||||
GetScaleMenuItem(wnd, 4),
|
||||
GetScaleMenuItem(wnd, 5),
|
||||
GetScaleMenuItem(wnd, 6)
|
||||
GetScaleMenuItem(wnd, 6),
|
||||
GetScaleMenuItem(wnd, 7),
|
||||
GetScaleMenuItem(wnd, 8),
|
||||
GetScaleMenuItem(wnd, 9),
|
||||
GetScaleMenuItem(wnd, 10)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -195,7 +199,7 @@ namespace Mesen.ViewModels
|
|||
return new ContextMenuAction() {
|
||||
ActionType = ActionType.Custom,
|
||||
CustomText = scale + "x",
|
||||
Shortcut = () => new DbgShortKeys(KeyModifiers.Alt, Key.D0 + scale),
|
||||
Shortcut = () => new DbgShortKeys(KeyModifiers.Alt, scale == 10 ? Key.D0 : Key.D0 + scale),
|
||||
OnClick = () => wnd.SetScale(scale),
|
||||
IsSelected = () => (int)((double)RendererSize.Height / EmuApi.GetBaseScreenSize().Height) == scale
|
||||
};
|
||||
|
|
|
@ -147,21 +147,20 @@ namespace Mesen.Windows
|
|||
private void InternalSetScale(double scale)
|
||||
{
|
||||
double dpiScale = LayoutHelper.GetLayoutScale(this);
|
||||
scale /= dpiScale;
|
||||
double aspectRatio = EmuApi.GetAspectRatio();
|
||||
|
||||
FrameInfo screenSize = EmuApi.GetBaseScreenSize();
|
||||
if(WindowState == WindowState.Normal) {
|
||||
_rendererSize = new Size();
|
||||
|
||||
double aspectRatio = EmuApi.GetAspectRatio();
|
||||
double menuHeight = _mainMenu.Bounds.Height;
|
||||
|
||||
double width = Math.Max(MinWidth, Math.Round(screenSize.Height * aspectRatio) * scale);
|
||||
double height = Math.Max(MinHeight, screenSize.Height * scale);
|
||||
double width = Math.Max(MinWidth, Math.Round(screenSize.Height * aspectRatio * scale) / dpiScale);
|
||||
double height = Math.Max(MinHeight, screenSize.Height * scale / dpiScale);
|
||||
ClientSize = new Size(width, height + menuHeight + _controlBar.Bounds.Height);
|
||||
ResizeRenderer();
|
||||
} else if(WindowState == WindowState.Maximized || WindowState == WindowState.FullScreen) {
|
||||
_rendererSize = new Size(Math.Floor(screenSize.Width * scale), Math.Floor(screenSize.Height * scale));
|
||||
_rendererSize = new Size(Math.Floor(screenSize.Width * scale * aspectRatio) / dpiScale, Math.Floor(screenSize.Height * scale) / dpiScale);
|
||||
ResizeRenderer();
|
||||
}
|
||||
}
|
||||
|
@ -175,27 +174,24 @@ namespace Mesen.Windows
|
|||
private void RendererPanel_LayoutUpdated(object? sender, EventArgs e)
|
||||
{
|
||||
double aspectRatio = EmuApi.GetAspectRatio();
|
||||
double dpiScale = LayoutHelper.GetLayoutScale(this);
|
||||
|
||||
Size finalSize = _rendererSize == default ? _rendererPanel.Bounds.Size : _rendererSize;
|
||||
double height = finalSize.Height;
|
||||
double width = finalSize.Height * aspectRatio;
|
||||
if(width > finalSize.Width) {
|
||||
width = finalSize.Width;
|
||||
height = width / aspectRatio;
|
||||
}
|
||||
|
||||
|
||||
if(ConfigManager.Config.Video.FullscreenForceIntegerScale && VisualRoot is Window wnd && (wnd.WindowState == WindowState.FullScreen || wnd.WindowState == WindowState.Maximized)) {
|
||||
FrameInfo baseSize = EmuApi.GetBaseScreenSize();
|
||||
double scale = height * LayoutHelper.GetLayoutScale(this) / baseSize.Height;
|
||||
double scale = height * dpiScale / baseSize.Height;
|
||||
if(scale != Math.Floor(scale)) {
|
||||
height = baseSize.Height * Math.Max(1, Math.Floor(scale / LayoutHelper.GetLayoutScale(this)));
|
||||
height = baseSize.Height * Math.Max(1, Math.Floor(scale / dpiScale));
|
||||
width = height * aspectRatio;
|
||||
}
|
||||
}
|
||||
|
||||
_model.RendererSize = new Size(
|
||||
Math.Round(width * LayoutHelper.GetLayoutScale(this)),
|
||||
Math.Round(height * LayoutHelper.GetLayoutScale(this))
|
||||
Math.Round(width * dpiScale),
|
||||
Math.Round(height * dpiScale)
|
||||
);
|
||||
|
||||
_renderer.Width = width;
|
||||
|
|
|
@ -427,23 +427,22 @@ namespace Mesen.Windows
|
|||
private void InternalSetScale(double scale)
|
||||
{
|
||||
double dpiScale = LayoutHelper.GetLayoutScale(this);
|
||||
scale /= dpiScale;
|
||||
double aspectRatio = EmuApi.GetAspectRatio();
|
||||
|
||||
FrameInfo screenSize = EmuApi.GetBaseScreenSize();
|
||||
if(WindowState == WindowState.Normal) {
|
||||
_rendererSize = new Size();
|
||||
|
||||
double aspectRatio = EmuApi.GetAspectRatio();
|
||||
|
||||
//When menu is set to auto-hide, don't count its height when calculating the window's final size
|
||||
double menuHeight = ConfigManager.Config.Preferences.AutoHideMenu ? 0 : _mainMenu.Bounds.Height;
|
||||
|
||||
double width = Math.Max(MinWidth, Math.Round(screenSize.Height * aspectRatio) * scale);
|
||||
double height = Math.Max(MinHeight, screenSize.Height * scale);
|
||||
double width = Math.Max(MinWidth, Math.Round(screenSize.Height * aspectRatio * scale) / dpiScale);
|
||||
double height = Math.Max(MinHeight, screenSize.Height * scale / dpiScale);
|
||||
ClientSize = new Size(width, height + menuHeight + _audioPlayer.Bounds.Height);
|
||||
ResizeRenderer();
|
||||
} else if(WindowState == WindowState.Maximized || WindowState == WindowState.FullScreen) {
|
||||
_rendererSize = new Size(Math.Floor(screenSize.Width * scale), Math.Floor(screenSize.Height * scale));
|
||||
_rendererSize = new Size(Math.Round(screenSize.Width * scale * aspectRatio) / dpiScale, Math.Round(screenSize.Height * scale) / dpiScale);
|
||||
ResizeRenderer();
|
||||
}
|
||||
}
|
||||
|
@ -457,26 +456,23 @@ namespace Mesen.Windows
|
|||
private void RendererPanel_LayoutUpdated(object? sender, EventArgs e)
|
||||
{
|
||||
double aspectRatio = EmuApi.GetAspectRatio();
|
||||
double dpiScale = LayoutHelper.GetLayoutScale(this);
|
||||
|
||||
Size finalSize = _rendererSize == default ? _rendererPanel.Bounds.Size : _rendererSize;
|
||||
double height = finalSize.Height;
|
||||
double width = finalSize.Height * aspectRatio;
|
||||
if(width > finalSize.Width) {
|
||||
width = finalSize.Width;
|
||||
height = width / aspectRatio;
|
||||
}
|
||||
|
||||
if(ConfigManager.Config.Video.FullscreenForceIntegerScale && VisualRoot is Window wnd && (wnd.WindowState == WindowState.FullScreen || wnd.WindowState == WindowState.Maximized)) {
|
||||
FrameInfo baseSize = EmuApi.GetBaseScreenSize();
|
||||
double scale = height * LayoutHelper.GetLayoutScale(this) / baseSize.Height;
|
||||
double scale = height * dpiScale / baseSize.Height;
|
||||
if(scale != Math.Floor(scale)) {
|
||||
height = baseSize.Height * Math.Max(1, Math.Floor(scale / LayoutHelper.GetLayoutScale(this)));
|
||||
height = baseSize.Height * Math.Max(1, Math.Floor(scale / dpiScale));
|
||||
width = height * aspectRatio;
|
||||
}
|
||||
}
|
||||
|
||||
uint realWidth = (uint)Math.Round(width * LayoutHelper.GetLayoutScale(this));
|
||||
uint realHeight = (uint)Math.Round(height * LayoutHelper.GetLayoutScale(this));
|
||||
uint realWidth = (uint)Math.Round(width * dpiScale);
|
||||
uint realHeight = (uint)Math.Round(height * dpiScale);
|
||||
EmuApi.SetRendererSize(realWidth, realHeight);
|
||||
_model.RendererSize = new Size(realWidth, realHeight);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue