diff options
author | Patric Stout <truebrain@openttd.org> | 2021-02-19 11:01:49 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-02-20 17:08:44 +0100 |
commit | 661eb39ecc3a128c24dbbc4f53d1c075fe89bc93 (patch) | |
tree | c579f44c8186f43169138cafce3ed02d38baf2ef /src/video/win32_v.cpp | |
parent | 38b4ae1c0ea05944cda66a499454a5b08a7a4462 (diff) | |
download | openttd-661eb39ecc3a128c24dbbc4f53d1c075fe89bc93.tar.xz |
Codechange: move all input-handling of video-drivers into InputLoop
Diffstat (limited to 'src/video/win32_v.cpp')
-rw-r--r-- | src/video/win32_v.cpp | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 3f230e621..f55a9c372 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -1118,6 +1118,40 @@ void VideoDriver_Win32::CheckPaletteAnim() this->MakeDirty(0, 0, _screen.width, _screen.height); } +void VideoDriver_Win32::InputLoop() +{ + bool old_ctrl_pressed = _ctrl_pressed; + + _ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL) < 0; + _shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0; + +#if defined(_DEBUG) + if (_shift_pressed) +#else + /* Speedup when pressing tab, except when using ALT+TAB + * to switch to another application. */ + if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0) +#endif + { + if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; + } else if (_fast_forward & 2) { + _fast_forward = 0; + } + + /* Determine which directional keys are down. */ + if (_wnd.has_focus) { + _dirkeys = + (GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) + + (GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) + + (GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) + + (GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0); + } else { + _dirkeys = 0; + } + + if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); +} + void VideoDriver_Win32::MainLoop() { MSG mesg; @@ -1174,18 +1208,6 @@ void VideoDriver_Win32::MainLoop() } if (_exit_game) break; -#if defined(_DEBUG) - if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0) -#else - /* Speed up using TAB, but disable for ALT+TAB of course */ - if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0) -#endif - { - if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; - } else if (_fast_forward & 2) { - _fast_forward = 0; - } - cur_ticks = std::chrono::steady_clock::now(); /* If more than a millisecond has passed, increase the _realtime_tick. */ @@ -1220,30 +1242,13 @@ void VideoDriver_Win32::MainLoop() /* Avoid next_draw_tick getting behind more and more if it cannot keep up. */ if (next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) next_draw_tick = cur_ticks; - bool old_ctrl_pressed = _ctrl_pressed; - - _ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0; - _shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0; - - /* determine which directional keys are down */ - if (_wnd.has_focus) { - _dirkeys = - (GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) + - (GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) + - (GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) + - (GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0); - } else { - _dirkeys = 0; - } - - if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); - if (_force_full_redraw) MarkWholeScreenDirty(); /* Flush GDI buffer to ensure we don't conflict with the drawing thread. */ GdiFlush(); - InputLoop(); + this->InputLoop(); + ::InputLoop(); UpdateWindows(); CheckPaletteAnim(); |