2024-02-05 23:49:00 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "Emu/Io/MouseHandler.h"
|
|
|
|
|
#include "Emu/RSX/display.h"
|
2024-05-20 14:01:20 +02:00
|
|
|
#include "Utilities/Config.h"
|
2024-05-23 01:20:25 +02:00
|
|
|
#include "Utilities/mutex.h"
|
2024-05-21 23:51:55 +02:00
|
|
|
#include "Utilities/Thread.h"
|
2024-02-05 23:49:00 +01:00
|
|
|
|
|
|
|
|
class raw_mouse_handler;
|
|
|
|
|
|
|
|
|
|
class raw_mouse
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
raw_mouse() {}
|
|
|
|
|
raw_mouse(u32 index, const std::string& device_name, void* handle, raw_mouse_handler* handler);
|
|
|
|
|
virtual ~raw_mouse();
|
|
|
|
|
|
|
|
|
|
void update_window_handle();
|
|
|
|
|
display_handle_t window_handle() const { return m_window_handle; }
|
|
|
|
|
|
2024-02-13 22:52:48 +01:00
|
|
|
void center_cursor();
|
|
|
|
|
|
2024-02-05 23:49:00 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
void update_values(const RAWMOUSE& state);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-05-20 14:01:20 +02:00
|
|
|
const std::string& device_name() const { return m_device_name; }
|
|
|
|
|
u32 index() const { return m_index; }
|
2024-07-30 21:11:01 +02:00
|
|
|
void set_index(u32 index);
|
2025-01-13 22:12:26 +01:00
|
|
|
void request_reload() { m_reload_requested = true; }
|
2024-05-20 14:01:20 +02:00
|
|
|
|
2024-02-05 23:49:00 +01:00
|
|
|
private:
|
2025-01-13 22:12:26 +01:00
|
|
|
struct mouse_button
|
|
|
|
|
{
|
|
|
|
|
int down = 0;
|
|
|
|
|
int up = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
static const std::unordered_map<int, raw_mouse::mouse_button> btn_pairs;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-06-26 18:57:41 +02:00
|
|
|
void reload_config();
|
2025-01-13 22:12:26 +01:00
|
|
|
static mouse_button get_mouse_button(const cfg::string& button);
|
2020-12-24 13:48:22 +01:00
|
|
|
|
2024-02-05 23:49:00 +01:00
|
|
|
u32 m_index = 0;
|
|
|
|
|
std::string m_device_name;
|
|
|
|
|
void* m_handle{};
|
|
|
|
|
display_handle_t m_window_handle{};
|
|
|
|
|
int m_window_width{};
|
|
|
|
|
int m_window_height{};
|
2024-02-14 19:26:27 +01:00
|
|
|
int m_window_width_old{};
|
|
|
|
|
int m_window_height_old{};
|
2024-02-05 23:49:00 +01:00
|
|
|
int m_pos_x{};
|
|
|
|
|
int m_pos_y{};
|
|
|
|
|
float m_mouse_acceleration = 1.0f;
|
|
|
|
|
raw_mouse_handler* m_handler{};
|
2025-01-13 22:12:26 +01:00
|
|
|
std::map<u8, mouse_button> m_buttons;
|
|
|
|
|
bool m_reload_requested = false;
|
2024-02-05 23:49:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class raw_mouse_handler final : public MouseHandlerBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
2024-06-20 18:23:36 +02:00
|
|
|
using MouseHandlerBase::MouseHandlerBase;
|
|
|
|
|
|
2024-02-05 23:49:00 +01:00
|
|
|
virtual ~raw_mouse_handler();
|
|
|
|
|
|
|
|
|
|
void Init(const u32 max_connect) override;
|
|
|
|
|
|
2025-01-13 22:12:26 +01:00
|
|
|
void set_is_for_gui(bool value) { m_is_for_gui = value; }
|
|
|
|
|
bool is_for_gui() const { return m_is_for_gui; }
|
2024-06-20 18:23:36 +02:00
|
|
|
|
2024-05-20 14:01:20 +02:00
|
|
|
const std::map<void*, raw_mouse>& get_mice() const { return m_raw_mice; };
|
|
|
|
|
|
2025-01-13 22:12:26 +01:00
|
|
|
void set_mouse_press_callback(std::function<void(const std::string&, s32, s32, bool)> cb)
|
2024-05-20 14:43:17 +02:00
|
|
|
{
|
|
|
|
|
m_mouse_press_callback = std::move(cb);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 22:12:26 +01:00
|
|
|
void mouse_press_callback(const std::string& device_name, s32 cell_code, s32 button_code, bool pressed)
|
2024-05-20 14:43:17 +02:00
|
|
|
{
|
|
|
|
|
if (m_mouse_press_callback)
|
|
|
|
|
{
|
2025-01-13 22:12:26 +01:00
|
|
|
m_mouse_press_callback(device_name, cell_code, button_code, pressed);
|
2024-05-20 14:43:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 00:39:08 +02:00
|
|
|
void update_devices();
|
|
|
|
|
|
2024-02-05 23:49:00 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
void handle_native_event(const MSG& msg);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-05-22 00:39:08 +02:00
|
|
|
shared_mutex m_raw_mutex;
|
|
|
|
|
|
2024-02-05 23:49:00 +01:00
|
|
|
private:
|
2024-05-21 23:51:55 +02:00
|
|
|
u32 get_now_connect(std::set<u32>& connected_mice);
|
2024-05-23 01:20:25 +02:00
|
|
|
std::map<void*, raw_mouse> enumerate_devices(u32 max_connect);
|
2024-02-05 23:49:00 +01:00
|
|
|
|
2024-05-21 23:04:48 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
void register_raw_input_devices();
|
2024-08-12 20:31:06 +02:00
|
|
|
void unregister_raw_input_devices() const;
|
2024-05-21 23:04:48 +02:00
|
|
|
bool m_registered_raw_input_devices = false;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-05-22 00:39:08 +02:00
|
|
|
bool m_is_for_gui = false;
|
2024-02-05 23:49:00 +01:00
|
|
|
std::map<void*, raw_mouse> m_raw_mice;
|
2025-01-13 22:12:26 +01:00
|
|
|
std::function<void(const std::string&, s32, s32, bool)> m_mouse_press_callback;
|
2024-05-21 23:51:55 +02:00
|
|
|
|
|
|
|
|
std::unique_ptr<named_thread<std::function<void()>>> m_thread;
|
2024-02-05 23:49:00 +01:00
|
|
|
};
|