forked from asousa-feup/FEUPAutom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathG7Draw.pas
5427 lines (4458 loc) · 159 KB
/
G7Draw.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
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit G7Draw;
{$MODE Delphi}
interface
uses
{$IFDEF Windows}
Windows,
{$ENDIF}
SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Printers, ComCtrls, Buttons,
math, Grids, ValEdit, Menus, PairSplitter,
//XML (by BrunoAugusto)
laz2_DOM, laz2_XMLRead, laz2_XMLWrite, laz2_XMLUtils,
//SYN
SynEdit,
SynEditHighlighter,
SynHighlighterPas, SynHighlighterAny, SynHighlighterMulti, SynCompletion,
//OUTROS:
PrintersDlgs,FileUtil ;
type
TPrinterParmeters = record
X_resolution : Integer; // horizontal printer resolution, in dpi
Y_resolution : Integer; // vertical printer resolution, in dpi
pagerect : TRect; // total page, in paper coordinates
printorigin : TPoint;
end;
TBarType = (btUnknown, btHigh, btLow);
TG7Flag = (g7fInitial, g7fLinkVisible, g7fActive);
TG7Type = (g7oEmpty, g7oStep, g7oTransition, g7oComment, {g7oUpLink,} g7oJumpStart, g7oJumpFinish);
TG7Flags = set of TG7Flag;
const
G7TypeNames: array[TG7Type] of string =('Empty', 'Step', 'Transition', 'Comment', {'UpLink',} 'JumpStart', 'JumpFinish');
type
TG7Object = record
Page, CellX, CellY: integer;
BarInIdx, BarOutIdx: integer;
Name: string;
Flags: TG7Flags;
Text, Code : string;
G7Type: TG7Type;
// Cache Variables
JumpIdx: integer;
end;
TG7Bar = record
Connections : integer;
Cxi, Cxf, Cy, CyMax : integer; // sempre horizontal
BarType: TBarType;
InCount, OutCount: integer;
Page : integer;
end;
TG7Comment = record
CellX,CellY : integer;
Tag : integer;
Comment : string
end;
TRectOffs = record
Left, Top, Right, Bottom, OffX, OffY : integer;
end;
type
{ TFormG7 }
TFormG7 = class(TForm)
BBRun_GR7: TBitBtn;
BBStop_GR7: TBitBtn;
BCompile: TButton;
BDebug: TButton;
BDebugActivateRandom: TButton;
BDumpBars: TButton;
BDumpObjs: TButton;
BIniRun: TBitBtn;
BPrintTransPage0: TButton;
BPrintTransPage1: TButton;
BPrintTransPage2: TButton;
BPrintTransPage3: TButton;
BStepsPage1: TButton;
BStepsPage2: TButton;
BStepsPage3: TButton;
BStepsPage4: TButton;
CBBarNum: TCheckBox;
CBConfirmDel: TCheckBox;
CBCursors: TCheckBox;
CBDebugStuff: TCheckBox;
CBEliminateNewLine: TCheckBox;
CBRoundStates: TCheckBox;
CBShowCode: TCheckBox;
EditAnimation: TEdit;
EditDebugVar: TEdit;
ImageHelpToolBar: TImage;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label2: TLabel;
Label6: TLabel;
Label7: TLabel;
LabelSteps: TLabel;
LabelTransitions: TLabel;
Label9: TLabel;
LabelCodeAreaSize: TLabel;
LabelCodeAreaSize1: TLabel;
LabelPage0: TLabel;
LabelPage1: TLabel;
LabelPage2: TLabel;
LabelPage3: TLabel;
LabelZoom: TLabel;
Memo1: TMemo;
MenuIOs: TMenuItem;
MenuItem1: TMenuItem;
MenuG7STCompileRunOnce: TMenuItem;
MenuItem2: TMenuItem;
MenuDebugMode: TMenuItem;
MenuCBResetOutsAtStartCycle: TMenuItem;
MenuItem3: TMenuItem;
MenuRoundStates: TMenuItem;
MenuNewLineContinuous: TMenuItem;
MenuShowCode: TMenuItem;
MenuItem4: TMenuItem;
MenuStartQAtPg2: TMenuItem;
MenuItem5: TMenuItem;
MenuRedraw: TMenuItem;
MenuStartGradingProcess: TMenuItem;
MenuSelfGrade: TMenuItem;
MenuVars: TMenuItem;
PairSplitBottom: TPairSplitterSide;
PairSplitRight: TPairSplitter;
PairSplitUp: TPairSplitterSide;
Panel2Right: TPanel;
SPComment: TSpeedButton;
SPConnector: TSpeedButton;
SPEdit: TSpeedButton;
SPJump: TSpeedButton;
SPStepTransition: TSpeedButton;
SPUpLink: TSpeedButton;
SynCompletionG7: TSynCompletion;
SynEditST_G7: TSynEdit;
TBCodeAreaSize: TTrackBar;
TBFont: TTrackBar;
TBFontCodeEditor: TTrackBar;
TBPage: TTrackBar;
TBStepHeight: TTrackBar;
TBZoom: TTrackBar;
Timer1: TTimer;
PrintDialog1: TPrintDialog; //ja da
G7_MainMenu: TMainMenu;
MenuEdit: TMenuItem;
MenuFile: TMenuItem;
G7_PopupMenu: TPopupMenu;
PopMenuInsertRow: TMenuItem;
PopMenuShiftRow: TMenuItem;
MenuUndo: TMenuItem;
PopMenuInsertCol: TMenuItem;
PopMenuShiftCol: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
MenuView: TMenuItem;
ToolBar: TToolBar;
ToolBar1: TToolBar;
VLEPropEdit: TValueListEditor;
Zoom1: TMenuItem;
MenuZoom200: TMenuItem;
MenuZoom100: TMenuItem;
MenuZoom50: TMenuItem;
MenuZoom25: TMenuItem;
MenuZoom20: TMenuItem;
N3: TMenuItem;
MenuZoomIn: TMenuItem;
MenuZoomOut: TMenuItem;
N4: TMenuItem;
MenuAbout: TMenuItem;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
N5: TMenuItem;
MenuExit: TMenuItem;
N6: TMenuItem;
MenuPrint: TMenuItem;
MenuNew: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
MenuDelete: TMenuItem;
MenuZoom33: TMenuItem;
MenuProject: TMenuItem;
MenuProjectEdit: TMenuItem;
Label3: TLabel;
Label4: TLabel;
PopMenuClearRow: TMenuItem;
PopupMenuClearCol: TMenuItem;
PopMenuUndo: TMenuItem;
N9: TMenuItem;
PopMenuDelete: TMenuItem;
Label5: TLabel;
MenuGenCod: TMenuItem;
UndoLastCodeGeneration1: TMenuItem;
MenuSaveProject: TMenuItem;
N10: TMenuItem;
MenuG7STCompile: TMenuItem;
MenuG7STRun: TMenuItem;
StatusBarG7: TStatusBar;
Splitter1: TSplitter;
Panel1Left: TPanel;
ScrollBox1: TScrollBox;
ImageG7: TImage;
N13: TMenuItem;
MenuedrawAll: TMenuItem;
MenuWindow: TMenuItem;
MenuST: TMenuItem;
LabelZones: TLabel;
N15: TMenuItem;
MenuG7STC: TMenuItem;
procedure BBRun_GR7Click(Sender: TObject);
procedure BBStop_GR7Click(Sender: TObject);
procedure BIniRunClick(Sender: TObject);
procedure BPrintTransPage0Click(Sender: TObject);
procedure BPrintTransPage_x_Click(Sender: TObject);
procedure CBDebugStuffChange(Sender: TObject);
procedure CBEliminateNewLineChange(Sender: TObject);
procedure EditDebugVarChange(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BRedrawAllClick(Sender: TObject);
procedure ImagesMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ImageG7MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure ImageG7MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BDebugClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure MenuCBResetOutsAtStartCycleClick(Sender: TObject);
procedure MenuedrawAllClick(Sender: TObject);
procedure MenuIOsClick(Sender: TObject);
procedure MenuItem1Click(Sender: TObject);
procedure MenuG7STCompileRunOnceClick(Sender: TObject);
procedure MenuItem3Click(Sender: TObject);
procedure MenuNewLineContinuousClick(Sender: TObject);
procedure MenuRedrawClick(Sender: TObject);
procedure MenuSelfGradeClick(Sender: TObject);
procedure MenuShowSelfGradeClick(Sender: TObject);
procedure MenuStartQAtPg2Click(Sender: TObject);
procedure MenuStartStopGradingClick(Sender: TObject);
procedure MenuVarsClick(Sender: TObject);
procedure PairSplitUpMouseEnter(Sender: TObject);
procedure PairSplitUpResize(Sender: TObject);
procedure SynEditST_G7MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure TBFontCodeEditorChange(Sender: TObject);
procedure SPModesClick(Sender: TObject);
procedure BInsertRowClick(Sender: TObject);
procedure BInsertColClick(Sender: TObject);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure MenuUndoClick(Sender: TObject);
procedure TBStepHeightChange(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
//procedure VLEPropEditEditButtonClick(Sender: TObject);
procedure VLEPropEditValidate(Sender: TObject; ACol, ARow: Integer;
const KeyName, KeyValue: String);
procedure VLEPropEditKeyPress(Sender: TObject; var Key: Char);
procedure PopMenuInsertRowClick(Sender: TObject);
procedure PopMenuShiftRowClick(Sender: TObject);
procedure PopMenuInsertColClick(Sender: TObject);
procedure PopMenuShiftColClick(Sender: TObject);
procedure MenuZoomClick(Sender: TObject);
procedure MenuZoomInClick(Sender: TObject);
procedure MenuZoomOutClick(Sender: TObject);
procedure TBZoomChange(Sender: TObject);
procedure MenuExitClick(Sender: TObject);
// procedure MenuLoadClick(Sender: TObject);
// procedure MenuSaveASClick(Sender: TObject);
procedure MenuPrintClick(Sender: TObject);
procedure MenuNewClick(Sender: TObject);
procedure MenuSaveClick(Sender: TObject);
procedure MenuDeleteClick(Sender: TObject);
procedure CBRoundStatesClick(Sender: TObject);
procedure CBEliminateNewLineClick(Sender: TObject);
procedure MenuProjectEditClick(Sender: TObject);
procedure TBPageChange(Sender: TObject);
procedure CBShowCodeClick(Sender: TObject);
procedure PopMenuClearRowClick(Sender: TObject);
procedure PopupMenuClearColClick(Sender: TObject);
procedure PopMenuDeleteClick(Sender: TObject);
procedure BCompileClick(Sender: TObject);
procedure BDebugActivateRandomClick(Sender: TObject);
procedure BDumpObjsClick(Sender: TObject);
procedure BDumpBarsClick(Sender: TObject);
procedure BUndoGenCodeClick(Sender: TObject);
procedure CBDebugStuffClick(Sender: TObject);
procedure MenuGenCodClick(Sender: TObject);
procedure UndoLastCodeGeneration1Click(Sender: TObject);
procedure BStepsPage_x_Click(Sender: TObject);
function G7LoadXML(const fn: string; onlyG7:boolean; SaveProjDoc:TDOMNode;
ImportGr7Page3Mode : Boolean = FALSE): boolean;
function G7SaveXML(const fn: string; onlyG7:boolean; SaveProjDoc:TXMLDocument):boolean;
procedure g7Print;
procedure ZapClick(Sender: TObject);
procedure SynEditST_G7Change(Sender: TObject);
procedure SynEditST_G7Exit(Sender: TObject);
procedure MenuSaveProjectClick(Sender: TObject);
procedure MenuSaveproject1Click(Sender: TObject);
procedure MenuG7STCompileClick(Sender: TObject);
procedure MenuG7STRunClick(Sender: TObject);
procedure TBFontChange(Sender: TObject);
procedure TBCodeAreaSizeChange(Sender: TObject);
procedure MenuAboutClick(Sender: TObject);
procedure FormInit;
procedure ImageHelpCodeAreaClick(Sender: TObject);
procedure MenuSTClick(Sender: TObject);
procedure MenuG7STCClick(Sender: TObject);
function DeleteObjectsInPage(DelPage : integer) : integer; // No Cleaning :(
private
procedure G7CleanUpForImport;
//procedure StopFlicker(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
function G7CreateObj(const pg, cx, cy : integer): integer;
function G7CreateStep(const pg, cx, cy: integer): integer;
function G7CreateTr(const pg, cx, cy: integer): integer;
function G7CreateJumpFinish(const pg, cx, cy: integer): integer;
function G7CreateJumpStart(const pg, cx, cy: integer): integer;
function G7CreateComment(const pg, cx, cy: integer): integer;
procedure G7DrawGrid;
procedure G7DrawStep(idx: integer);
procedure G7DrawTr(idx: integer);
procedure G7DrawJumpStart(idx: integer);
procedure G7DrawJumpFinish(idx: integer);
procedure G7DrawComment(idx: integer);
procedure G7DrawObject(i: integer);
procedure G7ShowModeInStatusBar();
procedure G7TextWrap( const r : trect; const TheText : string; const SubstituteNewLine:boolean=False) ;
procedure G7PixToCells(const x, y: integer; out CellX, CellY: integer);
function G7GetObjectAtPix(const clickX,clickY : integer; out G7ObjIdx : integer) : boolean;
function G7CellToRect(const xcell,ycell:integer; const R : TRect; const xoff : integer=0; const yoff: integer=0) : Trect; overload;
function G7CellToRect(const xcell,ycell:integer; const R : TRectOffs) : Trect; overload;
function G7CellToRect(const xcell,ycell, xi,yi, xf, yf:integer; const xoff : integer=0; const yoff: integer=0):Trect; overload;
// procedure UnselectAll;
// procedure AddToSelection(TheTr : TG7Tr); overload;
// procedure AddToSelection(TheStep: TG7Step); overload;
function G7GetFreeIndex: integer;
procedure G7SelectObject(ObjIdx: integer);
function IsMoveValid(Cx, Cy, G7ObjIdx: Integer): boolean;
function G7GetFreeBar: integer;
procedure G7Clear;
function IsDoubleLine(idx: integer): boolean;
procedure SetTemporaryTool(const shift : TShiftState);
function IsOverlappingAnotherBar(idx : integer) : boolean;
procedure G7DeleteObj(idx: integer);
function G7ObjIsStepLike(objIdx: integer): boolean;
function G7ObjIsTransitionLike(objIdx: integer): boolean;
function FindG7Name(theName: String; TheG7Type: TG7Type): integer;
function G7FlagsToInteger(TheFlags: TG7Flags): integer;
function G7IntegerToG7Flags(TheInt: integer): TG7Flags;
procedure G7InitCursors;
procedure DupG7Objects;
procedure G7UndoDupG7Objects;
function G7InsertRow(const TheRow : integer =-1) : boolean;
function G7InsertCol(const TheCol : integer =-1) : boolean;
function G7ShiftRow(const TheRow : integer =-1) : boolean;
function G7ShiftCol(const TheCol : integer =-1) : boolean;
function G7ClearCol(const TheCol : integer =-1; const ThePage : integer =-1) : boolean;
function G7ClearRow(const TheRow : integer =-1): boolean;
function G7GetObjectAtCell(const cx, cy : integer; out G7ObjIdx : integer) : boolean;
function G7GetZoomPercent: integer;
procedure G7SetZoomPercent(const WantZoom: integer);
procedure G7DrawaGridHoriz(const SubCellY : integer);
procedure G7DrawaGridVert(const SubCellX: integer);
function G7IsPhantom(const idx: integer): boolean;
function G7IsSelected(const idx: integer): boolean;
procedure G7DrawLine(const obj_i, obj_f, cxi,cyi,cxf,cyf : integer; DoubleLine : Boolean = False; UpLinkLine : boolean =False );
procedure G7GetDrawPix(idx: integer; below: boolean; out pixX, pixY: integer);
function IsValidCreateLink(const ConStartObjIdx, ConFinishObjIdx : integer) : boolean;
function IsValidAddToLink(const ConStartObjIdx, ConFinishObjIdx,
BarIdx: integer): boolean;
function IsCompatibleBar(const ConStartObjIdx, ConFinishObjIdx,
BarIdx: integer): boolean;
procedure G7ShowModeInStatursBar;
procedure VLEPropEditValidateAndSet(ObjIdx: Integer; const KeyName, KeyValue: String);
procedure G7ResetGUI;
procedure CalculateRectangles;
procedure CalculateDependents;
function GetStepIdx(const SearchName: string): integer;
function GetObjIdx(const SearchName: string): integer;
// procedure FlickerMode(const FullDrawWithFlicker: boolean);
procedure AppendZone(const source : TStrings;const CurPage:integer;const nameOfZone : string);
procedure AppendTitle(const source : TStrings;const CurPage:integer;const title : string);
public
MouseDownX, MouseDownY : integer;
ElasticXi,ElasticYi,ElasticXf,ElasticYf : integer;
CurG7Canvas : TCanvas;
g7Zoom : Double;
actPage, FontZoom: integer;
UpStartObj, UpFinishObj : TG7Object;
UpValid : boolean;
UpCurLabel : string;
MoveCellXOrigin, MoveCellYOrigin: integer;
MoveCellXOffset, MoveCellYOffset: integer;
MoveCellYMinLimit, MoveCellYMaxLimit, MoveCellYQuantum: integer;
MoveActive, MoveValid: boolean;
ConStartObjIdx, ConFinishObjIdx: integer;
TemporaryToolStatus : integer;
StepPrefix, TrPrefix,JumpPrefix, CommentPrefix: string;
StepCount, TrCount, JumpStartCount, JumpFinishCount, CommentCount : integer;
crG7Edit, crG7Move, crG7Step, crG7Tr, crG7Connect, crG7Disconnect, crG7Uplink,
crG7Delete, crG7Jumps: integer;
MouseMoveOldCX, MouseMoveOldCY : integer;
LabelPages : array [0..3] of TLabel;
published
function G7GetIdxFromName(theLabel: String; TheG7Type: TG7Type): integer;
procedure SetStepActivity(aStepIdx: integer; activeStep: boolean);
procedure G7RedrawAll;
function GenSTCode(InteratctiveMode: Boolean=True): Boolean;
procedure G7PageStart(const ThePage: integer);
procedure G7PageClear(const ThePage: integer);
end;
function GetStudentNumbers : string;
procedure ShowMessageOrLog(TheText : string);
Function SpecialSGFixAllG7Obj() : integer;
var
FormG7, FormViewG7 : TFormG7;
implementation
uses StrUtils, Types, G7Project, Main, G7Editor, StructuredTextUtils,
Variables, IOLeds, structuredtext2pas, ProjManage, Splash, SelfGrade;
{$R *.lfm}
//---------------------------------------------------------------------
// Global to this unit
//---------------------------------------------------------------------
var
// SubCell size (in pixels)
SubCellHeight,
SubCellWidth : integer;
// Object size (in subcells)
SizeX ,
StepSizeX ,
StepSizeY ,
TrSizeX ,
TrSizeY ,
BarSizeY ,
CellWidth ,
BlockHeight ,
BlockHeightPix : integer;
// Size of Sheet (in cells)
MaxCellsX ,
MaxCellsY ,
FullX ,
FullY : integer;
// Size of Sheet (in Pixels)
FullXPix ,
FullYPix : integer;
// Rectangles with offset - for each object (rect in subcells, offs in pixels)
StepOuterRect ,
StepInnerRect ,
StepRect_1 ,
StepRect_2 ,
StepRect_3 ,
StepLeftHalf ,
StepRightHalf ,
TrRect ,
TrRect_1 ,
TrLeftHalf ,
TrRightHalf ,
BarRect ,
JumpStartRect ,
JumpStartLeftHalf ,
JumpFinishRect ,
JumpFinishLeftHalf ,
CommentRect ,
InnerCommentRect : TRectOffs;
// Colors
clStep ,
clTr ,
clBkg ,
clCellGrid ,
clSubCellGrid ,
clCoded ,
clDistroUnconn ,
clDistroConn ,
clSelected ,
ClComment ,
clPhantom ,
clMove ,
clJumpStart ,
clJumpFinish ,
clElastic : TColor;
const
MAXG7Objects = 2048;
MAXG7Bars = 2048;
crlf=#13#10;
type
TG7Objects = array [0..MAXG7Objects+2] of TG7Object; // Last 2 are phantom objects
TG7Bars = array [0..MAXG7Bars-1] of TG7Bar;
var
SequenceYY : array [0..3] of integer;
ThresholdsYY : array [0..3] of integer;
G7Objects, G7ObjectsDup: TG7Objects;
G7ObjectsCount, G7ObjectsCountDup: integer;
SelectedG7Obj, SelectedG7ObjCount, SelectedG7ObjDup, SelectedG7ObjCountDup, G7BarsCountDup: integer;
G7Bars: TG7Bars;
G7BarsCount: integer;
//CREATE FORM:
procedure TFormG7.FormCreate(Sender: TObject);
//var xy:Boolean;
// kw: TSynHighlighterAttributes;
begin
//MenuZoomOut.ShortCut := ShortCut(Word('-'), [ssCtrl]);
FormG7.KeyPreview := True; //To keys work
FormG7.DoubleBuffered:=True;
ScrollBox1.DoubleBuffered:=True;
FormG7.MouseMoveOldCX:=-1;
FormG7.MouseMoveOldCY:=-1;
G7InitCursors();
StepPrefix := 'X';
TrPrefix := 't';
JumpPrefix:='Jump';
CommentPrefix:='Comment';
G7Clear;
MoveCellYQuantum := 4;
SequenceYY[0] := StepSizeY;
SequenceYY[1] := BarSizeY;
SequenceYY[2] := TrSizeY;
SequenceYY[3] := BarSizeY;
ThresholdsYY[0]:=StepSizeY;
ThresholdsYY[1]:=StepSizeY + BarSizeY;
ThresholdsYY[2]:=StepSizeY + BarSizeY + TrSizeY;
ThresholdsYY[3]:=StepSizeY + BarSizeY + TrSizeY + BarSizeY;
ImageG7.Height := 2048;
ImageG7.Width := 2048;
CurG7Canvas := ImageG7.Canvas;
G7ResetGUI;
SynEditST_G7.Tag:=-1;
LabelPages[0] := LabelPage0;
LabelPages[1] := LabelPage1;
LabelPages[2] := LabelPage2;
LabelPages[3] := LabelPage3;
end;
procedure TFormG7.BBStop_GR7Click(Sender: TObject);
begin
FMain.BBStopClick(Sender);
end;
procedure TFormG7.BIniRunClick(Sender: TObject);
begin
if (GenSTCode()) then begin
MenuG7STCompileClick(Sender);
FMain.MenuClearAllClick(Sender);
BBRun_GR7Click(Sender);
end;
end;
procedure TFormG7.BPrintTransPage0Click(Sender: TObject);
begin
end;
procedure TFormG7.BStepsPage_x_Click(Sender: TObject);
var i : integer;
begin
// FontZoom:=FontZoom+1;
// if FontZoom>4 then FontZoom:=-4;
// SynEditST_G7.Font.Size := 9+FontZoom;
// BRedrawAllClick(Sender);
if SelectedG7Obj<0 then begin beep;exit; end;
for i:=0 to high(G7Objects) do begin
if (G7Objects[i].Page=(sender as TButton).tag) and
(G7Objects[i].G7Type=g7oStep) and
(length(trim(G7Objects[i].Name))>0) then begin
SynEditST_G7.Append(G7Objects[i].Name+':=False;');
end;
end;
SynEditST_G7Change(Sender);
end;
procedure TFormG7.BPrintTransPage_x_Click(Sender: TObject);
var
i : integer;
begin
if SelectedG7Obj<0 then begin beep;exit; end;
for i:=0 to high(G7Objects) do begin
if (G7Objects[i].Page=(sender as TButton).tag) and
(G7Objects[i].G7Type=g7oTransition) and
(length(trim(G7Objects[i].Name))>0) then begin
SynEditST_G7.Append(G7Objects[i].Name+':=False;');
end;
end;
SynEditST_G7Change(Sender);
end;
procedure TFormG7.CBDebugStuffChange(Sender: TObject);
begin
Memo1.Visible := CBDebugStuff.Checked;
CBCursors.Visible := CBDebugStuff.Checked;
BDumpObjs.Visible := CBDebugStuff.Checked;
BDumpBars.Visible := CBDebugStuff.Checked;
BDebugActivateRandom.Visible := CBDebugStuff.Checked;
BCompile.Visible := CBDebugStuff.Checked;
BDebug.Visible := CBDebugStuff.Checked;
//EditDebug.Visible := CBDebugStuff.Checked;
BStepsPage1.Visible:=not CBDebugStuff.Checked;
BStepsPage2.Visible:=not CBDebugStuff.Checked;
BStepsPage3.Visible:=not CBDebugStuff.Checked;
BStepsPage4.Visible:=not CBDebugStuff.Checked;
BPrintTransPage0.Visible:=not CBDebugStuff.Checked;
BPrintTransPage1.Visible:=not CBDebugStuff.Checked;
BPrintTransPage2.Visible:=not CBDebugStuff.Checked;
BPrintTransPage3.Visible:=not CBDebugStuff.Checked;
LabelSteps.Visible:=not CBDebugStuff.Checked;
LabelTransitions.Visible:=not CBDebugStuff.Checked;
end;
procedure TFormG7.CBEliminateNewLineChange(Sender: TObject);
begin
end;
procedure TFormG7.EditDebugVarChange(Sender: TObject);
begin
FMain.StatusVarName := EditDebugVar.Text;
FMain.UpdateStatusVar();
end;
procedure TFormG7.FormActivate(Sender: TObject);
begin
PairSplitUp.Repaint;
end;
procedure TFormG7.BBRun_GR7Click(Sender: TObject);
begin
if (GenSTCode()) then begin
MenuG7STCompileClick(Sender);
FMain.BBRunClick(Sender);
end;
end;
function TFormG7.G7CellToRect(const xcell,ycell:integer; const R : TRect; const xoff : integer=0; const yoff: integer=0) : Trect;
begin
with R do
result:=G7CellToRect(xcell, ycell, left, top, right, bottom, xoff, yoff);
end;
function TFormG7.G7CellToRect(const xcell,ycell:integer; const R : TRectOffs) : Trect;
begin
with R do
result:=G7CellToRect(xcell, ycell, left, top, right, bottom, OffX, OffY);
end;
function TFormG7.G7CellToRect(const xcell,ycell, xi,yi, xf, yf:integer; const xoff : integer=0; const yoff: integer=0):Trect;
var VertBlocks, remainder : integer;
begin
with result do begin
// Left:= xoff + round((xCell * CellWidth + SubCellWidth * xi) * G7Zoom);
// Right:= -xoff + round((xCell * CellWidth + SubCellWidth * xf) * G7Zoom );
// Top := yoff + round((yCell * CellHeight + SubCellHeight * yi) * G7Zoom);
// Bottom:= -yoff + round((yCell * CellHeight + SubCellHeight * yf) * G7Zoom );
Left:= xoff + round((xCell * SizeX * SubCellWidth + SubCellWidth * xi) * G7Zoom);
Right:= -xoff + round((xCell * SizeX * SubCellWidth + SubCellWidth * xf) * G7Zoom );
VertBlocks := ycell div 4;
remainder := ycell - (VertBlocks*4);
Top := round ( VertBlocks * BlockHeight * SubCellHeight * G7Zoom ) ;
if remainder>2 then
top:=top+round(ThresholdsYY[2]*SubCellHeight*g7Zoom)
else
if remainder>1 then
top:=top+round(ThresholdsYY[1]*SubCellHeight*g7Zoom)
else
if remainder>0 then
top:=top+round(ThresholdsYY[0]*SubCellHeight*g7Zoom);
Bottom := -yoff + Top + round(SubCellHeight * yf * G7Zoom);
Top := yoff + Top + round(SubCellHeight * yi * G7Zoom);
end;
end;
function TFormG7.G7GetFreeIndex: integer;
begin
result := -1;
if G7ObjectsCount >= MAXG7Objects-1 then exit;
result:=0;
while G7Objects[result].G7Type <> g7oempty do begin
inc(result);
if result >= G7ObjectsCount then break;
end;
end;
procedure TFormG7.G7ResetGUI;
begin
actPage:=0;
G7SetZoomPercent(75);
end;
procedure TFormG7.G7Clear;
var i:integer;
begin
zeromemory(@G7Objects,sizeof(G7Objects));
G7ObjectsCount:= 0;
SelectedG7Obj := -1;
SelectedG7ObjCount := 0;
zeromemory(@G7Bars, sizeof(G7Bars));
G7BarsCount := 0;
StepCount := 0;
TrCount:=0;
CommentCount:=0;
JumpStartCount:=0;
JumpFinishCount:=0;
for i:=0 to high(G7Objects) do with G7Objects[i] do begin
BarInIdx := -1;
BarOutIdx := -1;
JumpIdx := -1;
end;
with UpStartObj do begin
BarInIdx := -1;
BarOutIdx := -1;
JumpIdx := -1;
end;
with UpFinishObj do begin
BarInIdx := -1;
BarOutIdx := -1;
JumpIdx := -1;
end;
end;
function TFormG7.DeleteObjectsInPage(DelPage : integer) : integer; // No Cleaning :(
var
i,cnt : integer;
begin
cnt := 0;
for i:=0 to high(G7Objects) do begin
if (G7Objects[i].G7Type <> g7oEmpty) AND
(G7Objects[i].Page = DelPage) then begin
// G7DeleteObj(i);
inc(cnt);
end;
end;
result := cnt;
for i:=0 to MaxCellsX-1 do begin
G7ClearCol(i, DelPage);
end;
end;
function TFormG7.G7IsSelected(const idx : integer) : boolean;
begin
result:=(idx = SelectedG7Obj);
end;
function TFormG7.G7IsPhantom(const idx : integer) : boolean;
begin
result:=(idx >= MAXG7Objects);
end;
procedure TFormG7.G7GetDrawPix(idx : integer; below : boolean; out pixX, pixY : integer);
var r : TRect;
begin
if idx=-1 then exit;
with G7Objects[idx] do begin
if G7Type = g7oStep then begin
r:=G7CellToRect(CellX,CellY,StepInnerRect);
end else
if G7Objects[idx].G7Type = g7oTransition then begin
r:=G7CellToRect(CellX,CellY,TrRect);
end else
if G7Objects[idx].G7Type = g7oJumpStart then begin
r:=G7CellToRect(CellX,CellY,JumpStartRect);
end else
if G7Objects[idx].G7Type = g7oJumpFinish then begin
r:=G7CellToRect(CellX,CellY,JumpFinishRect);
end else
if G7Objects[idx].G7Type = g7oComment then begin
r:=G7CellToRect(CellX,CellY,TrRect);
end else
if G7Objects[idx].G7Type = g7oEmpty then begin
r:=G7CellToRect(CellX,CellY,TrRect); // disfarçador de bugs !!!!!!!
end;
pixX := CenterPoint(r).X;
if below then begin
pixY := r.Bottom;
end else begin // ABOVE
pixY := r.Top;
end;
end;
end;
procedure TFormG7.G7DrawLine(const obj_i, obj_f, cxi,cyi,cxf,cyf : integer; DoubleLine : Boolean = False; UpLinkLine : boolean =False );
var
xi,xf,yi,yf: integer;
r : TRect;
begin
//if G7GetObjectAtCell(cxi,cyi,obj_i) then begin
if obj_i <> -1 then begin
G7GetDrawPix(obj_i, True, xi, yi);
end else begin
r:=G7CellToRect(cxi,cyi,BarRect);
with CenterPoint(r) do begin
xi := X;
yi := Y;
end;
end;
//if G7GetObjectAtCell(cxf,cyf,obj_f) then
if obj_f <> -1 then
G7GetDrawPix(obj_f, False, xf, yf)
else begin
r:=G7CellToRect(cxf,cyf,BarRect);
with CenterPoint(r) do begin
xf := X;
yf := Y;
end;
end;
if DoubleLine then begin
CurG7Canvas.MoveTo(xi,yi-1);
CurG7Canvas.LineTo(xf,yf-1);
CurG7Canvas.MoveTo(xi,yi+1);
CurG7Canvas.LineTo(xf,yf+1);
end else begin
CurG7Canvas.MoveTo(xi,yi);
CurG7Canvas.LineTo(xf,yf);
end;
if UpLinkLine and (yi<yf) then
if (cxi=cxf) then begin // uplink Rever -> UPARROW
//Brush.Style:=bsClear;
//CurG7Canvas.TextOut(xi-4, (yi+yf) div 2, '^');
with CurG7Canvas do begin
yi:=(yi+yf) div 2;
MoveTo(xi,yi);
LineTo(xi-round(4*g7Zoom)-2,yi+round(9*g7Zoom)+2);
MoveTo(xi,yi);
LineTo(xi+round(4*g7Zoom)+2,yi+round(9*g7Zoom)+2);
end;
end;
end;
procedure TFormG7.G7DrawStep(idx: integer);
var
r, r_step : TRect;
cx, cy, w: integer;
ShortName : String;
begin
with CurG7Canvas, G7Objects[idx] do begin // Magic numbers dependentes de SubCellCnt
Brush.Style:=bsClear;
if (g7fActive in flags) then Pen.Width:=3;
if g7fInitial in flags then begin
if G7IsSelected(idx) then begin
if MoveActive then begin
Pen.Color:=clMove;
end else Pen.Color:=ClSelected;
end else Pen.Color:=ClStep;
r:=G7CellToRect(Cellx,Celly,StepOuterRect);
if CBRoundStates.Checked then
Ellipse( r )
else
Rectangle( r );
end else Pen.Color:=clBkg;
cx := CellX;
cy := CellY;
if G7IsPhantom(idx) then
Pen.Color:=clPhantom
else
if G7IsSelected(idx) then begin
if MoveActive then begin
Pen.Color:=clMove;
cx := CellX + MoveCellXOffset;
cy := CellY + MoveCellYOffset;
end else Pen.Color:=ClSelected;
end else Pen.Color:=ClStep;
Font.Color := Pen.Color;
r := G7CellToRect(Cx,Cy,StepInnerRect);
if CBRoundStates.Checked then
Ellipse( r )
else
Rectangle( r );
r_step := r; // save for latter (in a hurry!)
if code<>'' then Brush.Color:=clCoded else Brush.Color:=clBkg;
(* // Turn off or on 3 small empty or blue squares
Rectangle( G7CellToRect(Cx,Cy,StepRect_1) );
//if code<>'' then Brush.Color:=clCoded else Brush.Color:=clBkg;