-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcomponent.pas
525 lines (488 loc) · 15.1 KB
/
component.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
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
unit component;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons;
type
TSeditform = class(TForm)
ListBox1: TListBox;
GB: TGroupBox;
PB: TPaintBox;
NewSymbolB: TBitBtn;
Symbolsave: TBitBtn;
GroupBox2: TGroupBox;
preview: TPaintBox;
Edit1: TEdit;
refreshB: TBitBtn;
BitBtn2: TBitBtn;
GroupBox1: TGroupBox;
L1x: TLabel;
L1y: TLabel;
L1mx: TLabel;
L1my: TLabel;
SB: TSpeedButton;
SBM: TSpeedButton;
L2x: TLabel;
L2y: TLabel;
L2mx: TLabel;
L2my: TLabel;
L3x: TLabel;
L3y: TLabel;
L3mx: TLabel;
L3my: TLabel;
L4x: TLabel;
L4y: TLabel;
L4mx: TLabel;
L4my: TLabel;
Button1: TButton;
procedure PBMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure NewSymbolBClick(Sender: TObject);
procedure SymbolsaveClick(Sender: TObject);
procedure refreshBClick(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure PBPaint(Sender: TObject);
procedure PPLabel(Sender: TObject);
procedure SBClick(Sender: TObject);
procedure SBMClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Seditform: TSeditform;
cursorx,cursory:byte;
PBFocus,getPP,getPPM:boolean;
implementation
uses main;
{$R *.DFM}
procedure ClearCursor;
Begin
//alte Cursor-Box grau überschreiben
SEditForm.pb.canvas.brush.Style:=bsclear;
SEditForm.pb.canvas.pen.color:=clgray;
SEditForm.pb.Canvas.Rectangle(cursorx*extentx,cursory*extenty,(cursorx+1)*extentx+1,(cursory+1)*extenty+1);
End;
procedure showcursor;
Begin;
//neuer Cursor anzeigen
SEditForm.pb.canvas.brush.Style:=bsclear;
SEditForm.pb.canvas.pen.color:=clblue;
SEditForm.pb.Canvas.Rectangle(cursorx*extentx,cursory*extenty,(cursorx+1)*extentx+1,(cursory+1)*extenty+1);
End;
Procedure ShowSymbol(const compindex:integer;var Target:TPaintBox);
var
ori,x,y,temp:byte;
Begin
//PaintBox löschen und Symbol in allen Ausrichtungen zeichen
SEditForm.PB.Canvas.Font.Color:=ClBlack;
Target.Canvas.FillRect(Rect(0,0,MatrixX*extentx,MatrixY*extenty)) ;
for ori:=1 to 4 do
for x:=0 to CompX-1 do
for y:=0 to CompY-1 do
Begin
If comp[compindex,ori,x,y]>0 Then
temp:=comp[compindex,ori,x,y]
Else temp:=32;
Target.Canvas.TextOut(x*extentx,(y+((ori-1)*compy))*extenty,chr(temp));
End;
End;
Procedure ShowPP(const compindex:integer);
var
ori,x,y,xm,ym:ShortInt;
Begin
PickPoints:=PickPointList.Items[compindex];
For ori:=0 to 3 do
Begin
x:=PickPoints^[ori].X;
y:=PickPoints^[ori].Y;
xm:=PickPoints^[ori].XM;
ym:=PickPoints^[ori].YM;
SEditForm.PB.Canvas.Font.Color:=clgreen;
SEditForm.PB.Canvas.TextOut(abs(x)*extentx,(abs(y)+CompY*ori)*extenty,'X');
SEditForm.PB.Canvas.Font.Color:=clyellow;
SEditForm.PB.Canvas.TextOut(abs(xm)*extentx,(abs(ym)+CompY*ori)*extenty,'M');
(SEditForm.FindComponent('L'+inttostr(ori+1)+'x')as TLabel).caption:='x= '+inttostr(x);
(SEditForm.FindComponent('L'+inttostr(ori+1)+'y')as TLabel).caption:='y= '+inttostr(y);
(SEditForm.FindComponent('L'+inttostr(ori+1)+'mx')as TLabel).caption:='x= '+inttostr(xm);
(SEditForm.FindComponent('L'+inttostr(ori+1)+'my')as TLabel).caption:='y= '+inttostr(ym);
if x>=0 Then
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'x')as TLabel).Tag:=0;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'x')as TLabel).Font.Color:=clgreen;
End
Else
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'x')as TLabel).Tag:=1;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'x')as TLabel).Font.Color:=clred;
End;
if y>=0 Then
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'y')as TLabel).Tag:=0;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'y')as TLabel).Font.Color:=clgreen;
End
Else
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'y')as TLabel).Tag:=1;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'y')as TLabel).Font.Color:=clred;
End;
if xm>=0 Then
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'mx')as TLabel).Tag:=0;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'mx')as TLabel).Font.Color:=clgreen;
End
Else
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'mx')as TLabel).Tag:=1;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'mx')as TLabel).Font.Color:=clred;
End;
if ym>=0 Then
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'my')as TLabel).Tag:=0;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'my')as TLabel).Font.Color:=clgreen;
End
Else
Begin
(SEditForm.FindComponent('L'+inttostr(ori+1)+'my')as TLabel).Tag:=1;
(SEditForm.FindComponent('L'+inttostr(ori+1)+'my')as TLabel).Font.Color:=clred;
End;
End;
End;
procedure InsertAndShowKey(const Key:Char);
var
ori,cy:byte;
Begin
ori:=trunc(CursorY/CompY); //ori aus der cursorposition berechnen
cy:=CursorY-(ori*CompY); //relativer Y-Cursor im Symbol berechnen
comp[SEditForm.listbox1.ItemIndex+1,ori+1,CursorX,cy]:=ord(key);
SEditForm.PB.canvas.brush.style:=bssolid;
SEditForm.PB.canvas.pen.color:=clblack;
SEditForm.PB.Canvas.TextOut(CursorX*ExtentX,CursorY*extentY,key);
End;
procedure PaintGrid;
var
temp:byte;
Begin
SEditForm.pb.canvas.pen.Color:=clgray;
for temp:=0 to compx do
Begin
SEditForm.pb.Canvas.MoveTo(temp*extentx,0);
SEditForm.pb.Canvas.LineTo(temp*extentx,compy*4*extenty);
End;
For temp:=0 to compy*4 do
Begin
If (temp mod compy)=0 Then SEditForm.pb.canvas.pen.color:=clred
Else SEditForm.pb.canvas.pen.color:=clgray;
SEditForm.pb.Canvas.MoveTo(0,temp*extenty);
SEditForm.pb.Canvas.LineTo(compx*extentx,temp*extenty);
End;
End;
procedure TSeditform.PBMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ori:byte;
begin
PBFocus:=True;
ClearCursor;
//neue Cursorposition berechnen
cursorx:=trunc(x/extentx); cursory:=trunc(y/extenty);
If getPP or getPPM then
Begin
PickPoints:=PickPointList.Items[SEditForm.listbox1.ItemIndex];
ori:=trunc(CursorY/CompY); //ori aus der cursorposition berechnen
If getPP Then
Begin
If (FindComponent('L'+inttostr(ori+1)+'x')as TLabel).Tag=0 Then
PickPoints^[ori].X:=CursorX
Else PickPoints^[ori].X:=-CursorX;
If (FindComponent('L'+inttostr(ori+1)+'y')as TLabel).Tag=0 Then
PickPoints^[ori].Y:=(CursorY-(ori*CompY))
Else PickPoints^[ori].Y:=-(CursorY-(ori*CompY));
End;
If getPPM Then
Begin
If (FindComponent('L'+inttostr(ori+1)+'mx')as TLabel).Tag=0 Then
PickPoints^[ori].XM:=CursorX
Else PickPoints^[ori].XM:=-CursorX;
If (FindComponent('L'+inttostr(ori+1)+'my')as TLabel).Tag=0 Then
PickPoints^[ori].YM:=(CursorY-(ori*CompY))
Else PickPoints^[ori].YM:=-(CursorY-(ori*CompY));
End;
PickPointList.Items[SEditForm.listbox1.ItemIndex]:=PickPoints;
PB.Cursor:=crHandPoint;
Seditform.refreshBClick(Sender);
showPP(ListBox1.ItemIndex);
End;
Showcursor;
end;
procedure TSeditform.FormKeyPress(Sender: TObject; var Key: Char);
begin
If PBFocus Then
Begin
clearcursor;
InsertAndShowKey(key);
If CursorX<(CompX-1) Then inc(cursorx)
Else
//CarryReturn And LineFeed ;-)
Begin CursorX:=0; INC(CursorY); End;
IF cursory>=compy*4 Then cursory:=0;
showcursor;
key:=chr(0);
End;
end;
procedure TSeditform.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
sendkey:char;
begin
If PBFocus Then
Begin
ClearCursor;
if (key=VK_UP) AND (cursory>0) then dec(cursory);
if (key=VK_down) AND (cursory<compy*4-1) then inc(cursory);
if (key=VK_right) AND (cursorx<compx-1) then inc(cursorx);
if (key=VK_left) AND (cursorx>0) then dec(cursorx);
Showcursor;
IF (KEY=VK_UP) OR (KEY=VK_down) OR(KEY=VK_left) OR(KEY=VK_right)
Then key:=0;
//pb.canvas.pen.color:=clblack;
//pb.canvas.brush.style:=bssolid;
//pb.canvas.brush.Color:=clsilver;
if key=VK_delete then
Begin
sendkey:=chr(0);
SEditForm.FormKeyPress(Sender,sendkey);
end;
key:=0;
End;
//key:=0;
end;
procedure TSeditform.FormShow(Sender: TObject);
begin
If Sprache=2 Then
Begin
seditform.NewSymbolB.caption:='new symbol';
seditform.Symbolsave.caption:='save symbols';
End;
pb.Width:=extentx*compx+1; pb.Height:=extenty*4*compy+1;
preview.Width:=compX*extentX+1; preview.Height:=compY*4*extentY+1;
listbox1.Items:=MainForm.listbox1.items;
listbox1.ItemIndex:=0;
//nEdit.Text:=Listbox1.Items[ListBox1.itemindex];
pbFocus:=False;
Seditform.refreshBClick(Sender);
end;
procedure TSeditform.ListBox1Click(Sender: TObject);
begin
PBFocus:=False;
GetPP:=False;
GetPPM:=False;
PB.Cursor:=crCross;
//nEdit.Text:=Listbox1.Items[ListBox1.itemindex];
pb.canvas.brush.style:=bssolid;
pb.Canvas.brush.Color:=clwhite;
ShowSymbol(Listbox1.ItemIndex+1,Seditform.pb);
ShowSymbol(Listbox1.ItemIndex+1,Seditform.preview);
PaintGrid;
//pb.Canvas.pen.color:=clblack;
end;
procedure TSeditform.NewSymbolBClick(Sender: TObject);
begin
listbox1.Items.Add(edit1.text);
PBFocus:=False;
GetPP:=False;
GetPPM:=False;
PB.Cursor:=crCross;
end;
function CheckEraser(const puffer:string):boolean;
Begin
Result:=( (pos('Eraser',puffer)>0) OR (pos('Viskelæder',puffer)>0) OR (pos('Radierer',puffer)>0))
End;
procedure FillEraser(const index:integer);
var
x,y,ori:integer;
Begin
// 2x2, 3x3, 4x4, 5x5 eraser anlegen;
for ori:=1 to 4 do
for y:=0 to CompY-1 do
for x:=0 to CompX-1 do
Begin
if ((x<ori+2) AND (y<ori+1)) Then comp[index,ori,x,y]:=32
Else comp[index,ori,x,y]:=0;
End;
End;
function AddPrefix(const z:shortint):shortstring;
Begin If z>=0 then result:='+'+inttostr(z) Else result:=inttostr(z); End;
procedure TSeditform.SymbolsaveClick(Sender: TObject);
var
BIB: TextFile;
filename:shortstring;
puffer:string;
x,y:integer; // Zähler für Raster
compindex,ori:byte; //orientation
char:byte;
name:shortstring;
PickPointsExist:boolean;
begin
// PBFocus:=False;
filename:=ExtractFilePath(Paramstr(0))+'component'+inttostr(sprache)+'.ini';
Assignfile(bib,filename);
rewrite(bib);
//reset(bib);
For compindex:=1 to listbox1.Items.Count Do
Begin
PickPointsExist:=((compindex-1)<(PickPointList.Count));
If PickPointsExist then PickPoints:=PickPointList.Items[compindex-1];
name:='<'+listbox1.Items[compindex-1]+'>';
//if ((name='<Radierer/Eraser>') OR (name='<Viskelæder>'))
If CheckEraser(name) Then FillEraser(compindex);
If PickPointsExist then puffer:=name+AddPrefix(PickPoints^[0].X)+AddPrefix(PickPoints^[0].Y)+' '+
AddPrefix(PickPoints^[0].XM)+AddPrefix(PickPoints^[0].YM)
else puffer:=name;
writeln(bib,puffer);
For ori:=1 to 4 Do
Begin
For y:=0 to compy-1 do
Begin
Puffer:='';
For x:=0 to compx-1 Do
Begin
char:=comp[compindex,ori,x,y];
IF (char=32) AND NOT CheckEraser(name)
Then char:=0;
puffer:=puffer+chr(char);
End;
writeln(bib,puffer);
End;
If ori<4 Then
Begin
If PickPointsExist then puffer:='<R>'+AddPrefix(PickPoints^[ori].X)+AddPrefix(PickPoints^[ori].Y)+' '+
AddPrefix(PickPoints^[ori].XM)+AddPrefix(PickPoints^[ori].YM)
else puffer:='<R>';
writeln(bib,puffer);
End;
End;
puffer:='</>';
writeln(bib,puffer);
End;
closefile(bib);
showmessage(ExtractFilePath(Paramstr(0))+'component'+inttostr(sprache)+'.ini'+' saved...');
end;
procedure TSeditform.refreshBClick(Sender: TObject);
begin
// ShowSymbol(Listbox1.ItemIndex+1,Seditform.preview);
// GetPP:=False;
pb.canvas.brush.style:=bssolid;
pb.Canvas.brush.Color:=clwhite;
ShowSymbol(Listbox1.ItemIndex+1,Seditform.pb);
ShowSymbol(Listbox1.ItemIndex+1,Seditform.preview);
PaintGrid;
end;
procedure TSeditform.Edit1Change(Sender: TObject);
begin
PBFocus:=False;
end;
procedure TSeditform.BitBtn2Click(Sender: TObject);
begin
LoadASC(MainForm.openasc.filename);
MainForm.neuzeichnen1Click(sender);
end;
procedure TSeditform.PBPaint(Sender: TObject);
begin
Seditform.refreshBClick(Sender);
end;
procedure TSeditform.PPLabel(Sender: TObject);
var
m_Label,x_Label,y_Label:boolean;
ori:byte;
begin
If TLabel(sender).Tag=1 Then
Begin
TLabel(sender).Tag:=0;
//TLabel(sender).Font.Color:=clgreen;
End
Else
Begin
TLabel(sender).Tag:=1;
//TLabel(sender).Font.Color:=clred;
End;
PickPoints:=PickPointList.Items[ListBox1.ItemIndex];
m_Label:=copy(TLabel(sender).name,3,1)='m';
If m_Label Then
Begin
x_Label:=copy(TLabel(sender).name,4,1)='x';
y_Label:=copy(TLabel(sender).name,4,1)='y';
End
Else
Begin
x_Label:=copy(TLabel(sender).name,3,1)='x';
y_Label:=copy(TLabel(sender).name,3,1)='y';
End;
ori:=strtoint(copy(TLabel(sender).name,2,1))-1;
If m_label Then
Begin
If x_Label Then
Begin
If TLabel(sender).Tag=1 Then
PickPoints^[ori].XM:=ABS(PickPoints^[ori].XM)*-1
Else
PickPoints^[ori].XM:=ABS(PickPoints^[ori].XM);
End;
If y_Label Then
Begin
If TLabel(sender).Tag=1 Then
PickPoints^[ori].YM:=ABS(PickPoints^[ori].YM)*-1
Else
PickPoints^[ori].YM:=ABS(PickPoints^[ori].YM);
End;
End
Else
Begin
If x_Label Then
Begin
If TLabel(sender).Tag=1 Then
PickPoints^[ori].X:=ABS(PickPoints^[ori].X)*-1
Else
PickPoints^[ori].X:=ABS(PickPoints^[ori].X);
End;
If y_Label Then
Begin
If TLabel(sender).Tag=1 Then
PickPoints^[ori].Y:=ABS(PickPoints^[ori].Y)*-1
Else
PickPoints^[ori].Y:=ABS(PickPoints^[ori].Y);
End;
End;
PickPointList.Items[SEditForm.listbox1.ItemIndex]:=PickPoints;
ShowPP(SEditForm.ListBox1.ItemIndex);
end;
procedure TSeditform.SBClick(Sender: TObject);
begin
getPP:=True;
getPPM:=False;
PB.Cursor:=crHandPoint;
// Seditform.refreshBClick(Sender);
// showPP(ListBox1.ItemIndex);
end;
procedure TSeditform.SBMClick(Sender: TObject);
begin
getPPM:=True;
getPP:=False;
PB.Cursor:=crHandPoint;
// Seditform.refreshBClick(Sender);
// showPP(ListBox1.ItemIndex);
end;
procedure TSeditform.Button1Click(Sender: TObject);
begin
Seditform.refreshBClick(Sender);
showPP(ListBox1.ItemIndex);
end;
end.