2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <QFrame>
|
|
|
|
#include <QPointer>
|
2021-11-05 03:54:22 +00:00
|
|
|
|
2021-09-21 00:47:45 +00:00
|
|
|
#include "common/input.h"
|
2021-11-05 03:54:22 +00:00
|
|
|
#include "common/settings_input.h"
|
2021-11-01 20:17:53 +00:00
|
|
|
#include "core/hid/emulated_controller.h"
|
2021-09-21 00:47:45 +00:00
|
|
|
#include "core/hid/hid_types.h"
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
class QLabel;
|
|
|
|
|
|
|
|
using AnalogParam = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>;
|
|
|
|
using ButtonParam = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
|
|
|
|
|
|
|
|
// Widget for representing controller animations
|
|
|
|
class PlayerControlPreview : public QFrame {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PlayerControlPreview(QWidget* parent);
|
|
|
|
~PlayerControlPreview() override;
|
|
|
|
|
2021-10-16 00:07:47 +00:00
|
|
|
// Sets the emulated controller to be displayed
|
2021-09-21 00:47:45 +00:00
|
|
|
void SetController(Core::HID::EmulatedController* controller);
|
2021-10-16 00:07:47 +00:00
|
|
|
|
|
|
|
// Disables events from the emulated controller
|
|
|
|
void UnloadController();
|
|
|
|
|
|
|
|
// Starts blinking animation at the button specified
|
2021-01-13 03:09:59 +00:00
|
|
|
void BeginMappingButton(std::size_t button_id);
|
2021-10-16 00:07:47 +00:00
|
|
|
|
|
|
|
// Starts moving animation at the stick specified
|
|
|
|
void BeginMappingAnalog(std::size_t stick_id);
|
|
|
|
|
|
|
|
// Stops any ongoing animation
|
2021-01-13 03:09:59 +00:00
|
|
|
void EndMapping();
|
2021-10-16 00:07:47 +00:00
|
|
|
|
|
|
|
// Handles emulated controller events
|
2021-09-21 00:47:45 +00:00
|
|
|
void ControllerUpdate(Core::HID::ControllerTriggerType type);
|
2021-10-16 00:07:47 +00:00
|
|
|
|
|
|
|
// Updates input on sheduled interval
|
2021-02-03 04:32:45 +00:00
|
|
|
void UpdateInput();
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent* event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class Direction : std::size_t {
|
|
|
|
None,
|
|
|
|
Up,
|
|
|
|
Right,
|
|
|
|
Down,
|
|
|
|
Left,
|
|
|
|
};
|
|
|
|
|
2021-01-15 17:18:17 +00:00
|
|
|
enum class Symbol {
|
|
|
|
House,
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
X,
|
|
|
|
Y,
|
2021-02-07 03:34:08 +00:00
|
|
|
L,
|
|
|
|
R,
|
|
|
|
C,
|
2021-02-03 03:39:47 +00:00
|
|
|
SL,
|
2021-01-15 17:18:17 +00:00
|
|
|
ZL,
|
|
|
|
ZR,
|
2021-02-03 03:39:47 +00:00
|
|
|
SR,
|
2022-02-02 18:22:22 +00:00
|
|
|
Charging,
|
2021-01-15 17:18:17 +00:00
|
|
|
};
|
|
|
|
|
2021-01-13 03:09:59 +00:00
|
|
|
struct ColorMapping {
|
|
|
|
QColor outline{};
|
|
|
|
QColor primary{};
|
|
|
|
QColor left{};
|
|
|
|
QColor right{};
|
|
|
|
QColor button{};
|
|
|
|
QColor button2{};
|
2023-01-29 18:23:30 +00:00
|
|
|
QColor button_turbo{};
|
2021-01-13 03:09:59 +00:00
|
|
|
QColor font{};
|
|
|
|
QColor font2{};
|
|
|
|
QColor highlight{};
|
|
|
|
QColor highlight2{};
|
|
|
|
QColor transparent{};
|
|
|
|
QColor indicator{};
|
2021-08-04 16:40:49 +00:00
|
|
|
QColor indicator2{};
|
2021-01-13 03:09:59 +00:00
|
|
|
QColor led_on{};
|
|
|
|
QColor led_off{};
|
|
|
|
QColor slider{};
|
|
|
|
QColor slider_button{};
|
|
|
|
QColor slider_arrow{};
|
|
|
|
QColor deadzone{};
|
2022-02-02 18:22:22 +00:00
|
|
|
QColor charging{};
|
2021-01-13 03:09:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void UpdateColors();
|
2021-05-30 15:57:20 +00:00
|
|
|
void ResetInputs();
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
// Draw controller functions
|
|
|
|
void DrawHandheldController(QPainter& p, QPointF center);
|
|
|
|
void DrawDualController(QPainter& p, QPointF center);
|
|
|
|
void DrawLeftController(QPainter& p, QPointF center);
|
|
|
|
void DrawRightController(QPainter& p, QPointF center);
|
|
|
|
void DrawProController(QPainter& p, QPointF center);
|
2021-02-07 03:34:08 +00:00
|
|
|
void DrawGCController(QPainter& p, QPointF center);
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
// Draw body functions
|
|
|
|
void DrawHandheldBody(QPainter& p, QPointF center);
|
|
|
|
void DrawDualBody(QPainter& p, QPointF center);
|
|
|
|
void DrawLeftBody(QPainter& p, QPointF center);
|
|
|
|
void DrawRightBody(QPainter& p, QPointF center);
|
|
|
|
void DrawProBody(QPainter& p, QPointF center);
|
2021-02-07 03:34:08 +00:00
|
|
|
void DrawGCBody(QPainter& p, QPointF center);
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
// Draw triggers functions
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawProTriggers(QPainter& p, QPointF center,
|
|
|
|
const Common::Input::ButtonStatus& left_pressed,
|
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
|
|
|
void DrawGCTriggers(QPainter& p, QPointF center, Common::Input::TriggerStatus left_trigger,
|
|
|
|
Common::Input::TriggerStatus right_trigger);
|
|
|
|
void DrawHandheldTriggers(QPainter& p, QPointF center,
|
|
|
|
const Common::Input::ButtonStatus& left_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);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawDualTriggersTopView(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& left_pressed,
|
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawDualZTriggersTopView(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& left_pressed,
|
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
|
|
|
void DrawLeftTriggers(QPainter& p, QPointF center,
|
|
|
|
const Common::Input::ButtonStatus& left_pressed);
|
|
|
|
void DrawLeftZTriggers(QPainter& p, QPointF center,
|
|
|
|
const Common::Input::ButtonStatus& left_pressed);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawLeftTriggersTopView(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& left_pressed);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawLeftZTriggersTopView(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& left_pressed);
|
|
|
|
void DrawRightTriggers(QPainter& p, QPointF center,
|
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
|
|
|
void DrawRightZTriggers(QPainter& p, QPointF center,
|
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawRightTriggersTopView(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawRightZTriggersTopView(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& right_pressed);
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
// Draw joystick functions
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawJoystick(QPainter& p, QPointF center, float size,
|
|
|
|
const Common::Input::ButtonStatus& pressed);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& pressed);
|
2021-08-04 16:40:49 +00:00
|
|
|
void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
|
|
|
|
void DrawJoystickProperties(QPainter& p, QPointF center,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::AnalogProperties& properties);
|
|
|
|
void DrawJoystickDot(QPainter& p, QPointF center, const Common::Input::StickStatus& stick,
|
|
|
|
bool raw);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& pressed);
|
|
|
|
void DrawGCJoystick(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
// Draw button functions
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawCircleButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
|
2021-09-21 00:47:45 +00:00
|
|
|
float button_size);
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawRoundButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
|
2021-09-21 00:47:45 +00:00
|
|
|
float width, float height, Direction direction = Direction::None,
|
|
|
|
float radius = 2);
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawMinusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
|
2021-09-21 00:47:45 +00:00
|
|
|
int button_size);
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawPlusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
|
2021-09-21 00:47:45 +00:00
|
|
|
int button_size);
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawGCButtonX(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
|
|
|
|
void DrawGCButtonY(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
|
|
|
|
void DrawGCButtonZ(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
|
2021-02-07 03:34:08 +00:00
|
|
|
void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawArrowButton(QPainter& p, QPointF center, Direction direction,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& pressed, float size = 1.0f);
|
2021-09-21 00:47:45 +00:00
|
|
|
void DrawTriggerButton(QPainter& p, QPointF center, Direction direction,
|
2021-10-31 03:23:10 +00:00
|
|
|
const Common::Input::ButtonStatus& pressed);
|
2023-01-29 18:23:30 +00:00
|
|
|
QColor GetButtonColor(QColor default_color, bool is_pressed, bool turbo);
|
2021-09-21 00:47:45 +00:00
|
|
|
|
|
|
|
// Draw battery functions
|
2021-10-31 03:23:10 +00:00
|
|
|
void DrawBattery(QPainter& p, QPointF center, Common::Input::BatteryLevel battery);
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
// Draw icon functions
|
2021-01-15 17:18:17 +00:00
|
|
|
void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);
|
2021-01-13 03:09:59 +00:00
|
|
|
void DrawArrow(QPainter& p, QPointF center, Direction direction, float size);
|
|
|
|
|
|
|
|
// Draw primitive types
|
|
|
|
template <size_t N>
|
|
|
|
void DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon);
|
|
|
|
void DrawCircle(QPainter& p, QPointF center, float size);
|
|
|
|
void DrawRectangle(QPainter& p, QPointF center, float width, float height);
|
|
|
|
void DrawRoundRectangle(QPainter& p, QPointF center, float width, float height, float round);
|
|
|
|
void DrawText(QPainter& p, QPointF center, float text_size, const QString& text);
|
|
|
|
void SetTextFont(QPainter& p, float text_size,
|
|
|
|
const QString& font_family = QStringLiteral("sans-serif"));
|
|
|
|
|
2021-09-21 00:47:45 +00:00
|
|
|
bool is_controller_set{};
|
|
|
|
bool is_connected{};
|
|
|
|
bool needs_redraw{};
|
2021-11-04 18:08:54 +00:00
|
|
|
Core::HID::NpadStyleIndex controller_type;
|
2021-01-13 03:09:59 +00:00
|
|
|
|
|
|
|
bool mapping_active{};
|
|
|
|
int blink_counter{};
|
2021-09-21 00:47:45 +00:00
|
|
|
int callback_key;
|
2021-01-13 03:09:59 +00:00
|
|
|
QColor button_color{};
|
|
|
|
ColorMapping colors{};
|
2021-10-11 05:43:11 +00:00
|
|
|
Core::HID::LedPattern led_pattern{0, 0, 0, 0};
|
2021-01-13 03:09:59 +00:00
|
|
|
std::size_t player_index{};
|
2021-09-21 00:47:45 +00:00
|
|
|
Core::HID::EmulatedController* controller;
|
|
|
|
std::size_t button_mapping_index{Settings::NativeButton::NumButtons};
|
|
|
|
std::size_t analog_mapping_index{Settings::NativeAnalog::NumAnalogs};
|
|
|
|
Core::HID::ButtonValues button_values{};
|
|
|
|
Core::HID::SticksValues stick_values{};
|
|
|
|
Core::HID::TriggerValues trigger_values{};
|
|
|
|
Core::HID::BatteryValues battery_values{};
|
2021-01-13 03:09:59 +00:00
|
|
|
};
|