-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGUITest.MainForm.pas
266 lines (225 loc) · 7.65 KB
/
GUITest.MainForm.pas
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
unit GUITest.MainForm;
interface
uses
Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes, System.UITypes, System.Math,
System.Generics.Collections, System.Generics.Defaults,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Buttons,
Vcl.Imaging.pngimage, Vcl.Imaging.jpeg,
MaterialColor.VCL,
MaterialColor.Quantize.Celebi, MaterialColor.Quantize.WsMeans,
MaterialColor.Score,
MaterialColor.Utils,
MaterialColor.CAM, MaterialColor.CAM.HCT,
MaterialColor.DynamicColor.DynamicScheme, MaterialColor.DynamicColor.Variant,
MaterialColor.DynamicColor.MaterialDynamicColor;
type
TForm2 = class(TForm)
ImageOpenDialog: TFileOpenDialog;
ImagePanel: TPanel;
Image1: TImage;
SamplesPanel: TFlowPanel;
SamplePanel1: TPanel;
SamplePanel2: TPanel;
SamplePanel3: TPanel;
SamplePanel4: TPanel;
SamplePanel5: TPanel;
SamplePanel6: TPanel;
SamplePanel7: TPanel;
SamplePanel8: TPanel;
PalettesPanel: TFlowPanel;
PrimaryPanel: TPanel;
SecondaryPanel: TPanel;
TertiaryPanel: TPanel;
ErrorPanel: TPanel;
LightOrDarkPanel: TPanel;
pLight: TPanel;
pDark: TPanel;
SchemesPanel: TPanel;
procedure Image1Click(Sender: TObject);
procedure SamplePanelClick(Sender: TObject);
procedure LightOrDarkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SchemePanelClick(Sender: TObject);
private
{ Déclarations privées }
FSchemePanels: array[TDynamicColorVariant] of TPanel;
FScoredColors: TArray<TColor>;
FSelectedColor: TColor;
FIsDark: Boolean;
FSchemeBuilder: TDynamicSchemeBuilderClass;
procedure ProcessImage;
procedure UpdateSchemes(const Scheme: TDynamicScheme);
procedure UpdateSamples;
procedure UpdateTheme;
public
{ Déclarations publiques }
end;
var
Form2: TForm2;
implementation
uses
MaterialColor.Scheme.Content,
MaterialColor.Scheme.Expressive,
MaterialColor.Scheme.Fidelity,
MaterialColor.Scheme.FruitSalad,
MaterialColor.Scheme.Monochrome,
MaterialColor.Scheme.Neutral,
MaterialColor.Scheme.Rainbow,
MaterialColor.Scheme.TonalSpot,
MaterialColor.Scheme.Vibrant;
{$R *.dfm}
const
SCHEMES: array[TDynamicColorVariant] of TDynamicSchemeBuilderClass = (
TSchemeMonochrome, TSchemeNeutral, TSchemeTonalSpot,
TSchemeVibrant, TSchemeExpressive, TSchemeFidelity,
TSchemeContent, TSchemeRainbow, TSchemeFruitSalad
);
NAMES: array[TDynamicColorVariant] of string = (
'Monochrome', 'Neutral', 'Tonal Spot', 'Vibrant', 'Expressive', 'Fidelity',
'Content', 'Rainbow', 'Fruit Salad'
);
function ResFolder: string;
begin
Result := ExpandFileName(ExtractFilePath(ParamStr(0)) + '..\..\res');
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
var ScaledMargin := MulDiv(5, Screen.PixelsPerInch, 96);
for var V := Low(TDynamicColorVariant) to High(TDynamicColorVariant) do
begin
var SchemePanel := TPanel.Create(Self);
SchemePanel.Name := StringReplace(NAMES[V], ' ', '', [rfReplaceAll]) + 'SchemePanel';
SchemePanel.Parent := SchemesPanel;
SchemePanel.Height := ((SchemesPanel.Height - ScaledMargin) div Length(NAMES)) - ScaledMargin;
SchemePanel.Margins.SetBounds(ScaledMargin, ScaledMargin, ScaledMargin, 0);
SchemePanel.AlignWithMargins := True;
SchemePanel.Align := alTop;
SchemePanel.BevelKind := bkNone;
SchemePanel.BevelOuter := bvNone;
SchemePanel.Caption := NAMES[V];
SchemePanel.ParentBackground := False;
SchemePanel.ParentFont := False;
SchemePanel.Tag := Ord(V);
SchemePanel.OnClick := SchemePanelClick;
SchemePanel.Font.Size := MulDiv(8, Screen.PixelsPerInch, 96);
FSchemePanels[V] := SchemePanel;
end;
FIsDark := False;
FSchemeBuilder := TSchemeTonalSpot;
ProcessImage;
end;
procedure TForm2.Image1Click(Sender: TObject);
begin
ImageOpenDialog.DefaultFolder := ResFolder;
if ImageOpenDialog.Execute then
begin
Image1.Picture.LoadFromFile(ImageOpenDialog.FileName);
ProcessImage;
end;
end;
procedure TForm2.ProcessImage;
begin
FScoredColors := PictureToRankedColors(Image1.Picture);
FSelectedColor := FScoredColors[0];
UpdateSamples;
UpdateTheme;
end;
procedure TForm2.UpdateSamples;
function SamplePanels: TArray<TPanel>;
begin
Result := [ SamplePanel1, SamplePanel2, SamplePanel3, SamplePanel4,
SamplePanel5, SamplePanel6, SamplePanel7, SamplePanel8 ];
end;
function SamplePanel(Index: Integer): TPanel;
begin
Result := SamplePanels[Index];
end;
begin
var SamplesCount := Length(FScoredColors);
for var I := 0 to SamplesCount -1 do
SamplePanel(I).Color := FScoredColors[I];
for var I := SamplesCount to Length(SamplePanels) -1 do
SamplePanel(I).Color := SamplesPanel.Color;
end;
procedure TForm2.UpdateSchemes(const Scheme: TDynamicScheme);
begin
var Surface := TMaterialDynamicColors.Surface.GetColor(Scheme);
var OnSurface := TMaterialDynamicColors.OnSurface.GetColor(Scheme);
var Primary := TMaterialDynamicColors.Primary.GetColor(Scheme);
var OnPrimary := TMaterialDynamicColors.OnPrimary.GetColor(Scheme);
for var V := Low(TDynamicColorVariant) to High(TDynamicColorVariant) do
if SCHEMES[V] = FSchemeBuilder then
begin
FSchemePanels[V].Color := Primary;
FSchemePanels[V].Font.Color := OnPrimary;
end
else
begin
FSchemePanels[V].Color := Surface;
FSchemePanels[V].Font.Color := OnSurface;
end;
end;
type
TColorSpeedButton = class(TSpeedButton)
end;
procedure TForm2.UpdateTheme;
begin
var Scheme := FSchemeBuilder.Construct(THCT.Create(ARGB(FSelectedColor)), FIsDark, 0.0);
Self.Color := TMaterialDynamicColors.Surface.GetColor(Scheme);
var SC_Color := TMaterialDynamicColors.SurfaceContainer.GetColor(Scheme);
ImagePanel.Color := SC_Color;
LightOrDarkPanel.Color := SC_Color;
SchemesPanel.Color := SC_Color;
SamplesPanel.Color := SC_Color;
PalettesPanel.Color := SC_Color;
var Primary := TMaterialDynamicColors.Primary.GetColor(Scheme);
var InvPrimary := TMaterialDynamicColors.InversePrimary.GetColor(Scheme);
var OnPrimary := TMaterialDynamicColors.OnPrimary.GetColor(Scheme);
var InvOnSurface := TMaterialDynamicColors.InverseOnSurface.GetColor(Scheme);
if FIsDark then
begin
pDark.Color := Primary;
pDark.Font.Color := OnPrimary;
pLight.Color := InvPrimary;
pLight.Font.Color := InvOnSurface;
end
else
begin
pLight.Color := Primary;
pLight.Font.Color := OnPrimary;
pDark.Color := InvPrimary;
pDark.Font.Color := InvOnSurface;
end;
UpdateSchemes(Scheme);
PrimaryPanel.Color := Primary;
PrimaryPanel.Font.Color := OnPrimary;
SecondaryPanel.Color := TMaterialDynamicColors.Secondary.GetColor(Scheme);
SecondaryPanel.Font.Color := TMaterialDynamicColors.OnSecondary.GetColor(Scheme);
TertiaryPanel.Color := TMaterialDynamicColors.Tertiary.GetColor(Scheme);
TertiaryPanel.Font.Color := TMaterialDynamicColors.OnTertiary.GetColor(Scheme);
ErrorPanel.Color := TMaterialDynamicColors.Error.GetColor(Scheme);
ErrorPanel.Font.Color := TMaterialDynamicColors.OnError.GetColor(Scheme);
end;
procedure TForm2.SamplePanelClick(Sender: TObject);
begin
var Id := TPanel(Sender).Tag;
if Id >= Length(FScoredColors) then
Exit;
FSelectedColor := FScoredColors[Id];
UpdateTheme;
end;
procedure TForm2.LightOrDarkClick(Sender: TObject);
begin
FIsDark := TPanel(Sender).Tag > 0;
UpdateTheme;
end;
procedure TForm2.SchemePanelClick(Sender: TObject);
begin
var Id := TPanel(Sender).Tag;
if (Id < 0) or (Id > Ord(High(TDynamicColorVariant))) then
Exit;
FSchemeBuilder := SCHEMES[TDynamicColorVariant(Id)];
UpdateTheme;
end;
end.