@@ -19,30 +19,20 @@ ENGINE_API Flags32 psMouseInvert = {FALSE};
1919
2020float stop_vibration_time = flt_max;
2121
22- #define MOUSEBUFFERSIZE 64
23- #define KEYBOARDBUFFERSIZE 64
24-
25- static bool g_exclusive = true ;
2622static void on_error_dialog (bool before)
2723{
28- if (!pInput || !g_exclusive || Device.editor ())
24+ if (!pInput || !pInput-> IsExclusiveMode () || Device.editor ())
2925 return ;
3026
3127 if (before)
32- {
33- pInput->ClipCursor (false );
34- pInput->unacquire ();
35- }
28+ pInput->GrabInput (false );
3629 else
37- {
38- pInput->ClipCursor (true );
39- pInput->acquire (true );
40- }
30+ pInput->GrabInput (true );
4131}
4232
43- CInput::CInput (bool exclusive, int deviceForInit )
33+ CInput::CInput (const bool exclusive)
4434{
45- g_exclusive = exclusive;
35+ exclusiveInput = exclusive;
4636
4737 Log (" Starting INPUT device..." );
4838
@@ -58,22 +48,20 @@ CInput::CInput(bool exclusive, int deviceForInit)
5848
5949 xrDebug::SetDialogHandler (on_error_dialog);
6050
51+ SDL_SetHint (SDL_HINT_GRAB_KEYBOARD, " 1" );
6152 SDL_StopTextInput (); // sanity
6253
63- #ifdef ENGINE_BUILD
6454 Device.seqAppActivate .Add (this );
6555 Device.seqAppDeactivate .Add (this , REG_PRIORITY_HIGH);
6656 Device.seqFrame .Add (this , REG_PRIORITY_HIGH);
67- #endif
6857}
6958
70- CInput::~CInput (void )
59+ CInput::~CInput ()
7160{
72- # ifdef ENGINE_BUILD
61+ GrabInput ( false );
7362 Device.seqFrame .Remove (this );
7463 Device.seqAppDeactivate .Remove (this );
7564 Device.seqAppActivate .Remove (this );
76- #endif
7765}
7866
7967// -----------------------------------------------------------------------
@@ -83,12 +71,6 @@ void CInput::DumpStatistics(IGameFont& font, IPerformanceAlert* alert)
8371 font.OutNext (" *** INPUT: %2.2fms" , pInput->GetStats ().FrameTime .result );
8472}
8573
86- void CInput::SetAllAcquire (bool bAcquire) {}
87-
88- void CInput::SetMouseAcquire (bool bAcquire) {}
89- void CInput::SetKBDAcquire (bool bAcquire) {}
90-
91-
9274void CInput::MouseUpdate ()
9375{
9476 SDL_PumpEvents ();
@@ -255,21 +237,37 @@ bool CInput::iGetAsyncBtnState(int btn)
255237{
256238 return mouseState[btn];
257239}
258- void CInput::ClipCursor (bool clip)
240+
241+ void CInput::ClipCursor (const bool clip)
259242{
260243 if (clip)
261244 {
262- SDL_SetWindowGrab (Device. m_sdlWnd , SDL_TRUE);
245+ SDL_ShowCursor ( SDL_TRUE);
263246 SDL_SetRelativeMouseMode (SDL_TRUE);
264247 }
265248 else
266249 {
267- SDL_SetWindowGrab (Device. m_sdlWnd , SDL_FALSE);
250+ SDL_ShowCursor ( SDL_FALSE);
268251 SDL_SetRelativeMouseMode (SDL_FALSE);
269252 }
270253}
271254
272- // -------------------------------------------------------
255+ void CInput::GrabInput (const bool grab)
256+ {
257+ ClipCursor (grab);
258+
259+ if (IsExclusiveMode ())
260+ SDL_SetWindowGrab (Device.m_sdlWnd , grab ? SDL_TRUE : SDL_FALSE);
261+
262+ inputGrabbed = grab;
263+
264+ }
265+
266+ bool CInput::InputIsGrabbed () const
267+ {
268+ return inputGrabbed;
269+ }
270+
273271void CInput::iCapture (IInputReceiver* p)
274272{
275273 VERIFY (p);
@@ -313,7 +311,6 @@ void CInput::OnAppActivate(void)
313311 if (CurrentIR ())
314312 CurrentIR ()->IR_OnActivate ();
315313
316- SetAllAcquire (true );
317314 ZeroMemory (mouseState, sizeof (mouseState));
318315 ZeroMemory (keyboardState, sizeof (keyboardState));
319316 ZeroMemory (mouseTimeStamp, sizeof (mouseTimeStamp));
@@ -325,7 +322,6 @@ void CInput::OnAppDeactivate(void)
325322 if (CurrentIR ())
326323 CurrentIR ()->IR_OnDeactivate ();
327324
328- SetAllAcquire (false );
329325 ZeroMemory (mouseState, sizeof (mouseState));
330326 ZeroMemory (keyboardState, sizeof (keyboardState));
331327 ZeroMemory (mouseTimeStamp, sizeof (mouseTimeStamp));
@@ -352,26 +348,18 @@ IInputReceiver* CInput::CurrentIR()
352348{
353349 if (cbStack.size ())
354350 return cbStack.back ();
355- else
356- return NULL ;
351+ return nullptr ;
357352}
358353
359- void CInput::unacquire () {}
360-
361- void CInput::acquire (const bool & exclusive)
354+ void CInput::ExclusiveMode (const bool exclusive)
362355{
363- // pMouse->SetCooperativeLevel(Device.editor() ? Device.editor()->main_handle() : RDEVICE.m_sdlWnd,
364- // ( exclusive ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE) | DISCL_FOREGROUND | DISCL_NOWINKEY) ;
365- // pMouse->Acquire( );
356+ GrabInput ( false );
357+ exclusiveInput = exclusive;
358+ GrabInput ( true );
366359}
367360
368- void CInput::exclusive_mode (const bool & exclusive)
369- {
370- g_exclusive = exclusive;
371- unacquire ();
372- acquire (exclusive);
373- }
374- bool CInput::get_exclusive_mode () { return g_exclusive; }
361+ bool CInput::IsExclusiveMode () const { return exclusiveInput; }
362+
375363void CInput::feedback (u16 s1, u16 s2, float time)
376364{
377365 stop_vibration_time = RDEVICE.fTimeGlobal + time;
0 commit comments