forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form.Base.pas
135 lines (111 loc) · 3.23 KB
/
Form.Base.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
unit Form.Base;
{$include lem_directives.inc}
interface
uses
LCLIntf, LCLType, LMessages,
SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
Gr32,
Base.Utils,
Prog.Types, Prog.App;
type
// abstract runtime black, fullscreen, ancestor form
TBaseForm = class(TForm)
protected
procedure NormalForm;
public
constructor Create(aOwner: TComponent); override;
procedure AfterConstruction; override; final;
end;
// a lemmings form with some virtuals
TBaseDosForm = class(TBaseForm, IDosForm) // todo: (major rework) embed inside mainform
private
fScreenIsClosing: Boolean;
protected
procedure CreateParams(var Params: TCreateParams); override; final;
protected
procedure PrepareGameParams; virtual;
procedure BuildScreen; virtual;
procedure BeforeCloseScreen(aNextScreen: TGameScreenType); virtual;
public
constructor Create(aOwner: TComponent); override;
procedure CloseScreen(aNextScreen: TGameScreenType);
function ShowScreen: TGameScreenType;
property ScreenIsClosing: Boolean read fScreenIsClosing;
end;
implementation
{ TBaseForm }
procedure TBaseForm.AfterConstruction;
begin
inherited;
//ScaleForCurrentDpi;
end;
constructor TBaseForm.Create(aOwner: TComponent);
begin
inherited CreateNew(aOwner);
//StyleElements := [];
Caption := 'Lemmix';
Color := clBlack;
BorderStyle := bsNone;
BorderIcons := [];
//WindowState := wsMaximized;
BoundsRect := CurrentDisplay.BoundsRect;
DefaultMonitor := TDefaultMonitor.dmMainForm; // show on the same monitor as the mainform
end;
procedure TBaseForm.NormalForm;
begin
Color := clWindow;
BorderStyle := bsSizeable;
BorderIcons := [biSystemMenu, biMinimize, biMaximize, biHelp];
WindowState := wsNormal;
Cursor := crDefault;
end;
{ TBaseDosForm }
procedure TBaseDosForm.BeforeCloseScreen(aNextScreen: TGameScreenType);
begin
// override for extra actions
end;
procedure TBaseDosForm.CloseScreen(aNextScreen: TGameScreenType);
begin
fScreenIsClosing := True;
Application.OnIdle := nil;
OnKeyDown := nil;
OnKeyPress := nil;
OnKeyUp := nil;
BeforeCloseScreen(aNextScreen);
ModalResult := Ord(aNextScreen); // all screens are modal. this closes the form
end;
constructor TBaseDosForm.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
Font.Name := 'Segoe UI';
Font.Size := 9;
KeyPreview := True;
end;
procedure TBaseDosForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
//Params.WindowClass.Style := Params.WindowClass.Style or CS_OWNDC; // maybe faster screen output
end;
procedure TBaseDosForm.PrepareGameParams;
begin
// do nothing
end;
procedure TBaseDosForm.BuildScreen;
begin
// do nothing
end;
function TBaseDosForm.ShowScreen: TGameScreenType;
// if the screen closed with alt+f4 (for example) it bypasses our logic, so we remap to unknown screen
var
res: TModalResult;
begin
PrepareGameParams;
BuildScreen;
res := ShowModal;
if (res >= Ord(Low(TGameScreenType))) and (res <= Ord(High(TGameScreenType))) then
Result := TGameScreenType(res)
else
Result := TGameScreenType.Unknown;
end;
end.