Use `Pens.*` instead of creating new ones from `Color` constants

This commit is contained in:
YoshiRulz 2024-09-26 08:08:24 +10:00 committed by James Groom
parent 64f6742c15
commit ca95336349
7 changed files with 23 additions and 10 deletions

View File

@ -6,7 +6,8 @@ namespace BizHawk.Client.EmuHawk.CustomControls
{
private Graphics _graphics;
private readonly Pen _currentPen = new Pen(Color.Black);
private readonly Pen _currentPen = Pens.Black.GetMutableCopy();
private readonly SolidBrush _currentBrush = new SolidBrush(Color.Black);
private readonly SolidBrush _currentStringBrush = new SolidBrush(Color.Black);
private Font _currentFont;

View File

@ -101,7 +101,7 @@ namespace BizHawk.Client.EmuHawk
e.Graphics.DrawImage(_bitmap!, new Rectangle(0, 0, Width, _drawingHeight));
if (Padding > 0)
{
e.Graphics.DrawRectangle(new Pen(Brushes.Black), new Rectangle(new Point(0, _drawingHeight), new Size(Width - 1, Padding - 1)));
e.Graphics.DrawRectangle(Pens.Black, new Rectangle(new Point(0, _drawingHeight), new Size(Width - 1, Padding - 1)));
e.Graphics.DrawString(Text, Font, Brushes.Black, new Rectangle(2, _drawingHeight, Width - 2, Height));
}

View File

@ -0,0 +1,12 @@
#nullable enable
using System.Drawing;
namespace BizHawk.Client.EmuHawk
{
public static class DrawingExtensions
{
public static Pen GetMutableCopy(this Pen p)
=> (Pen) p.Clone();
}
}

View File

@ -8,8 +8,9 @@ namespace BizHawk.Client.EmuHawk
private const int ScaleFactor = 4;
private const int _3DPadding = 5;
private readonly Pen _blackPen;
private readonly Pen _bluePen;
private readonly Pen _blackPen = Pens.Black;
private readonly Pen _bluePen = Pens.Cyan;
private int _maxX = 127;
private int _maxY = 127;
@ -76,9 +77,6 @@ namespace BizHawk.Client.EmuHawk
BackColor = Color.Gray;
BorderStyle = BorderStyle.Fixed3D;
_blackPen = new Pen(Brushes.Black);
_bluePen = new Pen(Brushes.Cyan);
InitializeComponent();
}

View File

@ -161,7 +161,7 @@ namespace BizHawk.Client.EmuHawk
break;
}
using var p = new Pen(Color.Black);
var p = Pens.Black;
e.Graphics.DrawLine(p, new Point(x, y), new Point(x + 8, y + 8));
e.Graphics.DrawLine(p, new Point(x + 8, y), new Point(x, y + 8));
e.Graphics.DrawRectangle(p, new Rectangle(x, y, 8, 8));

View File

@ -140,7 +140,8 @@ namespace BizHawk.Client.EmuHawk
private WatchSize WatchSize => (WatchSize)DataSize;
private readonly Pen _blackPen = new Pen(Color.Black);
private readonly Pen _blackPen = Pens.Black;
private SolidBrush _freezeBrush;
private SolidBrush _freezeHighlightBrush;
private SolidBrush _highlightBrush;

View File

@ -132,7 +132,8 @@ namespace BizHawk.Client.EmuHawk
private int GfxToRealY(int val) =>
MaybeReversedInY((_rangeY.Start + ((val - PixelMinY) / ScaleY).RoundToInt()).ConstrainWithin(_rangeY));
private readonly Pen _blackPen = new Pen(Brushes.Black);
private readonly Pen _blackPen = Pens.Black;
private readonly Pen _bluePen = new Pen(Brushes.Blue, 2);
private readonly Pen _grayPen = new Pen(Brushes.Gray, 2);