From 0dcb0b9bb444d05a3241e708752de20db39c4d85 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sat, 12 Oct 2019 22:34:53 -0400 Subject: [PATCH] Fix DPI scaling issue in custom message boxes (Snex9x/QuickNES accuracy warnings). --- .../CustomControls/MsgBox.cs | 13 +++--- .../CustomControls/MsgBox.designer.cs | 1 - BizHawk.Client.EmuHawk/MainForm.Events.cs | 4 +- BizHawk.Client.EmuHawk/UIHelper.cs | 43 ++++++------------- .../tools/TAStudio/TAStudio.cs | 4 +- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs b/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs index 278fc0c73d..7dabe03020 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/MsgBox.cs @@ -47,6 +47,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls { InitializeComponent(); + this.ControlBox = false; // Do not set in designer (causes problems with auto scaling) this.messageLbl.Text = message; this.Text = title; this.m_sysIcon = icon; @@ -58,7 +59,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls public void SetMessageToAutoSize() { this.messageLbl.AutoSize = true; - this.messageLbl.MaximumSize = new Size(this.MaximumSize.Width - this.m_sysIcon.Width - 25, this.MaximumSize.Height); + this.messageLbl.MaximumSize = new Size(this.MaximumSize.Width - this.m_sysIcon.Width - UIHelper.ScaleX(25), this.MaximumSize.Height); } /// @@ -220,11 +221,11 @@ namespace BizHawk.Client.EmuHawk.CustomControls } - const int FORM_Y_MARGIN = 10; - const int FORM_X_MARGIN = 16; - const int BUTTON_SPACE = 5; - const int CHECKBOX_SPACE = 15; - const int TEXT_Y_MARGIN = 30; + private static readonly int FORM_Y_MARGIN = UIHelper.ScaleY(10); + private static readonly int FORM_X_MARGIN = UIHelper.ScaleX(16); + private static readonly int BUTTON_SPACE = UIHelper.ScaleX(5); + private static readonly int CHECKBOX_SPACE = UIHelper.ScaleX(15); + private static readonly int TEXT_Y_MARGIN = UIHelper.ScaleY(30); /// /// Auto fits the dialog box to fit the text and the buttons. diff --git a/BizHawk.Client.EmuHawk/CustomControls/MsgBox.designer.cs b/BizHawk.Client.EmuHawk/CustomControls/MsgBox.designer.cs index 3c58b8066b..ccdd5ea1dd 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/MsgBox.designer.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/MsgBox.designer.cs @@ -105,7 +105,6 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btn1; this.ClientSize = new System.Drawing.Size(485, 149); - this.ControlBox = false; this.Controls.Add(this.btn3); this.Controls.Add(this.chkBx); this.Controls.Add(this.btn1); diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 362f9ee24f..3a6f38a98a 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -489,7 +489,7 @@ namespace BizHawk.Client.EmuHawk new[] { "Switch", "Continue" }, new[] { DialogResult.Yes, DialogResult.Cancel }); - box.MaximumSize = new Size(475, 350); + box.MaximumSize = UIHelper.Scale(new Size(475, 350)); box.SetMessageToAutoSize(); var result = box.ShowDialog(); @@ -514,7 +514,7 @@ namespace BizHawk.Client.EmuHawk new[] { "Switch", "Continue" }, new[] { DialogResult.Yes, DialogResult.Cancel }); - box.MaximumSize = new Size(475, 350); + box.MaximumSize = UIHelper.Scale(new Size(475, 350)); box.SetMessageToAutoSize(); var result = box.ShowDialog(); diff --git a/BizHawk.Client.EmuHawk/UIHelper.cs b/BizHawk.Client.EmuHawk/UIHelper.cs index 27fffa4448..f6e01d6f16 100644 --- a/BizHawk.Client.EmuHawk/UIHelper.cs +++ b/BizHawk.Client.EmuHawk/UIHelper.cs @@ -2,42 +2,19 @@ using System.Drawing; using System.Windows.Forms; -namespace BizHawk.Client.Common +namespace BizHawk.Client.EmuHawk { public static class UIHelper { - private static readonly AutoScaleMode _autoScaleMode = AutoScaleMode.Font; - private static readonly SizeF _autoScaleBaseSize = new SizeF(6F, 13F); - private static readonly SizeF _autoScaleCurrentSize = GetCurrentAutoScaleSize(_autoScaleMode); + public static AutoScaleMode AutoScaleMode { get; } = AutoScaleMode.Font; - private static SizeF GetCurrentAutoScaleSize(AutoScaleMode autoScaleMode) - { - using (Form form = new Form()) - { - form.AutoScaleMode = autoScaleMode; - return form.CurrentAutoScaleDimensions; - } - } + public static SizeF AutoScaleBaseSize { get; } = new SizeF(6F, 13F); - public static AutoScaleMode AutoScaleMode - { - get { return _autoScaleMode; } - } + public static SizeF AutoScaleCurrentSize { get; } = GetCurrentAutoScaleSize(AutoScaleMode); - public static SizeF AutoScaleBaseSize - { - get { return _autoScaleBaseSize; } - } + public static float AutoScaleFactorX { get; } = AutoScaleCurrentSize.Width / AutoScaleBaseSize.Width; - public static float AutoScaleFactorX - { - get { return _autoScaleCurrentSize.Width / _autoScaleBaseSize.Width; } - } - - public static float AutoScaleFactorY - { - get { return _autoScaleCurrentSize.Height / _autoScaleBaseSize.Height; } - } + public static float AutoScaleFactorY { get; } = AutoScaleCurrentSize.Height / AutoScaleBaseSize.Height; public static int ScaleX(int size) { @@ -58,5 +35,13 @@ namespace BizHawk.Client.Common { return new Size(ScaleX(s.Width), ScaleY(s.Height)); } + + private static SizeF GetCurrentAutoScaleSize(AutoScaleMode autoScaleMode) + { + using (var form = new Form { AutoScaleMode = autoScaleMode }) + { + return form.CurrentAutoScaleDimensions; + } + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 85a08c5ebe..183b37df89 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -332,7 +332,7 @@ namespace BizHawk.Client.EmuHawk new[] { "Switch", "Continue" }, new[] { DialogResult.Yes, DialogResult.Cancel }); - box.MaximumSize = new Size(475, 350); + box.MaximumSize = UIHelper.Scale(new Size(475, 350)); box.SetMessageToAutoSize(); var result = box.ShowDialog(); @@ -357,7 +357,7 @@ namespace BizHawk.Client.EmuHawk new[] { "Switch", "Continue" }, new[] { DialogResult.Yes, DialogResult.Cancel }); - box.MaximumSize = new Size(475, 350); + box.MaximumSize = UIHelper.Scale(new Size(475, 350)); box.SetMessageToAutoSize(); var result = box.ShowDialog();