Debian Codegraph @

src/window/castlewindow_backend_template.inc

raw
1 {%MainUnit castlewindow.pas}
2 {
3 Copyright 2004-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 {$ifdef read_interface_uses}
18 {$endif}
19
20 {$ifdef read_implementation_uses}
21 {$endif}
22
23 {$ifdef read_window_interface}
24 {$endif read_window_interface}
25
26 {$ifdef read_application_interface}
27 {$endif read_application_interface}
28
29 {$ifdef read_implementation}
30
31 { TCastleWindow ------------------------------------------------------------------ }
32
33 procedure TCastleWindow.CreateBackend;
34 begin
35 { TODO (initialize backend-specific per-window stuff; may do nothing) }
36 end;
37
38 procedure TCastleWindow.BackendMenuInitialize;
39 begin
40 { TODO (may do nothing if you do not care about displaying menu) }
41 end;
42
43 procedure TCastleWindow.BackendMenuFinalize;
44 begin
45 { TODO (may do nothing if you do not care about displaying menu) }
46 end;
47
48 procedure TCastleWindow.MenuUpdateCaption(Entry: TMenuEntryWithCaption);
49 begin
50 { TODO (may do nothing if you do not care about displaying menu;
51 may do MenuFinalize + MenuInitialize if you display menu,
52 but don't care about updating it fast) }
53 MenuFinalize;
54 MenuInitialize;
55 end;
56
57 procedure TCastleWindow.MenuUpdateEnabled(Entry: TMenuEntryWithCaption);
58 begin
59 { TODO (may do nothing if you do not care about displaying menu;
60 may do MenuFinalize + MenuInitialize if you display menu,
61 but don't care about updating it fast) }
62 MenuFinalize;
63 MenuInitialize;
64 end;
65
66 procedure TCastleWindow.MenuUpdateChecked(Entry: TMenuItemChecked);
67 begin
68 { TODO (may do nothing if you do not care about displaying menu;
69 may do MenuFinalize + MenuInitialize if you display menu,
70 but don't care about updating it fast) }
71 MenuFinalize;
72 MenuInitialize;
73 end;
74
75 function TCastleWindow.MenuUpdateCheckedFast: boolean;
76 begin
77 Result := false;
78 end;
79
80 procedure TCastleWindow.MenuInsert(const Parent: TMenu;
81 const ParentPosition: Integer; const Entry: TMenuEntry);
82 begin
83 { TODO (may do nothing if you do not care about displaying menu;
84 may do MenuFinalize + MenuInitialize if you display menu,
85 but don't care about updating it fast) }
86 MenuFinalize;
87 MenuInitialize;
88 end;
89
90 procedure TCastleWindow.MenuDelete(const Parent: TMenu;
91 const ParentPosition: Integer; const Entry: TMenuEntry);
92 begin
93 { TODO (may do nothing if you do not care about displaying menu;
94 may do MenuFinalize + MenuInitialize if you display menu,
95 but don't care about updating it fast) }
96 MenuFinalize;
97 MenuInitialize;
98 end;
99
100 procedure TCastleWindow.SwapBuffers;
101 begin
102 { TODO }
103 end;
104
105 procedure TCastleWindow.OpenBackend;
106 begin
107 { TODO (create OpenGL context, show window with this context) }
108
109 { Update position/size in case window is fullscreen.
110 If the backend always creates a fullscreen window for some reason
111 (e.g. typical on mobile), then you can remove the condition
112 "if FullScreen then" and just do this always, regardless of FullScreen value. }
113 if FullScreen then
114 begin
115 FLeft := 0;
116 FTop := 0;
117 DoResize(Application.ScreenWidth, Application.ScreenHeight, false);
118 end;
119
120 Application.OpenWindowsAdd(Self);
121
122 // TODO
123 // GetInitialCursorPos;
124 // UpdateCursor;
125 // InitializeDpi;
126 end;
127
128 procedure TCastleWindow.CloseBackend;
129 begin
130 { TODO (destroy OpenGL context, hide window; counterpart to OpenBackend) }
131 end;
132
133 procedure TCastleWindow.SetCaption(const Part: TCaptionPart; const Value: String);
134 begin
135 FCaption[Part] := Value;
136 if not Closed then { TODO: use GetWholeCaption };
137 end;
138
139 procedure TCastleWindow.BackendMakeCurrent;
140 begin
141 { TODO }
142 end;
143
144 procedure TCastleWindow.SetCursor(const Value: TMouseCursor);
145 begin
146 if FCursor <> Value then
147 begin
148 FCursor := Value;
149 if not Closed then
150 { TODO UpdateCursor };
151 end;
152 end;
153
154 function TCastleWindow.RedirectKeyDownToMenuClick: boolean;
155 begin
156 Result := { TODO } true;
157 end;
158
159 procedure TCastleWindow.SetMousePosition(const Value: TVector2);
160 begin
161 if not Closed then
162 { TODO };
163 end;
164
165 procedure TCastleWindow.UpdateFullScreenBackend;
166 begin
167 { This is the simplest implementation of this method: }
168 SimpleUpdateFullScreenBackend;
169 { Some backends may provide a better way of doing this.
170 Remove the above line then, and put better implementation here. }
171 end;
172
173 procedure TCastleWindow.BackendInsideUpdate;
174 begin
175 end;
176
177 { TCastleWindow dialogs -------------------------------------------------- }
178
179 { Methods below should make native-looking dialog boxes.
180 Alternatively, you can include castlewindow_dialogs_by_messages.inc
181 (outside of $ifdef read_implementation, usually at the beginning of
182 castlewindow_xxx.inc file), to have simple dialog boxes drawn on
183 OpenGL context using our CastleMessages unit. }
184
185 function TCastleWindow.BackendFileDialog(const Title: String; var FileName: String;
186 OpenDialog: boolean; FileFilters: TFileFilterList): boolean;
187 begin
188 { TODO } Result := false;
189 end;
190
191 function TCastleWindow.ColorDialog(var Color: TCastleColor): Boolean;
192 begin
193 { TODO } Result := false;
194 end;
195
196 procedure TCastleWindow.MessageOK(const S: String; const MessageType: TWindowMessageType);
197 begin
198 { TODO }
199 end;
200
201 function TCastleWindow.MessageYesNo(const S: String;
202 const MessageType: TWindowMessageType): boolean;
203 begin
204 { TODO } Result := true;
205 end;
206
207 { TCastleApplication ---------------------------------------------------------- }
208
209 procedure TCastleApplication.CreateBackend;
210 begin
211 { TODO (initialize backend-specific stuff for the whole application;
212 may do nothing if you don't need anything) }
213 end;
214
215 procedure TCastleApplication.DestroyBackend;
216 begin
217 { TODO }
218 end;
219
220 function TCastleApplication.ProcessMessage(WaitForMessage, WaitToLimitFPS: boolean): boolean;
221 begin
222 if Terminated then Exit(false);
223
224 { TODO:
225 Here process *one* window system message, if it's available in the queue.
226 Like a key press, mouse clicks etc.
227 Call DoKeyDown, DoMouseDown and other DoXxx methods when these events occur.
228
229 If WaitForMessage then you can (but don't have to) hang until new message arrives.
230
231 Be sure to recheck the "Terminated" state after calling any DoXxx method.
232 That's why below we have again a check for this. }
233
234 if Terminated then Exit(false);
235
236 { TODO: UpdateAndRenderEverything should be called only if no message was in the queue.
237
238 This follows castlewindow_winsystem.inc approach, and works very good
239 to prevent doing Update / Render when we're clogged with events
240 (typically happens when walking with mouse look, then we're clogged
241 with mouse move events). }
242
243 UpdateAndRenderEverything;
244 Result := not Terminated;
245
246 { TODO:
247 if (not WasAnyMessage) and
248 (not Terminated) and
249 (not WaitForMessage) and
250 WaitToLimitFPS then
251 DoLimitFPS;
252 }
253 end;
254
255 function TCastleApplication.ProcessAllMessages: boolean;
256 begin
257 { This implementation is valid for start: }
258 Result := ProcessMessage(false, false);
259
260 { In general, ProcessAllMessages should make sure that all messages
261 are handled, calling "ProcessMessage(false, false)" as long as some
262 message exists in window system queue.
263 Then it should call UpdateAndRenderEverything.
264 See the GTK backend for example. }
265 end;
266
267 procedure TCastleApplication.Run;
268 begin
269 if OpenWindowsCount = 0 then Exit;
270
271 { Implementing Run by calling ProcessMessage in a loop (like below)
272 is a valid and good implementation. Make sure your ProcessMessage
273 honours WaitForMessage and WaitToLimitFPS = true,
274 to avoid wasting CPU on "busy waiting". }
275 while ProcessMessage(true, true) do ;
276 end;
277
278 procedure TCastleApplication.BackendTerminate;
279 begin
280 end;
281
282 function TCastleApplication.ScreenWidth: integer;
283 begin
284 { TODO }
285 Result := 200;
286 end;
287
288 function TCastleApplication.ScreenHeight: integer;
289 begin
290 { TODO }
291 Result := 200;
292 end;
293
294 function TCastleApplication.BackendName: String;
295 begin
296 { TODO }
297 Result := 'My CastleWindow Backend';
298 end;
299
300 { TWindowContainer ----------------------------------------------------------- }
301
302 function TWindowContainer.SettingMousePositionCausesMotion: Boolean;
303 begin
304 { You should check, using window_events example, what is the correct value
305 (press "5", see if OnMotion is generated). }
306 Result := true;
307 end;
308
309 {$endif read_implementation}