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
72 {$INCLUDE ../nogl/noGLuses.inc}
73 {$IF DEFINED(LINUX) OR DEFINED(ANDROID)}
74 unixtype, linux
75 {$ELSEIF DEFINED(WINDOWS)}
76 Windows
77 {$ELSEIF DEFINED(HAIKU)}
78 unixtype
79 {$ELSE}
80 {$WARNING You suck!}
81 {$ENDIF}
82 ;
85 // ////////////////////////////////////////////////////////////////////////// //
86 var
90 procedure setFUIFPS (v: Integer); inline; begin if (v < 1) then v := 1 else if (v > 60*4) then v := 60*4; gEffFPS := v; end;
93 // ////////////////////////////////////////////////////////////////////////// //
94 {$IF DEFINED(LINUX)}
96 {$ELSE}
98 {$ENDIF}
100 var
105 var
107 begin
109 begin
110 {$IF DEFINED(LINUX)}
111 if (clock_getres(CLOCK_MONOTONIC, @r) <> 0) then raise Exception.Create('profiler error: cannot get timer resolution');
116 {$ELSEIF DEFINED(WINDOWS)}
120 {$ENDIF}
126 var
128 begin
129 //if (mFrequency = 0) then initTimerIntr();
130 {$IF DEFINED(LINUX)}
133 {$ELSEIF DEFINED(WINDOWS)}
136 {$ENDIF}
141 begin
146 // ////////////////////////////////////////////////////////////////////////// //
147 var
152 // ////////////////////////////////////////////////////////////////////////// //
153 const
155 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
156 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
157 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
158 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
159 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
160 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
161 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
163 );
167 var
169 begin
178 begin
184 // ////////////////////////////////////////////////////////////////////////// //
186 var
192 begin
202 begin
204 SDL_WINDOWEVENT_MINIMIZED: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
206 begin
208 begin
215 SDL_WINDOWEVENT_FOCUS_GAINED: if not fuiWinActive then begin fuiWinActive := true; if assigned(winFocusCB) then winFocusCB(); end;
216 SDL_WINDOWEVENT_FOCUS_LOST: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
220 begin
228 begin
229 // fix left/right modifiers
231 begin
233 end
234 else
235 begin
251 SDL_SCANCODE_LCTRL: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModCtrl) else fuiSetModState(fuiModState and (not TFUIEvent.ModCtrl));
252 SDL_SCANCODE_LALT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModAlt) else fuiSetModState(fuiModState and (not TFUIEvent.ModAlt));
253 SDL_SCANCODE_LSHIFT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModShift) else fuiSetModState(fuiModState and (not TFUIEvent.ModShift));
257 begin
264 begin
266 begin
268 end
269 else
270 begin
283 begin
284 // ev.button.clicks: Byte
285 if (ev.type_ = SDL_MOUSEBUTTONDOWN) then fuiSetButState(fuiButState or fev.but) else fuiSetButState(fuiButState and (not fev.but));
287 begin
293 SDL_MOUSEWHEEL:
294 begin
296 begin
306 begin
312 SDL_MOUSEMOTION:
313 begin
325 begin
331 SDL_TEXTINPUT:
333 begin
338 begin
353 begin