UI: DPI-related fixes/improvements
This commit is contained in:
parent
8fa506631a
commit
e9262c5333
4 changed files with 73 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using Mesen.GUI.Utilities;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
@ -61,7 +62,7 @@ namespace Mesen.GUI.Controls
|
||||||
_repeatCount++;
|
_repeatCount++;
|
||||||
_preventClick = true;
|
_preventClick = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btn_MouseDown(object sender, MouseEventArgs e)
|
private void btn_MouseDown(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
_repeatCount = 0;
|
_repeatCount = 0;
|
||||||
|
@ -93,20 +94,26 @@ namespace Mesen.GUI.Controls
|
||||||
private void txtValue_TextChanged(object sender, EventArgs e)
|
private void txtValue_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
decimal val;
|
decimal val;
|
||||||
|
int hexVal;
|
||||||
if(string.IsNullOrWhiteSpace(txtValue.Text)) {
|
if(string.IsNullOrWhiteSpace(txtValue.Text)) {
|
||||||
SetValue(0, false);
|
SetValue(0, false);
|
||||||
} else if(decimal.TryParse(txtValue.Text, out val)) {
|
} else if(!IsHex && decimal.TryParse(txtValue.Text, out val)) {
|
||||||
SetValue(val, false);
|
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)
|
private void txtValue_Validated(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
decimal val;
|
decimal val;
|
||||||
|
int hexVal;
|
||||||
if(string.IsNullOrWhiteSpace(txtValue.Text)) {
|
if(string.IsNullOrWhiteSpace(txtValue.Text)) {
|
||||||
SetValue(0, true);
|
SetValue(0, true);
|
||||||
} else if(decimal.TryParse(txtValue.Text, out val)) {
|
} else if(!IsHex && decimal.TryParse(txtValue.Text, out val)) {
|
||||||
SetValue(val, true);
|
SetValue(val, true);
|
||||||
|
} else if(IsHex && int.TryParse(txtValue.Text, System.Globalization.NumberStyles.HexNumber, null, out hexVal)) {
|
||||||
|
SetValue(hexVal, true);
|
||||||
} else {
|
} else {
|
||||||
SetValue(this.Value, true);
|
SetValue(this.Value, true);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +135,13 @@ namespace Mesen.GUI.Controls
|
||||||
ValueChanged?.Invoke(this, EventArgs.Empty);
|
ValueChanged?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
if(updateText) {
|
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
|
public new string Text
|
||||||
{
|
{
|
||||||
get { return txtValue.Text; }
|
get { return txtValue.Text; }
|
||||||
|
@ -177,6 +192,12 @@ namespace Mesen.GUI.Controls
|
||||||
if(this.Height < 21) {
|
if(this.Height < 21) {
|
||||||
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)
|
private void txtValue_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
@ -190,11 +211,16 @@ namespace Mesen.GUI.Controls
|
||||||
} else if(
|
} else if(
|
||||||
!((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) ||
|
!((e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) ||
|
||||||
(e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) ||
|
(e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) ||
|
||||||
e.KeyCode == Keys.OemPeriod || e.KeyCode == Keys.Oemcomma ||
|
e.KeyCode == Keys.OemPeriod || e.KeyCode == Keys.Oemcomma ||
|
||||||
e.KeyCode == Keys.Delete || e.KeyCode == Keys.Left ||
|
e.KeyCode == Keys.Delete || e.KeyCode == Keys.Left ||
|
||||||
e.KeyCode == Keys.Right || e.KeyCode == Keys.Home ||
|
e.KeyCode == Keys.Right || e.KeyCode == Keys.Home ||
|
||||||
e.KeyCode == Keys.End || e.KeyCode == Keys.Back)
|
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;
|
e.SuppressKeyPress = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ namespace Mesen.GUI.Debugger.Controls
|
||||||
|
|
||||||
private Timer _tmrScroll;
|
private Timer _tmrScroll;
|
||||||
private bool _scrollUp = false;
|
private bool _scrollUp = false;
|
||||||
|
private int _buttonSize = 15;
|
||||||
private const int _buttonSize = 15;
|
|
||||||
|
|
||||||
private IScrollbarColorProvider _colorProvider = null;
|
private IScrollbarColorProvider _colorProvider = null;
|
||||||
public IScrollbarColorProvider ColorProvider
|
public IScrollbarColorProvider ColorProvider
|
||||||
|
@ -57,6 +56,9 @@ namespace Mesen.GUI.Debugger.Controls
|
||||||
int width = rect.Width;
|
int width = rect.Width;
|
||||||
e.Graphics.FillRectangle(Brushes.DimGray, rect);
|
e.Graphics.FillRectangle(Brushes.DimGray, rect);
|
||||||
|
|
||||||
|
double scale = (double)width / 18;
|
||||||
|
_buttonSize = (int)(15 * scale);
|
||||||
|
|
||||||
int barTop = rect.Top + _buttonSize;
|
int barTop = rect.Top + _buttonSize;
|
||||||
int barHeight = this.Height - _buttonSize * 2;
|
int barHeight = this.Height - _buttonSize * 2;
|
||||||
|
|
||||||
|
@ -89,9 +91,9 @@ namespace Mesen.GUI.Debugger.Controls
|
||||||
|
|
||||||
float highlightTop = barTop + barHeight * startPos - HighlightOffset;
|
float highlightTop = barTop + barHeight * startPos - HighlightOffset;
|
||||||
using(SolidBrush brush = new SolidBrush(Color.FromArgb(120, 220, 220, 255))) {
|
using(SolidBrush brush = new SolidBrush(Color.FromArgb(120, 220, 220, 255))) {
|
||||||
e.Graphics.FillRectangle(brush, left + 1, highlightTop, width, HighlightHeight - 2);
|
e.Graphics.FillRectangle(brush, left + 1, highlightTop, width, (int)(HighlightHeight * scale) - 2);
|
||||||
e.Graphics.DrawRectangle(Pens.DarkSlateGray, left + 1, highlightTop, width - 2, HighlightHeight - 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, HighlightHeight - 4);
|
e.Graphics.DrawRectangle(Pens.Gray, left + 2, highlightTop + 1, width - 4, (int)(HighlightHeight * scale) - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.ColorProvider != null) {
|
if(this.ColorProvider != null) {
|
||||||
|
@ -122,8 +124,8 @@ namespace Mesen.GUI.Debugger.Controls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int arrowWidth = 10;
|
int arrowWidth = (int)(10 * scale);
|
||||||
int arrowHeight = 5;
|
int arrowHeight = (int)(5 * scale);
|
||||||
int bottom = barTop + barHeight + _buttonSize;
|
int bottom = barTop + barHeight + _buttonSize;
|
||||||
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
e.Graphics.FillRectangle(Brushes.Gainsboro, rect.Left + 1, rect.Top, this.Width - 1, _buttonSize);
|
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, 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 - _buttonSize, rect.Left + width, bottom - _buttonSize);
|
||||||
e.Graphics.DrawLine(Pens.DimGray, rect.Left + 1, bottom, rect.Left + width, bottom);
|
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.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.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);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1297,6 +1297,7 @@
|
||||||
<Compile Include="GoogleDriveIntegration\CloudSyncHelper.cs" />
|
<Compile Include="GoogleDriveIntegration\CloudSyncHelper.cs" />
|
||||||
<Compile Include="GoogleDriveIntegration\GoogleDriveAccessor.cs" />
|
<Compile Include="GoogleDriveIntegration\GoogleDriveAccessor.cs" />
|
||||||
<Compile Include="GoogleDriveIntegration\MesenCodeReceiver.cs" />
|
<Compile Include="GoogleDriveIntegration\MesenCodeReceiver.cs" />
|
||||||
|
<Compile Include="ImageExtensions.cs" />
|
||||||
<Compile Include="InteropEmu.cs" />
|
<Compile Include="InteropEmu.cs" />
|
||||||
<Compile Include="MonoToolStripHelper.cs" />
|
<Compile Include="MonoToolStripHelper.cs" />
|
||||||
<Compile Include="ThemeHelper.cs" />
|
<Compile Include="ThemeHelper.cs" />
|
||||||
|
|
27
GUI.NET/ImageExtensions.cs
Normal file
27
GUI.NET/ImageExtensions.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue