-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathState.razor.cs
More file actions
109 lines (92 loc) · 3.03 KB
/
State.razor.cs
File metadata and controls
109 lines (92 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Microsoft.AspNetCore.Components;
using Wacton.Unicolour.Icc;
namespace Wacton.Unicolour.Example.Web;
// global static properties arguably unpleasant
// but seems fine for a small app with a small number of items of shared state
// not worth the effort of state injection or cascading callbacks
public partial class State : ComponentBase
{
static State()
{
Colour = new Unicolour(Config, "ff1493");
}
public static readonly Configuration NoConfig = new(iccConfig: new IccConfiguration(profile: null, "⚠️ Uncalibrated CMYK"));
public static Configuration Config { get; private set; } = NoConfig;
private static Unicolour colour = null!;
public static Unicolour Colour
{
get => colour;
private set
{
colour = value;
UpdateColourProperties();
OnColourChange?.Invoke();
}
}
private static string busyMessage = string.Empty;
public static string BusyMessage
{
get => busyMessage;
private set
{
busyMessage = value;
OnBusyChange?.Invoke();
}
}
private static string cssInsideGamut;
private static string cssOutsideGamut;
public static Unicolour ColourInGamut { get; private set; } = null!;
public static ConversionResult ConversionResult { get; private set; }
public static bool IsBusy => !string.IsNullOrEmpty(BusyMessage);
public static event Action? OnColourChange;
public static event Action? OnBusyChange;
private static void UpdateColourProperties()
{
ColourInGamut = colour.MapToRgbGamut(GamutMap.RgbClipping);
cssInsideGamut = Utils.ToCss(colour, 100);
cssOutsideGamut = Utils.ToCss(colour, colour.IsInRgbGamut ? 100 : 50);
if (Utils.HasConversionError(colour))
{
ConversionResult = ConversionResult.Error;
}
else if (!colour.IsInRgbGamut)
{
ConversionResult = ConversionResult.OutOfGamut;
}
else
{
ConversionResult = ConversionResult.InGamut;
}
}
public static void UpdateColour(ColourSpace colourSpace, double first, double second, double third)
{
Colour = new Unicolour(Config, colourSpace, first, second, third);
}
public static void UpdateColour(Pigment[] pigments, double[] weights)
{
Colour = new Unicolour(Config, pigments, weights);
}
public static void UpdateColour(Channels channels)
{
Colour = new Unicolour(Config, channels);
}
public static void UpdateConfig(Configuration config)
{
Config = config;
colour = colour.ConvertToConfiguration(config); // avoid triggering onColourChange; colour isn't actually changing
}
public static void SetBusy(string message)
{
BusyMessage = message.ToUpper();
}
public static void ClearBusy()
{
BusyMessage = string.Empty;
}
}
public enum ConversionResult
{
InGamut,
OutOfGamut,
Error
}