diff options
Diffstat (limited to 'src/input_common/mouse')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 47 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.h | 17 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 20 |
3 files changed, 71 insertions, 13 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index b864d26f2..329e416c7 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp | |||
| @@ -59,7 +59,7 @@ void Mouse::UpdateYuzuSettings() { | |||
| 59 | }); | 59 | }); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | void Mouse::PressButton(int x, int y, int button_) { | 62 | void Mouse::PressButton(int x, int y, MouseButton button_) { |
| 63 | const auto button_index = static_cast<std::size_t>(button_); | 63 | const auto button_index = static_cast<std::size_t>(button_); |
| 64 | if (button_index >= mouse_info.size()) { | 64 | if (button_index >= mouse_info.size()) { |
| 65 | return; | 65 | return; |
| @@ -67,7 +67,7 @@ void Mouse::PressButton(int x, int y, int button_) { | |||
| 67 | 67 | ||
| 68 | const auto button = 1U << button_index; | 68 | const auto button = 1U << button_index; |
| 69 | buttons |= static_cast<u16>(button); | 69 | buttons |= static_cast<u16>(button); |
| 70 | last_button = static_cast<MouseButton>(button_index); | 70 | last_button = button_; |
| 71 | 71 | ||
| 72 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); | 72 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); |
| 73 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); | 73 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); |
| @@ -129,7 +129,7 @@ void Mouse::MouseMove(int x, int y, int center_x, int center_y) { | |||
| 129 | } | 129 | } |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | void Mouse::ReleaseButton(int button_) { | 132 | void Mouse::ReleaseButton(MouseButton button_) { |
| 133 | const auto button_index = static_cast<std::size_t>(button_); | 133 | const auto button_index = static_cast<std::size_t>(button_); |
| 134 | if (button_index >= mouse_info.size()) { | 134 | if (button_index >= mouse_info.size()) { |
| 135 | return; | 135 | return; |
| @@ -152,11 +152,52 @@ void Mouse::BeginConfiguration() { | |||
| 152 | 152 | ||
| 153 | void Mouse::EndConfiguration() { | 153 | void Mouse::EndConfiguration() { |
| 154 | buttons = 0; | 154 | buttons = 0; |
| 155 | for (MouseInfo& info : mouse_info) { | ||
| 156 | info.tilt_speed = 0; | ||
| 157 | info.data.pressed = false; | ||
| 158 | info.data.axis = {0, 0}; | ||
| 159 | } | ||
| 155 | last_button = MouseButton::Undefined; | 160 | last_button = MouseButton::Undefined; |
| 156 | mouse_queue.Clear(); | 161 | mouse_queue.Clear(); |
| 157 | configuring = false; | 162 | configuring = false; |
| 158 | } | 163 | } |
| 159 | 164 | ||
| 165 | bool Mouse::ToggleButton(std::size_t button_) { | ||
| 166 | if (button_ >= mouse_info.size()) { | ||
| 167 | return false; | ||
| 168 | } | ||
| 169 | const auto button = 1U << button_; | ||
| 170 | const bool button_state = (toggle_buttons & button) != 0; | ||
| 171 | const bool button_lock = (lock_buttons & button) != 0; | ||
| 172 | |||
| 173 | if (button_lock) { | ||
| 174 | return button_state; | ||
| 175 | } | ||
| 176 | |||
| 177 | lock_buttons |= static_cast<u16>(button); | ||
| 178 | |||
| 179 | if (button_state) { | ||
| 180 | toggle_buttons &= static_cast<u16>(0xFF - button); | ||
| 181 | } else { | ||
| 182 | toggle_buttons |= static_cast<u16>(button); | ||
| 183 | } | ||
| 184 | |||
| 185 | return !button_state; | ||
| 186 | } | ||
| 187 | |||
| 188 | bool Mouse::UnlockButton(std::size_t button_) { | ||
| 189 | if (button_ >= mouse_info.size()) { | ||
| 190 | return false; | ||
| 191 | } | ||
| 192 | |||
| 193 | const auto button = 1U << button_; | ||
| 194 | const bool button_state = (toggle_buttons & button) != 0; | ||
| 195 | |||
| 196 | lock_buttons &= static_cast<u16>(0xFF - button); | ||
| 197 | |||
| 198 | return button_state; | ||
| 199 | } | ||
| 200 | |||
| 160 | Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { | 201 | Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { |
| 161 | return mouse_queue; | 202 | return mouse_queue; |
| 162 | } | 203 | } |
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 46aa676c1..750d9b011 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h | |||
| @@ -18,10 +18,12 @@ namespace MouseInput { | |||
| 18 | 18 | ||
| 19 | enum class MouseButton { | 19 | enum class MouseButton { |
| 20 | Left, | 20 | Left, |
| 21 | Wheel, | ||
| 22 | Right, | 21 | Right, |
| 23 | Forward, | 22 | Wheel, |
| 24 | Backward, | 23 | Backward, |
| 24 | Forward, | ||
| 25 | Task, | ||
| 26 | Extra, | ||
| 25 | Undefined, | 27 | Undefined, |
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| @@ -51,7 +53,7 @@ public: | |||
| 51 | * @param y the y-coordinate of the cursor | 53 | * @param y the y-coordinate of the cursor |
| 52 | * @param button_ the button pressed | 54 | * @param button_ the button pressed |
| 53 | */ | 55 | */ |
| 54 | void PressButton(int x, int y, int button_); | 56 | void PressButton(int x, int y, MouseButton button_); |
| 55 | 57 | ||
| 56 | /** | 58 | /** |
| 57 | * Signals that mouse has moved. | 59 | * Signals that mouse has moved. |
| @@ -65,7 +67,10 @@ public: | |||
| 65 | /** | 67 | /** |
| 66 | * Signals that a motion sensor tilt has ended. | 68 | * Signals that a motion sensor tilt has ended. |
| 67 | */ | 69 | */ |
| 68 | void ReleaseButton(int button_); | 70 | void ReleaseButton(MouseButton button_); |
| 71 | |||
| 72 | [[nodiscard]] bool ToggleButton(std::size_t button_); | ||
| 73 | [[nodiscard]] bool UnlockButton(std::size_t button_); | ||
| 69 | 74 | ||
| 70 | [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); | 75 | [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); |
| 71 | [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; | 76 | [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; |
| @@ -92,9 +97,11 @@ private: | |||
| 92 | }; | 97 | }; |
| 93 | 98 | ||
| 94 | u16 buttons{}; | 99 | u16 buttons{}; |
| 100 | u16 toggle_buttons{}; | ||
| 101 | u16 lock_buttons{}; | ||
| 95 | std::thread update_thread; | 102 | std::thread update_thread; |
| 96 | MouseButton last_button{MouseButton::Undefined}; | 103 | MouseButton last_button{MouseButton::Undefined}; |
| 97 | std::array<MouseInfo, 5> mouse_info; | 104 | std::array<MouseInfo, 7> mouse_info; |
| 98 | Common::SPSCQueue<MouseStatus> mouse_queue; | 105 | Common::SPSCQueue<MouseStatus> mouse_queue; |
| 99 | bool configuring{false}; | 106 | bool configuring{false}; |
| 100 | bool update_thread_running{true}; | 107 | bool update_thread_running{true}; |
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index bb56787ee..0e1db54fb 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp | |||
| @@ -14,16 +14,25 @@ namespace InputCommon { | |||
| 14 | 14 | ||
| 15 | class MouseButton final : public Input::ButtonDevice { | 15 | class MouseButton final : public Input::ButtonDevice { |
| 16 | public: | 16 | public: |
| 17 | explicit MouseButton(u32 button_, const MouseInput::Mouse* mouse_input_) | 17 | explicit MouseButton(u32 button_, bool toggle_, MouseInput::Mouse* mouse_input_) |
| 18 | : button(button_), mouse_input(mouse_input_) {} | 18 | : button(button_), toggle(toggle_), mouse_input(mouse_input_) {} |
| 19 | 19 | ||
| 20 | bool GetStatus() const override { | 20 | bool GetStatus() const override { |
| 21 | return mouse_input->GetMouseState(button).pressed; | 21 | const bool button_state = mouse_input->GetMouseState(button).pressed; |
| 22 | if (!toggle) { | ||
| 23 | return button_state; | ||
| 24 | } | ||
| 25 | |||
| 26 | if (button_state) { | ||
| 27 | return mouse_input->ToggleButton(button); | ||
| 28 | } | ||
| 29 | return mouse_input->UnlockButton(button); | ||
| 22 | } | 30 | } |
| 23 | 31 | ||
| 24 | private: | 32 | private: |
| 25 | const u32 button; | 33 | const u32 button; |
| 26 | const MouseInput::Mouse* mouse_input; | 34 | const bool toggle; |
| 35 | MouseInput::Mouse* mouse_input; | ||
| 27 | }; | 36 | }; |
| 28 | 37 | ||
| 29 | MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_input_) | 38 | MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_input_) |
| @@ -32,8 +41,9 @@ MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_ | |||
| 32 | std::unique_ptr<Input::ButtonDevice> MouseButtonFactory::Create( | 41 | std::unique_ptr<Input::ButtonDevice> MouseButtonFactory::Create( |
| 33 | const Common::ParamPackage& params) { | 42 | const Common::ParamPackage& params) { |
| 34 | const auto button_id = params.Get("button", 0); | 43 | const auto button_id = params.Get("button", 0); |
| 44 | const auto toggle = params.Get("toggle", false); | ||
| 35 | 45 | ||
| 36 | return std::make_unique<MouseButton>(button_id, mouse_input.get()); | 46 | return std::make_unique<MouseButton>(button_id, toggle, mouse_input.get()); |
| 37 | } | 47 | } |
| 38 | 48 | ||
| 39 | Common::ParamPackage MouseButtonFactory::GetNextInput() const { | 49 | Common::ParamPackage MouseButtonFactory::GetNextInput() const { |