20363e688fd9345414248373f62f4e806974f005
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 {$IFNDEF USE_SDL2}
19 {$FATAL SDL2 required for flexui sdlcarcass}
20 {$ENDIF}
22 interface
24 uses
28 // ////////////////////////////////////////////////////////////////////////// //
29 // call this with SDL2 event; returns `true` if event was eaten
33 // ////////////////////////////////////////////////////////////////////////// //
34 // event handlers
35 var
36 winFocusCB: procedure () = nil; // this will be called when window got focus; `fuiWinActive` already set
37 winBlurCB: procedure () = nil; // this will be called when window lost focus; `fuiWinActive` already set
38 // for standalone
41 exposeFrameCB: procedure () = nil; // call `glSwap()` here instead; automatically set by standalone
42 //
50 var
51 // default size
58 // ////////////////////////////////////////////////////////////////////////// //
63 // ////////////////////////////////////////////////////////////////////////// //
64 // only for standalone mode
71 implementation
73 uses
75 {$IF DEFINED(LINUX) OR DEFINED(ANDROID)}
76 unixtype, linux
77 {$ELSEIF DEFINED(WINDOWS)}
78 Windows
79 {$ELSEIF DEFINED(HAIKU) OR DEFINED(UNIX)}
80 unixtype
81 {$ELSE}
82 {$WARNING You suck!}
83 {$ENDIF}
84 ;
87 // ////////////////////////////////////////////////////////////////////////// //
88 var
92 procedure setFUIFPS (v: Integer); inline; begin if (v < 1) then v := 1 else if (v > 60*4) then v := 60*4; gEffFPS := v; end;
95 // ////////////////////////////////////////////////////////////////////////// //
96 {$IF DEFINED(LINUX)}
98 {$ELSE}
100 {$ENDIF}
102 var
107 var
109 begin
111 begin
112 {$IF DEFINED(LINUX)}
113 if (clock_getres(CLOCK_MONOTONIC, @r) <> 0) then raise Exception.Create('profiler error: cannot get timer resolution');
118 {$ELSEIF DEFINED(WINDOWS)}
122 {$ENDIF}
128 var
130 begin
131 //if (mFrequency = 0) then initTimerIntr();
132 {$IF DEFINED(LINUX)}
135 {$ELSEIF DEFINED(WINDOWS)}
138 {$ENDIF}
143 begin
148 // ////////////////////////////////////////////////////////////////////////// //
149 var
154 // ////////////////////////////////////////////////////////////////////////// //
155 const
157 $0402,$0403,$201A,$0453,$201E,$2026,$2020,$2021,$20AC,$2030,$0409,$2039,$040A,$040C,$040B,$040F,
158 $0452,$2018,$2019,$201C,$201D,$2022,$2013,$2014,$003F,$2122,$0459,$203A,$045A,$045C,$045B,$045F,
159 $00A0,$040E,$045E,$0408,$00A4,$0490,$00A6,$00A7,$0401,$00A9,$0404,$00AB,$00AC,$00AD,$00AE,$0407,
160 $00B0,$00B1,$0406,$0456,$0491,$00B5,$00B6,$00B7,$0451,$2116,$0454,$00BB,$0458,$0405,$0455,$0457,
161 $0410,$0411,$0412,$0413,$0414,$0415,$0416,$0417,$0418,$0419,$041A,$041B,$041C,$041D,$041E,$041F,
162 $0420,$0421,$0422,$0423,$0424,$0425,$0426,$0427,$0428,$0429,$042A,$042B,$042C,$042D,$042E,$042F,
163 $0430,$0431,$0432,$0433,$0434,$0435,$0436,$0437,$0438,$0439,$043A,$043B,$043C,$043D,$043E,$043F,
165 );
169 var
171 begin
180 begin
186 // ////////////////////////////////////////////////////////////////////////// //
188 var
194 begin
204 begin
206 SDL_WINDOWEVENT_MINIMIZED: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
208 begin
210 begin
217 SDL_WINDOWEVENT_FOCUS_GAINED: if not fuiWinActive then begin fuiWinActive := true; if assigned(winFocusCB) then winFocusCB(); end;
218 SDL_WINDOWEVENT_FOCUS_LOST: if fuiWinActive then begin fuiResetKMState(true); fuiWinActive := false; if assigned(winBlurCB) then winBlurCB(); end;
222 begin
230 begin
231 // fix left/right modifiers
233 begin
235 end
236 else
237 begin
253 SDL_SCANCODE_LCTRL: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModCtrl) else fuiSetModState(fuiModState and (not TFUIEvent.ModCtrl));
254 SDL_SCANCODE_LALT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModAlt) else fuiSetModState(fuiModState and (not TFUIEvent.ModAlt));
255 SDL_SCANCODE_LSHIFT: if (fev.press) then fuiSetModState(fuiModState or TFUIEvent.ModShift) else fuiSetModState(fuiModState and (not TFUIEvent.ModShift));
259 begin
266 begin
268 begin
270 end
271 else
272 begin
285 begin
286 // ev.button.clicks: Byte
287 if (ev.type_ = SDL_MOUSEBUTTONDOWN) then fuiSetButState(fuiButState or fev.but) else fuiSetButState(fuiButState and (not fev.but));
289 begin
295 SDL_MOUSEWHEEL:
296 begin
298 begin
308 begin
314 SDL_MOUSEMOTION:
315 begin
327 begin
333 SDL_TEXTINPUT:
335 begin
340 begin
355 begin