-
Notifications
You must be signed in to change notification settings - Fork 7
/
MolHero.FormMain.pas
executable file
·230 lines (195 loc) · 6.33 KB
/
MolHero.FormMain.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
unit MolHero.FormMain;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Types3D, FMX.Objects3D,
FMX.Edit, FMX.Materials, System.Actions, FMX.ActnList, FMX.StdActns,
FMX.Ani, FMX.MaterialSources, FMX.Controls3D,
FMX.Viewport3D, FMX.StdCtrls, System.Math.Vectors, FMX.Controls.Presentation,
FMX.Layouts, FMX.MultiView, FMX.Objects, FMX.ListView.Types, FMX.ListView,
FMX.ListView.Appearances, FMX.ListView.Adapters.Base,
MolHero.Types, MolHero.Materials, MolHero.MoleculeModel;
const
CAMERA_MAX_Z = -2;
CAMERA_MIN_Z = -102;
ZOOM_STEP = 2;
type
TFormMain = class(TForm)
ViewportMain: TViewport3D;
CameraZ: TCamera;
Light1: TLight;
DummyMain: TDummy;
DummyXY: TDummy;
DummyModel: TDummy;
LayoutHeader: TLayout;
SpeedButtonMenu: TSpeedButton;
LabelTitle: TLabel;
LayoutClient: TLayout;
MultiViewMain: TMultiView;
RectangleMenu: TRectangle;
LayoutMenuTop: TLayout;
RectangleMenuTop: TRectangle;
LabelMenuTitle: TLabel;
ListViewMoleculeList: TListView;
LayoutBottom: TLayout;
SpeedButtonViewModeAB: TSpeedButton;
SpeedButtonViewModeA: TSpeedButton;
SpeedButtonViewModeB: TSpeedButton;
SpeedButtonZoomOut: TSpeedButton;
SpeedButtonZoomIn: TSpeedButton;
SpeedButtonInfo: TSpeedButton;
procedure ViewportMainMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure ViewportMainMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Single);
procedure ViewportMainMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; var Handled: Boolean);
procedure FormCreate(Sender: TObject);
procedure ListViewMoleculeListItemClick(const Sender: TObject;
const AItem: TListViewItem);
procedure SpeedButtonViewModeABClick(Sender: TObject);
procedure SpeedButtonViewModeAClick(Sender: TObject);
procedure SpeedButtonViewModeBClick(Sender: TObject);
procedure SpeedButtonZoomInClick(Sender: TObject);
procedure SpeedButtonZoomOutClick(Sender: TObject);
procedure SpeedButtonInfoClick(Sender: TObject);
private
FDefaultMoleculeIndex: integer;
FDown: TPointF;
FCurrViewMode: TMoleculeViewMode;
procedure LoadDefaultMolecule;
procedure LoadMoleculeList;
procedure LoadMoleculeByIndex(index: integer);
procedure DoZoom(aIn: boolean);
procedure ShowAppAbout;
procedure SetCurrViewMode(const Value: TMoleculeViewMode);
end;
var
FormMain: TFormMain;
implementation
{$R *.fmx}
uses MolHero.DMMain, MolHero.FormAbout;
procedure TFormMain.FormCreate(Sender: TObject);
begin
FDefaultMoleculeIndex := 3;
MultiViewMain.Mode := TMultiViewMode.Drawer;
SetCurrViewMode(TMoleculeViewMode.AB);
SpeedButtonViewModeAB.IsPressed := True;
LoadMoleculeList;
LoadDefaultMolecule;
end;
procedure TFormMain.DoZoom(aIn: boolean);
var newZ: single;
begin
if aIn then
newZ := CameraZ.Position.Z + ZOOM_STEP
else
newZ := CameraZ.Position.Z - ZOOM_STEP;
if (newZ < CAMERA_MAX_Z) and (newZ > CAMERA_MIN_Z) then
CameraZ.Position.Z := newZ;
end;
procedure TFormMain.ListViewMoleculeListItemClick(const Sender: TObject;
const AItem: TListViewItem);
begin
LoadMoleculeByIndex(aItem.Tag);
SetCurrViewMode(FCurrViewMode);
MultiViewMain.HideMaster;
end;
procedure TFormMain.LoadMoleculeByIndex(index: integer);
begin
DMMain.LoadMoleculeByIndex(DummyModel, index);
if DMMain.CurrentMolecule <> nil then
LabelTitle.Text := DMMain.CurrentMolecule.DisplayName
else
LabelTitle.Text := '';
Invalidate;
end;
procedure TFormMain.LoadDefaultMolecule;
begin
LoadMoleculeByIndex(FDefaultMoleculeIndex);
end;
procedure TFormMain.LoadMoleculeList;
var i, aCount: integer; s: string; lvi: TListViewItem;
begin
aCount := DMMain.GetMoleculeCount;
for i := 0 to aCount-1 do
begin
s := DMMain.GetMoleculeDisplayName(i);
lvi := ListViewMoleculeList.Items.Add;
lvi.Text := s;
lvi.Tag := i;
end;
end;
procedure TFormMain.SetCurrViewMode(const Value: TMoleculeViewMode);
var i: integer; sph: TSphere; cyl: TCylinder;
begin
FCurrViewMode := Value;
for i := 0 to DummyModel.ChildrenCount-1 do
begin
if DummyModel.Children[i] is TSphere then
begin
sph := TSphere(DummyModel.Children[i]);
sph.Visible := FCurrViewMode in [TMoleculeViewMode.AB, TMoleculeViewMode.A];
end
else if DummyModel.Children[i] is TCylinder then
begin
cyl := TCylinder(DummyModel.Children[i]);
cyl.Visible := FCurrViewMode in [TMoleculeViewMode.AB, TMoleculeViewMode.B];
end
end;
end;
procedure TFormMain.ShowAppAbout;
begin
if FormAbout = nil then
FormAbout := TFormAbout.Create(Application);
FormAbout.Show;
FormAbout.DoIntroAnimation
end;
procedure TFormMain.SpeedButtonInfoClick(Sender: TObject);
begin
ShowAppAbout;
end;
procedure TFormMain.SpeedButtonViewModeABClick(Sender: TObject);
begin
FCurrViewMode := TMoleculeViewMode.AB;
SetCurrViewMode(FCurrViewMode);
end;
procedure TFormMain.SpeedButtonViewModeAClick(Sender: TObject);
begin
FCurrViewMode := TMoleculeViewMode.A;
SetCurrViewMode(FCurrViewMode);
end;
procedure TFormMain.SpeedButtonViewModeBClick(Sender: TObject);
begin
FCurrViewMode := TMoleculeViewMode.B;
SetCurrViewMode(FCurrViewMode);
end;
procedure TFormMain.SpeedButtonZoomInClick(Sender: TObject);
begin
DoZoom(True);
end;
procedure TFormMain.SpeedButtonZoomOutClick(Sender: TObject);
begin
DoZoom(False);
end;
procedure TFormMain.ViewportMainMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
FDown := PointF(X, Y);
end;
procedure TFormMain.ViewportMainMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Single);
begin
if (ssLeft in Shift) then
begin
DummyXY.RotationAngle.X := DummyXY.RotationAngle.X - ((Y - FDown.Y) * 0.3);
DummyXY.RotationAngle.Y := DummyXY.RotationAngle.Y + ((X - FDown.X) * 0.3);
FDown := PointF(X, Y);
end;
end;
procedure TFormMain.ViewportMainMouseWheel(Sender: TObject;
Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
begin
DoZoom(WheelDelta > 0);
end;
end.