summaryrefslogtreecommitdiff
path: root/src/yuzu_cmd
diff options
context:
space:
mode:
authorGravatar german772021-02-23 20:39:02 -0600
committerGravatar german2021-02-27 17:53:10 -0600
commit4738e14cb052a44c53e47379e595f00cef034dca (patch)
tree4264dd4e9d4a750951d1581241c484513c89b571 /src/yuzu_cmd
parentMerge pull request #5944 from Morph1984/gc-vibrations (diff)
downloadyuzu-4738e14cb052a44c53e47379e595f00cef034dca.tar.gz
yuzu-4738e14cb052a44c53e47379e595f00cef034dca.tar.xz
yuzu-4738e14cb052a44c53e47379e595f00cef034dca.zip
inputCommon: Mouse fixes
Diffstat (limited to 'src/yuzu_cmd')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp24
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.h7
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) {
35 input_subsystem->GetMouse()->MouseMove(x, y, 0, 0); 35 input_subsystem->GetMouse()->MouseMove(x, y, 0, 0);
36} 36}
37 37
38MouseInput::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const {
39 switch (button) {
40 case SDL_BUTTON_LEFT:
41 return MouseInput::MouseButton::Left;
42 case SDL_BUTTON_RIGHT:
43 return MouseInput::MouseButton::Right;
44 case SDL_BUTTON_MIDDLE:
45 return MouseInput::MouseButton::Wheel;
46 case SDL_BUTTON_X1:
47 return MouseInput::MouseButton::Backward;
48 case SDL_BUTTON_X2:
49 return MouseInput::MouseButton::Forward;
50 default:
51 return MouseInput::MouseButton::Undefined;
52 }
53}
54
38void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { 55void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
56 const auto mouse_button = SDLButtonToMouseButton(button);
39 if (button == SDL_BUTTON_LEFT) { 57 if (button == SDL_BUTTON_LEFT) {
40 if (state == SDL_PRESSED) { 58 if (state == SDL_PRESSED) {
41 TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0); 59 TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0);
42 } else { 60 } else {
43 TouchReleased(0); 61 TouchReleased(0);
44 } 62 }
45 } else if (button == SDL_BUTTON_RIGHT) { 63 } else {
46 if (state == SDL_PRESSED) { 64 if (state == SDL_PRESSED) {
47 input_subsystem->GetMouse()->PressButton(x, y, button); 65 input_subsystem->GetMouse()->PressButton(x, y, mouse_button);
48 } else { 66 } else {
49 input_subsystem->GetMouse()->ReleaseButton(button); 67 input_subsystem->GetMouse()->ReleaseButton(mouse_button);
50 } 68 }
51 } 69 }
52} 70}
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 {
18class InputSubsystem; 18class InputSubsystem;
19} 19}
20 20
21namespace MouseInput {
22enum class MouseButton;
23}
24
21class EmuWindow_SDL2 : public Core::Frontend::EmuWindow { 25class EmuWindow_SDL2 : public Core::Frontend::EmuWindow {
22public: 26public:
23 explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem); 27 explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem);
@@ -42,6 +46,9 @@ protected:
42 /// Called by WaitEvent when the mouse moves. 46 /// Called by WaitEvent when the mouse moves.
43 void OnMouseMotion(s32 x, s32 y); 47 void OnMouseMotion(s32 x, s32 y);
44 48
49 /// Converts a SDL mouse button into MouseInput mouse button
50 MouseInput::MouseButton SDLButtonToMouseButton(u32 button) const;
51
45 /// Called by WaitEvent when a mouse button is pressed or released 52 /// Called by WaitEvent when a mouse button is pressed or released
46 void OnMouseButton(u32 button, u8 state, s32 x, s32 y); 53 void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
47 54