-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fSceneRoot.pas
120 lines (101 loc) · 2.79 KB
/
fSceneRoot.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
unit fSceneRoot;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Controls.Presentation, FMX.Ani, fMain;
type
TfrmSceneRoot = class(TFrame)
btnMenu: TButton;
aniShowScene: TFloatAnimation;
aniHideScene: TFloatAnimation;
procedure btnMenuClick(Sender: TObject);
procedure aniHideSceneFinish(Sender: TObject);
procedure aniShowSceneFinish(Sender: TObject);
private
{ Déclarations privées }
protected
fSceneParent: TfrmMain;
class function getSceneref: TfrmSceneRoot; virtual; abstract;
class function SceneCreate<T: TfrmSceneRoot>: T;
public
{ Déclarations publiques }
class procedure SceneShow<T: TfrmSceneRoot>;
procedure ShowScene;
procedure HideScene;
end;
procedure GoToScene(NewScene: TfrmSceneRoot);
function getCurrentScene: TfrmSceneRoot;
implementation
{$R *.fmx}
uses fSceneMenu;
var
CurrentScene: TfrmSceneRoot;
procedure GoToScene(NewScene: TfrmSceneRoot);
begin
if assigned(NewScene) then
begin
if assigned(CurrentScene) then
CurrentScene.HideScene;
CurrentScene := NewScene;
CurrentScene.ShowScene;
end;
end;
function getCurrentScene: TfrmSceneRoot;
begin
result := CurrentScene;
end;
{ TfrmSceneRoot }
procedure TfrmSceneRoot.aniHideSceneFinish(Sender: TObject);
begin
visible := false;
aniHideScene.Enabled := false;
end;
procedure TfrmSceneRoot.aniShowSceneFinish(Sender: TObject);
begin
aniShowScene.Enabled := false;
align := TAlignLayout.Client;
end;
procedure TfrmSceneRoot.btnMenuClick(Sender: TObject);
begin
TfrmSceneMenu.SceneShow<TfrmSceneMenu>;
end;
procedure TfrmSceneRoot.HideScene;
begin
align := TAlignLayout.None;
aniHideScene.StartValue := 0;
aniHideScene.StopValue := fSceneParent.Height;
aniHideScene.Enabled := true;
end;
class function TfrmSceneRoot.SceneCreate<T>: T;
begin
result := T.Create(application.mainform);
result.Parent := application.mainform;
if (application.mainform is TfrmMain) then
result.fSceneParent := application.mainform as TfrmMain
else
raise exception.Create('Wrong parent form for this scene.');
result.name := '';
end;
class procedure TfrmSceneRoot.SceneShow<T>;
var
SceneRef: TfrmSceneRoot;
begin
SceneRef := getSceneref;
if assigned(SceneRef) then
GoToScene(SceneRef)
else
raise exception.Create('Can''t schow scene.');
end;
procedure TfrmSceneRoot.ShowScene;
begin
align := TAlignLayout.None;
position.x := 0;
position.y := -fSceneParent.Height;
width := fSceneParent.width;
Height := fSceneParent.Height;
visible := true;
aniShowScene.Enabled := true;
end;
end.