kraken: Address comments from review

start lion review
This commit is contained in:
german77 2021-10-30 22:23:10 -05:00 committed by Narr the Reg
parent 61d9eb9f69
commit 2b1b0c2a30
31 changed files with 534 additions and 466 deletions

View file

@ -12,7 +12,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/param_package.h" #include "common/param_package.h"
namespace Input { namespace Common::Input {
enum class InputType { enum class InputType {
None, None,
@ -296,4 +296,4 @@ std::unique_ptr<InputDeviceType> CreateDevice(const Common::ParamPackage package
return pair->second->Create(package); return pair->second->Create(package);
} }
} // namespace Input } // namespace Common::Input

View file

@ -6,7 +6,6 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <atomic>
#include <map> #include <map>
#include <optional> #include <optional>
#include <string> #include <string>

View file

@ -55,21 +55,21 @@ void EmulatedConsole::SetTouchParams() {
void EmulatedConsole::ReloadInput() { void EmulatedConsole::ReloadInput() {
SetTouchParams(); SetTouchParams();
motion_devices = Input::CreateDevice<Input::InputDevice>(motion_params); motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params);
if (motion_devices) { if (motion_devices) {
Input::InputCallback motion_callback{ Common::Input::InputCallback motion_callback{
[this](Input::CallbackStatus callback) { SetMotion(callback); }}; [this](Common::Input::CallbackStatus callback) { SetMotion(callback); }};
motion_devices->SetCallback(motion_callback); motion_devices->SetCallback(motion_callback);
} }
std::size_t index = 0; std::size_t index = 0;
for (auto& touch_device : touch_devices) { for (auto& touch_device : touch_devices) {
touch_device = Input::CreateDevice<Input::InputDevice>(touch_params[index]); touch_device = Common::Input::CreateDevice<Common::Input::InputDevice>(touch_params[index]);
if (!touch_device) { if (!touch_device) {
continue; continue;
} }
Input::InputCallback touch_callback{ Common::Input::InputCallback touch_callback{
[this, index](Input::CallbackStatus callback) { SetTouch(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetTouch(callback, index); }};
touch_device->SetCallback(touch_callback); touch_device->SetCallback(touch_callback);
index++; index++;
} }
@ -117,7 +117,7 @@ void EmulatedConsole::SetMotionParam(Common::ParamPackage param) {
ReloadInput(); ReloadInput();
} }
void EmulatedConsole::SetMotion(Input::CallbackStatus callback) { void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) {
std::lock_guard lock{mutex}; std::lock_guard lock{mutex};
auto& raw_status = console.motion_values.raw_status; auto& raw_status = console.motion_values.raw_status;
auto& emulated = console.motion_values.emulated; auto& emulated = console.motion_values.emulated;
@ -152,7 +152,8 @@ void EmulatedConsole::SetMotion(Input::CallbackStatus callback) {
TriggerOnChange(ConsoleTriggerType::Motion); TriggerOnChange(ConsoleTriggerType::Motion);
} }
void EmulatedConsole::SetTouch(Input::CallbackStatus callback, [[maybe_unused]] std::size_t index) { void EmulatedConsole::SetTouch(Common::Input::CallbackStatus callback,
[[maybe_unused]] std::size_t index) {
if (index >= console.touch_values.size()) { if (index >= console.touch_values.size()) {
return; return;
} }

View file

@ -4,10 +4,13 @@
#pragma once #pragma once
#include <array>
#include <functional> #include <functional>
#include <memory>
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include "common/common_types.h"
#include "common/input.h" #include "common/input.h"
#include "common/param_package.h" #include "common/param_package.h"
#include "common/point.h" #include "common/point.h"
@ -20,18 +23,18 @@
namespace Core::HID { namespace Core::HID {
struct ConsoleMotionInfo { struct ConsoleMotionInfo {
Input::MotionStatus raw_status{}; Common::Input::MotionStatus raw_status{};
MotionInput emulated{}; MotionInput emulated{};
}; };
using ConsoleMotionDevices = std::unique_ptr<Input::InputDevice>; using ConsoleMotionDevices = std::unique_ptr<Common::Input::InputDevice>;
using TouchDevices = std::array<std::unique_ptr<Input::InputDevice>, 16>; using TouchDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, 16>;
using ConsoleMotionParams = Common::ParamPackage; using ConsoleMotionParams = Common::ParamPackage;
using TouchParams = std::array<Common::ParamPackage, 16>; using TouchParams = std::array<Common::ParamPackage, 16>;
using ConsoleMotionValues = ConsoleMotionInfo; using ConsoleMotionValues = ConsoleMotionInfo;
using TouchValues = std::array<Input::TouchStatus, 16>; using TouchValues = std::array<Common::Input::TouchStatus, 16>;
struct TouchFinger { struct TouchFinger {
u64 last_touch{}; u64 last_touch{};
@ -151,14 +154,14 @@ private:
* Updates the motion status of the console * Updates the motion status of the console
* @param A CallbackStatus containing gyro and accelerometer data * @param A CallbackStatus containing gyro and accelerometer data
*/ */
void SetMotion(Input::CallbackStatus callback); void SetMotion(Common::Input::CallbackStatus callback);
/** /**
* Updates the touch status of the console * Updates the touch status of the console
* @param callback: A CallbackStatus containing the touch position * @param callback: A CallbackStatus containing the touch position
* @param index: Finger ID to be updated * @param index: Finger ID to be updated
*/ */
void SetTouch(Input::CallbackStatus callback, std::size_t index); void SetTouch(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Triggers a callback that something has changed on the console status * Triggers a callback that something has changed on the console status

View file

@ -110,25 +110,25 @@ void EmulatedController::LoadDevices() {
std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
button_params.begin() + Settings::NativeButton::BUTTON_NS_END, button_params.begin() + Settings::NativeButton::BUTTON_NS_END,
button_devices.begin(), Input::CreateDevice<Input::InputDevice>); button_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(stick_params.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, std::transform(stick_params.begin() + Settings::NativeAnalog::STICK_HID_BEGIN,
stick_params.begin() + Settings::NativeAnalog::STICK_HID_END, stick_params.begin() + Settings::NativeAnalog::STICK_HID_END,
stick_devices.begin(), Input::CreateDevice<Input::InputDevice>); stick_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN,
motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, motion_params.begin() + Settings::NativeMotion::MOTION_HID_END,
motion_devices.begin(), Input::CreateDevice<Input::InputDevice>); motion_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(), std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(),
Input::CreateDevice<Input::InputDevice>); Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(), std::transform(battery_params.begin(), battery_params.begin(), battery_devices.end(),
Input::CreateDevice<Input::InputDevice>); Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(output_params.begin(), output_params.end(), output_devices.begin(), std::transform(output_params.begin(), output_params.end(), output_devices.begin(),
Input::CreateDevice<Input::OutputDevice>); Common::Input::CreateDevice<Common::Input::OutputDevice>);
// Initialize TAS devices // Initialize TAS devices
std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(), std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(),
Input::CreateDevice<Input::InputDevice>); Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(tas_stick_params.begin(), tas_stick_params.end(), tas_stick_devices.begin(), std::transform(tas_stick_params.begin(), tas_stick_params.end(), tas_stick_devices.begin(),
Input::CreateDevice<Input::InputDevice>); Common::Input::CreateDevice<Common::Input::InputDevice>);
} }
void EmulatedController::LoadTASParams() { void EmulatedController::LoadTASParams() {
@ -178,8 +178,8 @@ void EmulatedController::ReloadInput() {
if (!button_devices[index]) { if (!button_devices[index]) {
continue; continue;
} }
Input::InputCallback button_callback{ Common::Input::InputCallback button_callback{
[this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetButton(callback, index); }};
button_devices[index]->SetCallback(button_callback); button_devices[index]->SetCallback(button_callback);
button_devices[index]->ForceUpdate(); button_devices[index]->ForceUpdate();
} }
@ -188,8 +188,8 @@ void EmulatedController::ReloadInput() {
if (!stick_devices[index]) { if (!stick_devices[index]) {
continue; continue;
} }
Input::InputCallback stick_callback{ Common::Input::InputCallback stick_callback{
[this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetStick(callback, index); }};
stick_devices[index]->SetCallback(stick_callback); stick_devices[index]->SetCallback(stick_callback);
stick_devices[index]->ForceUpdate(); stick_devices[index]->ForceUpdate();
} }
@ -198,8 +198,8 @@ void EmulatedController::ReloadInput() {
if (!trigger_devices[index]) { if (!trigger_devices[index]) {
continue; continue;
} }
Input::InputCallback trigger_callback{ Common::Input::InputCallback trigger_callback{
[this, index](Input::CallbackStatus callback) { SetTrigger(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetTrigger(callback, index); }};
trigger_devices[index]->SetCallback(trigger_callback); trigger_devices[index]->SetCallback(trigger_callback);
trigger_devices[index]->ForceUpdate(); trigger_devices[index]->ForceUpdate();
} }
@ -208,8 +208,8 @@ void EmulatedController::ReloadInput() {
if (!battery_devices[index]) { if (!battery_devices[index]) {
continue; continue;
} }
Input::InputCallback battery_callback{ Common::Input::InputCallback battery_callback{
[this, index](Input::CallbackStatus callback) { SetBattery(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetBattery(callback, index); }};
battery_devices[index]->SetCallback(battery_callback); battery_devices[index]->SetCallback(battery_callback);
battery_devices[index]->ForceUpdate(); battery_devices[index]->ForceUpdate();
} }
@ -218,8 +218,8 @@ void EmulatedController::ReloadInput() {
if (!motion_devices[index]) { if (!motion_devices[index]) {
continue; continue;
} }
Input::InputCallback motion_callback{ Common::Input::InputCallback motion_callback{
[this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetMotion(callback, index); }};
motion_devices[index]->SetCallback(motion_callback); motion_devices[index]->SetCallback(motion_callback);
motion_devices[index]->ForceUpdate(); motion_devices[index]->ForceUpdate();
} }
@ -229,8 +229,8 @@ void EmulatedController::ReloadInput() {
if (!tas_button_devices[index]) { if (!tas_button_devices[index]) {
continue; continue;
} }
Input::InputCallback button_callback{ Common::Input::InputCallback button_callback{
[this, index](Input::CallbackStatus callback) { SetButton(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetButton(callback, index); }};
tas_button_devices[index]->SetCallback(button_callback); tas_button_devices[index]->SetCallback(button_callback);
} }
@ -238,8 +238,8 @@ void EmulatedController::ReloadInput() {
if (!tas_stick_devices[index]) { if (!tas_stick_devices[index]) {
continue; continue;
} }
Input::InputCallback stick_callback{ Common::Input::InputCallback stick_callback{
[this, index](Input::CallbackStatus callback) { SetStick(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) { SetStick(callback, index); }};
tas_stick_devices[index]->SetCallback(stick_callback); tas_stick_devices[index]->SetCallback(stick_callback);
} }
} }
@ -418,7 +418,7 @@ void EmulatedController::SetMotionParam(std::size_t index, Common::ParamPackage
ReloadInput(); ReloadInput();
} }
void EmulatedController::SetButton(Input::CallbackStatus callback, std::size_t index) { void EmulatedController::SetButton(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= controller.button_values.size()) { if (index >= controller.button_values.size()) {
return; return;
} }
@ -548,7 +548,7 @@ void EmulatedController::SetButton(Input::CallbackStatus callback, std::size_t i
TriggerOnChange(ControllerTriggerType::Button, true); TriggerOnChange(ControllerTriggerType::Button, true);
} }
void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t index) { void EmulatedController::SetStick(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= controller.stick_values.size()) { if (index >= controller.stick_values.size()) {
return; return;
} }
@ -587,7 +587,7 @@ void EmulatedController::SetStick(Input::CallbackStatus callback, std::size_t in
TriggerOnChange(ControllerTriggerType::Stick, true); TriggerOnChange(ControllerTriggerType::Stick, true);
} }
void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t index) { void EmulatedController::SetTrigger(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= controller.trigger_values.size()) { if (index >= controller.trigger_values.size()) {
return; return;
} }
@ -618,7 +618,7 @@ void EmulatedController::SetTrigger(Input::CallbackStatus callback, std::size_t
TriggerOnChange(ControllerTriggerType::Trigger, true); TriggerOnChange(ControllerTriggerType::Trigger, true);
} }
void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t index) { void EmulatedController::SetMotion(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= controller.motion_values.size()) { if (index >= controller.motion_values.size()) {
return; return;
} }
@ -655,7 +655,7 @@ void EmulatedController::SetMotion(Input::CallbackStatus callback, std::size_t i
TriggerOnChange(ControllerTriggerType::Motion, true); TriggerOnChange(ControllerTriggerType::Motion, true);
} }
void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t index) { void EmulatedController::SetBattery(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= controller.battery_values.size()) { if (index >= controller.battery_values.size()) {
return; return;
} }
@ -671,25 +671,25 @@ void EmulatedController::SetBattery(Input::CallbackStatus callback, std::size_t
bool is_powered = false; bool is_powered = false;
BatteryLevel battery_level = 0; BatteryLevel battery_level = 0;
switch (controller.battery_values[index]) { switch (controller.battery_values[index]) {
case Input::BatteryLevel::Charging: case Common::Input::BatteryLevel::Charging:
is_charging = true; is_charging = true;
is_powered = true; is_powered = true;
battery_level = 6; battery_level = 6;
break; break;
case Input::BatteryLevel::Medium: case Common::Input::BatteryLevel::Medium:
battery_level = 6; battery_level = 6;
break; break;
case Input::BatteryLevel::Low: case Common::Input::BatteryLevel::Low:
battery_level = 4; battery_level = 4;
break; break;
case Input::BatteryLevel::Critical: case Common::Input::BatteryLevel::Critical:
battery_level = 2; battery_level = 2;
break; break;
case Input::BatteryLevel::Empty: case Common::Input::BatteryLevel::Empty:
battery_level = 0; battery_level = 0;
break; break;
case Input::BatteryLevel::None: case Common::Input::BatteryLevel::None:
case Input::BatteryLevel::Full: case Common::Input::BatteryLevel::Full:
default: default:
is_powered = true; is_powered = true;
battery_level = 8; battery_level = 8;
@ -739,18 +739,19 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v
// Exponential amplification is too strong at low amplitudes. Switch to a linear // Exponential amplification is too strong at low amplitudes. Switch to a linear
// amplification if strength is set below 0.7f // amplification if strength is set below 0.7f
const Input::VibrationAmplificationType type = const Common::Input::VibrationAmplificationType type =
strength > 0.7f ? Input::VibrationAmplificationType::Exponential strength > 0.7f ? Common::Input::VibrationAmplificationType::Exponential
: Input::VibrationAmplificationType::Linear; : Common::Input::VibrationAmplificationType::Linear;
const Input::VibrationStatus status = { const Common::Input::VibrationStatus status = {
.low_amplitude = std::min(vibration.low_amplitude * strength, 1.0f), .low_amplitude = std::min(vibration.low_amplitude * strength, 1.0f),
.low_frequency = vibration.low_frequency, .low_frequency = vibration.low_frequency,
.high_amplitude = std::min(vibration.high_amplitude * strength, 1.0f), .high_amplitude = std::min(vibration.high_amplitude * strength, 1.0f),
.high_frequency = vibration.high_frequency, .high_frequency = vibration.high_frequency,
.type = type, .type = type,
}; };
return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None; return output_devices[device_index]->SetVibration(status) ==
Common::Input::VibrationError::None;
} }
bool EmulatedController::TestVibration(std::size_t device_index) { bool EmulatedController::TestVibration(std::size_t device_index) {
@ -762,14 +763,15 @@ bool EmulatedController::TestVibration(std::size_t device_index) {
} }
// Send a slight vibration to test for rumble support // Send a slight vibration to test for rumble support
constexpr Input::VibrationStatus status = { constexpr Common::Input::VibrationStatus status = {
.low_amplitude = 0.001f, .low_amplitude = 0.001f,
.low_frequency = 160.0f, .low_frequency = 160.0f,
.high_amplitude = 0.001f, .high_amplitude = 0.001f,
.high_frequency = 320.0f, .high_frequency = 320.0f,
.type = Input::VibrationAmplificationType::Linear, .type = Common::Input::VibrationAmplificationType::Linear,
}; };
return output_devices[device_index]->SetVibration(status) == Input::VibrationError::None; return output_devices[device_index]->SetVibration(status) ==
Common::Input::VibrationError::None;
} }
void EmulatedController::SetLedPattern() { void EmulatedController::SetLedPattern() {
@ -779,7 +781,7 @@ void EmulatedController::SetLedPattern() {
} }
const LedPattern pattern = GetLedPattern(); const LedPattern pattern = GetLedPattern();
const Input::LedStatus status = { const Common::Input::LedStatus status = {
.led_1 = pattern.position1 != 0, .led_1 = pattern.position1 != 0,
.led_2 = pattern.position2 != 0, .led_2 = pattern.position2 != 0,
.led_3 = pattern.position3 != 0, .led_3 = pattern.position3 != 0,

View file

@ -4,10 +4,13 @@
#pragma once #pragma once
#include <array>
#include <functional> #include <functional>
#include <memory>
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include "common/common_types.h"
#include "common/input.h" #include "common/input.h"
#include "common/param_package.h" #include "common/param_package.h"
#include "common/point.h" #include "common/point.h"
@ -20,20 +23,22 @@
namespace Core::HID { namespace Core::HID {
const std::size_t max_emulated_controllers = 2; const std::size_t max_emulated_controllers = 2;
struct ControllerMotionInfo { struct ControllerMotionInfo {
Input::MotionStatus raw_status{}; Common::Input::MotionStatus raw_status{};
MotionInput emulated{}; MotionInput emulated{};
}; };
using ButtonDevices = using ButtonDevices =
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeButton::NumButtons>; std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeButton::NumButtons>;
using StickDevices = using StickDevices =
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeAnalog::NumAnalogs>; std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeAnalog::NumAnalogs>;
using ControllerMotionDevices = using ControllerMotionDevices =
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeMotion::NumMotions>; std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeMotion::NumMotions>;
using TriggerDevices = using TriggerDevices =
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeTrigger::NumTriggers>;
using BatteryDevices = std::array<std::unique_ptr<Input::InputDevice>, max_emulated_controllers>; using BatteryDevices =
using OutputDevices = std::array<std::unique_ptr<Input::OutputDevice>, max_emulated_controllers>; std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>;
using OutputDevices =
std::array<std::unique_ptr<Common::Input::OutputDevice>, max_emulated_controllers>;
using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>;
@ -42,13 +47,14 @@ using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::
using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>;
using OutputParams = std::array<Common::ParamPackage, max_emulated_controllers>; using OutputParams = std::array<Common::ParamPackage, max_emulated_controllers>;
using ButtonValues = std::array<Input::ButtonStatus, Settings::NativeButton::NumButtons>; using ButtonValues = std::array<Common::Input::ButtonStatus, Settings::NativeButton::NumButtons>;
using SticksValues = std::array<Input::StickStatus, Settings::NativeAnalog::NumAnalogs>; using SticksValues = std::array<Common::Input::StickStatus, Settings::NativeAnalog::NumAnalogs>;
using TriggerValues = std::array<Input::TriggerStatus, Settings::NativeTrigger::NumTriggers>; using TriggerValues =
std::array<Common::Input::TriggerStatus, Settings::NativeTrigger::NumTriggers>;
using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>; using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::NativeMotion::NumMotions>;
using ColorValues = std::array<Input::BodyColorStatus, max_emulated_controllers>; using ColorValues = std::array<Common::Input::BodyColorStatus, max_emulated_controllers>;
using BatteryValues = std::array<Input::BatteryStatus, max_emulated_controllers>; using BatteryValues = std::array<Common::Input::BatteryStatus, max_emulated_controllers>;
using VibrationValues = std::array<Input::VibrationStatus, max_emulated_controllers>; using VibrationValues = std::array<Common::Input::VibrationStatus, max_emulated_controllers>;
struct AnalogSticks { struct AnalogSticks {
AnalogStickState left{}; AnalogStickState left{};
@ -307,35 +313,35 @@ private:
* @param callback: A CallbackStatus containing the button status * @param callback: A CallbackStatus containing the button status
* @param index: Button ID of the to be updated * @param index: Button ID of the to be updated
*/ */
void SetButton(Input::CallbackStatus callback, std::size_t index); void SetButton(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Updates the analog stick status of the controller * Updates the analog stick status of the controller
* @param callback: A CallbackStatus containing the analog stick status * @param callback: A CallbackStatus containing the analog stick status
* @param index: stick ID of the to be updated * @param index: stick ID of the to be updated
*/ */
void SetStick(Input::CallbackStatus callback, std::size_t index); void SetStick(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Updates the trigger status of the controller * Updates the trigger status of the controller
* @param callback: A CallbackStatus containing the trigger status * @param callback: A CallbackStatus containing the trigger status
* @param index: trigger ID of the to be updated * @param index: trigger ID of the to be updated
*/ */
void SetTrigger(Input::CallbackStatus callback, std::size_t index); void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Updates the motion status of the controller * Updates the motion status of the controller
* @param callback: A CallbackStatus containing gyro and accelerometer data * @param callback: A CallbackStatus containing gyro and accelerometer data
* @param index: motion ID of the to be updated * @param index: motion ID of the to be updated
*/ */
void SetMotion(Input::CallbackStatus callback, std::size_t index); void SetMotion(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Updates the battery status of the controller * Updates the battery status of the controller
* @param callback: A CallbackStatus containing the battery status * @param callback: A CallbackStatus containing the battery status
* @param index: Button ID of the to be updated * @param index: Button ID of the to be updated
*/ */
void SetBattery(Input::CallbackStatus callback, std::size_t index); void SetBattery(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Triggers a callback that something has changed on the controller status * Triggers a callback that something has changed on the controller status

View file

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included // Refer to the license.txt file included
#include <algorithm>
#include <fmt/format.h> #include <fmt/format.h>
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_devices.h"
@ -25,21 +26,25 @@ void EmulatedDevices::ReloadFromSettings() {
void EmulatedDevices::ReloadInput() { void EmulatedDevices::ReloadInput() {
std::transform(mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_BEGIN, std::transform(mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_BEGIN,
mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_END, mouse_button_params.begin() + Settings::NativeMouseButton::MOUSE_HID_END,
mouse_button_devices.begin(), Input::CreateDevice<Input::InputDevice>); mouse_button_devices.begin(),
Common::Input::CreateDevice<Common::Input::InputDevice>);
std::transform(Settings::values.keyboard_keys.begin(), Settings::values.keyboard_keys.end(), std::transform(Settings::values.keyboard_keys.begin(), Settings::values.keyboard_keys.end(),
keyboard_devices.begin(), Input::CreateDeviceFromString<Input::InputDevice>); keyboard_devices.begin(),
Common::Input::CreateDeviceFromString<Common::Input::InputDevice>);
std::transform(Settings::values.keyboard_mods.begin(), Settings::values.keyboard_mods.end(), std::transform(Settings::values.keyboard_mods.begin(), Settings::values.keyboard_mods.end(),
keyboard_modifier_devices.begin(), keyboard_modifier_devices.begin(),
Input::CreateDeviceFromString<Input::InputDevice>); Common::Input::CreateDeviceFromString<Common::Input::InputDevice>);
for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) {
if (!mouse_button_devices[index]) { if (!mouse_button_devices[index]) {
continue; continue;
} }
Input::InputCallback button_callback{ Common::Input::InputCallback button_callback{
[this, index](Input::CallbackStatus callback) { SetMouseButton(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) {
SetMouseButton(callback, index);
}};
mouse_button_devices[index]->SetCallback(button_callback); mouse_button_devices[index]->SetCallback(button_callback);
} }
@ -47,8 +52,10 @@ void EmulatedDevices::ReloadInput() {
if (!keyboard_devices[index]) { if (!keyboard_devices[index]) {
continue; continue;
} }
Input::InputCallback button_callback{ Common::Input::InputCallback button_callback{
[this, index](Input::CallbackStatus callback) { SetKeyboardButton(callback, index); }}; [this, index](Common::Input::CallbackStatus callback) {
SetKeyboardButton(callback, index);
}};
keyboard_devices[index]->SetCallback(button_callback); keyboard_devices[index]->SetCallback(button_callback);
} }
@ -56,7 +63,8 @@ void EmulatedDevices::ReloadInput() {
if (!keyboard_modifier_devices[index]) { if (!keyboard_modifier_devices[index]) {
continue; continue;
} }
Input::InputCallback button_callback{[this, index](Input::CallbackStatus callback) { Common::Input::InputCallback button_callback{
[this, index](Common::Input::CallbackStatus callback) {
SetKeyboardModifier(callback, index); SetKeyboardModifier(callback, index);
}}; }};
keyboard_modifier_devices[index]->SetCallback(button_callback); keyboard_modifier_devices[index]->SetCallback(button_callback);
@ -122,7 +130,7 @@ void EmulatedDevices::SetMouseButtonParam(std::size_t index, Common::ParamPackag
ReloadInput(); ReloadInput();
} }
void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::size_t index) { void EmulatedDevices::SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= device_status.keyboard_values.size()) { if (index >= device_status.keyboard_values.size()) {
return; return;
} }
@ -170,7 +178,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz
void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) { void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) {
constexpr u8 KEYS_PER_BYTE = 8; constexpr u8 KEYS_PER_BYTE = 8;
auto& entry = device_status.keyboard_state.key[key_index / KEYS_PER_BYTE]; auto& entry = device_status.keyboard_state.key[key_index / KEYS_PER_BYTE];
const u8 mask = 1 << (key_index % KEYS_PER_BYTE); const u8 mask = static_cast<u8>(1 << (key_index % KEYS_PER_BYTE));
if (status) { if (status) {
entry = entry | mask; entry = entry | mask;
} else { } else {
@ -178,7 +186,8 @@ void EmulatedDevices::UpdateKey(std::size_t key_index, bool status) {
} }
} }
void EmulatedDevices::SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index) { void EmulatedDevices::SetKeyboardModifier(Common::Input::CallbackStatus callback,
std::size_t index) {
if (index >= device_status.keyboard_moddifier_values.size()) { if (index >= device_status.keyboard_moddifier_values.size()) {
return; return;
} }
@ -247,7 +256,7 @@ void EmulatedDevices::SetKeyboardModifier(Input::CallbackStatus callback, std::s
TriggerOnChange(DeviceTriggerType::KeyboardModdifier); TriggerOnChange(DeviceTriggerType::KeyboardModdifier);
} }
void EmulatedDevices::SetMouseButton(Input::CallbackStatus callback, std::size_t index) { void EmulatedDevices::SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index) {
if (index >= device_status.mouse_button_values.size()) { if (index >= device_status.mouse_button_values.size()) {
return; return;
} }

View file

@ -4,10 +4,13 @@
#pragma once #pragma once
#include <array>
#include <functional> #include <functional>
#include <memory>
#include <mutex> #include <mutex>
#include <unordered_map> #include <unordered_map>
#include "common/common_types.h"
#include "common/input.h" #include "common/input.h"
#include "common/param_package.h" #include "common/param_package.h"
#include "common/settings.h" #include "common/settings.h"
@ -16,21 +19,22 @@
namespace Core::HID { namespace Core::HID {
using KeyboardDevices = using KeyboardDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeKeyboard::NumKeyboardKeys>; Settings::NativeKeyboard::NumKeyboardKeys>;
using KeyboardModifierDevices = using KeyboardModifierDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeKeyboard::NumKeyboardMods>; Settings::NativeKeyboard::NumKeyboardMods>;
using MouseButtonDevices = using MouseButtonDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
std::array<std::unique_ptr<Input::InputDevice>, Settings::NativeMouseButton::NumMouseButtons>; Settings::NativeMouseButton::NumMouseButtons>;
using MouseButtonParams = using MouseButtonParams =
std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>; std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>;
using KeyboardValues = std::array<Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>; using KeyboardValues =
std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>;
using KeyboardModifierValues = using KeyboardModifierValues =
std::array<Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardMods>; std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardMods>;
using MouseButtonValues = using MouseButtonValues =
std::array<Input::ButtonStatus, Settings::NativeMouseButton::NumMouseButtons>; std::array<Common::Input::ButtonStatus, Settings::NativeMouseButton::NumMouseButtons>;
struct MousePosition { struct MousePosition {
s32 x; s32 x;
@ -151,21 +155,21 @@ private:
* @param callback: A CallbackStatus containing the key status * @param callback: A CallbackStatus containing the key status
* @param index: key ID to be updated * @param index: key ID to be updated
*/ */
void SetKeyboardButton(Input::CallbackStatus callback, std::size_t index); void SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Updates the touch status of the console * Updates the touch status of the console
* @param callback: A CallbackStatus containing the modifier key status * @param callback: A CallbackStatus containing the modifier key status
* @param index: modifier key ID to be updated * @param index: modifier key ID to be updated
*/ */
void SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index); void SetKeyboardModifier(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Updates the touch status of the console * Updates the touch status of the console
* @param callback: A CallbackStatus containing the button status * @param callback: A CallbackStatus containing the button status
* @param index: Button ID of the to be updated * @param index: Button ID of the to be updated
*/ */
void SetMouseButton(Input::CallbackStatus callback, std::size_t index); void SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index);
/** /**
* Triggers a callback that something has changed on the device status * Triggers a callback that something has changed on the device status

View file

@ -9,35 +9,35 @@
namespace Core::HID { namespace Core::HID {
Input::BatteryStatus TransformToBattery(const Input::CallbackStatus& callback) { Common::Input::BatteryStatus TransformToBattery(const Common::Input::CallbackStatus& callback) {
Input::BatteryStatus battery{Input::BatteryStatus::None}; Common::Input::BatteryStatus battery{Common::Input::BatteryStatus::None};
switch (callback.type) { switch (callback.type) {
case Input::InputType::Analog: case Common::Input::InputType::Analog:
case Input::InputType::Trigger: { case Common::Input::InputType::Trigger: {
const auto value = TransformToTrigger(callback).analog.value; const auto value = TransformToTrigger(callback).analog.value;
battery = Input::BatteryLevel::Empty; battery = Common::Input::BatteryLevel::Empty;
if (value > 0.2f) { if (value > 0.2f) {
battery = Input::BatteryLevel::Critical; battery = Common::Input::BatteryLevel::Critical;
} }
if (value > 0.4f) { if (value > 0.4f) {
battery = Input::BatteryLevel::Low; battery = Common::Input::BatteryLevel::Low;
} }
if (value > 0.6f) { if (value > 0.6f) {
battery = Input::BatteryLevel::Medium; battery = Common::Input::BatteryLevel::Medium;
} }
if (value > 0.8f) { if (value > 0.8f) {
battery = Input::BatteryLevel::Full; battery = Common::Input::BatteryLevel::Full;
} }
if (value >= 1.0f) { if (value >= 1.0f) {
battery = Input::BatteryLevel::Charging; battery = Common::Input::BatteryLevel::Charging;
} }
break; break;
} }
case Input::InputType::Button: case Common::Input::InputType::Button:
battery = callback.button_status.value ? Input::BatteryLevel::Charging battery = callback.button_status.value ? Common::Input::BatteryLevel::Charging
: Input::BatteryLevel::Critical; : Common::Input::BatteryLevel::Critical;
break; break;
case Input::InputType::Battery: case Common::Input::InputType::Battery:
battery = callback.battery_status; battery = callback.battery_status;
break; break;
default: default:
@ -48,14 +48,14 @@ Input::BatteryStatus TransformToBattery(const Input::CallbackStatus& callback) {
return battery; return battery;
} }
Input::ButtonStatus TransformToButton(const Input::CallbackStatus& callback) { Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatus& callback) {
Input::ButtonStatus status{}; Common::Input::ButtonStatus status{};
switch (callback.type) { switch (callback.type) {
case Input::InputType::Analog: case Common::Input::InputType::Analog:
case Input::InputType::Trigger: case Common::Input::InputType::Trigger:
status.value = TransformToTrigger(callback).pressed; status.value = TransformToTrigger(callback).pressed;
break; break;
case Input::InputType::Button: case Common::Input::InputType::Button:
status = callback.button_status; status = callback.button_status;
break; break;
default: default:
@ -70,15 +70,15 @@ Input::ButtonStatus TransformToButton(const Input::CallbackStatus& callback) {
return status; return status;
} }
Input::MotionStatus TransformToMotion(const Input::CallbackStatus& callback) { Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatus& callback) {
Input::MotionStatus status{}; Common::Input::MotionStatus status{};
switch (callback.type) { switch (callback.type) {
case Input::InputType::Button: { case Common::Input::InputType::Button: {
if (TransformToButton(callback).value) { if (TransformToButton(callback).value) {
std::random_device device; std::random_device device;
std::mt19937 gen(device()); std::mt19937 gen(device());
std::uniform_int_distribution<s16> distribution(-1000, 1000); std::uniform_int_distribution<s16> distribution(-1000, 1000);
Input::AnalogProperties properties{ Common::Input::AnalogProperties properties{
.deadzone = 0.0, .deadzone = 0.0,
.range = 1.0f, .range = 1.0f,
.offset = 0.0, .offset = 0.0,
@ -116,7 +116,7 @@ Input::MotionStatus TransformToMotion(const Input::CallbackStatus& callback) {
} }
break; break;
} }
case Input::InputType::Motion: case Common::Input::InputType::Motion:
status = callback.motion_status; status = callback.motion_status;
break; break;
default: default:
@ -133,11 +133,11 @@ Input::MotionStatus TransformToMotion(const Input::CallbackStatus& callback) {
return status; return status;
} }
Input::StickStatus TransformToStick(const Input::CallbackStatus& callback) { Common::Input::StickStatus TransformToStick(const Common::Input::CallbackStatus& callback) {
Input::StickStatus status{}; Common::Input::StickStatus status{};
switch (callback.type) { switch (callback.type) {
case Input::InputType::Stick: case Common::Input::InputType::Stick:
status = callback.stick_status; status = callback.stick_status;
break; break;
default: default:
@ -160,11 +160,11 @@ Input::StickStatus TransformToStick(const Input::CallbackStatus& callback) {
return status; return status;
} }
Input::TouchStatus TransformToTouch(const Input::CallbackStatus& callback) { Common::Input::TouchStatus TransformToTouch(const Common::Input::CallbackStatus& callback) {
Input::TouchStatus status{}; Common::Input::TouchStatus status{};
switch (callback.type) { switch (callback.type) {
case Input::InputType::Touch: case Common::Input::InputType::Touch:
status = callback.touch_status; status = callback.touch_status;
break; break;
default: default:
@ -192,22 +192,22 @@ Input::TouchStatus TransformToTouch(const Input::CallbackStatus& callback) {
return status; return status;
} }
Input::TriggerStatus TransformToTrigger(const Input::CallbackStatus& callback) { Common::Input::TriggerStatus TransformToTrigger(const Common::Input::CallbackStatus& callback) {
Input::TriggerStatus status{}; Common::Input::TriggerStatus status{};
float& raw_value = status.analog.raw_value; float& raw_value = status.analog.raw_value;
bool calculate_button_value = true; bool calculate_button_value = true;
switch (callback.type) { switch (callback.type) {
case Input::InputType::Analog: case Common::Input::InputType::Analog:
status.analog.properties = callback.analog_status.properties; status.analog.properties = callback.analog_status.properties;
raw_value = callback.analog_status.raw_value; raw_value = callback.analog_status.raw_value;
break; break;
case Input::InputType::Button: case Common::Input::InputType::Button:
status.analog.properties.range = 1.0f; status.analog.properties.range = 1.0f;
status.analog.properties.inverted = callback.button_status.inverted; status.analog.properties.inverted = callback.button_status.inverted;
raw_value = callback.button_status.value ? 1.0f : 0.0f; raw_value = callback.button_status.value ? 1.0f : 0.0f;
break; break;
case Input::InputType::Trigger: case Common::Input::InputType::Trigger:
status = callback.trigger_status; status = callback.trigger_status;
calculate_button_value = false; calculate_button_value = false;
break; break;
@ -234,7 +234,7 @@ Input::TriggerStatus TransformToTrigger(const Input::CallbackStatus& callback) {
return status; return status;
} }
void SanitizeAnalog(Input::AnalogStatus& analog, bool clamp_value) { void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value) {
const auto& properties = analog.properties; const auto& properties = analog.properties;
float& raw_value = analog.raw_value; float& raw_value = analog.raw_value;
float& value = analog.value; float& value = analog.value;
@ -274,7 +274,8 @@ void SanitizeAnalog(Input::AnalogStatus& analog, bool clamp_value) {
} }
} }
void SanitizeStick(Input::AnalogStatus& analog_x, Input::AnalogStatus& analog_y, bool clamp_value) { void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
bool clamp_value) {
const auto& properties_x = analog_x.properties; const auto& properties_x = analog_x.properties;
const auto& properties_y = analog_y.properties; const auto& properties_y = analog_y.properties;
float& raw_x = analog_x.raw_value; float& raw_x = analog_x.raw_value;

View file

@ -16,7 +16,7 @@ namespace Core::HID {
* @param Supported callbacks: Analog, Battery, Trigger. * @param Supported callbacks: Analog, Battery, Trigger.
* @return A valid BatteryStatus object. * @return A valid BatteryStatus object.
*/ */
Input::BatteryStatus TransformToBattery(const Input::CallbackStatus& callback); Common::Input::BatteryStatus TransformToBattery(const Common::Input::CallbackStatus& callback);
/** /**
* Converts raw input data into a valid button status. Applies invert properties to the output. * Converts raw input data into a valid button status. Applies invert properties to the output.
@ -24,7 +24,7 @@ Input::BatteryStatus TransformToBattery(const Input::CallbackStatus& callback);
* @param Supported callbacks: Analog, Button, Trigger. * @param Supported callbacks: Analog, Button, Trigger.
* @return A valid TouchStatus object. * @return A valid TouchStatus object.
*/ */
Input::ButtonStatus TransformToButton(const Input::CallbackStatus& callback); Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatus& callback);
/** /**
* Converts raw input data into a valid motion status. * Converts raw input data into a valid motion status.
@ -32,7 +32,7 @@ Input::ButtonStatus TransformToButton(const Input::CallbackStatus& callback);
* @param Supported callbacks: Motion. * @param Supported callbacks: Motion.
* @return A valid TouchStatus object. * @return A valid TouchStatus object.
*/ */
Input::MotionStatus TransformToMotion(const Input::CallbackStatus& callback); Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatus& callback);
/** /**
* Converts raw input data into a valid stick status. Applies offset, deadzone, range and invert * Converts raw input data into a valid stick status. Applies offset, deadzone, range and invert
@ -41,7 +41,7 @@ Input::MotionStatus TransformToMotion(const Input::CallbackStatus& callback);
* @param Supported callbacks: Stick. * @param Supported callbacks: Stick.
* @return A valid StickStatus object. * @return A valid StickStatus object.
*/ */
Input::StickStatus TransformToStick(const Input::CallbackStatus& callback); Common::Input::StickStatus TransformToStick(const Common::Input::CallbackStatus& callback);
/** /**
* Converts raw input data into a valid touch status. * Converts raw input data into a valid touch status.
@ -49,7 +49,7 @@ Input::StickStatus TransformToStick(const Input::CallbackStatus& callback);
* @param Supported callbacks: Touch. * @param Supported callbacks: Touch.
* @return A valid TouchStatus object. * @return A valid TouchStatus object.
*/ */
Input::TouchStatus TransformToTouch(const Input::CallbackStatus& callback); Common::Input::TouchStatus TransformToTouch(const Common::Input::CallbackStatus& callback);
/** /**
* Converts raw input data into a valid trigger status. Applies offset, deadzone, range and * Converts raw input data into a valid trigger status. Applies offset, deadzone, range and
@ -58,20 +58,21 @@ Input::TouchStatus TransformToTouch(const Input::CallbackStatus& callback);
* @param Supported callbacks: Analog, Button, Trigger. * @param Supported callbacks: Analog, Button, Trigger.
* @return A valid TriggerStatus object. * @return A valid TriggerStatus object.
*/ */
Input::TriggerStatus TransformToTrigger(const Input::CallbackStatus& callback); Common::Input::TriggerStatus TransformToTrigger(const Common::Input::CallbackStatus& callback);
/** /**
* Converts raw analog data into a valid analog value * Converts raw analog data into a valid analog value
* @param An analog object containing raw data and properties, bool that determines if the value * @param An analog object containing raw data and properties, bool that determines if the value
* needs to be clamped between -1.0f and 1.0f. * needs to be clamped between -1.0f and 1.0f.
*/ */
void SanitizeAnalog(Input::AnalogStatus& analog, bool clamp_value); void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value);
/** /**
* Converts raw stick data into a valid stick value * Converts raw stick data into a valid stick value
* @param Two analog objects containing raw data and properties, bool that determines if the value * @param Two analog objects containing raw data and properties, bool that determines if the value
* needs to be clamped into the unit circle. * needs to be clamped into the unit circle.
*/ */
void SanitizeStick(Input::AnalogStatus& analog_x, Input::AnalogStatus& analog_y, bool clamp_value); void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
bool clamp_value);
} // namespace Core::HID } // namespace Core::HID

View file

@ -13,9 +13,6 @@
namespace Service::HID { namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x00000; constexpr std::size_t SHARED_MEMORY_OFFSET = 0x00000;
constexpr s32 HID_JOYSTICK_MAX = 0x7fff;
[[maybe_unused]] constexpr s32 HID_JOYSTICK_MIN = -0x7fff;
enum class JoystickId : std::size_t { Joystick_Left, Joystick_Right };
Controller_DebugPad::Controller_DebugPad(Core::System& system_) : ControllerBase{system_} { Controller_DebugPad::Controller_DebugPad(Core::System& system_) : ControllerBase{system_} {
controller = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Other); controller = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Other);

View file

@ -12,7 +12,6 @@
namespace Service::HID { namespace Service::HID {
constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800; constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800;
constexpr u8 KEYS_PER_BYTE = 8;
Controller_Keyboard::Controller_Keyboard(Core::System& system_) : ControllerBase{system_} { Controller_Keyboard::Controller_Keyboard(Core::System& system_) : ControllerBase{system_} {
emulated_devices = system.HIDCore().GetEmulatedDevices(); emulated_devices = system.HIDCore().GetEmulatedDevices();

View file

@ -403,8 +403,7 @@ private:
AppletFooterUiType type; AppletFooterUiType type;
INSERT_PADDING_BYTES(0x5B); // Reserved INSERT_PADDING_BYTES(0x5B); // Reserved
}; };
static_assert(sizeof(AppletFooterUi) == 0x60, static_assert(sizeof(AppletFooterUi) == 0x60, "AppletFooterUi is an invalid size");
"AppletFooterUi is an invalid size");
// This is nn::hid::NpadLarkType // This is nn::hid::NpadLarkType
enum class NpadLarkType : u32 { enum class NpadLarkType : u32 {

View file

@ -4,6 +4,8 @@
#pragma once #pragma once
#include <array>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/swap.h" #include "common/swap.h"
@ -29,10 +31,10 @@ struct Lifo {
} }
const AtomicStorage<State>& ReadPreviousEntry() const { const AtomicStorage<State>& ReadPreviousEntry() const {
return entries[GetPreviuousEntryIndex()]; return entries[GetPreviousEntryIndex()];
} }
std::size_t GetPreviuousEntryIndex() const { std::size_t GetPreviousEntryIndex() const {
return (buffer_tail + total_buffer_count - 1) % total_buffer_count; return (buffer_tail + total_buffer_count - 1) % total_buffer_count;
} }

View file

@ -248,7 +248,7 @@ bool GCAdapter::Setup() {
std::size_t port = 0; std::size_t port = 0;
for (GCController& pad : pads) { for (GCController& pad : pads) {
pad.identifier = { pad.identifier = {
.guid = Common::UUID{""}, .guid = Common::UUID{Common::INVALID_UUID},
.port = port++, .port = port++,
.pad = 0, .pad = 0,
}; };
@ -325,8 +325,8 @@ bool GCAdapter::GetGCEndpoint(libusb_device* device) {
return true; return true;
} }
Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier, Common::Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) { const Common::Input::VibrationStatus vibration) {
const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f; const auto mean_amplitude = (vibration.low_amplitude + vibration.high_amplitude) * 0.5f;
const auto processed_amplitude = const auto processed_amplitude =
static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8);
@ -334,9 +334,9 @@ Input::VibrationError GCAdapter::SetRumble(const PadIdentifier& identifier,
pads[identifier.port].rumble_amplitude = processed_amplitude; pads[identifier.port].rumble_amplitude = processed_amplitude;
if (!rumble_enabled) { if (!rumble_enabled) {
return Input::VibrationError::Disabled; return Common::Input::VibrationError::Disabled;
} }
return Input::VibrationError::None; return Common::Input::VibrationError::None;
} }
void GCAdapter::UpdateVibrations() { void GCAdapter::UpdateVibrations() {

View file

@ -4,8 +4,11 @@
#pragma once #pragma once
#include <array>
#include <memory>
#include <mutex> #include <mutex>
#include <stop_token> #include <stop_token>
#include <string>
#include <thread> #include <thread>
#include "input_common/input_engine.h" #include "input_common/input_engine.h"
@ -24,8 +27,8 @@ public:
explicit GCAdapter(const std::string input_engine_); explicit GCAdapter(const std::string input_engine_);
~GCAdapter(); ~GCAdapter();
Input::VibrationError SetRumble(const PadIdentifier& identifier, Common::Input::VibrationError SetRumble(
const Input::VibrationStatus vibration) override; const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override;
/// Used for automapping features /// Used for automapping features
std::vector<Common::ParamPackage> GetInputDevices() const override; std::vector<Common::ParamPackage> GetInputDevices() const override;

View file

@ -35,7 +35,7 @@ public:
private: private:
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{""}, .guid = Common::UUID{Common::INVALID_UUID},
.port = 0, .port = 0,
.pad = 0, .pad = 0,
}; };

View file

@ -63,7 +63,7 @@ private:
void StopPanning(); void StopPanning();
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{""}, .guid = Common::UUID{Common::INVALID_UUID},
.port = 0, .port = 0,
.pad = 0, .pad = 0,
}; };

View file

@ -92,7 +92,7 @@ public:
return motion; return motion;
} }
bool RumblePlay(const Input::VibrationStatus vibration) { bool RumblePlay(const Common::Input::VibrationStatus vibration) {
constexpr u32 rumble_max_duration_ms = 1000; constexpr u32 rumble_max_duration_ms = 1000;
if (sdl_controller) { if (sdl_controller) {
return SDL_GameControllerRumble( return SDL_GameControllerRumble(
@ -515,8 +515,8 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const {
} }
return devices; return devices;
} }
Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier, Common::Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
const Input::VibrationStatus vibration) { const Common::Input::VibrationStatus vibration) {
const auto joystick = const auto joystick =
GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port));
const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { const auto process_amplitude_exp = [](f32 amplitude, f32 factor) {
@ -527,7 +527,7 @@ Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
f32 factor = 0.35f; f32 factor = 0.35f;
// If vibration is set as a linear output use a flatter value // If vibration is set as a linear output use a flatter value
if (vibration.type == Input::VibrationAmplificationType::Linear) { if (vibration.type == Common::Input::VibrationAmplificationType::Linear) {
factor = 0.5f; factor = 0.5f;
} }
@ -536,19 +536,19 @@ Input::VibrationError SDLDriver::SetRumble(const PadIdentifier& identifier,
factor = 1.0f; factor = 1.0f;
} }
const Input::VibrationStatus new_vibration{ const Common::Input::VibrationStatus new_vibration{
.low_amplitude = process_amplitude_exp(vibration.low_amplitude, factor), .low_amplitude = process_amplitude_exp(vibration.low_amplitude, factor),
.low_frequency = vibration.low_frequency, .low_frequency = vibration.low_frequency,
.high_amplitude = process_amplitude_exp(vibration.high_amplitude, factor), .high_amplitude = process_amplitude_exp(vibration.high_amplitude, factor),
.high_frequency = vibration.high_frequency, .high_frequency = vibration.high_frequency,
.type = Input::VibrationAmplificationType::Exponential, .type = Common::Input::VibrationAmplificationType::Exponential,
}; };
if (!joystick->RumblePlay(new_vibration)) { if (!joystick->RumblePlay(new_vibration)) {
return Input::VibrationError::Unknown; return Common::Input::VibrationError::Unknown;
} }
return Input::VibrationError::None; return Common::Input::VibrationError::None;
} }
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid, Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
s32 axis, float value) const { s32 axis, float value) const {

View file

@ -58,8 +58,8 @@ public:
std::string GetHatButtonName(u8 direction_value) const override; std::string GetHatButtonName(u8 direction_value) const override;
u8 GetHatButtonId(const std::string direction_name) const override; u8 GetHatButtonId(const std::string direction_name) const override;
Input::VibrationError SetRumble(const PadIdentifier& identifier, Common::Input::VibrationError SetRumble(
const Input::VibrationStatus vibration) override; const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override;
private: private:
void InitJoystick(int joystick_index); void InitJoystick(int joystick_index);
@ -105,9 +105,6 @@ private:
/// Returns true if the button is on the left joycon /// Returns true if the button is on the left joycon
bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const; bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const;
// Set to true if SDL supports game controller subsystem
bool has_gamecontroller = false;
/// Map of GUID of a list of corresponding virtual Joysticks /// Map of GUID of a list of corresponding virtual Joysticks
std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map; std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
std::mutex joystick_map_mutex; std::mutex joystick_map_mutex;

View file

@ -41,7 +41,7 @@ public:
private: private:
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{""}, .guid = Common::UUID{Common::INVALID_UUID},
.port = 0, .port = 0,
.pad = 0, .pad = 0,
}; };

View file

@ -10,25 +10,27 @@
namespace InputCommon { namespace InputCommon {
class Stick final : public Input::InputDevice { class Stick final : public Common::Input::InputDevice {
public: public:
using Button = std::unique_ptr<Input::InputDevice>; using Button = std::unique_ptr<Common::Input::InputDevice>;
Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_,
float modifier_scale_, float modifier_angle_) float modifier_scale_, float modifier_angle_)
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
modifier_angle(modifier_angle_) { modifier_angle(modifier_angle_) {
Input::InputCallback button_up_callback{ Common::Input::InputCallback button_up_callback{
[this](Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }}; [this](Common::Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }};
Input::InputCallback button_down_callback{ Common::Input::InputCallback button_down_callback{
[this](Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }}; [this](Common::Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }};
Input::InputCallback button_left_callback{ Common::Input::InputCallback button_left_callback{
[this](Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }}; [this](Common::Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }};
Input::InputCallback button_right_callback{ Common::Input::InputCallback button_right_callback{
[this](Input::CallbackStatus callback_) { UpdateRightButtonStatus(callback_); }}; [this](Common::Input::CallbackStatus callback_) {
Input::InputCallback button_modifier_callback{ UpdateRightButtonStatus(callback_);
[this](Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }}; }};
Common::Input::InputCallback button_modifier_callback{
[this](Common::Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }};
up->SetCallback(button_up_callback); up->SetCallback(button_up_callback);
down->SetCallback(button_down_callback); down->SetCallback(button_down_callback);
left->SetCallback(button_left_callback); left->SetCallback(button_left_callback);
@ -129,27 +131,27 @@ public:
} }
} }
void UpdateUpButtonStatus(Input::CallbackStatus button_callback) { void UpdateUpButtonStatus(Common::Input::CallbackStatus button_callback) {
up_status = button_callback.button_status.value; up_status = button_callback.button_status.value;
UpdateStatus(); UpdateStatus();
} }
void UpdateDownButtonStatus(Input::CallbackStatus button_callback) { void UpdateDownButtonStatus(Common::Input::CallbackStatus button_callback) {
down_status = button_callback.button_status.value; down_status = button_callback.button_status.value;
UpdateStatus(); UpdateStatus();
} }
void UpdateLeftButtonStatus(Input::CallbackStatus button_callback) { void UpdateLeftButtonStatus(Common::Input::CallbackStatus button_callback) {
left_status = button_callback.button_status.value; left_status = button_callback.button_status.value;
UpdateStatus(); UpdateStatus();
} }
void UpdateRightButtonStatus(Input::CallbackStatus button_callback) { void UpdateRightButtonStatus(Common::Input::CallbackStatus button_callback) {
right_status = button_callback.button_status.value; right_status = button_callback.button_status.value;
UpdateStatus(); UpdateStatus();
} }
void UpdateModButtonStatus(Input::CallbackStatus button_callback) { void UpdateModButtonStatus(Common::Input::CallbackStatus button_callback) {
modifier_status = button_callback.button_status.value; modifier_status = button_callback.button_status.value;
UpdateStatus(); UpdateStatus();
} }
@ -193,8 +195,8 @@ public:
} }
last_update = now; last_update = now;
Input::CallbackStatus status{ Common::Input::CallbackStatus status{
.type = Input::InputType::Stick, .type = Common::Input::InputType::Stick,
.stick_status = GetStatus(), .stick_status = GetStatus(),
}; };
TriggerOnChange(status); TriggerOnChange(status);
@ -209,15 +211,15 @@ public:
} }
void SoftUpdate() override { void SoftUpdate() override {
Input::CallbackStatus status{ Common::Input::CallbackStatus status{
.type = Input::InputType::Stick, .type = Common::Input::InputType::Stick,
.stick_status = GetStatus(), .stick_status = GetStatus(),
}; };
TriggerOnChange(status); TriggerOnChange(status);
} }
Input::StickStatus GetStatus() const { Common::Input::StickStatus GetStatus() const {
Input::StickStatus status{}; Common::Input::StickStatus status{};
status.x.properties = properties; status.x.properties = properties;
status.y.properties = properties; status.y.properties = properties;
if (Settings::values.emulate_analog_keyboard) { if (Settings::values.emulate_analog_keyboard) {
@ -263,19 +265,23 @@ private:
bool left_status; bool left_status;
bool right_status; bool right_status;
bool modifier_status; bool modifier_status;
const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
std::chrono::time_point<std::chrono::steady_clock> last_update; std::chrono::time_point<std::chrono::steady_clock> last_update;
}; };
std::unique_ptr<Input::InputDevice> StickFromButton::Create(const Common::ParamPackage& params) { std::unique_ptr<Common::Input::InputDevice> StickFromButton::Create(
const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto up = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("up", null_engine)); auto up = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
auto down = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("down", null_engine)); params.Get("up", null_engine));
auto left = Input::CreateDeviceFromString<Input::InputDevice>(params.Get("left", null_engine)); auto down = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
auto right = params.Get("down", null_engine));
Input::CreateDeviceFromString<Input::InputDevice>(params.Get("right", null_engine)); auto left = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
auto modifier = params.Get("left", null_engine));
Input::CreateDeviceFromString<Input::InputDevice>(params.Get("modifier", null_engine)); auto right = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("right", null_engine));
auto modifier = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
params.Get("modifier", null_engine));
auto modifier_scale = params.Get("modifier_scale", 0.5f); auto modifier_scale = params.Get("modifier_scale", 0.5f);
auto modifier_angle = params.Get("modifier_angle", 5.5f); auto modifier_angle = params.Get("modifier_angle", 5.5f);
return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left), return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left),

View file

@ -12,7 +12,7 @@ namespace InputCommon {
* An analog device factory that takes direction button devices and combines them into a analog * An analog device factory that takes direction button devices and combines them into a analog
* device. * device.
*/ */
class StickFromButton final : public Input::Factory<Input::InputDevice> { class StickFromButton final : public Common::Input::Factory<Common::Input::InputDevice> {
public: public:
/** /**
* Creates an analog device from direction button devices * Creates an analog device from direction button devices
@ -24,7 +24,7 @@ public:
* - "modifier": a serialized ParamPackage for creating a button device as the modifier * - "modifier": a serialized ParamPackage for creating a button device as the modifier
* - "modifier_scale": a float for the multiplier the modifier gives to the position * - "modifier_scale": a float for the multiplier the modifier gives to the position
*/ */
std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
}; };
} // namespace InputCommon } // namespace InputCommon

View file

@ -9,22 +9,22 @@
namespace InputCommon { namespace InputCommon {
class TouchFromButtonDevice final : public Input::InputDevice { class TouchFromButtonDevice final : public Common::Input::InputDevice {
public: public:
using Button = std::unique_ptr<Input::InputDevice>; using Button = std::unique_ptr<Common::Input::InputDevice>;
TouchFromButtonDevice(Button button_, u32 touch_id_, float x_, float y_) TouchFromButtonDevice(Button button_, u32 touch_id_, float x_, float y_)
: button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) {
Input::InputCallback button_up_callback{ Common::Input::InputCallback button_up_callback{
[this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }};
button->SetCallback(button_up_callback); button->SetCallback(button_up_callback);
button->ForceUpdate(); button->ForceUpdate();
} }
Input::TouchStatus GetStatus(bool pressed) const { Common::Input::TouchStatus GetStatus(bool pressed) const {
const Input::ButtonStatus button_status{ const Common::Input::ButtonStatus button_status{
.value = pressed, .value = pressed,
}; };
Input::TouchStatus status{ Common::Input::TouchStatus status{
.pressed = button_status, .pressed = button_status,
.x = {}, .x = {},
.y = {}, .y = {},
@ -42,9 +42,9 @@ public:
return status; return status;
} }
void UpdateButtonStatus(Input::CallbackStatus button_callback) { void UpdateButtonStatus(Common::Input::CallbackStatus button_callback) {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Touch, .type = Common::Input::InputType::Touch,
.touch_status = GetStatus(button_callback.button_status.value), .touch_status = GetStatus(button_callback.button_status.value),
}; };
TriggerOnChange(status); TriggerOnChange(status);
@ -55,13 +55,14 @@ private:
const u32 touch_id; const u32 touch_id;
const float x; const float x;
const float y; const float y;
const Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false};
}; };
std::unique_ptr<Input::InputDevice> TouchFromButton::Create(const Common::ParamPackage& params) { std::unique_ptr<Common::Input::InputDevice> TouchFromButton::Create(
const Common::ParamPackage& params) {
const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize();
auto button = auto button = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>(
Input::CreateDeviceFromString<Input::InputDevice>(params.Get("button", null_engine)); params.Get("button", null_engine));
const auto touch_id = params.Get("touch_id", 0); const auto touch_id = params.Get("touch_id", 0);
const float x = params.Get("x", 0.0f) / 1280.0f; const float x = params.Get("x", 0.0f) / 1280.0f;
const float y = params.Get("y", 0.0f) / 720.0f; const float y = params.Get("y", 0.0f) / 720.0f;

View file

@ -11,12 +11,12 @@ namespace InputCommon {
/** /**
* A touch device factory that takes a list of button devices and combines them into a touch device. * A touch device factory that takes a list of button devices and combines them into a touch device.
*/ */
class TouchFromButton final : public Input::Factory<Input::InputDevice> { class TouchFromButton final : public Common::Input::Factory<Common::Input::InputDevice> {
public: public:
/** /**
* Creates a touch device from a list of button devices * Creates a touch device from a list of button devices
*/ */
std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
}; };
} // namespace InputCommon } // namespace InputCommon

View file

@ -116,22 +116,22 @@ public:
// Sets a led pattern for a controller // Sets a led pattern for a controller
virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier, virtual void SetLeds([[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::LedStatus led_status) { [[maybe_unused]] const Common::Input::LedStatus led_status) {
return; return;
} }
// Sets rumble to a controller // Sets rumble to a controller
virtual Input::VibrationError SetRumble( virtual Common::Input::VibrationError SetRumble(
[[maybe_unused]] const PadIdentifier& identifier, [[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::VibrationStatus vibration) { [[maybe_unused]] const Common::Input::VibrationStatus vibration) {
return Input::VibrationError::NotSupported; return Common::Input::VibrationError::NotSupported;
} }
// Sets polling mode to a controller // Sets polling mode to a controller
virtual Input::PollingError SetPollingMode( virtual Common::Input::PollingError SetPollingMode(
[[maybe_unused]] const PadIdentifier& identifier, [[maybe_unused]] const PadIdentifier& identifier,
[[maybe_unused]] const Input::PollingMode vibration) { [[maybe_unused]] const Common::Input::PollingMode vibration) {
return Input::PollingError::NotSupported; return Common::Input::PollingError::NotSupported;
} }
// Returns the engine name // Returns the engine name

View file

@ -10,13 +10,13 @@
namespace InputCommon { namespace InputCommon {
class DummyInput final : public Input::InputDevice { class DummyInput final : public Common::Input::InputDevice {
public: public:
explicit DummyInput() {} explicit DummyInput() {}
~DummyInput() {} ~DummyInput() {}
}; };
class InputFromButton final : public Input::InputDevice { class InputFromButton final : public Common::Input::InputDevice {
public: public:
explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_,
InputEngine* input_engine_) InputEngine* input_engine_)
@ -37,7 +37,7 @@ public:
input_engine->DeleteCallback(callback_key); input_engine->DeleteCallback(callback_key);
} }
Input::ButtonStatus GetStatus() const { Common::Input::ButtonStatus GetStatus() const {
return { return {
.value = input_engine->GetButton(identifier, button), .value = input_engine->GetButton(identifier, button),
.inverted = inverted, .inverted = inverted,
@ -46,8 +46,8 @@ public:
} }
void ForceUpdate() { void ForceUpdate() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Button, .type = Common::Input::InputType::Button,
.button_status = GetStatus(), .button_status = GetStatus(),
}; };
@ -56,8 +56,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Button, .type = Common::Input::InputType::Button,
.button_status = GetStatus(), .button_status = GetStatus(),
}; };
@ -77,7 +77,7 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromHatButton final : public Input::InputDevice { class InputFromHatButton final : public Common::Input::InputDevice {
public: public:
explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_,
bool inverted_, InputEngine* input_engine_) bool inverted_, InputEngine* input_engine_)
@ -98,7 +98,7 @@ public:
input_engine->DeleteCallback(callback_key); input_engine->DeleteCallback(callback_key);
} }
Input::ButtonStatus GetStatus() const { Common::Input::ButtonStatus GetStatus() const {
return { return {
.value = input_engine->GetHatButton(identifier, button, direction), .value = input_engine->GetHatButton(identifier, button, direction),
.inverted = inverted, .inverted = inverted,
@ -107,8 +107,8 @@ public:
} }
void ForceUpdate() { void ForceUpdate() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Button, .type = Common::Input::InputType::Button,
.button_status = GetStatus(), .button_status = GetStatus(),
}; };
@ -117,8 +117,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Button, .type = Common::Input::InputType::Button,
.button_status = GetStatus(), .button_status = GetStatus(),
}; };
@ -139,11 +139,12 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromStick final : public Input::InputDevice { class InputFromStick final : public Common::Input::InputDevice {
public: public:
explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_,
Input::AnalogProperties properties_x_, Common::Input::AnalogProperties properties_x_,
Input::AnalogProperties properties_y_, InputEngine* input_engine_) Common::Input::AnalogProperties properties_y_,
InputEngine* input_engine_)
: identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_),
properties_y(properties_y_), input_engine(input_engine_) { properties_y(properties_y_), input_engine(input_engine_) {
UpdateCallback engine_callback{[this]() { OnChange(); }}; UpdateCallback engine_callback{[this]() { OnChange(); }};
@ -170,8 +171,8 @@ public:
input_engine->DeleteCallback(callback_key_y); input_engine->DeleteCallback(callback_key_y);
} }
Input::StickStatus GetStatus() const { Common::Input::StickStatus GetStatus() const {
Input::StickStatus status; Common::Input::StickStatus status;
status.x = { status.x = {
.raw_value = input_engine->GetAxis(identifier, axis_x), .raw_value = input_engine->GetAxis(identifier, axis_x),
.properties = properties_x, .properties = properties_x,
@ -184,8 +185,8 @@ public:
} }
void ForceUpdate() { void ForceUpdate() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Stick, .type = Common::Input::InputType::Stick,
.stick_status = GetStatus(), .stick_status = GetStatus(),
}; };
@ -195,8 +196,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Stick, .type = Common::Input::InputType::Stick,
.stick_status = GetStatus(), .stick_status = GetStatus(),
}; };
@ -212,8 +213,8 @@ private:
const PadIdentifier identifier; const PadIdentifier identifier;
const u32 axis_x; const u32 axis_x;
const u32 axis_y; const u32 axis_y;
const Input::AnalogProperties properties_x; const Common::Input::AnalogProperties properties_x;
const Input::AnalogProperties properties_y; const Common::Input::AnalogProperties properties_y;
int callback_key_x; int callback_key_x;
int callback_key_y; int callback_key_y;
float last_axis_x_value; float last_axis_x_value;
@ -221,12 +222,13 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromTouch final : public Input::InputDevice { class InputFromTouch final : public Common::Input::InputDevice {
public: public:
explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_,
bool inverted_, u32 axis_x_, u32 axis_y_, bool inverted_, u32 axis_x_, u32 axis_y_,
Input::AnalogProperties properties_x_, Common::Input::AnalogProperties properties_x_,
Input::AnalogProperties properties_y_, InputEngine* input_engine_) Common::Input::AnalogProperties properties_y_,
InputEngine* input_engine_)
: identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_), : identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_),
inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_),
properties_y(properties_y_), input_engine(input_engine_) { properties_y(properties_y_), input_engine(input_engine_) {
@ -263,8 +265,8 @@ public:
input_engine->DeleteCallback(callback_key_y); input_engine->DeleteCallback(callback_key_y);
} }
Input::TouchStatus GetStatus() const { Common::Input::TouchStatus GetStatus() const {
Input::TouchStatus status; Common::Input::TouchStatus status;
status.id = touch_id; status.id = touch_id;
status.pressed = { status.pressed = {
.value = input_engine->GetButton(identifier, button), .value = input_engine->GetButton(identifier, button),
@ -283,8 +285,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Touch, .type = Common::Input::InputType::Touch,
.touch_status = GetStatus(), .touch_status = GetStatus(),
}; };
@ -306,8 +308,8 @@ private:
const bool inverted; const bool inverted;
const u32 axis_x; const u32 axis_x;
const u32 axis_y; const u32 axis_y;
const Input::AnalogProperties properties_x; const Common::Input::AnalogProperties properties_x;
const Input::AnalogProperties properties_y; const Common::Input::AnalogProperties properties_y;
int callback_key_button; int callback_key_button;
int callback_key_x; int callback_key_x;
int callback_key_y; int callback_key_y;
@ -317,10 +319,10 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromTrigger final : public Input::InputDevice { class InputFromTrigger final : public Common::Input::InputDevice {
public: public:
explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_,
u32 axis_, Input::AnalogProperties properties_, u32 axis_, Common::Input::AnalogProperties properties_,
InputEngine* input_engine_) InputEngine* input_engine_)
: identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_),
axis(axis_), properties(properties_), input_engine(input_engine_) { axis(axis_), properties(properties_), input_engine(input_engine_) {
@ -348,8 +350,8 @@ public:
input_engine->DeleteCallback(axis_callback_key); input_engine->DeleteCallback(axis_callback_key);
} }
Input::TriggerStatus GetStatus() const { Common::Input::TriggerStatus GetStatus() const {
const Input::AnalogStatus analog_status{ const Common::Input::AnalogStatus analog_status{
.raw_value = input_engine->GetAxis(identifier, axis), .raw_value = input_engine->GetAxis(identifier, axis),
.properties = properties, .properties = properties,
}; };
@ -360,8 +362,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Trigger, .type = Common::Input::InputType::Trigger,
.trigger_status = GetStatus(), .trigger_status = GetStatus(),
}; };
@ -379,7 +381,7 @@ private:
const bool toggle; const bool toggle;
const bool inverted; const bool inverted;
const u32 axis; const u32 axis;
const Input::AnalogProperties properties; const Common::Input::AnalogProperties properties;
int callback_key_button; int callback_key_button;
int axis_callback_key; int axis_callback_key;
bool last_button_value; bool last_button_value;
@ -387,10 +389,11 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromAnalog final : public Input::InputDevice { class InputFromAnalog final : public Common::Input::InputDevice {
public: public:
explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_,
Input::AnalogProperties properties_, InputEngine* input_engine_) Common::Input::AnalogProperties properties_,
InputEngine* input_engine_)
: identifier(identifier_), axis(axis_), properties(properties_), : identifier(identifier_), axis(axis_), properties(properties_),
input_engine(input_engine_) { input_engine(input_engine_) {
UpdateCallback engine_callback{[this]() { OnChange(); }}; UpdateCallback engine_callback{[this]() { OnChange(); }};
@ -408,7 +411,7 @@ public:
input_engine->DeleteCallback(callback_key); input_engine->DeleteCallback(callback_key);
} }
Input::AnalogStatus GetStatus() const { Common::Input::AnalogStatus GetStatus() const {
return { return {
.raw_value = input_engine->GetAxis(identifier, axis), .raw_value = input_engine->GetAxis(identifier, axis),
.properties = properties, .properties = properties,
@ -416,8 +419,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Analog, .type = Common::Input::InputType::Analog,
.analog_status = GetStatus(), .analog_status = GetStatus(),
}; };
@ -430,13 +433,13 @@ public:
private: private:
const PadIdentifier identifier; const PadIdentifier identifier;
const u32 axis; const u32 axis;
const Input::AnalogProperties properties; const Common::Input::AnalogProperties properties;
int callback_key; int callback_key;
float last_axis_value; float last_axis_value;
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromBattery final : public Input::InputDevice { class InputFromBattery final : public Common::Input::InputDevice {
public: public:
explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_) explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_)
: identifier(identifier_), input_engine(input_engine_) { : identifier(identifier_), input_engine(input_engine_) {
@ -447,7 +450,7 @@ public:
.index = 0, .index = 0,
.callback = engine_callback, .callback = engine_callback,
}; };
last_battery_value = Input::BatteryStatus::Charging; last_battery_value = Common::Input::BatteryStatus::Charging;
callback_key = input_engine->SetCallback(input_identifier); callback_key = input_engine->SetCallback(input_identifier);
} }
@ -455,13 +458,13 @@ public:
input_engine->DeleteCallback(callback_key); input_engine->DeleteCallback(callback_key);
} }
Input::BatteryStatus GetStatus() const { Common::Input::BatteryStatus GetStatus() const {
return static_cast<Input::BatteryLevel>(input_engine->GetBattery(identifier)); return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier));
} }
void ForceUpdate() { void ForceUpdate() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Battery, .type = Common::Input::InputType::Battery,
.battery_status = GetStatus(), .battery_status = GetStatus(),
}; };
@ -470,8 +473,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Battery, .type = Common::Input::InputType::Battery,
.battery_status = GetStatus(), .battery_status = GetStatus(),
}; };
@ -484,11 +487,11 @@ public:
private: private:
const PadIdentifier identifier; const PadIdentifier identifier;
int callback_key; int callback_key;
Input::BatteryStatus last_battery_value; Common::Input::BatteryStatus last_battery_value;
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromMotion final : public Input::InputDevice { class InputFromMotion final : public Common::Input::InputDevice {
public: public:
explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_,
InputEngine* input_engine_) InputEngine* input_engine_)
@ -507,10 +510,10 @@ public:
input_engine->DeleteCallback(callback_key); input_engine->DeleteCallback(callback_key);
} }
Input::MotionStatus GetStatus() const { Common::Input::MotionStatus GetStatus() const {
const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor);
Input::MotionStatus status{}; Common::Input::MotionStatus status{};
const Input::AnalogProperties properties = { const Common::Input::AnalogProperties properties = {
.deadzone = 0.001f, .deadzone = 0.001f,
.range = 1.0f, .range = 1.0f,
.offset = 0.0f, .offset = 0.0f,
@ -526,8 +529,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Motion, .type = Common::Input::InputType::Motion,
.motion_status = GetStatus(), .motion_status = GetStatus(),
}; };
@ -541,12 +544,13 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class InputFromAxisMotion final : public Input::InputDevice { class InputFromAxisMotion final : public Common::Input::InputDevice {
public: public:
explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_,
Input::AnalogProperties properties_x_, Common::Input::AnalogProperties properties_x_,
Input::AnalogProperties properties_y_, Common::Input::AnalogProperties properties_y_,
Input::AnalogProperties properties_z_, InputEngine* input_engine_) Common::Input::AnalogProperties properties_z_,
InputEngine* input_engine_)
: identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_), : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_),
properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_), properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_),
input_engine(input_engine_) { input_engine(input_engine_) {
@ -583,8 +587,8 @@ public:
input_engine->DeleteCallback(callback_key_z); input_engine->DeleteCallback(callback_key_z);
} }
Input::MotionStatus GetStatus() const { Common::Input::MotionStatus GetStatus() const {
Input::MotionStatus status{}; Common::Input::MotionStatus status{};
status.gyro.x = { status.gyro.x = {
.raw_value = input_engine->GetAxis(identifier, axis_x), .raw_value = input_engine->GetAxis(identifier, axis_x),
.properties = properties_x, .properties = properties_x,
@ -601,8 +605,8 @@ public:
} }
void ForceUpdate() { void ForceUpdate() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Motion, .type = Common::Input::InputType::Motion,
.motion_status = GetStatus(), .motion_status = GetStatus(),
}; };
@ -613,8 +617,8 @@ public:
} }
void OnChange() { void OnChange() {
const Input::CallbackStatus status{ const Common::Input::CallbackStatus status{
.type = Input::InputType::Motion, .type = Common::Input::InputType::Motion,
.motion_status = GetStatus(), .motion_status = GetStatus(),
}; };
@ -633,9 +637,9 @@ private:
const u32 axis_x; const u32 axis_x;
const u32 axis_y; const u32 axis_y;
const u32 axis_z; const u32 axis_z;
const Input::AnalogProperties properties_x; const Common::Input::AnalogProperties properties_x;
const Input::AnalogProperties properties_y; const Common::Input::AnalogProperties properties_y;
const Input::AnalogProperties properties_z; const Common::Input::AnalogProperties properties_z;
int callback_key_x; int callback_key_x;
int callback_key_y; int callback_key_y;
int callback_key_z; int callback_key_z;
@ -645,20 +649,21 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
class OutputFromIdentifier final : public Input::OutputDevice { class OutputFromIdentifier final : public Common::Input::OutputDevice {
public: public:
explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
: identifier(identifier_), input_engine(input_engine_) {} : identifier(identifier_), input_engine(input_engine_) {}
virtual void SetLED(Input::LedStatus led_status) { virtual void SetLED(Common::Input::LedStatus led_status) {
input_engine->SetLeds(identifier, led_status); input_engine->SetLeds(identifier, led_status);
} }
virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) { virtual Common::Input::VibrationError SetVibration(
Common::Input::VibrationStatus vibration_status) {
return input_engine->SetRumble(identifier, vibration_status); return input_engine->SetRumble(identifier, vibration_status);
} }
virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) { virtual Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) {
return input_engine->SetPollingMode(identifier, polling_mode); return input_engine->SetPollingMode(identifier, polling_mode);
} }
@ -667,7 +672,7 @@ private:
InputEngine* input_engine; InputEngine* input_engine;
}; };
std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
@ -690,7 +695,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateButtonDevice(
input_engine.get()); input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateHatButtonDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
@ -709,7 +714,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateHatButtonDevice(
input_engine.get()); input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f);
const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f);
@ -721,7 +726,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice(
}; };
const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); const auto axis_x = static_cast<u32>(params.Get("axis_x", 0));
const Input::AnalogProperties properties_x = { const Common::Input::AnalogProperties properties_x = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -730,7 +735,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice(
}; };
const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); const auto axis_y = static_cast<u32>(params.Get("axis_y", 1));
const Input::AnalogProperties properties_y = { const Common::Input::AnalogProperties properties_y = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -744,7 +749,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateStickDevice(
input_engine.get()); input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateAnalogDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
@ -753,7 +758,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateAnalogDevice(
}; };
const auto axis = static_cast<u32>(params.Get("axis", 0)); const auto axis = static_cast<u32>(params.Get("axis", 0));
const Input::AnalogProperties properties = { const Common::Input::AnalogProperties properties = {
.deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f),
.range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f),
.threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f),
@ -765,7 +770,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateAnalogDevice(
return std::make_unique<InputFromAnalog>(identifier, axis, properties, input_engine.get()); return std::make_unique<InputFromAnalog>(identifier, axis, properties, input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateTriggerDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTriggerDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
@ -778,7 +783,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTriggerDevice(
const auto inverted = params.Get("inverted", false); const auto inverted = params.Get("inverted", false);
const auto axis = static_cast<u32>(params.Get("axis", 0)); const auto axis = static_cast<u32>(params.Get("axis", 0));
const Input::AnalogProperties properties = { const Common::Input::AnalogProperties properties = {
.deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f),
.range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f),
.threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f),
@ -792,7 +797,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTriggerDevice(
properties, input_engine.get()); properties, input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const auto touch_id = params.Get("touch_id", 0); const auto touch_id = params.Get("touch_id", 0);
const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f);
@ -809,7 +814,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice(
const auto inverted = params.Get("inverted", false); const auto inverted = params.Get("inverted", false);
const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); const auto axis_x = static_cast<u32>(params.Get("axis_x", 0));
const Input::AnalogProperties properties_x = { const Common::Input::AnalogProperties properties_x = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -818,7 +823,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice(
}; };
const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); const auto axis_y = static_cast<u32>(params.Get("axis_y", 1));
const Input::AnalogProperties properties_y = { const Common::Input::AnalogProperties properties_y = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -833,7 +838,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateTouchDevice(
axis_y, properties_x, properties_y, input_engine.get()); axis_y, properties_x, properties_y, input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateBatteryDevice( std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice(
const Common::ParamPackage& params) { const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
@ -845,7 +850,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateBatteryDevice(
return std::make_unique<InputFromBattery>(identifier, input_engine.get()); return std::make_unique<InputFromBattery>(identifier, input_engine.get());
} }
std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::ParamPackage params) { std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
Common::ParamPackage params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
.port = static_cast<std::size_t>(params.Get("port", 0)), .port = static_cast<std::size_t>(params.Get("port", 0)),
@ -864,7 +870,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f);
const auto axis_x = static_cast<u32>(params.Get("axis_x", 0)); const auto axis_x = static_cast<u32>(params.Get("axis_x", 0));
const Input::AnalogProperties properties_x = { const Common::Input::AnalogProperties properties_x = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -873,7 +879,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
}; };
const auto axis_y = static_cast<u32>(params.Get("axis_y", 1)); const auto axis_y = static_cast<u32>(params.Get("axis_y", 1));
const Input::AnalogProperties properties_y = { const Common::Input::AnalogProperties properties_y = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -882,7 +888,7 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
}; };
const auto axis_z = static_cast<u32>(params.Get("axis_z", 1)); const auto axis_z = static_cast<u32>(params.Get("axis_z", 1));
const Input::AnalogProperties properties_z = { const Common::Input::AnalogProperties properties_z = {
.deadzone = deadzone, .deadzone = deadzone,
.range = range, .range = range,
.threshold = threshold, .threshold = threshold,
@ -900,7 +906,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::CreateMotionDevice(Common::Par
InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_)
: input_engine(std::move(input_engine_)) {} : input_engine(std::move(input_engine_)) {}
std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPackage& params) { std::unique_ptr<Common::Input::InputDevice> InputFactory::Create(
const Common::ParamPackage& params) {
if (params.Has("battery")) { if (params.Has("battery")) {
return CreateBatteryDevice(params); return CreateBatteryDevice(params);
} }
@ -935,7 +942,8 @@ std::unique_ptr<Input::InputDevice> InputFactory::Create(const Common::ParamPack
OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_) OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_)
: input_engine(std::move(input_engine_)) {} : input_engine(std::move(input_engine_)) {}
std::unique_ptr<Input::OutputDevice> OutputFactory::Create(const Common::ParamPackage& params) { std::unique_ptr<Common::Input::OutputDevice> OutputFactory::Create(
const Common::ParamPackage& params) {
const PadIdentifier identifier = { const PadIdentifier identifier = {
.guid = Common::UUID{params.Get("guid", "")}, .guid = Common::UUID{params.Get("guid", "")},
.port = static_cast<std::size_t>(params.Get("port", 0)), .port = static_cast<std::size_t>(params.Get("port", 0)),

View file

@ -17,7 +17,7 @@ class InputEngine;
* An Input factory. It receives input events and forward them to all input devices it created. * An Input factory. It receives input events and forward them to all input devices it created.
*/ */
class OutputFactory final : public Input::Factory<Input::OutputDevice> { class OutputFactory final : public Common::Input::Factory<Common::Input::OutputDevice> {
public: public:
explicit OutputFactory(std::shared_ptr<InputEngine> input_engine_); explicit OutputFactory(std::shared_ptr<InputEngine> input_engine_);
@ -29,13 +29,14 @@ public:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique ouput device with the parameters specified * @return an unique ouput device with the parameters specified
*/ */
std::unique_ptr<Input::OutputDevice> Create(const Common::ParamPackage& params) override; std::unique_ptr<Common::Input::OutputDevice> Create(
const Common::ParamPackage& params) override;
private: private:
std::shared_ptr<InputEngine> input_engine; std::shared_ptr<InputEngine> input_engine;
}; };
class InputFactory final : public Input::Factory<Input::InputDevice> { class InputFactory final : public Common::Input::Factory<Common::Input::InputDevice> {
public: public:
explicit InputFactory(std::shared_ptr<InputEngine> input_engine_); explicit InputFactory(std::shared_ptr<InputEngine> input_engine_);
@ -64,7 +65,7 @@ public:
* @param - "battery": Only used as a placeholder to set the input type * @param - "battery": Only used as a placeholder to set the input type
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> Create(const Common::ParamPackage& params) override; std::unique_ptr<Common::Input::InputDevice> Create(const Common::ParamPackage& params) override;
private: private:
/** /**
@ -79,7 +80,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateButtonDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateButtonDevice(
const Common::ParamPackage& params);
/** /**
* Creates a hat button device from the parameters given. * Creates a hat button device from the parameters given.
@ -93,7 +95,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateHatButtonDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateHatButtonDevice(
const Common::ParamPackage& params);
/** /**
* Creates a stick device from the parameters given. * Creates a stick device from the parameters given.
@ -112,7 +115,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateStickDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateStickDevice(
const Common::ParamPackage& params);
/** /**
* Creates an analog device from the parameters given. * Creates an analog device from the parameters given.
@ -128,7 +132,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateAnalogDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateAnalogDevice(
const Common::ParamPackage& params);
/** /**
* Creates a trigger device from the parameters given. * Creates a trigger device from the parameters given.
@ -148,7 +153,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateTriggerDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateTriggerDevice(
const Common::ParamPackage& params);
/** /**
* Creates a touch device from the parameters given. * Creates a touch device from the parameters given.
@ -171,7 +177,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateTouchDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateTouchDevice(
const Common::ParamPackage& params);
/** /**
* Creates a battery device from the parameters given. * Creates a battery device from the parameters given.
@ -181,7 +188,8 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateBatteryDevice(const Common::ParamPackage& params); std::unique_ptr<Common::Input::InputDevice> CreateBatteryDevice(
const Common::ParamPackage& params);
/** /**
* Creates a motion device from the parameters given. * Creates a motion device from the parameters given.
@ -202,7 +210,7 @@ private:
* @param - "pad": slot of the connected controller * @param - "pad": slot of the connected controller
* @return an unique input device with the parameters specified * @return an unique input device with the parameters specified
*/ */
std::unique_ptr<Input::InputDevice> CreateMotionDevice(Common::ParamPackage params); std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
std::shared_ptr<InputEngine> input_engine; std::shared_ptr<InputEngine> input_engine;
}; };

View file

@ -33,89 +33,97 @@ struct InputSubsystem::Impl {
keyboard->SetMappingCallback(mapping_callback); keyboard->SetMappingCallback(mapping_callback);
keyboard_factory = std::make_shared<InputFactory>(keyboard); keyboard_factory = std::make_shared<InputFactory>(keyboard);
keyboard_output_factory = std::make_shared<OutputFactory>(keyboard); keyboard_output_factory = std::make_shared<OutputFactory>(keyboard);
Input::RegisterFactory<Input::InputDevice>(keyboard->GetEngineName(), keyboard_factory); Common::Input::RegisterFactory<Common::Input::InputDevice>(keyboard->GetEngineName(),
Input::RegisterFactory<Input::OutputDevice>(keyboard->GetEngineName(), keyboard_factory);
Common::Input::RegisterFactory<Common::Input::OutputDevice>(keyboard->GetEngineName(),
keyboard_output_factory); keyboard_output_factory);
mouse = std::make_shared<Mouse>("mouse"); mouse = std::make_shared<Mouse>("mouse");
mouse->SetMappingCallback(mapping_callback); mouse->SetMappingCallback(mapping_callback);
mouse_factory = std::make_shared<InputFactory>(mouse); mouse_factory = std::make_shared<InputFactory>(mouse);
mouse_output_factory = std::make_shared<OutputFactory>(mouse); mouse_output_factory = std::make_shared<OutputFactory>(mouse);
Input::RegisterFactory<Input::InputDevice>(mouse->GetEngineName(), mouse_factory); Common::Input::RegisterFactory<Common::Input::InputDevice>(mouse->GetEngineName(),
Input::RegisterFactory<Input::OutputDevice>(mouse->GetEngineName(), mouse_output_factory); mouse_factory);
Common::Input::RegisterFactory<Common::Input::OutputDevice>(mouse->GetEngineName(),
mouse_output_factory);
touch_screen = std::make_shared<TouchScreen>("touch"); touch_screen = std::make_shared<TouchScreen>("touch");
touch_screen_factory = std::make_shared<InputFactory>(touch_screen); touch_screen_factory = std::make_shared<InputFactory>(touch_screen);
Input::RegisterFactory<Input::InputDevice>(touch_screen->GetEngineName(), Common::Input::RegisterFactory<Common::Input::InputDevice>(touch_screen->GetEngineName(),
touch_screen_factory); touch_screen_factory);
gcadapter = std::make_shared<GCAdapter>("gcpad"); gcadapter = std::make_shared<GCAdapter>("gcpad");
gcadapter->SetMappingCallback(mapping_callback); gcadapter->SetMappingCallback(mapping_callback);
gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter); gcadapter_input_factory = std::make_shared<InputFactory>(gcadapter);
gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter); gcadapter_output_factory = std::make_shared<OutputFactory>(gcadapter);
Input::RegisterFactory<Input::InputDevice>(gcadapter->GetEngineName(), Common::Input::RegisterFactory<Common::Input::InputDevice>(gcadapter->GetEngineName(),
gcadapter_input_factory); gcadapter_input_factory);
Input::RegisterFactory<Input::OutputDevice>(gcadapter->GetEngineName(), Common::Input::RegisterFactory<Common::Input::OutputDevice>(gcadapter->GetEngineName(),
gcadapter_output_factory); gcadapter_output_factory);
udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp"); udp_client = std::make_shared<CemuhookUDP::UDPClient>("cemuhookudp");
udp_client->SetMappingCallback(mapping_callback); udp_client->SetMappingCallback(mapping_callback);
udp_client_factory = std::make_shared<InputFactory>(udp_client); udp_client_factory = std::make_shared<InputFactory>(udp_client);
Input::RegisterFactory<Input::InputDevice>(udp_client->GetEngineName(), udp_client_factory); Common::Input::RegisterFactory<Common::Input::InputDevice>(udp_client->GetEngineName(),
udp_client_factory);
tas_input = std::make_shared<TasInput::Tas>("tas"); tas_input = std::make_shared<TasInput::Tas>("tas");
tas_input->SetMappingCallback(mapping_callback); tas_input->SetMappingCallback(mapping_callback);
tas_input_factory = std::make_shared<InputFactory>(tas_input); tas_input_factory = std::make_shared<InputFactory>(tas_input);
tas_output_factory = std::make_shared<OutputFactory>(tas_input); tas_output_factory = std::make_shared<OutputFactory>(tas_input);
Input::RegisterFactory<Input::InputDevice>(tas_input->GetEngineName(), tas_input_factory); Common::Input::RegisterFactory<Common::Input::InputDevice>(tas_input->GetEngineName(),
Input::RegisterFactory<Input::OutputDevice>(tas_input->GetEngineName(), tas_output_factory); tas_input_factory);
Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(),
tas_output_factory);
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
sdl = std::make_shared<SDLDriver>("sdl"); sdl = std::make_shared<SDLDriver>("sdl");
sdl->SetMappingCallback(mapping_callback); sdl->SetMappingCallback(mapping_callback);
sdl_input_factory = std::make_shared<InputFactory>(sdl); sdl_input_factory = std::make_shared<InputFactory>(sdl);
sdl_output_factory = std::make_shared<OutputFactory>(sdl); sdl_output_factory = std::make_shared<OutputFactory>(sdl);
Input::RegisterFactory<Input::InputDevice>(sdl->GetEngineName(), sdl_input_factory); Common::Input::RegisterFactory<Common::Input::InputDevice>(sdl->GetEngineName(),
Input::RegisterFactory<Input::OutputDevice>(sdl->GetEngineName(), sdl_output_factory); sdl_input_factory);
Common::Input::RegisterFactory<Common::Input::OutputDevice>(sdl->GetEngineName(),
sdl_output_factory);
#endif #endif
Input::RegisterFactory<Input::InputDevice>("touch_from_button", Common::Input::RegisterFactory<Common::Input::InputDevice>(
std::make_shared<TouchFromButton>()); "touch_from_button", std::make_shared<TouchFromButton>());
Input::RegisterFactory<Input::InputDevice>("analog_from_button", Common::Input::RegisterFactory<Common::Input::InputDevice>(
std::make_shared<StickFromButton>()); "analog_from_button", std::make_shared<StickFromButton>());
} }
void Shutdown() { void Shutdown() {
Input::UnregisterFactory<Input::InputDevice>(keyboard->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(keyboard->GetEngineName());
Input::UnregisterFactory<Input::OutputDevice>(keyboard->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::OutputDevice>(keyboard->GetEngineName());
keyboard.reset(); keyboard.reset();
Input::UnregisterFactory<Input::InputDevice>(mouse->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(mouse->GetEngineName());
Input::UnregisterFactory<Input::OutputDevice>(mouse->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::OutputDevice>(mouse->GetEngineName());
mouse.reset(); mouse.reset();
Input::UnregisterFactory<Input::InputDevice>(touch_screen->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(touch_screen->GetEngineName());
touch_screen.reset(); touch_screen.reset();
Input::UnregisterFactory<Input::InputDevice>(gcadapter->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(gcadapter->GetEngineName());
Input::UnregisterFactory<Input::OutputDevice>(gcadapter->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::OutputDevice>(gcadapter->GetEngineName());
gcadapter.reset(); gcadapter.reset();
Input::UnregisterFactory<Input::InputDevice>(udp_client->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(udp_client->GetEngineName());
udp_client.reset(); udp_client.reset();
Input::UnregisterFactory<Input::InputDevice>(tas_input->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(tas_input->GetEngineName());
Input::UnregisterFactory<Input::OutputDevice>(tas_input->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName());
tas_input.reset(); tas_input.reset();
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
Input::UnregisterFactory<Input::InputDevice>(sdl->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::InputDevice>(sdl->GetEngineName());
Input::UnregisterFactory<Input::OutputDevice>(sdl->GetEngineName()); Common::Input::UnregisterFactory<Common::Input::OutputDevice>(sdl->GetEngineName());
sdl.reset(); sdl.reset();
#endif #endif
Input::UnregisterFactory<Input::InputDevice>("touch_from_button"); Common::Input::UnregisterFactory<Common::Input::InputDevice>("touch_from_button");
Input::UnregisterFactory<Input::InputDevice>("analog_from_button"); Common::Input::UnregisterFactory<Common::Input::InputDevice>("analog_from_button");
} }
[[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const {

View file

@ -1945,8 +1945,8 @@ void PlayerControlPreview::DrawRightBody(QPainter& p, const QPointF center) {
} }
void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& left_pressed, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, pro_left_trigger.size() / 2> qleft_trigger; std::array<QPointF, pro_left_trigger.size() / 2> qleft_trigger;
std::array<QPointF, pro_left_trigger.size() / 2> qright_trigger; std::array<QPointF, pro_left_trigger.size() / 2> qright_trigger;
std::array<QPointF, pro_body_top.size()> qbody_top; std::array<QPointF, pro_body_top.size()> qbody_top;
@ -1984,8 +1984,8 @@ void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawGCTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawGCTriggers(QPainter& p, const QPointF center,
Input::TriggerStatus left_trigger, Common::Input::TriggerStatus left_trigger,
Input::TriggerStatus right_trigger) { Common::Input::TriggerStatus right_trigger) {
std::array<QPointF, left_gc_trigger.size() / 2> qleft_trigger; std::array<QPointF, left_gc_trigger.size() / 2> qleft_trigger;
std::array<QPointF, left_gc_trigger.size() / 2> qright_trigger; std::array<QPointF, left_gc_trigger.size() / 2> qright_trigger;
@ -2022,8 +2022,8 @@ void PlayerControlPreview::DrawGCTriggers(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawHandheldTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawHandheldTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& left_pressed, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger; std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger; std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
@ -2048,8 +2048,8 @@ void PlayerControlPreview::DrawHandheldTriggers(QPainter& p, const QPointF cente
} }
void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& left_pressed, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger; std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger; std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
constexpr float size = 1.62f; constexpr float size = 1.62f;
@ -2076,9 +2076,9 @@ void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center,
DrawPolygon(p, qright_trigger); DrawPolygon(p, qright_trigger);
} }
void PlayerControlPreview::DrawDualTriggersTopView(QPainter& p, const QPointF center, void PlayerControlPreview::DrawDualTriggersTopView(
const Input::ButtonStatus& left_pressed, QPainter& p, const QPointF center, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joystick_L_topview.size() / 2> qleft_trigger; std::array<QPointF, left_joystick_L_topview.size() / 2> qleft_trigger;
std::array<QPointF, left_joystick_L_topview.size() / 2> qright_trigger; std::array<QPointF, left_joystick_L_topview.size() / 2> qright_trigger;
constexpr float size = 0.9f; constexpr float size = 0.9f;
@ -2113,9 +2113,9 @@ void PlayerControlPreview::DrawDualTriggersTopView(QPainter& p, const QPointF ce
DrawSymbol(p, center + QPointF(177, -84), Symbol::R, 1.0f); DrawSymbol(p, center + QPointF(177, -84), Symbol::R, 1.0f);
} }
void PlayerControlPreview::DrawDualZTriggersTopView(QPainter& p, const QPointF center, void PlayerControlPreview::DrawDualZTriggersTopView(
const Input::ButtonStatus& left_pressed, QPainter& p, const QPointF center, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joystick_ZL_topview.size() / 2> qleft_trigger; std::array<QPointF, left_joystick_ZL_topview.size() / 2> qleft_trigger;
std::array<QPointF, left_joystick_ZL_topview.size() / 2> qright_trigger; std::array<QPointF, left_joystick_ZL_topview.size() / 2> qright_trigger;
constexpr float size = 0.9f; constexpr float size = 0.9f;
@ -2149,7 +2149,7 @@ void PlayerControlPreview::DrawDualZTriggersTopView(QPainter& p, const QPointF c
} }
void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& left_pressed) { const Common::Input::ButtonStatus& left_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger; std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
constexpr float size = 1.78f; constexpr float size = 1.78f;
constexpr float offset = 311.5f; constexpr float offset = 311.5f;
@ -2166,7 +2166,7 @@ void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& left_pressed) { const Common::Input::ButtonStatus& left_pressed) {
std::array<QPointF, left_joycon_sideview_zl.size() / 2> qleft_trigger; std::array<QPointF, left_joycon_sideview_zl.size() / 2> qleft_trigger;
constexpr float size = 1.1115f; constexpr float size = 1.1115f;
constexpr float offset2 = 335; constexpr float offset2 = 335;
@ -2184,8 +2184,8 @@ void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center,
225 * 16, 44 * 16); 225 * 16, 44 * 16);
} }
void PlayerControlPreview::DrawLeftTriggersTopView(QPainter& p, const QPointF center, void PlayerControlPreview::DrawLeftTriggersTopView(
const Input::ButtonStatus& left_pressed) { QPainter& p, const QPointF center, const Common::Input::ButtonStatus& left_pressed) {
std::array<QPointF, left_joystick_L_topview.size() / 2> qleft_trigger; std::array<QPointF, left_joystick_L_topview.size() / 2> qleft_trigger;
for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) { for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) {
@ -2203,8 +2203,8 @@ void PlayerControlPreview::DrawLeftTriggersTopView(QPainter& p, const QPointF ce
DrawSymbol(p, center + QPointF(-143, -36), Symbol::L, 1.0f); DrawSymbol(p, center + QPointF(-143, -36), Symbol::L, 1.0f);
} }
void PlayerControlPreview::DrawLeftZTriggersTopView(QPainter& p, const QPointF center, void PlayerControlPreview::DrawLeftZTriggersTopView(
const Input::ButtonStatus& left_pressed) { QPainter& p, const QPointF center, const Common::Input::ButtonStatus& left_pressed) {
std::array<QPointF, left_joystick_ZL_topview.size() / 2> qleft_trigger; std::array<QPointF, left_joystick_ZL_topview.size() / 2> qleft_trigger;
for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) { for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) {
@ -2223,7 +2223,7 @@ void PlayerControlPreview::DrawLeftZTriggersTopView(QPainter& p, const QPointF c
} }
void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger; std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
constexpr float size = 1.78f; constexpr float size = 1.78f;
constexpr float offset = 311.5f; constexpr float offset = 311.5f;
@ -2240,7 +2240,7 @@ void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawRightZTriggers(QPainter& p, const QPointF center, void PlayerControlPreview::DrawRightZTriggers(QPainter& p, const QPointF center,
const Input::ButtonStatus& right_pressed) { const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joycon_sideview_zl.size() / 2> qright_trigger; std::array<QPointF, left_joycon_sideview_zl.size() / 2> qright_trigger;
constexpr float size = 1.1115f; constexpr float size = 1.1115f;
constexpr float offset2 = 335; constexpr float offset2 = 335;
@ -2259,8 +2259,8 @@ void PlayerControlPreview::DrawRightZTriggers(QPainter& p, const QPointF center,
271 * 16, 44 * 16); 271 * 16, 44 * 16);
} }
void PlayerControlPreview::DrawRightTriggersTopView(QPainter& p, const QPointF center, void PlayerControlPreview::DrawRightTriggersTopView(
const Input::ButtonStatus& right_pressed) { QPainter& p, const QPointF center, const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joystick_L_topview.size() / 2> qright_trigger; std::array<QPointF, left_joystick_L_topview.size() / 2> qright_trigger;
for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) { for (std::size_t point = 0; point < left_joystick_L_topview.size() / 2; ++point) {
@ -2278,8 +2278,8 @@ void PlayerControlPreview::DrawRightTriggersTopView(QPainter& p, const QPointF c
DrawSymbol(p, center + QPointF(137, -36), Symbol::R, 1.0f); DrawSymbol(p, center + QPointF(137, -36), Symbol::R, 1.0f);
} }
void PlayerControlPreview::DrawRightZTriggersTopView(QPainter& p, const QPointF center, void PlayerControlPreview::DrawRightZTriggersTopView(
const Input::ButtonStatus& right_pressed) { QPainter& p, const QPointF center, const Common::Input::ButtonStatus& right_pressed) {
std::array<QPointF, left_joystick_ZL_topview.size() / 2> qright_trigger; std::array<QPointF, left_joystick_ZL_topview.size() / 2> qright_trigger;
for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) { for (std::size_t point = 0; point < left_joystick_ZL_topview.size() / 2; ++point) {
@ -2298,7 +2298,7 @@ void PlayerControlPreview::DrawRightZTriggersTopView(QPainter& p, const QPointF
} }
void PlayerControlPreview::DrawJoystick(QPainter& p, const QPointF center, float size, void PlayerControlPreview::DrawJoystick(QPainter& p, const QPointF center, float size,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
const float radius1 = 13.0f * size; const float radius1 = 13.0f * size;
const float radius2 = 9.0f * size; const float radius2 = 9.0f * size;
@ -2317,7 +2317,8 @@ void PlayerControlPreview::DrawJoystick(QPainter& p, const QPointF center, float
} }
void PlayerControlPreview::DrawJoystickSideview(QPainter& p, const QPointF center, float angle, void PlayerControlPreview::DrawJoystickSideview(QPainter& p, const QPointF center, float angle,
float size, const Input::ButtonStatus& pressed) { float size,
const Common::Input::ButtonStatus& pressed) {
QVector<QPointF> joystick; QVector<QPointF> joystick;
joystick.reserve(static_cast<int>(left_joystick_sideview.size() / 2)); joystick.reserve(static_cast<int>(left_joystick_sideview.size() / 2));
@ -2342,7 +2343,7 @@ void PlayerControlPreview::DrawJoystickSideview(QPainter& p, const QPointF cente
void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, const QPointF offset, void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, const QPointF offset,
float offset_scalar, float offset_scalar,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
const float radius1 = 24.0f; const float radius1 = 24.0f;
const float radius2 = 17.0f; const float radius2 = 17.0f;
@ -2377,7 +2378,7 @@ void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, co
} }
void PlayerControlPreview::DrawGCJoystick(QPainter& p, const QPointF center, void PlayerControlPreview::DrawGCJoystick(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
// Outer circle // Outer circle
p.setPen(colors.outline); p.setPen(colors.outline);
p.setBrush(pressed.value ? colors.highlight : colors.button); p.setBrush(pressed.value ? colors.highlight : colors.button);
@ -2414,8 +2415,8 @@ void PlayerControlPreview::DrawRawJoystick(QPainter& p, QPointF center_left, QPo
} }
} }
void PlayerControlPreview::DrawJoystickProperties(QPainter& p, const QPointF center, void PlayerControlPreview::DrawJoystickProperties(
const Input::AnalogProperties& properties) { QPainter& p, const QPointF center, const Common::Input::AnalogProperties& properties) {
constexpr float size = 45.0f; constexpr float size = 45.0f;
const float range = size * properties.range; const float range = size * properties.range;
const float deadzone = size * properties.deadzone; const float deadzone = size * properties.deadzone;
@ -2435,7 +2436,7 @@ void PlayerControlPreview::DrawJoystickProperties(QPainter& p, const QPointF cen
} }
void PlayerControlPreview::DrawJoystickDot(QPainter& p, const QPointF center, void PlayerControlPreview::DrawJoystickDot(QPainter& p, const QPointF center,
const Input::StickStatus& stick, bool raw) { const Common::Input::StickStatus& stick, bool raw) {
constexpr float size = 45.0f; constexpr float size = 45.0f;
const float range = size * stick.x.properties.range; const float range = size * stick.x.properties.range;
@ -2450,7 +2451,7 @@ void PlayerControlPreview::DrawJoystickDot(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center, void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center,
const Input::ButtonStatus& pressed, float width, const Common::Input::ButtonStatus& pressed, float width,
float height, Direction direction, float radius) { float height, Direction direction, float radius) {
p.setBrush(button_color); p.setBrush(button_color);
if (pressed.value) { if (pressed.value) {
@ -2476,13 +2477,15 @@ void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center,
p.drawRoundedRect(rect, radius, radius); p.drawRoundedRect(rect, radius, radius);
} }
void PlayerControlPreview::DrawMinusButton(QPainter& p, const QPointF center, void PlayerControlPreview::DrawMinusButton(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed, int button_size) { const Common::Input::ButtonStatus& pressed,
int button_size) {
p.setPen(colors.outline); p.setPen(colors.outline);
p.setBrush(pressed.value ? colors.highlight : colors.button); p.setBrush(pressed.value ? colors.highlight : colors.button);
DrawRectangle(p, center, button_size, button_size / 3.0f); DrawRectangle(p, center, button_size, button_size / 3.0f);
} }
void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center, void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed, int button_size) { const Common::Input::ButtonStatus& pressed,
int button_size) {
// Draw outer line // Draw outer line
p.setPen(colors.outline); p.setPen(colors.outline);
p.setBrush(pressed.value ? colors.highlight : colors.button); p.setBrush(pressed.value ? colors.highlight : colors.button);
@ -2499,7 +2502,7 @@ void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawGCButtonX(QPainter& p, const QPointF center, void PlayerControlPreview::DrawGCButtonX(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
std::array<QPointF, gc_button_x.size() / 2> button_x; std::array<QPointF, gc_button_x.size() / 2> button_x;
for (std::size_t point = 0; point < gc_button_x.size() / 2; ++point) { for (std::size_t point = 0; point < gc_button_x.size() / 2; ++point) {
@ -2512,7 +2515,7 @@ void PlayerControlPreview::DrawGCButtonX(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawGCButtonY(QPainter& p, const QPointF center, void PlayerControlPreview::DrawGCButtonY(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
std::array<QPointF, gc_button_y.size() / 2> button_x; std::array<QPointF, gc_button_y.size() / 2> button_x;
for (std::size_t point = 0; point < gc_button_y.size() / 2; ++point) { for (std::size_t point = 0; point < gc_button_y.size() / 2; ++point) {
@ -2525,7 +2528,7 @@ void PlayerControlPreview::DrawGCButtonY(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawGCButtonZ(QPainter& p, const QPointF center, void PlayerControlPreview::DrawGCButtonZ(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
std::array<QPointF, gc_button_z.size() / 2> button_x; std::array<QPointF, gc_button_z.size() / 2> button_x;
for (std::size_t point = 0; point < gc_button_z.size() / 2; ++point) { for (std::size_t point = 0; point < gc_button_z.size() / 2; ++point) {
@ -2539,7 +2542,8 @@ void PlayerControlPreview::DrawGCButtonZ(QPainter& p, const QPointF center,
} }
void PlayerControlPreview::DrawCircleButton(QPainter& p, const QPointF center, void PlayerControlPreview::DrawCircleButton(QPainter& p, const QPointF center,
const Input::ButtonStatus& pressed, float button_size) { const Common::Input::ButtonStatus& pressed,
float button_size) {
p.setBrush(button_color); p.setBrush(button_color);
if (pressed.value) { if (pressed.value) {
p.setBrush(colors.highlight); p.setBrush(colors.highlight);
@ -2571,7 +2575,7 @@ void PlayerControlPreview::DrawArrowButtonOutline(QPainter& p, const QPointF cen
void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center, void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center,
const Direction direction, const Direction direction,
const Input::ButtonStatus& pressed, float size) { const Common::Input::ButtonStatus& pressed, float size) {
std::array<QPointF, up_arrow_button.size() / 2> arrow_button; std::array<QPointF, up_arrow_button.size() / 2> arrow_button;
QPoint offset; QPoint offset;
@ -2628,7 +2632,7 @@ void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center,
void PlayerControlPreview::DrawTriggerButton(QPainter& p, const QPointF center, void PlayerControlPreview::DrawTriggerButton(QPainter& p, const QPointF center,
const Direction direction, const Direction direction,
const Input::ButtonStatus& pressed) { const Common::Input::ButtonStatus& pressed) {
std::array<QPointF, trigger_button.size() / 2> qtrigger_button; std::array<QPointF, trigger_button.size() / 2> qtrigger_button;
for (std::size_t point = 0; point < trigger_button.size() / 2; ++point) { for (std::size_t point = 0; point < trigger_button.size() / 2; ++point) {
@ -2655,8 +2659,9 @@ void PlayerControlPreview::DrawTriggerButton(QPainter& p, const QPointF center,
DrawPolygon(p, qtrigger_button); DrawPolygon(p, qtrigger_button);
} }
void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center, Input::BatteryLevel battery) { void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center,
if (battery == Input::BatteryLevel::None) { Common::Input::BatteryLevel battery) {
if (battery == Common::Input::BatteryLevel::None) {
return; return;
} }
p.setPen(colors.outline); p.setPen(colors.outline);
@ -2665,29 +2670,29 @@ void PlayerControlPreview::DrawBattery(QPainter& p, QPointF center, Input::Batte
p.drawRect(center.x() + 56, center.y() + 6, 3, 8); p.drawRect(center.x() + 56, center.y() + 6, 3, 8);
p.setBrush(colors.deadzone); p.setBrush(colors.deadzone);
switch (battery) { switch (battery) {
case Input::BatteryLevel::Charging: case Common::Input::BatteryLevel::Charging:
p.setBrush(colors.indicator2); p.setBrush(colors.indicator2);
p.drawText(center + QPoint(2, 14), tr("Charging")); p.drawText(center + QPoint(2, 14), tr("Charging"));
break; break;
case Input::BatteryLevel::Full: case Common::Input::BatteryLevel::Full:
p.drawRect(center.x() + 42, center.y(), 14, 20); p.drawRect(center.x() + 42, center.y(), 14, 20);
p.drawRect(center.x() + 28, center.y(), 14, 20); p.drawRect(center.x() + 28, center.y(), 14, 20);
p.drawRect(center.x() + 14, center.y(), 14, 20); p.drawRect(center.x() + 14, center.y(), 14, 20);
p.drawRect(center.x(), center.y(), 14, 20); p.drawRect(center.x(), center.y(), 14, 20);
break; break;
case Input::BatteryLevel::Medium: case Common::Input::BatteryLevel::Medium:
p.drawRect(center.x() + 28, center.y(), 14, 20); p.drawRect(center.x() + 28, center.y(), 14, 20);
p.drawRect(center.x() + 14, center.y(), 14, 20); p.drawRect(center.x() + 14, center.y(), 14, 20);
p.drawRect(center.x(), center.y(), 14, 20); p.drawRect(center.x(), center.y(), 14, 20);
break; break;
case Input::BatteryLevel::Low: case Common::Input::BatteryLevel::Low:
p.drawRect(center.x() + 14, center.y(), 14, 20); p.drawRect(center.x() + 14, center.y(), 14, 20);
p.drawRect(center.x(), center.y(), 14, 20); p.drawRect(center.x(), center.y(), 14, 20);
break; break;
case Input::BatteryLevel::Critical: case Common::Input::BatteryLevel::Critical:
p.drawRect(center.x(), center.y(), 14, 20); p.drawRect(center.x(), center.y(), 14, 20);
break; break;
case Input::BatteryLevel::Empty: case Common::Input::BatteryLevel::Empty:
p.drawRect(center.x(), center.y(), 5, 20); p.drawRect(center.x(), center.y(), 5, 20);
break; break;
default: default:

View file

@ -115,66 +115,75 @@ private:
void DrawGCBody(QPainter& p, QPointF center); void DrawGCBody(QPainter& p, QPointF center);
// Draw triggers functions // Draw triggers functions
void DrawProTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed, void DrawProTriggers(QPainter& p, QPointF center,
const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& left_pressed,
void DrawGCTriggers(QPainter& p, QPointF center, Input::TriggerStatus left_trigger, const Common::Input::ButtonStatus& right_pressed);
Input::TriggerStatus right_trigger); void DrawGCTriggers(QPainter& p, QPointF center, Common::Input::TriggerStatus left_trigger,
void DrawHandheldTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed, Common::Input::TriggerStatus right_trigger);
const Input::ButtonStatus& right_pressed); void DrawHandheldTriggers(QPainter& p, QPointF center,
void DrawDualTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& right_pressed);
void DrawDualTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed,
const Common::Input::ButtonStatus& right_pressed);
void DrawDualTriggersTopView(QPainter& p, QPointF center, void DrawDualTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& right_pressed);
void DrawDualZTriggersTopView(QPainter& p, QPointF center, void DrawDualZTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed, const Common::Input::ButtonStatus& left_pressed,
const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& right_pressed);
void DrawLeftTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed); void DrawLeftTriggers(QPainter& p, QPointF center,
void DrawLeftZTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& left_pressed); const Common::Input::ButtonStatus& left_pressed);
void DrawLeftZTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& left_pressed);
void DrawLeftTriggersTopView(QPainter& p, QPointF center, void DrawLeftTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed); const Common::Input::ButtonStatus& left_pressed);
void DrawLeftZTriggersTopView(QPainter& p, QPointF center, void DrawLeftZTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& left_pressed); const Common::Input::ButtonStatus& left_pressed);
void DrawRightTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& right_pressed); void DrawRightTriggers(QPainter& p, QPointF center,
void DrawRightZTriggers(QPainter& p, QPointF center, const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& right_pressed);
void DrawRightZTriggers(QPainter& p, QPointF center,
const Common::Input::ButtonStatus& right_pressed);
void DrawRightTriggersTopView(QPainter& p, QPointF center, void DrawRightTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& right_pressed);
void DrawRightZTriggersTopView(QPainter& p, QPointF center, void DrawRightZTriggersTopView(QPainter& p, QPointF center,
const Input::ButtonStatus& right_pressed); const Common::Input::ButtonStatus& right_pressed);
// Draw joystick functions // Draw joystick functions
void DrawJoystick(QPainter& p, QPointF center, float size, const Input::ButtonStatus& pressed); void DrawJoystick(QPainter& p, QPointF center, float size,
const Common::Input::ButtonStatus& pressed);
void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size, void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size,
const Input::ButtonStatus& pressed); const Common::Input::ButtonStatus& pressed);
void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right); void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
void DrawJoystickProperties(QPainter& p, QPointF center, void DrawJoystickProperties(QPainter& p, QPointF center,
const Input::AnalogProperties& properties); const Common::Input::AnalogProperties& properties);
void DrawJoystickDot(QPainter& p, QPointF center, const Input::StickStatus& stick, bool raw); void DrawJoystickDot(QPainter& p, QPointF center, const Common::Input::StickStatus& stick,
bool raw);
void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar, void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
const Input::ButtonStatus& pressed); const Common::Input::ButtonStatus& pressed);
void DrawGCJoystick(QPainter& p, QPointF center, const Input::ButtonStatus& pressed); void DrawGCJoystick(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
// Draw button functions // Draw button functions
void DrawCircleButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed, void DrawCircleButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
float button_size); float button_size);
void DrawRoundButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed, void DrawRoundButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
float width, float height, Direction direction = Direction::None, float width, float height, Direction direction = Direction::None,
float radius = 2); float radius = 2);
void DrawMinusButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed, void DrawMinusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
int button_size); int button_size);
void DrawPlusButton(QPainter& p, QPointF center, const Input::ButtonStatus& pressed, void DrawPlusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
int button_size); int button_size);
void DrawGCButtonX(QPainter& p, QPointF center, const Input::ButtonStatus& pressed); void DrawGCButtonX(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
void DrawGCButtonY(QPainter& p, QPointF center, const Input::ButtonStatus& pressed); void DrawGCButtonY(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
void DrawGCButtonZ(QPainter& p, QPointF center, const Input::ButtonStatus& pressed); void DrawGCButtonZ(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f); void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f);
void DrawArrowButton(QPainter& p, QPointF center, Direction direction, void DrawArrowButton(QPainter& p, QPointF center, Direction direction,
const Input::ButtonStatus& pressed, float size = 1.0f); const Common::Input::ButtonStatus& pressed, float size = 1.0f);
void DrawTriggerButton(QPainter& p, QPointF center, Direction direction, void DrawTriggerButton(QPainter& p, QPointF center, Direction direction,
const Input::ButtonStatus& pressed); const Common::Input::ButtonStatus& pressed);
// Draw battery functions // Draw battery functions
void DrawBattery(QPainter& p, QPointF center, Input::BatteryLevel battery); void DrawBattery(QPainter& p, QPointF center, Common::Input::BatteryLevel battery);
// Draw icon functions // Draw icon functions
void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size); void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);