mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-14 11:25:09 -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>
74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using System.Drawing;
|
|
using OpenNest.Forms;
|
|
|
|
namespace OpenNest.WinForms.Tests;
|
|
|
|
[Collection("Fill operation lifetime")]
|
|
public class CustomDrawingColorTests
|
|
{
|
|
[Fact]
|
|
public void DrawingPropertiesMarksOnlyAChangedColorAsCustom() => StaTestThread.Run(() =>
|
|
{
|
|
var drawing = new Drawing("Bracket") { Color = Color.Coral };
|
|
using (var unchanged = new EditDrawingForm())
|
|
{
|
|
unchanged.LoadDrawing(drawing);
|
|
unchanged.SaveDrawing(drawing);
|
|
}
|
|
Assert.False(drawing.HasCustomColor);
|
|
|
|
using var picked = new EditDrawingForm();
|
|
picked.LoadDrawing(drawing);
|
|
var dialog = (System.Windows.Forms.ColorDialog)typeof(EditDrawingForm)
|
|
.GetField("colorDialog1", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
|
|
.GetValue(picked)!;
|
|
dialog.Color = Color.Red;
|
|
picked.SaveDrawing(drawing);
|
|
|
|
Assert.True(drawing.HasCustomColor);
|
|
Assert.Equal(Color.Red.ToArgb(), drawing.Color.ToArgb());
|
|
}, TimeSpan.FromMinutes(1), "Drawing properties color test timed out.");
|
|
|
|
[Fact]
|
|
public void DrawingPropertiesAutomaticColorClearsTheCustomColor() => StaTestThread.Run(() =>
|
|
{
|
|
var previous = ColorSchemeSerializer.Deserialize(ColorSchemeSerializer.Serialize(ColorScheme.Default));
|
|
try
|
|
{
|
|
ColorSchemeRegistry.Apply(ColorSchemeRegistry.Get("Classic"));
|
|
var nest = new Nest("Automatic");
|
|
nest.Drawings.Add(new Drawing("First"));
|
|
nest.Drawings.Add(new Drawing("Cutoff") { IsCutOff = true });
|
|
var drawing = new Drawing("Bracket") { Color = Color.Red, HasCustomColor = true };
|
|
nest.Drawings.Add(drawing);
|
|
|
|
using var form = new EditDrawingForm();
|
|
form.LoadDrawing(drawing, nest);
|
|
form.Show();
|
|
var modeLabel = Assert.IsType<System.Windows.Forms.Label>(form.Controls.Find("colorModeLabel", true).Single());
|
|
var automatic = Assert.IsType<System.Windows.Forms.Button>(form.Controls.Find("automaticColorButton", true).Single());
|
|
Assert.Equal("Custom color", modeLabel.Text);
|
|
Assert.True(automatic.Enabled);
|
|
|
|
automatic.PerformClick();
|
|
|
|
Assert.StartsWith("Automatic", modeLabel.Text);
|
|
Assert.False(automatic.Enabled);
|
|
Assert.True(drawing.HasCustomColor);
|
|
|
|
form.SaveDrawing(drawing);
|
|
|
|
Assert.False(drawing.HasCustomColor);
|
|
Assert.Equal(Drawing.GetPartColor(1).ToArgb(), drawing.Color.ToArgb());
|
|
|
|
using var reopened = new EditDrawingForm();
|
|
reopened.LoadDrawing(drawing, nest);
|
|
Assert.StartsWith("Automatic", reopened.Controls.Find("colorModeLabel", true).Single().Text);
|
|
}
|
|
finally
|
|
{
|
|
ColorSchemeRegistry.Apply(previous);
|
|
}
|
|
}, TimeSpan.FromMinutes(1), "Drawing properties automatic color test timed out.");
|
|
}
|