From aa899d6b35253f12aed4ee2ba3ab4912c9fb3704 Mon Sep 17 00:00:00 2001 From: Sour Date: Mon, 13 Apr 2020 11:21:45 -0400 Subject: [PATCH] UI: DPI-related fixes/improvements --- UI/Controls/MesenNumericUpDown.cs | 9 ++++++- UI/Debugger/Controls/ctrlCodeScrollbar.cs | 20 ++++++++------ .../PpuViewer/frmPaletteViewer.Designer.cs | 10 ++++--- UI/Debugger/PpuViewer/frmPaletteViewer.cs | 3 +++ UI/Debugger/PpuViewer/frmTileViewer.cs | 3 +++ UI/UI.csproj | 1 + UI/Utilities/ImageExtensions.cs | 27 +++++++++++++++++++ 7 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 UI/Utilities/ImageExtensions.cs diff --git a/UI/Controls/MesenNumericUpDown.cs b/UI/Controls/MesenNumericUpDown.cs index ef781db..05d6b01 100644 --- a/UI/Controls/MesenNumericUpDown.cs +++ b/UI/Controls/MesenNumericUpDown.cs @@ -1,4 +1,5 @@ -using System; +using Mesen.GUI.Utilities; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; @@ -191,6 +192,12 @@ namespace Mesen.GUI.Controls if(this.Height < 21) { this.Height = 21; } + + double scale = (double)this.Height / 21; + if(scale > 1) { + btnDown.Image = Properties.Resources.NudDownArrow.GetScaledImage(scale); + btnUp.Image = Properties.Resources.NudUpArrow.GetScaledImage(scale); + } } private void txtValue_KeyDown(object sender, KeyEventArgs e) diff --git a/UI/Debugger/Controls/ctrlCodeScrollbar.cs b/UI/Debugger/Controls/ctrlCodeScrollbar.cs index 665efa7..cd819e5 100644 --- a/UI/Debugger/Controls/ctrlCodeScrollbar.cs +++ b/UI/Debugger/Controls/ctrlCodeScrollbar.cs @@ -16,8 +16,7 @@ namespace Mesen.GUI.Debugger.Controls private Timer _tmrScroll; private bool _scrollUp = false; private bool _mouseDown = false; - - private const int _buttonSize = 15; + private int _buttonSize = 15; private IScrollbarColorProvider _colorProvider = null; public IScrollbarColorProvider ColorProvider @@ -58,6 +57,9 @@ namespace Mesen.GUI.Debugger.Controls int width = rect.Width; e.Graphics.FillRectangle(Brushes.DimGray, rect); + double scale = (double)width / 18; + _buttonSize = (int)(15 * scale); + int barTop = rect.Top + _buttonSize; int barHeight = this.Height - _buttonSize * 2; @@ -90,9 +92,9 @@ namespace Mesen.GUI.Debugger.Controls float highlightTop = barTop + barHeight * startPos - HighlightOffset; using(SolidBrush brush = new SolidBrush(Color.FromArgb(120, 220, 220, 255))) { - e.Graphics.FillRectangle(brush, left + 1, highlightTop, width, HighlightHeight - 2); - e.Graphics.DrawRectangle(Pens.DarkSlateGray, left + 1, highlightTop, width - 2, HighlightHeight - 2); - e.Graphics.DrawRectangle(Pens.Gray, left + 2, highlightTop + 1, width - 4, HighlightHeight - 4); + e.Graphics.FillRectangle(brush, left + 1, highlightTop, width, (int)(HighlightHeight * scale) - 2); + e.Graphics.DrawRectangle(Pens.DarkSlateGray, left + 1, highlightTop, width - 2, (int)(HighlightHeight * scale) - 2); + e.Graphics.DrawRectangle(Pens.Gray, left + 2, highlightTop + 1, width - 4, (int)(HighlightHeight * scale) - 4); } if(this.ColorProvider != null) { @@ -123,8 +125,8 @@ namespace Mesen.GUI.Debugger.Controls } } - int arrowWidth = 10; - int arrowHeight = 5; + int arrowWidth = (int)(10 * scale); + int arrowHeight = (int)(5 * scale); int bottom = barTop + barHeight + _buttonSize; e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; e.Graphics.FillRectangle(Brushes.Gainsboro, rect.Left + 1, rect.Top, this.Width - 1, _buttonSize); @@ -132,8 +134,10 @@ namespace Mesen.GUI.Debugger.Controls e.Graphics.DrawLine(Pens.DimGray, rect.Left + 1, rect.Top + _buttonSize, rect.Left + width, rect.Top + _buttonSize); e.Graphics.DrawLine(Pens.DimGray, rect.Left + 1, bottom - _buttonSize, rect.Left + width, bottom - _buttonSize); e.Graphics.DrawLine(Pens.DimGray, rect.Left + 1, bottom, rect.Left + width, bottom); - e.Graphics.TranslateTransform(5, (_buttonSize - arrowHeight) / 2); + + e.Graphics.TranslateTransform((int)(5 * scale), (_buttonSize - arrowHeight) / 2); e.Graphics.FillPolygon(Brushes.DimGray, new Point[] { new Point(left, rect.Top + arrowHeight), new Point(left + arrowWidth, rect.Top + arrowHeight), new Point(left + arrowWidth / 2, rect.Top) }, FillMode.Winding); + e.Graphics.TranslateTransform(0, -(_buttonSize - arrowHeight)); e.Graphics.FillPolygon(Brushes.DimGray, new Point[] { new Point(left, bottom - arrowHeight), new Point(left + arrowWidth, bottom - arrowHeight), new Point(left + arrowWidth / 2, bottom) }, FillMode.Winding); } diff --git a/UI/Debugger/PpuViewer/frmPaletteViewer.Designer.cs b/UI/Debugger/PpuViewer/frmPaletteViewer.Designer.cs index 759077a..dc1dfbc 100644 --- a/UI/Debugger/PpuViewer/frmPaletteViewer.Designer.cs +++ b/UI/Debugger/PpuViewer/frmPaletteViewer.Designer.cs @@ -50,7 +50,7 @@ // ctrlScanlineCycleSelect // this.ctrlScanlineCycleSelect.Dock = System.Windows.Forms.DockStyle.Bottom; - this.ctrlScanlineCycleSelect.Location = new System.Drawing.Point(0, 263); + this.ctrlScanlineCycleSelect.Location = new System.Drawing.Point(0, 275); this.ctrlScanlineCycleSelect.Name = "ctrlScanlineCycleSelect"; this.ctrlScanlineCycleSelect.Size = new System.Drawing.Size(398, 28); this.ctrlScanlineCycleSelect.TabIndex = 5; @@ -68,7 +68,7 @@ this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(398, 263); + this.tableLayoutPanel1.Size = new System.Drawing.Size(398, 275); this.tableLayoutPanel1.TabIndex = 7; // // ctrlPaletteViewer @@ -76,9 +76,11 @@ this.ctrlPaletteViewer.Location = new System.Drawing.Point(3, 3); this.ctrlPaletteViewer.Name = "ctrlPaletteViewer"; this.ctrlPaletteViewer.PaletteScale = 16; + this.ctrlPaletteViewer.SelectedPalette = 0; this.ctrlPaletteViewer.SelectionMode = Mesen.GUI.Debugger.PaletteSelectionMode.SingleColor; this.ctrlPaletteViewer.Size = new System.Drawing.Size(256, 256); this.ctrlPaletteViewer.TabIndex = 0; + this.ctrlPaletteViewer.TabStop = false; this.ctrlPaletteViewer.SelectionChanged += new Mesen.GUI.Debugger.ctrlPaletteViewer.SelectionChangedHandler(this.ctrlPaletteViewer_SelectionChanged); // // tableLayoutPanel2 @@ -109,7 +111,7 @@ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel2.Size = new System.Drawing.Size(130, 257); + this.tableLayoutPanel2.Size = new System.Drawing.Size(136, 269); this.tableLayoutPanel2.TabIndex = 1; // // txtR @@ -224,7 +226,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(398, 291); + this.ClientSize = new System.Drawing.Size(398, 303); this.Controls.Add(this.tableLayoutPanel1); this.Controls.Add(this.ctrlScanlineCycleSelect); this.Name = "frmPaletteViewer"; diff --git a/UI/Debugger/PpuViewer/frmPaletteViewer.cs b/UI/Debugger/PpuViewer/frmPaletteViewer.cs index 84f0ee7..33a0eec 100644 --- a/UI/Debugger/PpuViewer/frmPaletteViewer.cs +++ b/UI/Debugger/PpuViewer/frmPaletteViewer.cs @@ -27,6 +27,9 @@ namespace Mesen.GUI.Debugger _refreshManager.AutoRefresh = true; ctrlScanlineCycleSelect.Initialize(241, 0); + double scale = (double)ctrlPaletteViewer.Width / 256; + ctrlPaletteViewer.PaletteScale = (int)(16 * scale); + ctrlPaletteViewer.RefreshData(); ctrlPaletteViewer.RefreshViewer(); UpdateFields(); diff --git a/UI/Debugger/PpuViewer/frmTileViewer.cs b/UI/Debugger/PpuViewer/frmTileViewer.cs index 8f9815c..75f9860 100644 --- a/UI/Debugger/PpuViewer/frmTileViewer.cs +++ b/UI/Debugger/PpuViewer/frmTileViewer.cs @@ -74,6 +74,9 @@ namespace Mesen.GUI.Debugger chkShowTileGrid.Checked = config.ShowTileGrid; ctrlImagePanel.ImageScale = config.ImageScale; ctrlScanlineCycleSelect.Initialize(config.RefreshScanline, config.RefreshCycle); + + double scale = (double)ctrlPaletteViewer.Width / 176; + ctrlPaletteViewer.PaletteScale = (int)(11 * scale); ctrlPaletteViewer.SelectedPalette = config.SelectedPalette; nudSize.Increment = 0x1000; diff --git a/UI/UI.csproj b/UI/UI.csproj index 61f7eb3..8c70071 100644 --- a/UI/UI.csproj +++ b/UI/UI.csproj @@ -980,6 +980,7 @@ + diff --git a/UI/Utilities/ImageExtensions.cs b/UI/Utilities/ImageExtensions.cs new file mode 100644 index 0000000..afe2581 --- /dev/null +++ b/UI/Utilities/ImageExtensions.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Mesen.GUI.Utilities +{ + static class ImageExtensions + { + public static Image GetScaledImage(this Image img, double scale) + { + int newWidth = (int)(img.Width * scale); + int newHeight = (int)(img.Height * scale); + + Bitmap scaledImg = new Bitmap(newWidth, newHeight); + using(Graphics g = Graphics.FromImage(scaledImg)) { + g.InterpolationMode = scale >= 2 ? InterpolationMode.NearestNeighbor : InterpolationMode.HighQualityBicubic; + g.DrawImage(img, 0, 0, newWidth, newHeight); + } + + return scaledImg; + } + } +}