-
Notifications
You must be signed in to change notification settings - Fork 0
/
layerform1.pas
335 lines (300 loc) · 8.98 KB
/
layerform1.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
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
//Copyright (c) 2012 by Donald R. Ziesig
//
//Donald.at.Ziesig.org
//
//This file is part of MagicTracks.
//
//MagicTracks is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//MagicTracks is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with MagicTracks. If not, see <http://www.gnu.org/licenses/>.
unit LayerForm1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, ColorBox, Buttons, types, Layers1;
type
{ TLayerForm }
TLayerForm = class(TForm)
OkBitBtn: TBitBtn;
CancelBitBtn: TBitBtn;
SurfaceColorListBox: TColorListBox;
GroupBox2: TGroupBox;
Label3: TLabel;
ViewAllLayersButton: TButton;
ViewLayersCG: TCheckGroup;
LineColorListBox: TColorListBox;
LineStyleCB: TComboBox;
TrackTypeCB: TComboBox;
TrackTypeLabel: TLabel;
RailLabel: TLabel;
LineSizeCB: TComboBox;
LineStartCB: TComboBox;
LineEndingCB: TComboBox;
RailSizeCB: TComboBox;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
SizeLabel: TLabel;
LineStartLabel: TLabel;
LineEndingLabel: TLabel;
PaintBox1: TPaintBox;
EditLayerRG: TRadioGroup;
procedure OkBitBtnClick(Sender: TObject);
procedure EditLayerRGClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ViewAllLayersButtonClick(Sender: TObject);
procedure LineStyleCBChange(Sender: TObject);
procedure LineStyleCBDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure LineSizeCBChange(Sender: TObject);
procedure LineSizeCBDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure PaintBox1Paint(Sender: TObject);
private
{ private declarations }
fLayers : TLayers;
fActiveLayer : TLayer;
fViewLayers : TViewLayers;
procedure SetActiveLayer(const AValue: TLayer);
procedure ActiveLayerToControls;
procedure ControlsToActiveLayer;
procedure SetViewLayers( const AValue : TViewLayers );
procedure GetViewLayers( var AValue : TViewLayers );
public
{ public declarations }
property Layers : TLayers read fLayers;
procedure Assign( Source : TLayers);
property Activelayer : TLayer read fActiveLayer write SetActiveLayer;
end;
var
LayerForm: TLayerForm;
implementation
{$R *.lfm}
uses
Common1, LCLType;
{ TLayerForm }
procedure TLayerForm.ViewAllLayersButtonClick(Sender: TObject);
var
Kind : TLayerKinds;
begin
for Kind in TLayerKinds do
ViewLayersCG.Checked[ord(Kind)] := True;
end;
procedure TLayerForm.ActiveLayerToControls;
var
Lines : Boolean;
begin
LineColorListBox.ItemIndex := ActiveLayer.LineColor;
SurfaceColorListBox.ItemIndex := ActiveLayer.SurfaceColor;
LineStyleCB.ItemIndex := ActiveLayer.LineStyle;
LineSizeCB.ItemIndex := ActiveLayer.LineSize;
RailSizeCB.ItemIndex := ActiveLayer.RailSize;
LineStartCB.ItemIndex := ActiveLayer.LineStart;
LineEndingCB.ItemIndex := ActiveLayer.LineEnd;
TrackTypeCB.ItemIndex := ActiveLayer.TrackType;
Lines := ActiveLayer.LineStyle <= 4;
LineSizeCB.Visible := Lines;
SizeLabel.Visible := Lines;
RailSizeCB.Visible := not Lines;
RailLabel.Visible := not Lines;
LineEndingLabel.Visible := Lines;
LineEndingCB.Visible := Lines;
LineStartLabel.Visible := Lines;
LineStartCB.Visible := Lines;
TrackTypeLabel.visible := not Lines;
TrackTypeCB.Visible := not Lines;
end;
procedure TLayerForm.Assign(Source: TLayers);
var
Index : Integer;
begin
Layers.Assign( Source );
Index := ord(Layers.ActiveLayerKind);
fActiveLayer := nil;
Application.ProcessMessages; // Fix timing bug in Lazarus
ActiveLayer := TLayer(Layers.Items[Index]);
Application.ProcessMessages; // Fix timing bug in Lazarus
ActiveLayerToControls;
SetViewLayers(Layers.ViewLayers);
end;
procedure TLayerForm.OkBitBtnClick(Sender: TObject);
var
I : Integer;
begin
I := EditLayerRG.ItemIndex;
fActiveLayer := TLayer(Layers.Items[I]);
GetViewLayers(fViewLayers);
Layers.ViewLayers := fViewLayers;
ControlsToActiveLayer;
end;
procedure TLayerForm.ControlsToActiveLayer;
begin
if fActiveLayer = nil then raise Exception.Create('Active Layer = nil');
ActiveLayer.LineColor := LineColorListBox.ItemIndex;
ActiveLayer.SurfaceColor := SurfaceColorListBox.ItemIndex;
ActiveLayer.LineStyle := LineStyleCB.ItemIndex;
ActiveLayer.LineSize := LineSizeCB.ItemIndex;
ActiveLayer.RailSize := RailSizeCB.ItemIndex;
ActiveLayer.LineStart := LineStartCB.ItemIndex;
ActiveLayer.LineEnd := LineEndingCB.ItemIndex;
ActiveLayer.TrackType := TrackTypeCB.ItemIndex;
end;
procedure TLayerForm.LineStyleCBChange(Sender: TObject);
var
Lines : Boolean;
begin
Lines := LineStyleCB.ItemIndex <= 4;
RailLabel.Visible := not Lines;
RailSizeCB.Visible := not Lines;
SizeLabel.Visible := Lines;
LineSizeCB.Visible := Lines;
LineEndingLabel.Visible := Lines;
LineEndingCB.Visible := Lines;
LineStartLabel.Visible := Lines;
LineStartCB.Visible := Lines;
TrackTypeLabel.visible := not Lines;
TrackTypeCB.Visible := not Lines;
end;
procedure TLayerForm.LineStyleCBDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
var
ComboBox : TComboBox;
H, W : Integer;
BG, FG : TColor;
begin
BG := clGray;
FG := clGreen;
ComboBox := Control as TComboBox;
if State = [odNoAccel,odNoFocusRect] then
begin
BG := clWhite;
FG := clBlack;
end;
if odSelected in State then
begin
BG := clWhite;
FG := clBlack;
end;
if odFocused in State then
begin
BG := clBlack;
FG := clWhite;
end;
if odComboBoxEdit in State then
begin
BG := clWhite;
FG := clBlack;
ComboBox.Canvas.Font.Color := clBlack;
end;
ComboBox.Canvas.Brush.Color := BG;
ComboBox.Canvas.Pen.Color := FG;
ComboBox.Canvas.FillRect(ARect);
H := ARect.Top + ((ARect.Bottom - ARect.Top) div 2);
W := ARect.Right - ARect.Left;
if Index <= 4 then
begin
ComboBox.Canvas.Pen.Style := TPenStyle(Index);
ComboBox.Canvas.MoveTo(0,H);
ComboBox.Canvas.LineTo(W,H);
end
else
begin
ComboBox.Canvas.FillRect(ARect);
ComboBox.Canvas.TextOut(6,ARect.Top,ComboBox.Items[Index]);
end;
end;
procedure TLayerForm.EditLayerRGClick(Sender: TObject);
var
I : Integer;
begin
I := EditLayerRG.ItemIndex;
ActiveLayer := TLayer(Layers[I]);
Layers.ActiveLayerKind := TLayerKinds(I);
end;
procedure TLayerForm.FormCreate(Sender: TObject);
begin
fLayers := TLayers.Create;
end;
procedure TLayerForm.FormShow(Sender: TObject);
var
I : Integer;
begin
fActiveLayer := nil;
I := ord(Layers.ActiveLayerKind);
EditlayerRG.ItemIndex := I;
fActiveLayer := TLayer(Layers[I]);
ActiveLayerToControls;
end;
procedure TLayerForm.GetViewLayers(var AValue: TViewLayers);
var
I : TLayerKinds;
begin
AValue := [];
for I in TLayerKinds do
begin
if ViewLayersCG.Checked[ord(i)] then
AValue := AValue + [I];
end;
end;
procedure TLayerForm.LineSizeCBChange(Sender: TObject);
begin
end;
procedure TLayerForm.LineSizeCBDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
const
LineWidths : array[0..3] of Integer = (1,3,5,7);
var
ComboBox : TComboBox;
H, W : Integer;
begin
ComboBox := Control as TComboBox;
ComboBox.Canvas.Brush.Color := clWhite;
ComboBox.Canvas.FillRect(ARect);
H := ARect.Top + ((ARect.Bottom - ARect.Top) div 2);
W := ARect.Right - ARect.Left;
ComboBox.Canvas.Pen.Style := psSolid;
ComboBox.Canvas.Pen.Width := LineWidths[Index];
ComboBox.Canvas.Pen.Color := clBlack;
ComboBox.Canvas.MoveTo(0,H);
ComboBox.Canvas.LineTo(W,H);
end;
procedure TLayerForm.PaintBox1Paint(Sender: TObject);
var
DrawingRect : TRect;
begin
DrawingRect := RectToOrigin(PaintBox1.BoundsRect );
PaintBox1.Canvas.Brush.Style := bsSolid;
PaintBox1.Canvas.Brush.Color := clWhite;
PaintBox1.Canvas.Pen.Style := psSolid;
PaintBox1.Canvas.Pen.Color := clBlack;
PaintBox1.Canvas.Pen.Width := 1;
PaintBox1.Canvas.Rectangle( DrawingRect )
end;
procedure TLayerForm.SetActiveLayer(const AValue: TLayer);
begin
if fActiveLayer <> nil then
begin
ControlsToActiveLayer;
end;
fActiveLayer:=AValue;
ActiveLayerToControls;
end;
procedure TLayerForm.SetViewLayers(const AValue: TViewLayers);
var
I : TLayerKinds;
begin
for I in TLayerKinds do
ViewLayersCG.Checked[ord(I)] := I in AValue;
end;
end.