-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlib_unit.pas
More file actions
319 lines (217 loc) · 8.92 KB
/
lib_unit.pas
File metadata and controls
319 lines (217 loc) · 8.92 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
(*
================================================================================
This file is part of OpenTemplot2024, a computer program for the design of model railway track.
Copyright (C) 2024 Martin Wynne. email: martin@85a.uk
This program is free software: you may redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation, either version 3 of the Licence, or
(at your option) any later version.
This program 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 Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program. See the file: licence.txt
Or if not, refer to the web site: https://www.gnu.org/licenses/
================================================================================
This file was saved from Delphi5
This file was derived from Templot2 version 244e
*)
unit lib_unit;
{$MODE Delphi}
{$ALIGN OFF}
interface
uses
StdCtrls, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls;
type
Tlib_form = class(TForm)
hide_panel: TPanel;
hide_button: TButton;
lib_listbox: TListBox;
datestamp_label: TLabel;
empty_label: TLabel;
group_to_library_button: TButton;
store_control_button: TButton;
lib_label: TLabel;
count_label: TLabel;
procedure FormCreate(Sender: TObject);
procedure hide_buttonClick(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure lib_listboxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure lib_listboxMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure FormDeactivate(Sender: TObject);
procedure store_control_buttonClick(Sender: TObject);
procedure lib_listboxClick(Sender: TObject);
procedure group_to_library_buttonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
lib_form: Tlib_form;
implementation
{$R *.lfm}
uses
pad_unit,keep_select,math_unit;
//______________________________________________________________________________
procedure Tlib_form.FormCreate(Sender: TObject);
begin
pad_form.InsertControl(lib_form);
AutoScroll:=False;
ClientWidth:=200;
ClientHeight:=696;
end;
//______________________________________________________________________________
procedure Tlib_form.hide_buttonClick(Sender: TObject);
begin
Hide;
end;
//______________________________________________________________________________
procedure lib_resize;
begin
with lib_form do begin
hide_panel.Left:=Clientwidth-hide_panel.Width;
hide_panel.Top:=ClientHeight-hide_panel.Height-datestamp_label.Height;
store_control_button.Top:=hide_panel.Top-store_control_button.Height-datestamp_label.Height;
group_to_library_button.Top:=store_control_button.Top-group_to_library_button.Height-datestamp_label.Height;
lib_label.Top:=group_to_library_button.Top-lib_label.Height;
count_label.Top:=hide_panel.Top;
lib_listbox.Width:=ClientWidth;
lib_listbox.Height:=lib_label.Top-datestamp_label.Height;
lib_listbox.ItemHeight:=Round(lib_listbox.Width/2)+6+Canvas.TextHeight('A')*3 DIV 2; // allow for spacing around bitmap + text below it
end;//with
current_state(-1); // to update bitmaps
end;
//______________________________________________________________________________
procedure Tlib_form.FormResize(Sender: TObject);
begin
lib_resize;
end;
//______________________________________________________________________________
procedure Tlib_form.FormShow(Sender: TObject);
begin
lib_listbox.Visible:=(any_library>0);
end;
//______________________________________________________________________________
function create_rect(x1,y1,x2,y2:integer):TRect;
begin
RESULT:=Rect(x1,y1,x2,y2);
end;
//______________________________________________________________________________
procedure Tlib_form.lib_listboxDrawItem(Control:TWinControl; Index:Integer; Rect:TRect; State:TOwnerDrawState);
var
lib_rect,copy_rect,border_rect:TRect;
lib_w,lib_h:integer;
begin
with lib_listbox do begin
lib_w:=Tlib_item(Items.Objects[Index]).bitmap.Width;
lib_h:=Tlib_item(Items.Objects[Index]).bitmap.Height;
with Canvas do begin
Brush.Style:=bsSolid;
Pen.Width:=1;
if (odSelected in State)=True
then Brush.Color:=$00FF8000 // soft blue
else Brush.Color:=lib_listbox.Color;
FillRect(create_rect(Rect.Left,Rect.Top,Rect.Right,Rect.Bottom)); // this clears the item rectangle (old focus marks)
lib_rect:=create_rect(0,0,lib_w,lib_h);
copy_rect:=create_rect(Rect.Left+4, Rect.Top+4, Rect.Left+4+lib_w, Rect.Top+4+lib_h);
border_rect:=create_rect(Rect.Left+3, Rect.Top+3, Rect.Left+6+lib_w, Rect.Top+6+lib_h);
Brush.Color:=clWhite;
if (odSelected in State)=True
then Pen.Color:=$00FF8000 // soft blue
else Pen.Color:=clGray;
Pen.Style:=psSolid;
Rectangle(border_rect);
Brush.Color:=lib_listbox.Color;
CopyMode:=cmSrcCopy;
CopyRect(copy_rect,Tlib_item(Items.Objects[Index]).bitmap.Canvas,lib_rect);
if (odSelected in State)=True
then begin
Brush.Color:=$00FF8000; // soft blue
Font.Color:=clWhite;
end
else begin
Brush.Color:=lib_listbox.Color;
Font.Color:=clBlack;
end;
TextOut(Rect.Left+12, Rect.Top+8+lib_h, Items.Strings[Index]);
if (odFocused in State)=True then DrawFocusRect(Rect); // repeat XOR to remove focus rectangle
end;
end;
end;
//______________________________________________________________________________
procedure Tlib_form.lib_listboxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); // highlight on hover
var
n:integer;
lib_w,lib_h:integer;
begin
with lib_listbox do begin
for n:=0 to (Height DIV ItemHeight)-1 do begin
lib_w:=Tlib_item(Items.Objects[0]).bitmap.Width; // all same size
lib_h:=Tlib_item(Items.Objects[0]).bitmap.Height;
if (Y>ItemHeight*n+3) and (Y<ItemHeight*n+3+lib_h) and (X<lib_w+3)
then begin
if Canvas.Pixels[3,ItemHeight*n+3]=$00FF8000 then BREAK; // already highlighted or selected
Repaint; // remove previous highlighting
Application.ProcessMessages;
with Canvas do begin
Pen.Width:=2;
Pen.Color:=$00FF8000; // soft blue
Brush.Style:=bsClear;
Rectangle(create_rect(3,ItemHeight*n+3,lib_w+6,ItemHeight*n+lib_h+6));
end;//with
BREAK;
end;
end;//next
end;//with
end;
//______________________________________________________________________________
procedure Tlib_form.FormDeactivate(Sender: TObject);
begin
if Showing=True then lib_listbox.Repaint;
end;
//______________________________________________________________________________
procedure Tlib_form.store_control_buttonClick(Sender: TObject);
begin
if check_control_template_is_valid('store')=False then EXIT; // zero length
store_unused(True,False); // library_template,control_template_on_save
lib_form.lib_listbox.Visible:=(any_library>0); // 227a
end;
//______________________________________________________________________________
procedure Tlib_form.lib_listboxClick(Sender: TObject);
var
i:integer;
new_notch_data:Tnotch;
begin
with lib_listbox do begin
i:=ItemIndex;
if (i<0) or (i>(Items.Count-1)) then EXIT;
list_position:=Tlib_item(Items.Objects[i]).list_index;
end;//with
cancel_adjusts(False);
keep_form.copy_to_control_radiobutton.Checked:=True;
copy_keep_to_current(False,False,True,False); // on_reload, bgnd_options, name_options, mint_from
gocalc(0,0);
pad_form.notch_under_peg_menu_entry.Click; // to get peg angle
// move notch to screen centre, don't change angle ...
with new_notch_data do begin
notch_x:=zoom_offsetx+screenx/2;
notch_y:=zoom_offsety+screeny/2;
notch_k:=notch_angle;
end;//with
new_notch(new_notch_data,True);
pad_form.shift_current_onto_notch_menu_entry.Click;
pad_form.cycle_notch_menu_entry.Click; // restore it..
pad_form.cycle_notch_menu_entry.Click;
show_and_redraw(True,True); // in case curent hidden.
end;
//______________________________________________________________________________
procedure Tlib_form.group_to_library_buttonClick(Sender: TObject);
begin
create_copied_group(True,False); // library, unused
lib_form.lib_listbox.Visible:=(any_library>0); // 227a
end;
//______________________________________________________________________________
end.