-
Notifications
You must be signed in to change notification settings - Fork 4
/
rmcolor.pas
192 lines (147 loc) · 4.3 KB
/
rmcolor.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
unit rmcolor;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
ComCtrls, ColorPalette, RMCore;
type
{ TRMEGAColorDialog }
TRMEGAColorDialog = class(TForm)
EGAIndexLabel: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
OK: TButton;
ColorPalette1: TColorPalette;
Shape1: TShape;
TrackBar1: TTrackBar;
TrackBar2: TTrackBar;
TrackBar3: TTrackBar;
procedure ColorPalette1ColorPick(Sender: TObject; AColor: TColor;
Shift: TShiftState);
procedure OKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure InitColorBox;
procedure AddEGA64;
procedure UpdateColorChange;
procedure UpdateTrackValues;
// procedure TRMEGAColorDialog;
function GetPickedIndex : Integer;
function GetPickedColor : TColor;
procedure TrackBar1Change(Sender: TObject);
procedure TrackBar2Change(Sender: TObject);
procedure TrackBar3Change(Sender: TObject);
private
SelectedColor : integer;
PickedIndex : integer;
pickedColor : TColor;
end;
var
RMEGAColorDialog: TRMEGAColorDialog;
implementation
{$R *.lfm}
procedure TRMEGAColorDialog.FormCreate(Sender: TObject);
begin
end;
procedure TRMEGAColorDialog.OKClick(Sender: TObject);
begin
modalresult:= mrOk;
end;
procedure TRMEGAColorDialog.ColorPalette1ColorPick(Sender: TObject; AColor: TColor;
Shift: TShiftState);
begin
PickedIndex:=ColorPalette1.PickedIndex;
EGAIndexLabel.Caption:='EGA Index: '+IntToStr(PickedIndex);
PickedColor:=AColor;
Shape1.Brush.Color:=PickedColor;
UpdateTrackValues;
end;
procedure TRMEGAColorDialog.InitColorBox;
var
r,g,b : integer;
begin
PickedIndex:=-1;
SelectedColor:=RMCoreBase.GetCurColor;
r:=RMCoreBase.Palette.GetRed(SelectedColor);
g:=RMCoreBase.Palette.GetGreen(SelectedColor);
b:=RMCoreBase.Palette.GetBlue(SelectedColor);
SelectedColor:=RGBToEGAIndex(r,g,b);
ColorPalette1.ClearColors;
AddEGA64;
ColorPalette1.PickedIndex:=SelectedColor;
PickedColor:=rgbToColor(r,g,b);
Shape1.Brush.Color:=PickedColor;
EGAIndexLabel.Caption:='EGA Index: '+IntToStr(RGBToEGAIndex(r,g,b));
UpdateTrackValues;
end;
procedure TRMEGAColorDialog.AddEGA64;
var
i : integer;
tc : TColor;
cr : TRMColorRec;
begin
for i:=0 to 63 do
begin
GetDefaultRGBEGA64(i,cr);
TC:=RGBToColor(cr.r,cr.g,cr.b);
ColorPalette1.AddColor(TC);
end;
end;
function TRMEGAColorDialog.GetPickedIndex : integer;
begin
GetPickedIndex:=PickedIndex;
end;
function TRMEGAColorDialog.GetPickedColor : TColor;
begin
GetPickedColor:=PickedColor;
end;
procedure TRMEGAColorDialog.UpdateColorChange;
var
r,g,b : integer;
begin
r:=TwoToEightBit(TrackBar1.position);
g:=TwoToEightBit(TrackBar2.position);
b:=TwoToEightBit(TrackBar3.position);
PickedColor:=rgbToColor(r,g,b);
Shape1.Brush.Color:=PickedColor;
PickedIndex:=RGBToEGAIndex(r,g,b);
// VgaIndexLabel.Caption:='VGA Index: '+IntToStr(PickedIndex);
EGAIndexLabel.Caption:='EGA Index: '+IntToStr(PickedIndex);
ColorPalette1.PickedIndex:=PickedIndex;
// ColorPalette.Colors[PickedIndex]:=PickedColor;
end;
procedure TRMEGAColorDialog.UpdateTrackValues;
var
r,g,b : Byte;
begin
r:=Red(Shape1.Brush.Color);
g:=Green(Shape1.Brush.Color);
b:=Blue(Shape1.Brush.Color);
//TrackBar1.position:=round((double(r) * 63) / 255);
TrackBar1.position:=EightToTwoBit(r);
TrackBar2.position:=EightToTwoBit(g);
TrackBar3.position:=EightToTwoBit(b);
// Label4.Caption:=IntToStr(TrackBar1.position)+' '+IntToStr((TrackBar1.position * 255) div 63 );
Label4.Caption:='['+IntToStr(TrackBar1.position)+'] '+IntToStr(TwoToEightBit(TrackBar1.Position));
Label5.Caption:='['+IntToStr(TrackBar2.position)+'] '+IntToStr(TwoToEightBit(TrackBar2.Position));
Label6.Caption:='['+IntToStr(TrackBar3.position)+'] '+IntToStr(TwoToEightBit(TrackBar3.Position));
end;
procedure TRMEGAColorDialog.TrackBar1Change(Sender: TObject);
begin
UpdateColorChange;
UpdateTrackValues;
end;
procedure TRMEGAColorDialog.TrackBar2Change(Sender: TObject);
begin
UpdateColorChange;
UpdateTrackValues;
end;
procedure TRMEGAColorDialog.TrackBar3Change(Sender: TObject);
begin
UpdateColorChange;
UpdateTrackValues;
end;
end.