-
Notifications
You must be signed in to change notification settings - Fork 10
/
uMain.pas
235 lines (207 loc) · 6.73 KB
/
uMain.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
unit uMain;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
Generics.Collections,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Menus, FMX.Edit, FMX.ListBox, msDiagramm,
msDiagramms,
msDiagrammsController,
msInterfaces, FMX.Controls.Presentation
;
type
TfmMain = class(TForm)
mmMain: TMainMenu;
miFile: TMenuItem;
miExit: TMenuItem;
miAbout: TMenuItem;
pnlTop: TPanel;
imgMain: TPaintBox;
btnClearImage: TButton;
cbShapes: TComboBox;
cbDiagramm: TComboBox;
btAddDiagramm: TButton;
btSaveDiagramm: TButton;
btLoadDiagramm: TButton;
btnSaveToPNG: TButton;
pnlToolBar: TPanel;
pnlBottom: TPanel;
btnSaveJsonAndPng: TButton;
procedure miExitClick(Sender: TObject);
procedure miAboutClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure btnClearImageClick(Sender: TObject);
procedure imgMainPaint(Sender: TObject; Canvas: TCanvas);
private
FDiagrammsController: ImsDiagrammsController;
procedure CreateToolBar(const aPanelWidth: Single);
procedure CreateScrollButtons;
procedure CreateScript;
public
{ Public declarations }
end;
var
fmMain: TfmMain;
implementation
uses
System.Math.Vectors,
msShape,
msTool,
msShapeButton,
msShapesForToolbar,
msPaletteShapeCreator,
msShapeClass,
msScrollShapeUp,
msScrollShapeDown,
msScrollShapeRight,
msScrollShapeLeft,
msScrollShapeUpLeft,
msScrollShapeUpRight,
msScrollShapeDownLeft,
msScrollShapeDownRight,
msScrollShapeResetOrigin,
tfwScriptEngineEX
;
{$R *.fmx}
procedure TfmMain.btnClearImageClick(Sender: TObject);
begin
FDiagrammsController.Clear;
end;
procedure TfmMain.CreateScript;
//var
// l_TestScriptEngine : TtfwScriptEngineEX;
begin
// l_TestScriptEngine := TtfwScriptEngineEX.Create;
// FreeAndNil(l_TestScriptEngine);
end;
procedure TfmMain.CreateScrollButtons;
function BuildButton(aShape: ImsShapeClass) : TmsShapeButton;
begin
Result := TmsShapeButton.Create(pnlBottom,
aShape,
cbShapes, 0, 0,
FDiagrammsController.As_ImsDiagrammsHolder);
end;
var
l_Button : TmsShapeButton;
l_P: TPointF;
begin
// TmsScrollShapeUpLeft
l_Button := BuildButton(TmsScrollShapeUpLeft.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(0, 0);
l_Button.Position.X := l_P.X;
l_Button.Position.Y := l_P.Y;
l_Button.Anchors := [TAnchorKind.akTop, TAnchorKind.akLeft];
// TmsScrollShapeUp
l_Button := BuildButton(TmsScrollShapeUp.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(pnlBottom.Width / 2, 0);
l_Button.Position.X := l_P.X - l_Button.LocalRect.Width / 2;
l_Button.Position.Y := l_P.Y;
l_Button.Anchors := [TAnchorKind.akTop];
// TmsScrollShapeUpRight
l_Button := BuildButton(TmsScrollShapeUpRight.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(pnlBottom.Width, 0);
l_Button.Position.X := l_P.X - l_Button.LocalRect.Width;
l_Button.Position.Y := l_P.Y;
l_Button.Anchors := [TAnchorKind.akTop, TAnchorKind.akRight];
// TmsScrollShapeLeft
l_Button := BuildButton(TmsScrollShapeLeft.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(0, pnlBottom.Height / 2);
l_Button.Position.X := l_P.X;
l_Button.Position.Y := l_P.Y - l_Button.LocalRect.Height / 2;
l_Button.Anchors := [TAnchorKind.akLeft];
// TmsScrollShapeRight
l_Button := BuildButton(TmsScrollShapeRight.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(pnlBottom.Width, pnlBottom.Height / 2);
l_Button.Position.X := l_P.X - l_Button.LocalRect.Width;
l_Button.Position.Y := l_P.Y - l_Button.LocalRect.Height / 2;
l_Button.Anchors := [TAnchorKind.akRight];
// TmsScrollShapeDownLeft
l_Button := BuildButton(TmsScrollShapeDownLeft.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(0, pnlBottom.Height);
l_Button.Position.X := l_P.X;
l_Button.Position.Y := l_P.Y - l_Button.LocalRect.Height;
l_Button.Anchors := [TAnchorKind.akLeft, TAnchorKind.akBottom];
// TmsScrollShapeDown
l_Button := BuildButton(TmsScrollShapeDown.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(pnlBottom.Width / 2 , pnlBottom.Height);
l_Button.Position.X := l_P.X - l_Button.LocalRect.Width / 2;
l_Button.Position.Y := l_P.Y - l_Button.LocalRect.Height;
l_Button.Anchors := [TAnchorKind.akBottom];
// TmsScrollShapeDownRight
l_Button := BuildButton(TmsScrollShapeDownRight.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(pnlBottom.Width, pnlBottom.Height);
l_Button.Position.X := l_P.X - l_Button.LocalRect.Width;
l_Button.Position.Y := l_P.Y - l_Button.LocalRect.Height;
l_Button.Anchors := [TAnchorKind.akRight, TAnchorKind.akBottom];
// TmsScrollShapeResetOrigin
l_Button := BuildButton(TmsScrollShapeResetOrigin.MC);
pnlBottom.AddObject(l_Button);
l_P := TPointF.Create(0, 0);
l_Button.Position.X := l_P.X + l_Button.LocalRect.Width;
l_Button.Position.Y := l_P.Y;
l_Button.Anchors := [TAnchorKind.akTop, TAnchorKind.akLeft];
end;
procedure TfmMain.CreateToolBar(const aPanelWidth: Single);
var
l_Row, l_Column : Integer;
begin
l_Row := 0;
l_Column := 0;
TmsShapesForToolbar.Instance.IterateShapes(
procedure (const aShapeClass : MCmsShape)
function GetColumnCount: Integer;
begin//GetColumnCount
Result := Round(aPanelWidth) div TmsPaletteShapeCreator.ButtonSize;
end;//GetColumnCount
begin
pnlToolBar.AddObject(TmsShapeButton.Create(pnlToolBar, aShapeClass, cbShapes, l_Column, l_Row, FDiagrammsController.As_ImsDiagrammsHolder));
Inc(l_Column);
if (l_Column > GetColumnCount-1) then
begin
l_Column := 0;
Inc(l_Row);
end;//l_Column > GetColumnCount-1
end
);
end;
procedure TfmMain.FormCreate(Sender: TObject);
begin
FDiagrammsController := TmsDiagrammsController.Create(imgMain,
cbShapes,
cbDiagramm,
btAddDiagramm,
btSaveDiagramm,
btLoadDiagramm,
btnSaveToPNG,
btnSaveJsonAndPng);
CreateToolBar(pnlToolBar.Width);
CreateScrollButtons;
CreateScript;
end;
procedure TfmMain.FormDestroy(Sender: TObject);
begin
FDiagrammsController := nil;
end;
procedure TfmMain.imgMainPaint(Sender: TObject; Canvas: TCanvas);
begin
FDiagrammsController.DrawTo(Canvas);
end;
procedure TfmMain.miAboutClick(Sender: TObject);
begin
ShowMessage(Self.Caption);
end;
procedure TfmMain.miExitClick(Sender: TObject);
begin
Self.Close;
end;
end.