Fix control positions/sizes in the cases where auto scaling doesn't apply (e.g. dynamically created controls).

This commit is contained in:
jdpurcell 2014-12-28 21:59:53 +00:00
parent 30d3b02a7f
commit 9a1108e9f7
9 changed files with 110 additions and 65 deletions

View File

@ -202,6 +202,7 @@
<Compile Include="tools\RamSearchEngine.cs" /> <Compile Include="tools\RamSearchEngine.cs" />
<Compile Include="tools\Watch.cs" /> <Compile Include="tools\Watch.cs" />
<Compile Include="tools\WatchList.cs" /> <Compile Include="tools\WatchList.cs" />
<Compile Include="UIHelper.cs" />
<Compile Include="XmlGame.cs" /> <Compile Include="XmlGame.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,41 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace BizHawk.Client.Common
{
public static class UIHelper
{
private static SizeF _autoScaleBaseSize = new SizeF(6F, 13F);
private static SizeF _autoScaleCurrentSize = GetCurrentAutoScaleSize(AutoScaleMode.Font);
private static SizeF GetCurrentAutoScaleSize(AutoScaleMode autoScaleMode)
{
using (Form form = new Form())
{
form.AutoScaleMode = autoScaleMode;
return form.CurrentAutoScaleDimensions;
}
}
public static float AutoScaleFactorX
{
get { return _autoScaleCurrentSize.Width / _autoScaleBaseSize.Width; }
}
public static float AutoScaleFactorY
{
get { return _autoScaleCurrentSize.Height / _autoScaleBaseSize.Height; }
}
public static int ScaleX(int size)
{
return (int)Math.Round(size * AutoScaleFactorX);
}
public static int ScaleY(int size)
{
return (int)Math.Round(size * AutoScaleFactorY);
}
}
}

View File

