3b019a224ac8594c602466f96cccfe866ada1de6
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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
19 interface
21 uses
25 // ////////////////////////////////////////////////////////////////////////// //
26 // call this with SDL2 event; returns `true` if event was eaten
30 // ////////////////////////////////////////////////////////////////////////// //
31 // event handlers
32 var
33 winFocusCB: procedure () = nil; // this will be called when window got focus; `fuiWinActive` already set
34 winBlurCB: procedure () = nil; // this will be called when window lost focus; `fuiWinActive` already set
35 // for standalone
38 exposeFrameCB: procedure () = nil; // call `glSwap()` here instead; automatically set by standalone
39 //
47 var
48 // default size
55 // ////////////////////////////////////////////////////////////////////////// //
60 // ////////////////////////////////////////////////////////////////////////// //
61 // only for standalone mode
68 implementation
70 uses
73 {$IF DEFINED(LINUX)}
74 unixtype, linux
75 {$ELSEIF DEFINED(WINDOWS)}
76 Windows
77 {$ELSE}
78 {$WARNING You suck!}
79 {$ENDIF}
80 ;
83 // ////////////////////////////////////////////////////////////////////////// //
84 var
88 procedure setFUIFPS (v: Integer); inline; begin if (v < 1) then v := 1 else if (v > 60*4) then v := 60*4; gEffFPS := v; end;
91 // ////////////////////////////////////////////////////////////////////////// //
92 {$IF DEFINED(LINUX)}
94 {$ELSE}
96 {$ENDIF}
98 var
103 var
105 begin
107 begin
108 {$IF DEFINED(LINUX)}
109 if (clock_getres(CLOCK_MONOTONIC, @r) <> 0) then raise Exception.Create('profiler error: cannot get timer resolution');
114 {$ELSE}
118 {$ENDIF}
124 var
126 begin
127 //if (mFrequency = 0) then initTimerIntr();
128 {$IF DEFINED(LINUX)}
131 {$ELSE}
134 {$ENDIF}
139 begin
144 // ////////////////////////////////////////////////////////////////////////// //
146 var
151 begin
161 begin
163 SDL_WINDOWEVENT_MINIMIZED: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
165 begin
167 begin
174 SDL_WINDOWEVENT_FOCUS_GAINED: if not fuiWinActive then begin fuiWinActive := true; if assigned(winFocusCB) then winFocusCB(); end;
175 SDL_WINDOWEVENT_FOCUS_LOST: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
179 begin
187 begin
188 // fix left/right modifiers
191 if (ev.type_ = SDL_KEYDOWN) then kev.kind := THKeyEvent.TKind.Press else kev.kind := THKeyEvent.TKind.Release;
193 //kev.sym := ev.key.keysym.sym;
200 {
201 if (kev.sym = SDLK_RCTRL) then kev.sym := SDLK_LCTRL;
202 if (kev.sym = SDLK_RALT) then kev.sym := SDLK_LALT;
203 if (kev.sym = SDLK_RSHIFT) then kev.sym := SDLK_LSHIFT;
204 if (kev.sym = SDLK_RGUI) then kev.sym := SDLK_LGUI;
205 }
213 SDL_SCANCODE_LCTRL: if (kev.press) then fuiSetModState(fuiModState or THKeyEvent.ModCtrl) else fuiSetModState(fuiModState and (not THKeyEvent.ModCtrl));
214 SDL_SCANCODE_LALT: if (kev.press) then fuiSetModState(fuiModState or THKeyEvent.ModAlt) else fuiSetModState(fuiModState and (not THKeyEvent.ModAlt));
215 SDL_SCANCODE_LSHIFT: if (kev.press) then fuiSetModState(fuiModState or THKeyEvent.ModShift) else fuiSetModState(fuiModState and (not THKeyEvent.ModShift));
219 begin
226 begin
229 if (ev.type_ = SDL_MOUSEBUTTONDOWN) then mev.kind := THMouseEvent.TKind.Press else mev.kind := THMouseEvent.TKind.Release;
240 begin
241 // ev.button.clicks: Byte
242 if (ev.type_ = SDL_MOUSEBUTTONDOWN) then fuiSetButState(fuiButState or mev.but) else fuiSetButState(fuiButState and (not mev.but));
244 begin
250 SDL_MOUSEWHEEL:
251 begin
253 begin
259 if (ev.wheel.y < 0) then mev.but := THMouseEvent.WheelUp else mev.but := THMouseEvent.WheelDown;
265 begin
271 SDL_MOUSEMOTION:
272 begin
286 begin
292 {
293 SDL_TEXTINPUT:
294 begin
295 Utf8ToUnicode(@uc, PChar(ev.text.text), 1);
296 keychr := Word(uc);
297 if (keychr > 127) then keychr := Word(wchar2win(WideChar(keychr)));
298 CharPress(AnsiChar(keychr));
299 end;
300 }
305 begin