-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPalMan.pas
More file actions
791 lines (713 loc) · 20.2 KB
/
PalMan.pas
File metadata and controls
791 lines (713 loc) · 20.2 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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
unit PalMan;
{
Tile Studio
Copyright (c) 2000-2017, Mike Wiering, Wiering Software
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
}
{$I SETTINGS.INC}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, Spin, PNGUnit;
const
DEFAULT_PAL_SIZE = 256;
DEFAULT_PRESET = 128;
type
TPaletteManager = class(TForm)
TopPanel: TPanel;
PaletteTab: TTabControl;
BottomPanel: TPanel;
PaletteColors: TPaintBox;
NewButton: TButton;
CloseButton: TButton;
DeleteButton: TButton;
L1: TLabel;
L0: TLabel;
PaletteSize: TSpinEdit;
Identifier: TEdit;
L2: TLabel;
Preset: TSpinEdit;
ColorDialog1: TColorDialog;
ImportButton: TButton;
GenerateButton: TButton;
ExportButton: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
RGBDepthGroupBox: TGroupBox;
edR: TSpinEdit;
L3: TLabel;
L4: TLabel;
edG: TSpinEdit;
L5: TLabel;
edB: TSpinEdit;
UseThisPalette: TCheckBox;
SetAsDefault: TCheckBox;
CopyButton: TButton;
PasteButton: TButton;
procedure CloseButtonClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure NewButtonClick(Sender: TObject);
procedure DeleteButtonClick(Sender: TObject);
procedure PaletteColorsPaint(Sender: TObject);
procedure PaletteSizeChange(Sender: TObject);
procedure PresetChange(Sender: TObject);
procedure PaletteTabChange(Sender: TObject);
procedure PaletteColorsMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure IdentifierChange(Sender: TObject);
procedure GenerateButtonClick(Sender: TObject);
procedure ImportButtonClick(Sender: TObject);
procedure ExportButtonClick(Sender: TObject);
procedure edChange(Sender: TObject);
procedure UseThisPaletteClick(Sender: TObject);
procedure SetAsDefaultClick(Sender: TObject);
procedure CopyButtonClick(Sender: TObject);
procedure PasteButtonClick(Sender: TObject);
private
{ Private declarations }
function CheckRGBDepth: Boolean;
procedure EnableDisable;
function MakePalName: string;
public
{ Public declarations }
procedure ClearPalettes;
procedure ImportPalette (Filename: string; tab: Integer; PalType: Integer);
function GetID (n: Integer): string;
procedure setID (n: Integer; NewID: string);
end;
var
PaletteManager: TPaletteManager;
var
aaiPal: array of array of Integer;
aiPalSize: array of Integer;
aiPreset: array of Integer;
aiOrig: array of Integer;
aiUsedColors: array of Integer;
aiClip: array of Integer;
bmp: TBitmap;
const
DefaultPalette: Integer = -1;
SelectedPalette: Integer = -1;
var
DefaultPaletteChanged,
SelectedPaletteChanged: Boolean;
implementation
uses Main;
{$R *.DFM}
var
LastColor: Integer;
procedure TPaletteManager.CloseButtonClick(Sender: TObject);
begin
Close;
end;
procedure TPaletteManager.FormShow(Sender: TObject);
begin
if (SelectedPalette > -1) and (SelectedPalette < PaletteTab.Tabs.Count) then
PaletteTab.TabIndex := SelectedPalette; // 2.34 - start with selected palette
EnableDisable;
CloseButton.SetFocus;
if PaletteTab.Tabs.Count > 0 then
begin
PaletteTabChange (Sender);
PaletteTab.Repaint;
end;
end;
function TPaletteManager.MakePalName: string;
var
i: Integer;
s: string;
begin
i := 0;
repeat
Inc (i);
s := 'Palette' + IntToStr (i);
until PaletteTab.Tabs.IndexOf (s) = -1;
MakePalName := s;
end;
procedure TPaletteManager.NewButtonClick(Sender: TObject);
var
i, j, k: Integer;
s: string;
begin
s := MakePalName;
i := PaletteTab.Tabs.Count;
SetLength (aaiPal, i + 1);
SetLength (aaiPal[i], DEFAULT_PAL_SIZE);
for j := 0 to 255 do
aaiPal[i, j] := clWhite;
SetLength (aiPalSize, i + 1);
aiPalSize[i] := DEFAULT_PAL_SIZE;
SetLength (aiPreset, i + 1);
aiPreset[i] := DEFAULT_PRESET;
SetLength (aiOrig, i + 1);
aiOrig[i] := -1;
k := Length (aiUsedColors);
if k <> 0 then
begin
// SetLength (aaiPal[i], k);
for j := 0 to k - 1 do
aaiPal[i, j] := aiUsedColors[j];
aiPalSize[i] := k;
aiPreset[i] := k;
end;
PaletteTab.Tabs.Add (s);
with PaletteTab do
TabIndex := Tabs.IndexOf (s);
if Sender <> nil then
begin
PaletteSize.Value := aiPalSize[i];
Preset.Value := aiPreset[i];
EnableDisable;
if k = 0 then
begin
PaletteSize.Value := DEFAULT_PAL_SIZE;
Preset.Value := DEFAULT_PRESET;
end;
SetAsDefault.Checked := FALSE;
UseThisPalette.Checked := FALSE;
end;
end;
function TPaletteManager.CheckRGBDepth: Boolean;
begin
try
CheckRGBDepth := (edR.Value * edG.Value * edB.Value) <= 256;
except
CheckRGBDepth := FALSE;
end;
end;
procedure TPaletteManager.EnableDisable;
var
b: Boolean;
begin
b := PaletteTab.Tabs.Count > 0;
if b and (PaletteTab.TabIndex < 0) then
PaletteTab.TabIndex := 0;
DeleteButton.Enabled := b;
Identifier.Enabled := b;
PaletteSize.Enabled := b;
Preset.Enabled := b;
ImportButton.Enabled := b;
ExportButton.Enabled := b;
SetAsDefault.Enabled := b;
UseThisPalette.Enabled := b;
edR.Enabled := b;
edG.Enabled := b;
edB.Enabled := b;
CopyButton.Enabled := b and (PaletteSize.Value > 0);
PasteButton.Enabled := b and (Length (aiClip) > 0);
GenerateButton.Enabled := b and CheckRGBDepth;
if b then
begin
Identifier.Text := PaletteTab.Tabs.Strings[PaletteTab.TabIndex]
end
else
begin
Identifier.Text := '';
end;
end;
procedure TPaletteManager.DeleteButtonClick(Sender: TObject);
var
i, j, k: Integer;
begin
with PaletteTab do
begin
if MessageDlg ('Delete palette "' + Tabs[TabIndex] + '"?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
if SelectedPalette = TabIndex then
SelectedPalette := -1
else
if SelectedPalette > TabIndex then
Dec (SelectedPalette);
if DefaultPalette = TabIndex then
DefaultPalette := -1
else
if DefaultPalette > TabIndex then
Dec (DefaultPalette);
for k := TabIndex to (Tabs.Count - 1) - 1 do
begin
SetLength (aaiPal[k], Length (aaiPal[k + 1]));
Tabs[k] := Tabs[k + 1];
for i := 0 to Length (aaiPal[k]) - 1 do
aaiPal[k, i] := aaiPal[k + 1, i];
aiPalSize[k] := aiPalSize[k + 1];
aiPreset[k] := aiPreset[k + 1];
aiOrig[k] := aiOrig[k + 1];
end;
j := TabIndex;
i := Tabs.Count - 1;
Tabs.Delete (i);
SetLength (aaiPal[i], 0);
SetLength (aaiPal, i);
SetLength (aiPalSize, i);
SetLength (aiPreset, i);
SetLength (aiOrig, i);
if j - 1 >= 0 then
TabIndex := j - 1
else
TabIndex := 0;
EnableDisable;
PaletteTabChange (Sender);
end;
end;
// PaletteColors.Repaint;
end;
procedure TPaletteManager.PaletteColorsPaint(Sender: TObject);
var
CW, CH: Integer;
X, Y, W, H, Wd, Ht, NH, NV: Integer;
i, j: Integer;
n, tab: Integer;
begin
tab := PaletteTab.TabIndex;
if tab >= 0 then
begin
CW := PaletteTab.ClientWidth - 2 * 5;
CH := PaletteTab.ClientHeight - BottomPanel.Height - 16 - 2 * 7;
NH := 16;
NV := 16;
W := CW div NH;
H := CH div NV;
Wd := W * NH;
Ht := H * NV;
X := (CW - Wd) div 2;
Y := (CH - Ht) div 2;
n := 0;
// with PaletteColors.Canvas do
// Rectangle (0, 0, CW + 1, CH + 1);
for j := 0 to NV - 1 do
for i := 0 to NH - 1 do
begin
with PaletteColors.Canvas do
begin
Pen.Color := clBlack;
Pen.Style := psSolid;
if n < Length (aaiPal[tab]) then // bug fix 4.42
begin
if n < aiPreset[tab] then
Brush.Color := aaiPal[tab, n]
else
Brush.Color := clBtnFace;
Brush.Style := bsSolid;
if n < aiPalSize[tab] then
Rectangle (X + i * W, Y + j * H,
X + (i + 1) * W + 1, Y + (j + 1) * H + 1);
end;
end;
Inc (n);
end;
end;
end;
procedure TPaletteManager.PaletteSizeChange(Sender: TObject);
begin
try
aiPalSize[PaletteTab.TabIndex] := PaletteSize.Value;
SetLength (aaiPal[PaletteTab.TabIndex], PaletteSize.Value);
finally
PaletteColors.Repaint;
end;
end;
procedure TPaletteManager.PresetChange(Sender: TObject);
begin
try
aiPreset[PaletteTab.TabIndex] := Preset.Value;
if Preset.Value > PaletteSize.Value then
begin
aiPalSize[PaletteTab.TabIndex] := PaletteSize.Value;
PaletteSize.Value := Preset.Value;
SetLength (aaiPal[PaletteTab.TabIndex], PaletteSize.Value);
end;
finally
PaletteColors.Repaint;
end;
end;
procedure TPaletteManager.PaletteTabChange(Sender: TObject);
var
tab: Integer;
begin
tab := PaletteTab.TabIndex;
if tab <> -1 then
begin
Identifier.Text := PaletteTab.Tabs.Strings[tab];
PaletteSize.Value := aiPalSize[tab];
Preset.Value := aiPreset[tab];
end;
UseThisPalette.Checked := tab = SelectedPalette;
SetAsDefault.Checked := tab = DefaultPalette;
LastColor := -1;
PaletteColors.Repaint;
end;
procedure GetRGB (RGB: Integer; var R: Integer; var G: Integer; var B: Integer);
begin
R := RGB;
G := RGB div $100;
B := RGB div $10000;
R := R and $FF;
G := G and $FF;
B := B and $FF;
end;
procedure Fade (tab, n1, n2: Integer);
var
Start, Count: Integer;
R1, G1, B1: Integer;
R2, G2, B2: Integer;
i, C: Integer;
begin
if n2 > n1 then
Start := n1
else
Start := n2;
Count := Abs (n2 - n1) + 1;
if Count < 3 then
Exit;
GetRGB (aaiPal[tab, Start], R1, G1, B1);
GetRGB (aaiPal[tab, Start + Count - 1], R2, G2, B2);
for i := 0 to Count - 1 do
begin
C := RGB (R1 + i * (R2 - R1) div (Count - 1),
G1 + i * (G2 - G1) div (Count - 1),
B1 + i * (B2 - B1) div (Count - 1));
aaiPal[tab, Start + i] := C;
end;
end;
procedure TPaletteManager.PaletteColorsMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
CW, CH: Integer;
XP, YP, W, H, Wd, Ht, NH, NV: Integer;
n, tab: Integer;
begin
tab := PaletteTab.TabIndex;
if tab >= 0 then
begin
CW := PaletteTab.ClientWidth - 2 * 5;
CH := PaletteTab.ClientHeight - BottomPanel.Height - 16 - 2 * 7;
NH := 16;
NV := 16;
W := CW div NH;
H := CH div NV;
Wd := W * NH;
Ht := H * NV;
XP := (CW - Wd) div 2;
YP := (CH - Ht) div 2;
n := (X - XP) div W + (Y - YP) div H * 16;
if n < aiPreset[tab] then
begin
if Button = mbLeft then
ColorDialog1.Color := aaiPal[tab, n];
if ColorDialog1.Execute then
begin
aaiPal[tab, n] := ColorDialog1.Color;
if ssShift in Shift then
if LastColor > -1 then
Fade (tab, LastColor, n);
PaletteColors.Repaint;
LastColor := n;
end;
end;
end;
end;
procedure TPaletteManager.IdentifierChange(Sender: TObject);
var
i: Integer;
s: string;
begin
if PaletteTab.TabIndex = -1 then
Exit;
s := Identifier.Text;
for i := Length (s) downto 1 do
if not (s[i] in ['a'..'z', 'A'..'Z', '_', '0'..'9']) then
Delete (s, i, 1);
with PaletteTab do
for i := 0 to Tabs.Count - 1 do
if i <> TabIndex then
if Tabs.Strings[i] = s then
s := '';
if s = '' then
s := MakePalName;
PaletteTab.Tabs.Strings[PaletteTab.TabIndex] := s;
end;
procedure TPaletteManager.GenerateButtonClick(Sender: TObject);
var
R, G, B: Integer;
RR, GG, BB: Integer;
Total, n: Integer;
tab: Integer;
{ i, j, k: Integer;
R1, G1, B1: Integer;
R2, G2, B2: Integer; }
begin
tab := PaletteTab.TabIndex;
if (tab >= 0) and (CheckRGBDepth) then
begin
RR := edR.Value;
GG := edG.Value;
BB := edB.Value;
Total := RR * GG * BB;
PaletteSize.Value := Total;
Preset.Value := Total;
SetLength (aaiPal[tab], Total);
n := 0;
for r := 0 to RR - 1 do
for g := 0 to GG - 1 do
for b := 0 to BB - 1 do
begin
aaiPal[tab, n] := RGB (r * 255 div (RR - 1),
g * 255 div (GG - 1),
b * 255 div (BB - 1));
Inc (n)
end;
end;
{
for i := 0 to 215 do
for j := i + 1 to 215 do
begin
GetRGB (aaiPal[tab, i], R1, G1, B1);
GetRGB (aaiPal[tab, j], R2, G2, B2);
if R1 * R1 + G1 * G1 + B1 * B1 > R2 * R2 + G2 * G2 + B2 * B2 then
begin
k := aaiPal[tab, i];
aaiPal[tab, i] := aaiPal[tab, j];
aaiPal[tab, j] := k;
end;
end;
}
PaletteColors.Repaint;
end;
procedure TPaletteManager.ImportPalette (Filename: string; tab: Integer; PalType: Integer);
var
R, G, B: Byte;
n: Integer;
F: file of Byte;
C0, C1: Byte;
begin
SetLength (aaiPal[tab], DEFAULT_PAL_SIZE);
AssignFile (F, Filename);
n := 0;
try
Reset (F);
repeat
case PalType of
1: begin // 8 bit
Read (F, R);
Read (F, G);
Read (F, B);
aaiPal[tab, n] := RGB (R, G, B);
end;
2: begin // 6 bit
Read (F, R);
Read (F, G);
Read (F, B);
aaiPal[tab, n] := RGB ((R shl 2) and $FF, (G shl 2) and $FF, (B shl 2) and $FF);
end;
3: begin // 5 bit
Read (F, C0);
Read (F, C1);
aaiPal[tab, n] :=
RGB (((C0) and $1F) shl 3,
((C0 shr 5 + (C1 and 3) shl 3) and $1F) shl 3,
((C1 shr 2) and $1F) shl 3);
end;
end;
Inc (n);
until (n >= DEFAULT_PAL_SIZE) or eof (F);
finally
PaletteSize.Value := n;
Preset.Value := n;
CloseFile (F);
end;
end;
procedure TPaletteManager.ImportButtonClick(Sender: TObject);
var
tab: Integer;
begin
tab := PaletteTab.TabIndex;
if tab >= 0 then
if OpenDialog1.Execute then
begin
ImportPalette (OpenDialog1.FileName, tab, OpenDialog1.FilterIndex);
PaletteColors.Repaint;
end;
end;
procedure TPaletteManager.ExportButtonClick(Sender: TObject);
var
R, G, B, c: Integer;
tab: Integer;
i, j, n: Integer;
F: file of Byte;
C0, C1: Byte;
function NumStr4 (n: Integer): string;
var
s: string;
begin
Str (n: 4, s);
result := s;
end;
procedure WriteString (s: string);
var
i: Integer;
begin
for i := 1 to Length (s) do
Write (F, Byte (s[i]));
end;
begin
tab := PaletteTab.TabIndex;
if tab >= 0 then
if SaveDialog1.Execute then
begin
if (SaveDialog1.FilterIndex = 4) then
begin
bmp := TBitmap.Create();
bmp.PixelFormat := pf32bit;
bmp.Width := 16;
bmp.Height := 16;
for j := 0 to 15 do
for i := 0 to 15 do
begin
n := j * 16 + i;
GetRGB (aaiPal[tab, n], R, G, B);
bmp.Canvas.Pixels[i, j] := RGB(R, G, B);
end;
PNGUnit.WriteBitmapToPNGFile (SaveDialog1.FileName, bmp, RGB(0, 0, 0));
bmp.free();
end
else
begin
AssignFile (F, SaveDialog1.Filename);
try
ReWrite (F);
for n := 0 to aiPalSize[tab] - 1 do
begin
GetRGB (aaiPal[tab, n], R, G, B);
case SaveDialog1.FilterIndex of
1: begin
Write (F, R);
Write (F, G);
Write (F, B);
end;
2: begin
R := R shr 2;
G := G shr 2;
B := B shr 2;
Write (F, R);
Write (F, G);
Write (F, B);
end;
3: begin
c := (R shr 3) and $1F +
((G shr 3) and $1F) shl 5 +
((B shr 3) and $1F) shl 10;
C0 := Lo (c);
C1 := Hi (c);
Write (F, C0);
Write (F, C1);
end;
5: begin
if (n = 0) then
WriteString ('GIMP Palette'#13#10'#'#13#10);
WriteString (NumStr4 (R) + NumStr4 (G) + NumStr4 (B) + ' Untitled'#13#10);
end;
end;
end;
finally
CloseFile (F);
end;
end;
PaletteColors.Repaint;
end;
end;
procedure TPaletteManager.edChange(Sender: TObject);
begin
GenerateButton.Enabled := CheckRGBDepth;
end;
procedure TPaletteManager.UseThisPaletteClick(Sender: TObject);
begin
if UseThisPalette.Checked then
SelectedPalette := PaletteTab.TabIndex;
SelectedPaletteChanged := TRUE;
end;
procedure TPaletteManager.SetAsDefaultClick(Sender: TObject);
begin
if SetAsDefault.Checked then
DefaultPalette := PaletteTab.TabIndex;
DefaultPaletteChanged := TRUE;
end;
procedure TPaletteManager.ClearPalettes;
var
i: Integer;
begin
for i := PaletteTab.Tabs.Count - 1 downto 0 do
PaletteTab.Tabs.Delete (i);
for i := 0 to Length (aaiPal) - 1 do
SetLength (aaiPal[i], 0);
SetLength (aiPalSize, 0);
SetLength (aiPreset, 0);
SetLength (aiOrig, 0);
DefaultPalette := -1;
SelectedPalette := -1;
end;
function TPaletteManager.GetID (n: Integer): string;
begin
if PaletteTab.Tabs.Count = 0 then // 2.32
GetID := ''
else
if not (n in [0..PaletteTab.Tabs.Count - 1]) then
GetID := ''
else
GetID := PaletteTab.Tabs.Strings[n];
end;
procedure TPaletteManager.setID (n: Integer; NewID: string);
begin
if n >= PaletteTab.Tabs.Count then
PaletteTab.Tabs.Add (NewID)
else
PaletteTab.Tabs.Strings[n] := NewID;
end;
procedure TPaletteManager.CopyButtonClick(Sender: TObject);
var
tab: Integer;
i: Integer;
begin
tab := PaletteTab.TabIndex;
if tab >= 0 then
begin
SetLength (aiClip, aiPreset[tab]);
for i := 0 to aiPreset[tab] - 1 do
aiClip[i] := aaiPal[tab, i];
EnableDisable;
end;
end;
procedure TPaletteManager.PasteButtonClick(Sender: TObject);
var
i: Integer;
tab: Integer;
begin
tab := PaletteTab.TabIndex;
i := 0;
if tab >= 0 then
while (i < Length (aiClip)) and (aiPreset[tab] < 256) do
begin
aaiPal[tab, aiPreset[tab]] := aiClip[i];
Inc (aiPreset[tab]);
if aiPreset[tab] > aiPalSize[tab] then
aiPalSize[tab] := aiPreset[tab];
Inc (i);
end;
PaletteTabChange (Sender);
PaletteTab.Repaint;
end;
end.