-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrolpanel.pas
225 lines (191 loc) · 6.4 KB
/
controlpanel.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
unit ControlPanel;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Math, CastleUIState,
{$ifndef cgeapp}
Forms, Controls, Graphics, Dialogs, CastleControl,
{$else}
CastleWindow,
{$endif}
CastleControls, CastleColors, CastleUIControls,
CastleTriangles, CastleShapes, CastleVectors,
CastleSceneCore, CastleScene, CastleTransform,
CastleViewport, CastleCameras, CastleProjection,
X3DNodes, X3DFields, X3DTIme, CastleNotifications, CastleFilesUtils,
CastleImages, CastleGLImages, CastleRectangles, CastleQuaternions,
CastleTextureImages, CastleLog,
CastleApplicationProperties, CastleTimeUtils, CastleKeysMouse,
CastleGLUtils, multimodel, staging, MiscFunctions, ControlPanelControls,
CastlePageControl, SpriteControlPanel;
type
{ TControlPanel }
TControlPanel = class(TCastleUserInterface)
constructor Create(AOwner: TComponent); override;
constructor Create(AOwner: TComponent; const AWidth: Single);
procedure Resize; override;
private
SpritePanel: TSpriteControlPanel;
TopSectionHeight: Single;
TopSection: TCastleUserInterface;
CtlGrabSCreenBtn: TCastleButton;
CtlViewModeBtn: TCastleButton;
CtlCenterBtn: TCastleButton;
CtlResetBtn: TCastleButton;
procedure DoGrabScreen(Sender: TObject);
procedure DoChangeViewMode(Sender: TObject);
procedure DoDebug(Sender: TObject);
procedure DoReset(Sender: TObject);
public
TabTest: TCastlePageControl;
PanelWidth: Single;
end;
implementation
{$ifdef cgeapp}
uses MainGameUnit;
{$else}
uses GUIInitialization, MainGameUnit;
{$endif}
{ TControlPanel }
constructor TControlPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
constructor TControlPanel.Create(AOwner: TComponent; const AWidth: Single);
var
BtnWidth: Single;
BtnHeight: Single;
BtnFontScale: Single;
BtnImageScale: Single;
BtnMargin: Single;
BtnRow: Cardinal;
procedure PlaceButton(var obj: TCastleButton; const BtnCol: Integer);
begin
obj.Left := (BtnCol * (BtnWidth + BtnMargin)) + BtnMargin;
obj.Bottom := (BtnRow * (BtnHeight + BtnMargin)) + BtnMargin;
obj.Width := BtnWidth;
obj.Height := BtnHeight;
obj.FontScale := BtnFontScale;
obj.ImageScale := BtnImageScale;
end;
begin
Create(AOwner);
BtnRow := 0;
BtnMargin := 10;
{$if defined(ANDROID)}
BtnHeight := 90;
BtnFontScale := 0.8;
{$elseif defined(CASTLE_IOS)}
BtnHeight := 90;
BtnFontScale := 0.8;
{$else}
BtnHeight := 40;
BtnFontScale := 0.8;
{$endif}
BtnWidth := BtnHeight;
BtnImageScale := (BtnHeight / 64) * BtnFontScale;
TopSectionHeight := BtnHeight + (2 * BtnMargin);
Width := AWidth - 2;
Height := ParentRect.Height - 2;
PanelWidth := AWidth - 2;
Anchor(hpRight);
Anchor(vpTop);
BorderColor := White;
Border.AllSides := 1;
TUIState(AOwner).InsertFront(Self);
TopSection := TCastleUserInterface.Create(Self);
TopSection.Height := TopSectionHeight;
TopSection.Width := Width;
TopSection.HorizontalAnchorParent := hpRight;
TopSection.HorizontalAnchorSelf := hpRight;
TopSection.HorizontalAnchorDelta := 0;
TopSection.VerticalAnchorParent := vpTop;
TopSection.VerticalAnchorSelf := vpTop;
TopSection.VerticalAnchorDelta := 0;
Self.InsertFront(TopSection);
TabTest := TCastlePageControl.Create(Self);
TabTest.Height := Height - TopSectionHeight;
TabTest.Width := Width;
TabTest.HorizontalAnchorParent := hpLeft;
TabTest.HorizontalAnchorSelf := hpLeft;
TabTest.HorizontalAnchorDelta := 0;
TabTest.VerticalAnchorParent := vpTop;
TabTest.VerticalAnchorSelf := vpTop;
TabTest.VerticalAnchorDelta := -TopSectionHeight;
// TabTest.Border.AllSides := 1;
// TabTest.BorderColor := Blue;
Self.InsertFront(TabTest);
SpritePanel := TSpriteControlPanel.Create(AOwner, AWidth, TabTest);
TabTest.AddTab('Orientation', 'castle-data:/icons/orientation.png', SpritePanel);
TabTest.AddTab('Position', 'castle-data:/icons/position.png');
TabTest.AddTab('Define Frames', 'castle-data:/icons/record.png');
TopSection.CreateButton(CtlGrabSCreenBtn, '', @DoGrabScreen, 'castle-data:/icons/b_camera.png');
PlaceButton(CtlGrabScreenBtn, 0);
TopSection.CreateButton(CtlViewModeBtn, '', @DoChangeViewMode, 'castle-data:/icons/b_view.png');
PlaceButton(CtlViewModeBtn, 1);
TopSection.CreateButton(CtlCenterBtn, '', @DoDebug, 'castle-data:/icons/b_debug.png');
PlaceButton(CtlCenterBtn, 2);
TopSection.CreateButton(CtlResetBtn, '', @DoReset, 'castle-data:/icons/b_settings.png');
PlaceButton(CtlResetBtn, 3);
end;
procedure TControlPanel.Resize;
begin
inherited;
Height := ParentRect.Height - 2;
TopSection.Height := TopSectionHeight;
TopSection.Width := PanelWidth - Border.Left - Border.Right;
// TopSection.Border.AllSides := 1;
// TopSection.BorderColor := Red;
TabTest.Height := Height - TopSectionHeight;
TabTest.Width := PanelWidth - Border.Left - Border.Right;
TabTest.ExtResize;
SpritePanel.ExtResize;
WriteLnLog('Height : ' + FloatToStr(Height));
WriteLnLog('TopSection.Height : ' + FloatToStr(TopSection.Height));
WriteLnLog('TabTest.Height : ' + FloatToStr(TabTest.Height));
end;
procedure TControlPanel.DoGrabScreen(Sender: TObject);
var
Sprite: TCastleImage;
SName: String;
begin
with Parent as TCastleApp do
begin
if not (WorkingModel.Scene = nil) then
begin
Sprite := CastleApp.CreateSpriteImage(CastleApp.WorkingModel.Scene, SpriteWidth * OverSample, SpriteHeight * OverSample, CastleApp.UseTransparency);
if not(Sprite = nil) then
begin
if (OverSample > 1) then
begin
Sprite.Resize(SpriteWidth, SpriteHeight, riLanczos); // Mitchel);
end;
SName := FileNameAutoInc('grab_%4.4d.png');
SaveImage(Sprite, SName);
FreeAndNil(Sprite);
end;
end;
end;
end;
procedure TControlPanel.DoChangeViewMode(Sender: TObject);
begin
with Parent as TCastleApp do
ViewMode := ViewMode + 1;
end;
procedure TControlPanel.DoDebug(Sender: TObject);
begin
with Parent as TCastleApp do
begin
WorkingModel.Debug.Exists := not WorkingModel.Debug.Exists;
{$ifndef cgeapp}
CastleForm.DebugBoxMenu.Checked := WorkingModel.Debug.Exists;
{$endif}
end;
end;
procedure TControlPanel.DoReset(Sender: TObject);
begin
with Parent as TCastleApp do
WorkingModel.Normalize;
end;
end.
*