From ca95336349571768d1e6fa5de7865555c2ca1073 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 26 Sep 2024 08:08:24 +1000 Subject: [PATCH] Use `Pens.*` instead of creating new ones from `Color` constants --- .../ControlRenderer/GdiPlusRenderer.cs | 3 ++- .../CustomControls/ScreenshotForm.cs | 2 +- .../Extensions/DrawingExtensions.cs | 12 ++++++++++++ .../config/AnalogRangeConfig.cs | 8 +++----- .../config/Messages/MessageEdit.cs | 2 +- .../tools/HexEditor/HexEditor.cs | 3 ++- .../controls/components/AnalogStickPanel.cs | 3 ++- 7 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/BizHawk.Client.EmuHawk/Extensions/DrawingExtensions.cs diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/ControlRenderer/GdiPlusRenderer.cs b/src/BizHawk.Client.EmuHawk/CustomControls/ControlRenderer/GdiPlusRenderer.cs index e12d344835..d40ed508fc 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/ControlRenderer/GdiPlusRenderer.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/ControlRenderer/GdiPlusRenderer.cs @@ -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; diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/ScreenshotForm.cs b/src/BizHawk.Client.EmuHawk/CustomControls/ScreenshotForm.cs index 6cb92e775c..dac7167dc0 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/ScreenshotForm.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/ScreenshotForm.cs @@ -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)); } diff --git a/src/BizHawk.Client.EmuHawk/Extensions/DrawingExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/DrawingExtensions.cs new file mode 100644 index 0000000000..03398dbca4 --- /dev/null +++ b/src/BizHawk.Client.EmuHawk/Extensions/DrawingExtensions.cs @@ -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(); + } +} diff --git a/src/BizHawk.Client.EmuHawk/config/AnalogRangeConfig.cs b/src/BizHawk.Client.EmuHawk/config/AnalogRangeConfig.cs index c9a4e222c8..e70c11dbb4 100644 --- a/src/BizHawk.Client.EmuHawk/config/AnalogRangeConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/AnalogRangeConfig.cs @@ -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(); } diff --git a/src/BizHawk.Client.EmuHawk/config/Messages/MessageEdit.cs b/src/BizHawk.Client.EmuHawk/config/Messages/MessageEdit.cs index 6d212762da..c17b3267f9 100644 --- a/src/BizHawk.Client.EmuHawk/config/Messages/MessageEdit.cs +++ b/src/BizHawk.Client.EmuHawk/config/Messages/MessageEdit.cs @@ -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)); diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index f149eb847f..1fec01de63 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -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; diff --git a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs index 50e9341d88..d8336a9cf2 100644 --- a/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs +++ b/src/BizHawk.Client.EmuHawk/tools/VirtualPads/controls/components/AnalogStickPanel.cs @@ -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);