mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-01 22:51:36 -05:00
refactor(desktop): share the separator line controls' pens and painting
HorizontalLine and VerticalLine had identical constructors, Dispose and resize handling. They now derive from SeparatorLine and only say which way the line runs. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e231e44f72
commit
24169a5f8f
4 files changed
+70
-93
No files matched your search
@@ -75,7 +75,7 @@ public class SeparatorPenLifetimeTests
|
||||
horizontal ? new HorizontalLine() : new VerticalLine();
|
||||
|
||||
private static Pen GetPen(Control control, string name) =>
|
||||
Assert.IsType<Pen>(control.GetType()
|
||||
Assert.IsType<Pen>(typeof(SeparatorLine)
|
||||
.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(control));
|
||||
|
||||
private static bool GetStyle(Control control, ControlStyles style) =>
|
||||
|
||||
@@ -1,54 +1,12 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenNest.Controls
|
||||
{
|
||||
public class HorizontalLine : Control
|
||||
public class HorizontalLine : SeparatorLine
|
||||
{
|
||||
private readonly Pen lightPen;
|
||||
private readonly Pen darkPen;
|
||||
protected override int Across => Height;
|
||||
|
||||
public HorizontalLine()
|
||||
{
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
SetStyle(ControlStyles.Selectable, false);
|
||||
|
||||
lightPen = new Pen(ProfessionalColors.SeparatorLight);
|
||||
darkPen = new Pen(ProfessionalColors.SeparatorDark);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
lightPen.Dispose();
|
||||
darkPen.Dispose();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
float midpoint = Height * 0.5f;
|
||||
|
||||
e.Graphics.DrawLine(darkPen, 0, midpoint, Width, midpoint);
|
||||
midpoint++;
|
||||
e.Graphics.DrawLine(lightPen, 0, midpoint, Width, midpoint);
|
||||
}
|
||||
protected override void DrawLine(Graphics graphics, Pen pen, float position) =>
|
||||
graphics.DrawLine(pen, 0, position, Width, position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenNest.Controls
|
||||
{
|
||||
/// <summary>An etched separator: a dark line at the middle with a light line beside it.</summary>
|
||||
public abstract class SeparatorLine : Control
|
||||
{
|
||||
private readonly Pen lightPen;
|
||||
private readonly Pen darkPen;
|
||||
|
||||
protected SeparatorLine()
|
||||
{
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
SetStyle(ControlStyles.Selectable, false);
|
||||
|
||||
lightPen = new Pen(ProfessionalColors.SeparatorLight);
|
||||
darkPen = new Pen(ProfessionalColors.SeparatorDark);
|
||||
}
|
||||
|
||||
/// <summary>The control's size across the line: Height for a horizontal line.</summary>
|
||||
protected abstract int Across { get; }
|
||||
|
||||
/// <summary>Draws the full-length line at <paramref name="position"/> across it.</summary>
|
||||
protected abstract void DrawLine(Graphics graphics, Pen pen, float position);
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
lightPen.Dispose();
|
||||
darkPen.Dispose();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
float midpoint = Across * 0.5f;
|
||||
|
||||
DrawLine(e.Graphics, darkPen, midpoint);
|
||||
midpoint++;
|
||||
DrawLine(e.Graphics, lightPen, midpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +1,12 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenNest.Controls
|
||||
{
|
||||
public class VerticalLine : Control
|
||||
public class VerticalLine : SeparatorLine
|
||||
{
|
||||
private readonly Pen lightPen;
|
||||
private readonly Pen darkPen;
|
||||
protected override int Across => Width;
|
||||
|
||||
public VerticalLine()
|
||||
{
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
SetStyle(ControlStyles.Selectable, false);
|
||||
|
||||
lightPen = new Pen(ProfessionalColors.SeparatorLight);
|
||||
darkPen = new Pen(ProfessionalColors.SeparatorDark);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
lightPen.Dispose();
|
||||
darkPen.Dispose();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
|
||||
float midpoint = Width * 0.5f;
|
||||
|
||||
e.Graphics.DrawLine(darkPen, midpoint, 0, midpoint, Height);
|
||||
midpoint++;
|
||||
e.Graphics.DrawLine(lightPen, midpoint, 0, midpoint, Height);
|
||||
}
|
||||
protected override void DrawLine(Graphics graphics, Pen pen, float position) =>
|
||||
graphics.DrawLine(pen, position, 0, position, Height);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user