input: simplify raw mouse button press handling

This commit is contained in:
Megamouse 2025-01-13 22:37:13 +01:00
parent b65f977c54
commit 78a661db79
4 changed files with 15 additions and 31 deletions

View File

@ -148,45 +148,29 @@ void raw_mouse::update_values(const RAWMOUSE& state)
// Only update the value if either down or up flags are present
if ((state.usButtonFlags & btn.down))
{
m_handler->mouse_press_callback(m_device_name, 0, up, true);
m_handler->mouse_press_callback(m_device_name, up, true);
}
else if ((state.usButtonFlags & btn.up))
{
m_handler->mouse_press_callback(m_device_name, 0, up, false);
m_handler->mouse_press_callback(m_device_name, up, false);
}
}
return;
}
const auto get_button_pressed = [this](u8 button, int button_flags)
// Get mouse buttons
for (const auto& [button, btn] : m_buttons)
{
const auto it = m_buttons.find(button);
if (it == m_buttons.cend()) return;
const mouse_button& btn = it->second;
// Only update the value if either down or up flags are present
if ((button_flags & btn.down))
if ((state.usButtonFlags & btn.down))
{
m_handler->Button(m_index, button, true);
m_handler->mouse_press_callback(m_device_name, button, btn.up, true);
}
else if ((button_flags & btn.up))
else if ((state.usButtonFlags & btn.up))
{
m_handler->Button(m_index, button, false);
m_handler->mouse_press_callback(m_device_name, button, btn.up, false);
}
};
// Get mouse buttons
get_button_pressed(CELL_MOUSE_BUTTON_1, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_2, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_3, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_4, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_5, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_6, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_7, state.usButtonFlags);
get_button_pressed(CELL_MOUSE_BUTTON_8, state.usButtonFlags);
}
// Get mouse wheel
if ((state.usButtonFlags & RI_MOUSE_WHEEL))

View File

@ -73,16 +73,16 @@ public:
const std::map<void*, raw_mouse>& get_mice() const { return m_raw_mice; };
void set_mouse_press_callback(std::function<void(const std::string&, s32, s32, bool)> cb)
void set_mouse_press_callback(std::function<void(const std::string&, s32, bool)> cb)
{
m_mouse_press_callback = std::move(cb);
}
void mouse_press_callback(const std::string& device_name, s32 cell_code, s32 button_code, bool pressed)
void mouse_press_callback(const std::string& device_name, s32 button_code, bool pressed)
{
if (m_mouse_press_callback)
{
m_mouse_press_callback(device_name, cell_code, button_code, pressed);
m_mouse_press_callback(device_name, button_code, pressed);
}
}
@ -106,7 +106,7 @@ private:
bool m_is_for_gui = false;
std::map<void*, raw_mouse> m_raw_mice;
std::function<void(const std::string&, s32, s32, bool)> m_mouse_press_callback;
std::function<void(const std::string&, s32, bool)> m_mouse_press_callback;
std::unique_ptr<named_thread<std::function<void()>>> m_thread;
};

View File

@ -70,9 +70,9 @@ raw_mouse_settings_dialog::raw_mouse_settings_dialog(QWidget* parent)
g_raw_mouse_handler = std::make_unique<raw_mouse_handler>();
g_raw_mouse_handler->set_is_for_gui(true);
g_raw_mouse_handler->Init(std::max(max_devices, ::size32(g_cfg_raw_mouse.players)));
g_raw_mouse_handler->set_mouse_press_callback([this](const std::string& device_name, s32 cell_code, s32 button_code, bool pressed)
g_raw_mouse_handler->set_mouse_press_callback([this](const std::string& device_name, s32 button_code, bool pressed)
{
mouse_press(device_name, cell_code, button_code, pressed);
mouse_press(device_name, button_code, pressed);
});
m_buttons = new QButtonGroup(this);
@ -346,7 +346,7 @@ void raw_mouse_settings_dialog::reset_config()
}
}
void raw_mouse_settings_dialog::mouse_press(const std::string& device_name, s32 /*cell_code*/, s32 button_code, bool pressed)
void raw_mouse_settings_dialog::mouse_press(const std::string& device_name, s32 button_code, bool pressed)
{
if (m_button_id < 0 || pressed) // Let's only react to mouse releases
{

View File

@ -30,7 +30,7 @@ private:
void on_enumeration();
void reset_config();
void on_button_click(int id);
void mouse_press(const std::string& device_name, s32 cell_code, s32 button_code, bool pressed);
void mouse_press(const std::string& device_name, s32 button_code, bool pressed);
void handle_device_change(const std::string& device_name);
bool is_device_active(const std::string& device_name);
std::string get_current_device_name(int player);