suyu/src/input_common/mouse/mouse_input.h

117 lines
2.9 KiB
C++
Raw Normal View History

2020-11-18 05:55:09 +01:00
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
2020-12-03 16:25:10 +01:00
#include <array>
2020-11-18 05:55:09 +01:00
#include <mutex>
#include <stop_token>
2020-11-18 05:55:09 +01:00
#include <thread>
2020-12-03 16:25:10 +01:00
2020-11-18 05:55:09 +01:00
#include "common/common_types.h"
#include "common/threadsafe_queue.h"
2020-12-03 16:25:10 +01:00
#include "common/vector_math.h"
2020-11-18 05:55:09 +01:00
#include "core/frontend/input.h"
#include "input_common/motion_input.h"
namespace MouseInput {
enum class MouseButton {
Left,
Right,
2021-02-24 03:39:02 +01:00
Wheel,
2020-11-18 05:55:09 +01:00
Backward,
2021-02-24 03:39:02 +01:00
Forward,
Task,
Extra,
2020-11-18 05:55:09 +01:00
Undefined,
};
struct MouseStatus {
MouseButton button{MouseButton::Undefined};
};
struct MouseData {
bool pressed{};
std::array<int, 2> axis{};
Input::MotionStatus motion{};
Input::TouchStatus touch{};
};
class Mouse {
public:
Mouse();
~Mouse();
/// Used for polling
void BeginConfiguration();
void EndConfiguration();
/**
* Signals that a button is pressed.
* @param x the x-coordinate of the cursor
* @param y the y-coordinate of the cursor
* @param button_ the button pressed
2020-11-18 05:55:09 +01:00
*/
2021-02-24 03:39:02 +01:00
void PressButton(int x, int y, MouseButton button_);
2020-11-18 05:55:09 +01:00
/**
* Signals that mouse has moved.
* @param x the x-coordinate of the cursor
* @param y the y-coordinate of the cursor
2021-02-03 19:34:25 +01:00
* @param center_x the x-coordinate of the middle of the screen
* @param center_y the y-coordinate of the middle of the screen
2020-11-18 05:55:09 +01:00
*/
2021-02-03 19:34:25 +01:00
void MouseMove(int x, int y, int center_x, int center_y);
2020-11-18 05:55:09 +01:00
/**
* Signals that a button is released.
* @param button_ the button pressed
2020-11-18 05:55:09 +01:00
*/
2021-02-24 03:39:02 +01:00
void ReleaseButton(MouseButton button_);
2020-11-18 05:55:09 +01:00
/**
* Signals that all buttons are released
*/
void ReleaseAllButtons();
2021-03-06 20:27:02 +01:00
[[nodiscard]] bool ToggleButton(std::size_t button_);
[[nodiscard]] bool UnlockButton(std::size_t button_);
2020-11-18 05:55:09 +01:00
[[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue();
[[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const;
[[nodiscard]] MouseData& GetMouseState(std::size_t button);
[[nodiscard]] const MouseData& GetMouseState(std::size_t button) const;
private:
void UpdateThread(std::stop_token stop_token);
2020-11-18 05:55:09 +01:00
void UpdateYuzuSettings();
2021-02-03 19:34:25 +01:00
void StopPanning();
2020-11-18 05:55:09 +01:00
struct MouseInfo {
InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f};
Common::Vec2<int> mouse_origin;
Common::Vec2<int> last_mouse_position;
2021-02-03 19:34:25 +01:00
Common::Vec2<float> last_mouse_change;
2020-11-18 05:55:09 +01:00
bool is_tilting = false;
float sensitivity{0.120f};
float tilt_speed = 0;
Common::Vec2<float> tilt_direction;
MouseData data;
};
u16 buttons{};
2021-03-06 20:27:02 +01:00
u16 toggle_buttons{};
u16 lock_buttons{};
std::jthread update_thread;
2020-11-18 05:55:09 +01:00
MouseButton last_button{MouseButton::Undefined};
2021-02-24 03:39:02 +01:00
std::array<MouseInfo, 7> mouse_info;
2020-11-18 05:55:09 +01:00
Common::SPSCQueue<MouseStatus> mouse_queue;
bool configuring{false};
2021-02-03 19:34:25 +01:00
int mouse_panning_timout{};
2020-11-18 05:55:09 +01:00
};
} // namespace MouseInput