diff options
author | bunnei <bunneidev@gmail.com> | 2021-03-08 23:50:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 23:50:58 +0100 |
commit | 9c4c9f1e7df65d74fed156c1788f48df6424e917 (patch) | |
tree | e04abbe4824d77458205596ad27f28816c38e597 /src/yuzu_cmd | |
parent | Merge pull request #6041 from bunnei/fiber-leaks (diff) | |
parent | inputCommon: Mouse fixes (diff) | |
download | yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.tar yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.tar.gz yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.tar.bz2 yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.tar.lz yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.tar.xz yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.tar.zst yuzu-9c4c9f1e7df65d74fed156c1788f48df6424e917.zip |
Diffstat (limited to 'src/yuzu_cmd')
-rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 24 | ||||
-rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.h | 7 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 7e391ab89..ce8b7c218 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -35,18 +35,36 @@ void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { input_subsystem->GetMouse()->MouseMove(x, y, 0, 0); } +MouseInput::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { + switch (button) { + case SDL_BUTTON_LEFT: + return MouseInput::MouseButton::Left; + case SDL_BUTTON_RIGHT: + return MouseInput::MouseButton::Right; + case SDL_BUTTON_MIDDLE: + return MouseInput::MouseButton::Wheel; + case SDL_BUTTON_X1: + return MouseInput::MouseButton::Backward; + case SDL_BUTTON_X2: + return MouseInput::MouseButton::Forward; + default: + return MouseInput::MouseButton::Undefined; + } +} + void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { + const auto mouse_button = SDLButtonToMouseButton(button); if (button == SDL_BUTTON_LEFT) { if (state == SDL_PRESSED) { TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0); } else { TouchReleased(0); } - } else if (button == SDL_BUTTON_RIGHT) { + } else { if (state == SDL_PRESSED) { - input_subsystem->GetMouse()->PressButton(x, y, button); + input_subsystem->GetMouse()->PressButton(x, y, mouse_button); } else { - input_subsystem->GetMouse()->ReleaseButton(button); + input_subsystem->GetMouse()->ReleaseButton(mouse_button); } } } diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h index 51a12a6a9..0e17bbca7 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h @@ -18,6 +18,10 @@ namespace InputCommon { class InputSubsystem; } +namespace MouseInput { +enum class MouseButton; +} + class EmuWindow_SDL2 : public Core::Frontend::EmuWindow { public: explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem); @@ -42,6 +46,9 @@ protected: /// Called by WaitEvent when the mouse moves. void OnMouseMotion(s32 x, s32 y); + /// Converts a SDL mouse button into MouseInput mouse button + MouseInput::MouseButton SDLButtonToMouseButton(u32 button) const; + /// Called by WaitEvent when a mouse button is pressed or released void OnMouseButton(u32 button, u8 state, s32 x, s32 y); |