mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-11-14 13:52:53 +00:00
hid: Add controller bindings for Mouse controller
This commit is contained in:
parent
0fd45e78f4
commit
3b25426bd9
|
@ -5,6 +5,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
|
#include "core/frontend/emu_window.h"
|
||||||
#include "core/hle/service/hid/controllers/mouse.h"
|
#include "core/hle/service/hid/controllers/mouse.h"
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
|
@ -14,7 +15,6 @@ Controller_Mouse::Controller_Mouse() = default;
|
||||||
Controller_Mouse::~Controller_Mouse() = default;
|
Controller_Mouse::~Controller_Mouse() = default;
|
||||||
|
|
||||||
void Controller_Mouse::OnInit() {}
|
void Controller_Mouse::OnInit() {}
|
||||||
|
|
||||||
void Controller_Mouse::OnRelease() {}
|
void Controller_Mouse::OnRelease() {}
|
||||||
|
|
||||||
void Controller_Mouse::OnUpdate(u8* data, std::size_t size) {
|
void Controller_Mouse::OnUpdate(u8* data, std::size_t size) {
|
||||||
|
@ -34,10 +34,29 @@ void Controller_Mouse::OnUpdate(u8* data, std::size_t size) {
|
||||||
|
|
||||||
cur_entry.sampling_number = last_entry.sampling_number + 1;
|
cur_entry.sampling_number = last_entry.sampling_number + 1;
|
||||||
cur_entry.sampling_number2 = cur_entry.sampling_number;
|
cur_entry.sampling_number2 = cur_entry.sampling_number;
|
||||||
// TODO(ogniK): Update mouse states
|
|
||||||
|
if (Settings::values.mouse_enabled) {
|
||||||
|
const auto [px, py, sx, sy] = mouse_device->GetStatus();
|
||||||
|
const auto x = static_cast<s32>(px * Layout::ScreenUndocked::Width);
|
||||||
|
const auto y = static_cast<s32>(py * Layout::ScreenUndocked::Height);
|
||||||
|
cur_entry.x = x;
|
||||||
|
cur_entry.y = y;
|
||||||
|
cur_entry.delta_x = x - last_entry.x;
|
||||||
|
cur_entry.delta_y = y - last_entry.y;
|
||||||
|
cur_entry.mouse_wheel_x = sx;
|
||||||
|
cur_entry.mouse_wheel_y = sy;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < mouse_button_devices.size(); ++i) {
|
||||||
|
cur_entry.button |= (mouse_button_devices[i]->GetStatus() << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
|
std::memcpy(data + SHARED_MEMORY_OFFSET, &shared_memory, sizeof(SharedMemory));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller_Mouse::OnLoadInputDevices() {}
|
void Controller_Mouse::OnLoadInputDevices() {
|
||||||
|
mouse_device = Input::CreateDevice<Input::MouseDevice>(Settings::values.mouse_device);
|
||||||
|
std::transform(Settings::values.mouse_buttons.begin(), Settings::values.mouse_buttons.end(),
|
||||||
|
mouse_button_devices.begin(), Input::CreateDevice<Input::ButtonDevice>);
|
||||||
|
}
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
|
#include "core/frontend/input.h"
|
||||||
#include "core/hle/service/hid/controllers/controller_base.h"
|
#include "core/hle/service/hid/controllers/controller_base.h"
|
||||||
|
#include "core/settings.h"
|
||||||
|
|
||||||
namespace Service::HID {
|
namespace Service::HID {
|
||||||
class Controller_Mouse final : public ControllerBase {
|
class Controller_Mouse final : public ControllerBase {
|
||||||
|
@ -35,7 +37,8 @@ private:
|
||||||
s32_le y;
|
s32_le y;
|
||||||
s32_le delta_x;
|
s32_le delta_x;
|
||||||
s32_le delta_y;
|
s32_le delta_y;
|
||||||
s32_le mouse_wheel;
|
s32_le mouse_wheel_x;
|
||||||
|
s32_le mouse_wheel_y;
|
||||||
s32_le button;
|
s32_le button;
|
||||||
s32_le attribute;
|
s32_le attribute;
|
||||||
};
|
};
|
||||||
|
@ -46,5 +49,9 @@ private:
|
||||||
std::array<MouseState, 17> mouse_states;
|
std::array<MouseState, 17> mouse_states;
|
||||||
};
|
};
|
||||||
SharedMemory shared_memory{};
|
SharedMemory shared_memory{};
|
||||||
|
|
||||||
|
std::unique_ptr<Input::MouseDevice> mouse_device;
|
||||||
|
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeMouseButton::NumMouseButtons>
|
||||||
|
mouse_button_devices;
|
||||||
};
|
};
|
||||||
} // namespace Service::HID
|
} // namespace Service::HID
|
||||||
|
|
Loading…
Reference in a new issue