1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
18 interface
20 uses
24 // ////////////////////////////////////////////////////////////////////////// //
25 // call this with SDL2 event; returns `true` if event was eaten
29 // ////////////////////////////////////////////////////////////////////////// //
30 // event handlers
31 var
32 winFocusCB: procedure () = nil; // this will be called when window got focus; `fuiWinActive` already set
33 winBlurCB: procedure () = nil; // this will be called when window lost focus; `fuiWinActive` already set
34 // for standalone
37 exposeFrameCB: procedure () = nil; // call `glSwap()` here instead; automatically set by standalone
38 //
46 var
47 // default size
54 // ////////////////////////////////////////////////////////////////////////// //
59 // ////////////////////////////////////////////////////////////////////////// //
60 // only for standalone mode
67 implementation
69 uses
71 {$INCLUDE ../nogl/noGLuses.inc}
72 {$IF DEFINED(LINUX) OR DEFINED(ANDROID)}
73 unixtype, linux
74 {$ELSEIF DEFINED(WINDOWS)}
75 Windows
76 {$ELSEIF DEFINED(HAIKU) OR DEFINED(UNIX)}
77 unixtype
78 {$ELSE}
79 {$WARNING You suck!}
80 {$ENDIF}
81 ;
84 // ////////////////////////////////////////////////////////////////////////// //
85 var
89 procedure setFUIFPS (v: Integer); inline; begin if (v < 1) then v := 1 else if (v > 60*4) then v := 60*4; gEffFPS := v; end;
92 // ////////////////////////////////////////////////////////////////////////// //
93 {$IF DEFINED(LINUX)}
95 {$ELSE}
97 {$ENDIF}
99 var
104 var
106 begin
108 begin
109 {$IF DEFINED(LINUX)}
110 if (clock_getres(CLOCK_MONOTONIC, @r) <> 0) then raise Exception.Create('profiler error: cannot get timer resolution');
115 {$ELSEIF DEFINED(WINDOWS)}
119 {$ENDIF}
125 var
127 begin
128 //if (mFrequency = 0) then initTimerIntr();
129 {$IF DEFINED(LINUX)}
132 {$ELSEIF DEFINED(WINDOWS)}
135 {$ENDIF}
140 begin
145 // ////////////////////////////////////////////////////////////////////////// //
147 var
153 begin
163 begin
165 SDL_WINDOWEVENT_MINIMIZED: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
167 begin
169 begin
176 SDL_WINDOWEVENT_FOCUS_GAINED: if not fuiWinActive then begin fuiWinActive := true; if assigned(winFocusCB) then winFocusCB(); end;
177 SDL_WINDOWEVENT_FOCUS_LOST: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
181 begin
189 begin
190 // fix left/right modifiers
192 begin
194 end
195 else
196 begin
212 SDL_SCANCODE_LCTRL: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModCtrl) else fuiSetModState(fuiModState and (not TFUIEvent.ModCtrl));
213 SDL_SCANCODE_LALT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModAlt) else fuiSetModState(fuiModState and (not TFUIEvent.ModAlt));
214 SDL_SCANCODE_LSHIFT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModShift) else fuiSetModState(fuiModState and (not TFUIEvent.ModShift));
218 begin
225 begin
227 begin
229 end
230 else
231 begin
244 begin
245 // ev.button.clicks: Byte
246 if (ev.type_ = SDL_MOUSEBUTTONDOWN) then fuiSetButState(fuiButState or fev.but) else fuiSetButState(fuiButState and (not fev.but));
248 begin
254 SDL_MOUSEWHEEL:
255 begin
257 begin
267 begin
273 SDL_MOUSEMOTION:
274 begin
286 begin
292 SDL_TEXTINPUT:
294 begin
299 begin
314 begin