UI: DPI-related fixes/improvements

This commit is contained in:
Sour 2020-04-13 11:21:34 -04:00
parent 8fa506631a
commit e9262c5333
4 changed files with 73 additions and 15 deletions

View file

@ -1,4 +1,5 @@
using System;
using Mesen.GUI.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
@ -93,20 +94,26 @@ namespace Mesen.GUI.Controls
private void txtValue_TextChanged(object sender, EventArgs e)
{
decimal val;
int hexVal;
if(string.IsNullOrWhiteSpace(txtValue.Text)) {
SetValue(0, false);
} else if(decimal.TryParse(txtValue.Text, out val)) {
} else if(!IsHex && decimal.TryParse(txtValue.Text, out val)) {
SetValue(val, false);
} else if(IsHex && int.TryParse(txtValue.Text, System.Globalization.NumberStyles.HexNumber, null, out hexVal)) {
SetValue(hexVal, false);
}
}
private void txtValue_Validated(object sender, EventArgs e)
{
decimal val;
int hexVal;
if(string.IsNullOrWhiteSpace(txtValue.Text)) {
SetValue(0, true);
} else if(decimal.TryParse(txtValue.Text, out val)) {
} else if(!IsHex && decimal.TryParse(txtValue.Text, out val)) {
SetValue(val, true);
} else if(IsHex && int.TryParse(txtValue.Text, System.Globalization.NumberStyles.HexNumber, null, out hexVal)) {
SetValue(hexVal, true);
} else {
SetValue(this.Value, true);
}
@ -128,7 +135,13 @@ namespace Mesen.GUI.Controls
ValueChanged?.Invoke(this, EventArgs.Empty);
}
if(updateText) {
txtValue.Text = value.ToString("0" + (this.DecimalPlaces > 0 ? "." : "") + new string('0', this.DecimalPlaces));
txtValue.TextChanged -= txtValue_TextChanged;
if(IsHex) {
txtValue.Text = ((int)_value).ToString("X");
} else {
txtValue.Text = _value.ToString("0" + (this.DecimalPlaces > 0 ? "." : "") + new string('0', this.DecimalPlaces));
}
txtValue.TextChanged += txtValue_TextChanged;
}
}
@ -142,6 +155,8 @@ namespace Mesen.GUI.Controls
}
}
public bool IsHex { get; set; } = false;
public new string Text
{
get { return txtValue.Text; }
@ -177,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)
@ -195,6 +216,11 @@ namespace Mesen.GUI.Controls
e.KeyCode == Keys.Right || e.KeyCode == Keys.Home ||
e.KeyCode == Keys.End || e.KeyCode == Keys.Back)
) {
if(IsHex && e.KeyCode >= Keys.A && e.KeyCode <= Keys.F) {
//Allow A-F when in hex mode
return;
}
e.SuppressKeyPress = true;
}
}

View file

@ -15,8 +15,7 @@ namespace Mesen.GUI.Debugger.Controls
private Timer _tmrScroll;
private bool _scrollUp = false;
private const int _buttonSize = 15;
private int _buttonSize = 15;
private IScrollbarColorProvider _colorProvider = null;
public IScrollbarColorProvider ColorProvider
@ -57,6 +56,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;
@ -89,9 +91,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) {
@ -122,8 +124,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);
@ -131,8 +133,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);
}

View file

@ -1297,6 +1297,7 @@
<Compile Include="GoogleDriveIntegration\CloudSyncHelper.cs" />
<Compile Include="GoogleDriveIntegration\GoogleDriveAccessor.cs" />
<Compile Include="GoogleDriveIntegration\MesenCodeReceiver.cs" />
<Compile Include="ImageExtensions.cs" />
<Compile Include="InteropEmu.cs" />
<Compile Include="MonoToolStripHelper.cs" />
<Compile Include="ThemeHelper.cs" />

View file

@ -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;
}
}
}