@ -4,6 +4,8 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
// this is a little messy right now because of remnants of the old config system // this is a little messy right now because of remnants of the old config system
@ -17,14 +19,14 @@ namespace BizHawk.Client.EmuHawk
public List<string> buttons = new List<string>(); public List<string> buttons = new List<string>();
public int InputMarginLeft = 0; public int InputMarginLeft = UIHelper.ScaleX(0);
public int LabelPadding = 5; public int LabelPadding = UIHelper.ScaleX(5);
public int MarginTop = 0; public int MarginTop = UIHelper.ScaleY(0);
public int Spacing = 24; public int Spacing = UIHelper.ScaleY(24);
public int InputSize = 170; public int InputSize = UIHelper.ScaleX(170);
public int ColumnWidth = 280; public int ColumnWidth = UIHelper.ScaleX(280);
public int LabelWidth = 60; public int LabelWidth = UIHelper.ScaleX(60);
public ToolTip Tooltip; public ToolTip Tooltip;
@ -105,7 +107,7 @@ namespace BizHawk.Client.EmuHawk
for (int i = 0; i < buttons.Count; i++) for (int i = 0; i < buttons.Count; i++)
{ {
y += Spacing; y += Spacing;
if (y > (_panelSize.Height - 30)) if (y > (_panelSize.Height - UIHelper.ScaleY(30)))
{ {
y = MarginTop; y = MarginTop;
x += ColumnWidth; x += ColumnWidth;
@ -114,7 +116,7 @@ namespace BizHawk.Client.EmuHawk
InputCompositeWidget iw = new InputCompositeWidget InputCompositeWidget iw = new InputCompositeWidget
{ {
Location = new Point(x, y), Location = new Point(x, y),
Size = new Size(InputSize, 23), Size = new Size(InputSize, UIHelper.ScaleY(23)),
TabIndex = i, TabIndex = i,
AutoTab = this.Autotab AutoTab = this.Autotab
}; };
@ -126,7 +128,8 @@ namespace BizHawk.Client.EmuHawk
Inputs.Add(iw); Inputs.Add(iw);
Label label = new Label Label label = new Label
{ {
Location = new Point(x + InputSize + LabelPadding, y + 3), Location = new Point(x + InputSize + LabelPadding, y + UIHelper.ScaleY(3)),
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
Text = buttons[i].Replace('_', ' ').Trim(), Text = buttons[i].Replace('_', ' ').Trim(),
}; };

View File

@ -20,7 +20,7 @@ namespace BizHawk.Client.EmuHawk
private void FileExtensionPreferences_Load(object sender, EventArgs e) private void FileExtensionPreferences_Load(object sender, EventArgs e)
{ {
int spacing = 30; int spacing = UIHelper.ScaleY(30);
int count = 0; int count = 0;
foreach (var kvp in Global.Config.PreferredPlatformsForExtensions) foreach (var kvp in Global.Config.PreferredPlatformsForExtensions)
{ {
@ -28,7 +28,7 @@ namespace BizHawk.Client.EmuHawk
{ {
FileExtension = kvp.Key, FileExtension = kvp.Key,
OriginalPreference = kvp.Value, OriginalPreference = kvp.Value,
Location = new Point(15, 15 + (spacing * count)) Location = new Point(UIHelper.ScaleX(15), UIHelper.ScaleY(15) + (spacing * count))
}; };
count++; count++;

View File

@ -110,23 +110,23 @@ namespace BizHawk.Client.EmuHawk
foreach (var tab in Tabs) foreach (var tab in Tabs)
{ {
var _y = 14; var _y = UIHelper.ScaleY(14);
var _x = 6; var _x = UIHelper.ScaleX(6);
var tb = new TabPage {Name = tab, Text = tab}; var tb = new TabPage {Name = tab, Text = tab};
var bindings = Global.Config.HotkeyBindings.Where(x => x.TabGroup == tab).OrderBy(x => x.Ordinal).ThenBy(x => x.DisplayName).ToList(); var bindings = Global.Config.HotkeyBindings.Where(x => x.TabGroup == tab).OrderBy(x => x.Ordinal).ThenBy(x => x.DisplayName).ToList();
const int iwOffsetX = 110; int iwOffsetX = UIHelper.ScaleX(110);
const int iwOffsetY = -4; int iwOffsetY = UIHelper.ScaleY(-4);
const int iwWidth = 120; int iwWidth = UIHelper.ScaleX(120);
foreach (var b in bindings) foreach (var b in bindings)
{ {
var l = new Label var l = new Label
{ {
Text = b.DisplayName, Text = b.DisplayName,
Location = new Point(_x, _y), Location = new Point(_x, _y),
Width = iwOffsetX - 2, Size = new Size(iwOffsetX - UIHelper.ScaleX(2), UIHelper.ScaleY(15)),
}; };
var w = new InputCompositeWidget var w = new InputCompositeWidget
@ -145,11 +145,11 @@ namespace BizHawk.Client.EmuHawk
tb.Controls.Add(l); tb.Controls.Add(l);
tb.Controls.Add(w); tb.Controls.Add(w);
_y += 24; _y += UIHelper.ScaleY(24);
if (_y > HotkeyTabControl.Height - 35) if (_y > HotkeyTabControl.Height - UIHelper.ScaleY(35))
{ {
_x += iwOffsetX + iwWidth + 10; _x += iwOffsetX + iwWidth + UIHelper.ScaleX(10);
_y = 14; _y = UIHelper.ScaleY(14);
} }
} }

View File

@ -67,17 +67,9 @@ namespace BizHawk.Client.EmuHawk
YNumeric.Maximum = Global.Emulator.VideoProvider.BufferHeight - 12; YNumeric.Maximum = Global.Emulator.VideoProvider.BufferHeight - 12;
PositionPanel.Size = new Size(Global.Emulator.VideoProvider.BufferWidth + 2, Global.Emulator.VideoProvider.BufferHeight + 2); PositionPanel.Size = new Size(Global.Emulator.VideoProvider.BufferWidth + 2, Global.Emulator.VideoProvider.BufferHeight + 2);
int width; PositionGroupBox.Size = new Size(
if (Global.Emulator.VideoProvider.BufferWidth > 128) Math.Max(Global.Emulator.VideoProvider.BufferWidth, UIHelper.ScaleX(128)) + UIHelper.ScaleX(44),
{ Global.Emulator.VideoProvider.BufferHeight + UIHelper.ScaleY(52));
width = Global.Emulator.VideoProvider.BufferWidth + 44;
}
else
{
width = 128 + 44;
}
PositionGroupBox.Size = new Size(width, Global.Emulator.VideoProvider.BufferHeight + 52);
} }
private void SetColorBox() private void SetColorBox()

View File

@ -95,12 +95,14 @@ namespace BizHawk.Client.EmuHawk
var tabPages = new List<TabPage>(systems.Count); var tabPages = new List<TabPage>(systems.Count);
const int _x = 6; int _x = UIHelper.ScaleX(6);
const int textboxWidth = 70; int textboxWidth = UIHelper.ScaleX(70);
const int padding = 5; int padding = UIHelper.ScaleX(5);
const int buttonWidth = 26; int buttonWidth = UIHelper.ScaleX(26);
const int widgetOffset = 85; int buttonHeight = UIHelper.ScaleY(23);
const int rowHeight = 30; int buttonOffsetY = -1; // To align the top with the textbox I guess? Always 1 pixel regardless of scaling.
int widgetOffset = UIHelper.ScaleX(85);
int rowHeight = UIHelper.ScaleY(30);
foreach (var systemDisplayName in systems) foreach (var systemDisplayName in systems)
{ {
@ -109,10 +111,11 @@ namespace BizHawk.Client.EmuHawk
{ {
Text = systemDisplayName, Text = systemDisplayName,
Name = systemId, Name = systemId,
Width = UIHelper.ScaleX(200) // Initial Left/Width of child controls are based on this size.
}; };
var paths = pathCollection.Where(x => x.System == systemId).OrderBy(x => x.Ordinal).ThenBy(x => x.Type).ToList(); var paths = pathCollection.Where(x => x.System == systemId).OrderBy(x => x.Ordinal).ThenBy(x => x.Type).ToList();
var _y = 14; var _y = UIHelper.ScaleY(14);
foreach (var path in paths) foreach (var path in paths)
{ {
var box = new TextBox var box = new TextBox
@ -122,7 +125,7 @@ namespace BizHawk.Client.EmuHawk
Width = textboxWidth, Width = textboxWidth,
Name = path.Type, Name = path.Type,
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right, Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
MinimumSize = new Size(26, 23), MinimumSize = new Size(UIHelper.ScaleX(26), UIHelper.ScaleY(23)),
AutoCompleteMode = AutoCompleteMode.SuggestAppend, AutoCompleteMode = AutoCompleteMode.SuggestAppend,
AutoCompleteCustomSource = AutoCompleteOptions, AutoCompleteCustomSource = AutoCompleteOptions,
AutoCompleteSource = AutoCompleteSource.CustomSource, AutoCompleteSource = AutoCompleteSource.CustomSource,
@ -132,8 +135,8 @@ namespace BizHawk.Client.EmuHawk
{ {
Text = string.Empty, Text = string.Empty,
Image = Properties.Resources.OpenFile, Image = Properties.Resources.OpenFile,
Location = new Point(widgetOffset, _y - 1), Location = new Point(widgetOffset, _y + buttonOffsetY),
Width = buttonWidth, Size = new Size(buttonWidth, buttonHeight),
Name = path.Type, Name = path.Type,
Anchor = AnchorStyles.Top | AnchorStyles.Right, Anchor = AnchorStyles.Top | AnchorStyles.Right,
}; };
@ -146,18 +149,18 @@ namespace BizHawk.Client.EmuHawk
BrowseFolder(tempBox, tempPath, tempSystem); BrowseFolder(tempBox, tempPath, tempSystem);
}; };
int infoPadding = 0; int infoPadding = UIHelper.ScaleX(0);
if (t.Name.Contains("Global") && path.Type == "Firmware") if (t.Name.Contains("Global") && path.Type == "Firmware")
{ {
infoPadding = 26; infoPadding = UIHelper.ScaleX(26);
var firmwareButton = new Button var firmwareButton = new Button
{ {
Name = "Global", Name = "Global",
Text = String.Empty, Text = String.Empty,
Image = Properties.Resources.Help, Image = Properties.Resources.Help,
Location = new Point(115, _y - 1), Location = new Point(UIHelper.ScaleX(115), _y + buttonOffsetY),
Width = 26, Size = new Size(buttonWidth, buttonHeight),
Anchor = AnchorStyles.Top | AnchorStyles.Right Anchor = AnchorStyles.Top | AnchorStyles.Right
}; };
@ -179,8 +182,8 @@ namespace BizHawk.Client.EmuHawk
var label = new Label var label = new Label
{ {
Text = path.Type, Text = path.Type,
Location = new Point(widgetOffset + buttonWidth + padding + infoPadding, _y + 4), Location = new Point(widgetOffset + buttonWidth + padding + infoPadding, _y + UIHelper.ScaleY(4)),
Width = 100, Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
Name = path.Type, Name = path.Type,
Anchor = AnchorStyles.Top | AnchorStyles.Right, Anchor = AnchorStyles.Top | AnchorStyles.Right,
}; };

View File

@ -43,7 +43,8 @@ namespace BizHawk.Client.EmuHawk
{ {
var c = new ComboBox var c = new ComboBox
{ {
Location = new Point(35, 17), Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(17)),
Width = UIHelper.ScaleX(121),
DropDownStyle = ComboBoxStyle.DropDownList DropDownStyle = ComboBoxStyle.DropDownList
}; };
@ -57,7 +58,8 @@ namespace BizHawk.Client.EmuHawk
{ {
DisassemblerBox.Controls.Add(new Label DisassemblerBox.Controls.Add(new Label
{ {
Location = new Point(35, 23), Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(23)),
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
Text = Disassembler.Cpu Text = Disassembler.Cpu
}); });
} }
@ -66,7 +68,8 @@ namespace BizHawk.Client.EmuHawk
{ {
DisassemblerBox.Controls.Add(new Label DisassemblerBox.Controls.Add(new Label
{ {
Location = new Point(35, 23), Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(23)),
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
Text = Disassembler.Cpu Text = Disassembler.Cpu
}); });
} }
@ -80,7 +83,8 @@ namespace BizHawk.Client.EmuHawk
DisassemblerView.ItemCount = 0; DisassemblerView.ItemCount = 0;
DisassemblerBox.Controls.Add(new Label DisassemblerBox.Controls.Add(new Label
{ {
Location = new Point(35, 23), Location = new Point(UIHelper.ScaleX(35), UIHelper.ScaleY(23)),
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
Text = "Unknown" Text = "Unknown"
}); });

View File

@ -7,6 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -142,14 +143,14 @@ namespace BizHawk.Client.EmuHawk
var registers = Core.GetCpuFlagsAndRegisters(); var registers = Core.GetCpuFlagsAndRegisters();
int y = 0; int y = UIHelper.ScaleY(0);
foreach (var register in registers.Where(r => r.Value.BitSize != 1)) foreach (var register in registers.Where(r => r.Value.BitSize != 1))
{ {
this.Controls.Add(new Label this.Controls.Add(new Label
{ {
Text = register.Key.Replace("Flag ", "") + (canset ? ": " : ""), Text = register.Key.Replace("Flag ", "") + (canset ? ": " : ""),
Location = new Point(5, y + 2), Location = new Point(UIHelper.ScaleX(5), y + UIHelper.ScaleY(2)),
Width = 35 Size = new Size(UIHelper.ScaleX(35), UIHelper.ScaleY(15))
}); });
if (canset) if (canset)
@ -158,8 +159,8 @@ namespace BizHawk.Client.EmuHawk
{ {
Name = register.Key, Name = register.Key,
Text = register.Value.Value.ToHexString(register.Value.BitSize / 16), Text = register.Value.Value.ToHexString(register.Value.BitSize / 16),
Width = 6 + ((register.Value.BitSize / 4) * 9), Width = UIHelper.ScaleX(6 + ((register.Value.BitSize / 4) * 9)),
Location = new Point(40, y), Location = new Point(UIHelper.ScaleX(40), y),
MaxLength = register.Value.BitSize / 4, MaxLength = register.Value.BitSize / 4,
CharacterCasing = CharacterCasing.Upper CharacterCasing = CharacterCasing.Upper
}; };
@ -187,12 +188,12 @@ namespace BizHawk.Client.EmuHawk
{ {
Name = register.Key, Name = register.Key,
Text = register.Value.Value.ToString(), Text = register.Value.Value.ToString(),
Width = 45, Size = new Size(UIHelper.ScaleX(45), UIHelper.ScaleY(15)),
Location = new Point(40, y) Location = new Point(UIHelper.ScaleX(40), y)
}); });
} }
y += 25; y += UIHelper.ScaleY(25);
} }
var flags = registers.Where(r => r.Value.BitSize == 1); var flags = registers.Where(r => r.Value.BitSize == 1);
@ -202,9 +203,9 @@ namespace BizHawk.Client.EmuHawk
var p = new Panel var p = new Panel
{ {
Name = "FlagPanel", Name = "FlagPanel",
Location = new Point(5, y), Location = new Point(UIHelper.ScaleX(5), y),
BorderStyle = BorderStyle.None, BorderStyle = BorderStyle.None,
Size = new Size(240, 23), Size = new Size(UIHelper.ScaleX(240), UIHelper.ScaleY(23)),
AutoScroll = true AutoScroll = true
}; };
@ -216,9 +217,9 @@ namespace BizHawk.Client.EmuHawk
Name = flag.Key, Name = flag.Key,
Text = flag.Key.Replace("Flag", "").Trim(), // Hack Text = flag.Key.Replace("Flag", "").Trim(), // Hack
Checked = flag.Value.Value == 1 ? true : false, Checked = flag.Value.Value == 1 ? true : false,
Location = new Point(40, y), Location = new Point(UIHelper.ScaleX(40), y),
Dock = DockStyle.Left, Dock = DockStyle.Left,
Size = new Size(23, 23), Size = new Size(UIHelper.ScaleX(23), UIHelper.ScaleY(23)),
Enabled = canset Enabled = canset
}; };