mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-14 06:55:07 -05:00
ColorScheme, ColorSchemeRegistry, ColorSchemeSerializer and the Schemes folder move into the toolkit-neutral library, keeping the OpenNest namespace, so the Avalonia app can share the built-in palettes, the scheme files and the recolour-on-open rule. ColorScheme is now pure colour data with a Version that changes with any colour. Its GDI+ pens and brushes move to GdiSchemeTools in the WinForms project (still one set per thread, rebuilt after a colour change), reached through scheme.Gdi(). The legacy part outline uses ColorShade.Dark, a port of ControlPaint.Dark's HLS arithmetic; a WinForms test compares the two across a colour sweep on Windows. The registry no longer walks Application.OpenForms: Apply raises Applied, and EditNestForm subscribes once to recolour every open nest window as before. The saved scheme is read under the same ActiveColorScheme setting (SavedSchemeName/ApplySaved for the shared user-settings file); WinForms still reads it through Settings.Default. Schemes/*.json now copies beside both desktop apps from OpenNest.Desktop. Pure scheme tests move to OpenNest.Desktop.Tests, with new ones for built-in round trips, scheme files, bad files, the saved name and the recolour rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace OpenNest.WinForms.Tests;
|
|
|
|
public class GdiSchemeToolsTests
|
|
{
|
|
[Fact]
|
|
public void SharedShadeMatchesControlPaintDark()
|
|
{
|
|
var colors = new List<Color> { SystemColors.Control, Color.Coral, Color.White, Color.Black };
|
|
for (var r = 0; r < 256; r += 15)
|
|
{
|
|
for (var g = 0; g < 256; g += 17)
|
|
{
|
|
for (var b = 0; b < 256; b += 13)
|
|
colors.Add(Color.FromArgb(r, g, b));
|
|
}
|
|
}
|
|
|
|
Assert.All(colors, color => Assert.Equal(ControlPaint.Dark(color), ColorShade.Dark(color)));
|
|
Assert.All(colors, color => Assert.Equal(ControlPaint.Dark(color, 0.25f), ColorShade.Dark(color, 0.25f)));
|
|
}
|
|
|
|
[Fact]
|
|
public void PensFollowTheSchemeAndAreRebuiltAfterAColorChange()
|
|
{
|
|
var scheme = ColorSchemeSerializer.Deserialize(ColorSchemeSerializer.Serialize(ColorSchemeRegistry.Get("Classic")));
|
|
var tools = scheme.Gdi();
|
|
|
|
Assert.Same(tools, scheme.Gdi());
|
|
Assert.Equal(scheme.RapidColor.ToArgb(), tools.RapidPen.Color.ToArgb());
|
|
Assert.Equal(Color.FromArgb(30, scheme.PreviewPartColor).ToArgb(),
|
|
((SolidBrush)tools.ActivePreviewPartBrush).Color.ToArgb());
|
|
|
|
scheme.LayoutFillColor = Color.Coral;
|
|
var rebuilt = scheme.Gdi();
|
|
|
|
Assert.NotSame(tools, rebuilt);
|
|
Assert.Equal(Color.Coral.ToArgb(), ((SolidBrush)rebuilt.LayoutFillBrush).Color.ToArgb());
|
|
}
|
|
|
|
[Fact]
|
|
public void EachThreadDrawsWithItsOwnPens()
|
|
{
|
|
var scheme = ColorSchemeRegistry.Get("Workshop");
|
|
var here = scheme.Gdi();
|
|
GdiSchemeTools? other = null;
|
|
var thread = new Thread(() => other = scheme.Gdi());
|
|
thread.Start();
|
|
thread.Join();
|
|
|
|
Assert.NotNull(other);
|
|
Assert.NotSame(here, other);
|
|
Assert.NotSame(here.LayoutOutlinePen, other.LayoutOutlinePen);
|
|
}
|
|
}
|