Compare commits
1 Commits
controller
...
motion
Author | SHA1 | Date | |
---|---|---|---|
4f5f4e1b15 |
@ -24,6 +24,7 @@ enum class InputType {
|
|||||||
Analog,
|
Analog,
|
||||||
Trigger,
|
Trigger,
|
||||||
Motion,
|
Motion,
|
||||||
|
VirtualMotion,
|
||||||
Touch,
|
Touch,
|
||||||
Color,
|
Color,
|
||||||
Vibration,
|
Vibration,
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#include "common/input.h"
|
#include "common/input.h"
|
||||||
|
#include "common/math_util.h"
|
||||||
|
#include "common/quaternion.h"
|
||||||
#include "core/hid/input_converter.h"
|
#include "core/hid/input_converter.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
@ -81,7 +83,7 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
|||||||
Common::Input::MotionStatus status{};
|
Common::Input::MotionStatus status{};
|
||||||
switch (callback.type) {
|
switch (callback.type) {
|
||||||
case Common::Input::InputType::Button: {
|
case Common::Input::InputType::Button: {
|
||||||
Common::Input::AnalogProperties properties{
|
const Common::Input::AnalogProperties properties{
|
||||||
.deadzone = 0.0f,
|
.deadzone = 0.0f,
|
||||||
.range = 1.0f,
|
.range = 1.0f,
|
||||||
.offset = 0.0f,
|
.offset = 0.0f,
|
||||||
@ -93,31 +95,18 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
|||||||
.raw_value = 0.0f,
|
.raw_value = 0.0f,
|
||||||
.properties = properties,
|
.properties = properties,
|
||||||
};
|
};
|
||||||
status.accel.y = {
|
status.delta_timestamp = 5000;
|
||||||
.value = 0.0f,
|
status.force_update = true;
|
||||||
.raw_value = 0.0f,
|
status.accel.x = default_analog_status;
|
||||||
.properties = properties,
|
status.accel.y = default_analog_status;
|
||||||
};
|
|
||||||
status.accel.z = {
|
status.accel.z = {
|
||||||
.value = 0.0f,
|
.value = 0.0f,
|
||||||
.raw_value = -1.0f,
|
.raw_value = -1.0f,
|
||||||
.properties = properties,
|
.properties = properties,
|
||||||
};
|
};
|
||||||
status.gyro.x = {
|
status.gyro.x = default_analog_status;
|
||||||
.value = 0.0f,
|
status.gyro.y = default_analog_status;
|
||||||
.raw_value = 0.0f,
|
status.gyro.z = default_analog_status;
|
||||||
.properties = properties,
|
|
||||||
};
|
|
||||||
status.gyro.y = {
|
|
||||||
.value = 0.0f,
|
|
||||||
.raw_value = 0.0f,
|
|
||||||
.properties = properties,
|
|
||||||
};
|
|
||||||
status.gyro.z = {
|
|
||||||
.value = 0.0f,
|
|
||||||
.raw_value = 0.0f,
|
|
||||||
.properties = properties,
|
|
||||||
};
|
|
||||||
if (TransformToButton(callback).value) {
|
if (TransformToButton(callback).value) {
|
||||||
std::random_device device;
|
std::random_device device;
|
||||||
std::mt19937 gen(device());
|
std::mt19937 gen(device());
|
||||||
@ -134,6 +123,9 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
|||||||
case Common::Input::InputType::Motion:
|
case Common::Input::InputType::Motion:
|
||||||
status = callback.motion_status;
|
status = callback.motion_status;
|
||||||
break;
|
break;
|
||||||
|
case Common::Input::InputType::VirtualMotion:
|
||||||
|
status = GetVirtualMotion(callback.motion_status);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(Input, "Conversion from type {} to motion not implemented", callback.type);
|
LOG_ERROR(Input, "Conversion from type {} to motion not implemented", callback.type);
|
||||||
break;
|
break;
|
||||||
@ -437,4 +429,32 @@ void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Common::Input::MotionStatus GetVirtualMotion(Common::Input::MotionStatus input_data,
|
||||||
|
Common::Vec3f last_giro) {
|
||||||
|
Common::Input::MotionStatus motion_status = input_data;
|
||||||
|
|
||||||
|
// Axis data is stored in the gyro value
|
||||||
|
float wx = input_data.gyro.x.raw_value;
|
||||||
|
float wy = input_data.gyro.y.raw_value;
|
||||||
|
|
||||||
|
float rotX = (wy * 2 - 1.0f) * 135.0f; // up/down best
|
||||||
|
float rotY = (wx * 2 - 1.0f) * -180.0f; // left/right
|
||||||
|
float rotZ = input_data.gyro.y.raw_value * 14.0f + m_lastGyroRotation.z;
|
||||||
|
|
||||||
|
Common::Vec3f rotation(rotX - m_lastGyroRotation.x, (rotY - m_lastGyroRotation.y) * 15.0f,
|
||||||
|
rotZ - m_lastGyroRotation.z);
|
||||||
|
|
||||||
|
rotation.x = std::min(1.0f, std::max(-1.0f, rotation.x / 360.0f));
|
||||||
|
rotation.y = std::min(1.0f, std::max(-1.0f, rotation.y / 360.0f));
|
||||||
|
rotation.z = std::min(1.0f, std::max(-1.0f, rotation.z / 360.0f));
|
||||||
|
|
||||||
|
motion_status.gyro.x.raw_value = rotation.x;
|
||||||
|
motion_status.gyro.y.raw_value = rotation.y;
|
||||||
|
motion_status.gyro.z.raw_value = rotation.z;
|
||||||
|
|
||||||
|
motion_status.accel.x.raw_value = 0.0f;
|
||||||
|
motion_status.accel.y.raw_value = 0.0f;
|
||||||
|
motion_status.accel.z.raw_value = -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Core::HID
|
} // namespace Core::HID
|
||||||
|
@ -116,4 +116,21 @@ void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value);
|
|||||||
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
|
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
|
||||||
bool clamp_value);
|
bool clamp_value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts raw stick data into a valid stick value
|
||||||
|
* @param analog_x raw analog data and properties for the x-axis
|
||||||
|
* @param analog_y raw analog data and properties for the y-axis
|
||||||
|
* @param clamp_value bool that determines if the value needs to be clamped into the unit circle.
|
||||||
|
*/
|
||||||
|
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
|
||||||
|
bool clamp_value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the accelerometer value needed to reach the axis position as if it was a pointer to a screen
|
||||||
|
*
|
||||||
|
* @param input_data Motion status containing the position of all 3 axis
|
||||||
|
* @return Motion status with accelerometer data
|
||||||
|
*/
|
||||||
|
Common::Input::MotionStatus GetVirtualMotion(Common::Input::MotionStatus input_data);
|
||||||
|
|
||||||
} // namespace Core::HID
|
} // namespace Core::HID
|
||||||
|
@ -674,7 +674,7 @@ public:
|
|||||||
|
|
||||||
void ForceUpdate() override {
|
void ForceUpdate() override {
|
||||||
const Common::Input::CallbackStatus status{
|
const Common::Input::CallbackStatus status{
|
||||||
.type = Common::Input::InputType::Motion,
|
.type = Common::Input::InputType::VirtualMotion,
|
||||||
.motion_status = GetStatus(),
|
.motion_status = GetStatus(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -686,7 +686,7 @@ public:
|
|||||||
|
|
||||||
void OnChange() {
|
void OnChange() {
|
||||||
const Common::Input::CallbackStatus status{
|
const Common::Input::CallbackStatus status{
|
||||||
.type = Common::Input::InputType::Motion,
|
.type = Common::Input::InputType::VirtualMotion,
|
||||||
.motion_status = GetStatus(),
|
.motion_status = GetStatus(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1039,21 +1039,28 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
|
||||||
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", "")},
|
||||||
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
||||||
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (params.Has("motion")) {
|
const auto motion_sensor = params.Get("motion", 0);
|
||||||
const auto motion_sensor = params.Get("motion", 0);
|
const auto gyro_threshold = params.Get("threshold", 0.007f);
|
||||||
const auto gyro_threshold = params.Get("threshold", 0.007f);
|
input_engine->PreSetController(identifier);
|
||||||
input_engine->PreSetController(identifier);
|
input_engine->PreSetMotion(identifier, motion_sensor);
|
||||||
input_engine->PreSetMotion(identifier, motion_sensor);
|
return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold,
|
||||||
return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold,
|
input_engine.get());
|
||||||
input_engine.get());
|
}
|
||||||
}
|
|
||||||
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateVirtualMotionDevice(
|
||||||
|
const Common::ParamPackage& params) {
|
||||||
|
const PadIdentifier identifier = {
|
||||||
|
.guid = Common::UUID{params.Get("guid", "")},
|
||||||
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
||||||
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
||||||
|
};
|
||||||
|
|
||||||
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);
|
||||||
@ -1147,7 +1154,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create(
|
|||||||
return CreateHatButtonDevice(params);
|
return CreateHatButtonDevice(params);
|
||||||
}
|
}
|
||||||
if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) {
|
if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) {
|
||||||
return CreateMotionDevice(params);
|
return CreateVirtualMotionDevice(params);
|
||||||
}
|
}
|
||||||
if (params.Has("motion")) {
|
if (params.Has("motion")) {
|
||||||
return CreateMotionDevice(params);
|
return CreateMotionDevice(params);
|
||||||
|
@ -204,6 +204,19 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Creates a motion device from the parameters given.
|
* Creates a motion device from the parameters given.
|
||||||
* @param params contains parameters for creating the device:
|
* @param params contains parameters for creating the device:
|
||||||
|
* - "motion": index of the motion sensor
|
||||||
|
* - "threshold": gyro deadzone to avoid drifting
|
||||||
|
* - "guid": text string for identifying controllers
|
||||||
|
* - "port": port of the connected device
|
||||||
|
* - "pad": slot of the connected controller
|
||||||
|
* @returns a unique input device with the parameters specified
|
||||||
|
*/
|
||||||
|
std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(
|
||||||
|
const Common::ParamPackage& params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a virtual motion device from the parameters given.
|
||||||
|
* @param params contains parameters for creating the device:
|
||||||
* - "axis_x": the controller horizontal axis id to bind with the input
|
* - "axis_x": the controller horizontal axis id to bind with the input
|
||||||
* - "axis_y": the controller vertical axis id to bind with the input
|
* - "axis_y": the controller vertical axis id to bind with the input
|
||||||
* - "axis_z": the controller forward axis id to bind with the input
|
* - "axis_z": the controller forward axis id to bind with the input
|
||||||
@ -220,7 +233,8 @@ private:
|
|||||||
* - "pad": slot of the connected controller
|
* - "pad": slot of the connected controller
|
||||||
* @returns a unique input device with the parameters specified
|
* @returns a unique input device with the parameters specified
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params);
|
std::unique_ptr<Common::Input::InputDevice> CreateVirtualMotionDevice(
|
||||||
|
const Common::ParamPackage& params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a camera device from the parameters given.
|
* Creates a camera device from the parameters given.
|
||||||
|
@ -199,14 +199,6 @@ add_executable(yuzu
|
|||||||
util/clickable_label.h
|
util/clickable_label.h
|
||||||
util/controller_navigation.cpp
|
util/controller_navigation.cpp
|
||||||
util/controller_navigation.h
|
util/controller_navigation.h
|
||||||
util/controller_viewer/common_shapes.cpp
|
|
||||||
util/controller_viewer/common_shapes.h
|
|
||||||
util/controller_viewer/controller_base.cpp
|
|
||||||
util/controller_viewer/controller_base.h
|
|
||||||
util/controller_viewer/controller_viewer.cpp
|
|
||||||
util/controller_viewer/controller_viewer.h
|
|
||||||
util/controller_viewer/pro_controller.cpp
|
|
||||||
util/controller_viewer/pro_controller.h
|
|
||||||
util/limitable_input_dialog.cpp
|
util/limitable_input_dialog.cpp
|
||||||
util/limitable_input_dialog.h
|
util/limitable_input_dialog.h
|
||||||
util/overlay_dialog.cpp
|
util/overlay_dialog.cpp
|
||||||
|
@ -1,407 +0,0 @@
|
|||||||
// Copyright 2020 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "common/input.h"
|
|
||||||
#include "yuzu/util/controller_viewer/common_shapes.h"
|
|
||||||
|
|
||||||
namespace ControllerViewer {
|
|
||||||
|
|
||||||
void CommonShapes::DrawBattery(QPainter& p, QPointF center, Common::Input::BatteryLevel battery,
|
|
||||||
QColor outline, QColor battery_color, QColor charging_outline,
|
|
||||||
QColor charging_color) {
|
|
||||||
if (battery == Common::Input::BatteryLevel::None) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Draw outline
|
|
||||||
p.setPen(QPen(outline, 5));
|
|
||||||
p.setBrush(Qt::transparent);
|
|
||||||
p.drawRoundedRect(center.x(), center.y(), 34, 16, 2, 2);
|
|
||||||
|
|
||||||
p.setPen(QPen(outline, 3));
|
|
||||||
p.drawRect(center.x() + 35, center.y() + 4.5f, 4, 7);
|
|
||||||
|
|
||||||
// Draw Battery shape
|
|
||||||
p.setPen(QPen(battery_color, 3));
|
|
||||||
p.setBrush(Qt::transparent);
|
|
||||||
p.drawRoundedRect(center.x(), center.y(), 34, 16, 2, 2);
|
|
||||||
|
|
||||||
p.setPen(QPen(battery_color, 1));
|
|
||||||
p.setBrush(battery_color);
|
|
||||||
p.drawRect(center.x() + 35, center.y() + 4.5f, 4, 7);
|
|
||||||
switch (battery) {
|
|
||||||
case Common::Input::BatteryLevel::Charging:
|
|
||||||
p.drawRect(center.x(), center.y(), 34, 16);
|
|
||||||
p.setPen(charging_outline);
|
|
||||||
p.setBrush(charging_color);
|
|
||||||
DrawSymbol(p, center + QPointF(17.0f, 8.0f), Symbol::Charging, 2.1f);
|
|
||||||
break;
|
|
||||||
case Common::Input::BatteryLevel::Full:
|
|
||||||
p.drawRect(center.x(), center.y(), 34, 16);
|
|
||||||
break;
|
|
||||||
case Common::Input::BatteryLevel::Medium:
|
|
||||||
p.drawRect(center.x(), center.y(), 25, 16);
|
|
||||||
break;
|
|
||||||
case Common::Input::BatteryLevel::Low:
|
|
||||||
p.drawRect(center.x(), center.y(), 17, 16);
|
|
||||||
break;
|
|
||||||
case Common::Input::BatteryLevel::Critical:
|
|
||||||
p.drawRect(center.x(), center.y(), 6, 16);
|
|
||||||
break;
|
|
||||||
case Common::Input::BatteryLevel::Empty:
|
|
||||||
p.drawRect(center.x(), center.y(), 3, 16);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonShapes::DrawSymbol(QPainter& p, const QPointF center, Symbol symbol, float icon_size) {
|
|
||||||
std::array<QPointF, house.size() / 2> house_icon;
|
|
||||||
std::array<QPointF, symbol_a.size() / 2> a_icon;
|
|
||||||
std::array<QPointF, symbol_b.size() / 2> b_icon;
|
|
||||||
std::array<QPointF, symbol_x.size() / 2> x_icon;
|
|
||||||
std::array<QPointF, symbol_y.size() / 2> y_icon;
|
|
||||||
std::array<QPointF, symbol_l.size() / 2> l_icon;
|
|
||||||
std::array<QPointF, symbol_r.size() / 2> r_icon;
|
|
||||||
std::array<QPointF, symbol_c.size() / 2> c_icon;
|
|
||||||
std::array<QPointF, symbol_zl.size() / 2> zl_icon;
|
|
||||||
std::array<QPointF, symbol_sl.size() / 2> sl_icon;
|
|
||||||
std::array<QPointF, symbol_zr.size() / 2> zr_icon;
|
|
||||||
std::array<QPointF, symbol_sr.size() / 2> sr_icon;
|
|
||||||
std::array<QPointF, symbol_charging.size() / 2> charging_icon;
|
|
||||||
switch (symbol) {
|
|
||||||
case Symbol::House:
|
|
||||||
for (std::size_t point = 0; point < house.size() / 2; ++point) {
|
|
||||||
house_icon[point] = center + QPointF(house[point * 2] * icon_size,
|
|
||||||
(house[point * 2 + 1] - 0.025f) * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(house_icon.data(), static_cast<int>(house_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::A:
|
|
||||||
for (std::size_t point = 0; point < symbol_a.size() / 2; ++point) {
|
|
||||||
a_icon[point] = center + QPointF(symbol_a[point * 2] * icon_size,
|
|
||||||
symbol_a[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(a_icon.data(), static_cast<int>(a_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::B:
|
|
||||||
for (std::size_t point = 0; point < symbol_b.size() / 2; ++point) {
|
|
||||||
b_icon[point] = center + QPointF(symbol_b[point * 2] * icon_size,
|
|
||||||
symbol_b[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(b_icon.data(), static_cast<int>(b_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::X:
|
|
||||||
for (std::size_t point = 0; point < symbol_x.size() / 2; ++point) {
|
|
||||||
x_icon[point] = center + QPointF(symbol_x[point * 2] * icon_size,
|
|
||||||
symbol_x[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(x_icon.data(), static_cast<int>(x_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::Y:
|
|
||||||
for (std::size_t point = 0; point < symbol_y.size() / 2; ++point) {
|
|
||||||
y_icon[point] = center + QPointF(symbol_y[point * 2] * icon_size,
|
|
||||||
(symbol_y[point * 2 + 1] - 1.0f) * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(y_icon.data(), static_cast<int>(y_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::L:
|
|
||||||
for (std::size_t point = 0; point < symbol_l.size() / 2; ++point) {
|
|
||||||
l_icon[point] = center + QPointF(symbol_l[point * 2] * icon_size,
|
|
||||||
(symbol_l[point * 2 + 1] - 1.0f) * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(l_icon.data(), static_cast<int>(l_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::R:
|
|
||||||
for (std::size_t point = 0; point < symbol_r.size() / 2; ++point) {
|
|
||||||
r_icon[point] = center + QPointF(symbol_r[point * 2] * icon_size,
|
|
||||||
(symbol_r[point * 2 + 1] - 1.0f) * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(r_icon.data(), static_cast<int>(r_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::C:
|
|
||||||
for (std::size_t point = 0; point < symbol_c.size() / 2; ++point) {
|
|
||||||
c_icon[point] = center + QPointF(symbol_c[point * 2] * icon_size,
|
|
||||||
(symbol_c[point * 2 + 1] - 1.0f) * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(c_icon.data(), static_cast<int>(c_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::ZL:
|
|
||||||
for (std::size_t point = 0; point < symbol_zl.size() / 2; ++point) {
|
|
||||||
zl_icon[point] = center + QPointF(symbol_zl[point * 2] * icon_size,
|
|
||||||
symbol_zl[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(zl_icon.data(), static_cast<int>(zl_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::SL:
|
|
||||||
for (std::size_t point = 0; point < symbol_sl.size() / 2; ++point) {
|
|
||||||
sl_icon[point] = center + QPointF(symbol_sl[point * 2] * icon_size,
|
|
||||||
symbol_sl[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(sl_icon.data(), static_cast<int>(sl_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::ZR:
|
|
||||||
for (std::size_t point = 0; point < symbol_zr.size() / 2; ++point) {
|
|
||||||
zr_icon[point] = center + QPointF(symbol_zr[point * 2] * icon_size,
|
|
||||||
symbol_zr[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(zr_icon.data(), static_cast<int>(zr_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::SR:
|
|
||||||
for (std::size_t point = 0; point < symbol_sr.size() / 2; ++point) {
|
|
||||||
sr_icon[point] = center + QPointF(symbol_sr[point * 2] * icon_size,
|
|
||||||
symbol_sr[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(sr_icon.data(), static_cast<int>(sr_icon.size()));
|
|
||||||
break;
|
|
||||||
case Symbol::Charging:
|
|
||||||
for (std::size_t point = 0; point < symbol_charging.size() / 2; ++point) {
|
|
||||||
charging_icon[point] = center + QPointF(symbol_charging[point * 2] * icon_size,
|
|
||||||
symbol_charging[point * 2 + 1] * icon_size);
|
|
||||||
}
|
|
||||||
p.drawPolygon(charging_icon.data(), static_cast<int>(charging_icon.size()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonShapes::DrawArrow(QPainter& p, const QPointF center, const Direction direction,
|
|
||||||
float size) {
|
|
||||||
|
|
||||||
std::array<QPointF, up_arrow_symbol.size() / 2> arrow_symbol;
|
|
||||||
|
|
||||||
for (std::size_t point = 0; point < up_arrow_symbol.size() / 2; ++point) {
|
|
||||||
const float up_arrow_x = up_arrow_symbol[point * 2 + 0];
|
|
||||||
const float up_arrow_y = up_arrow_symbol[point * 2 + 1];
|
|
||||||
|
|
||||||
switch (direction) {
|
|
||||||
case Direction::Up:
|
|
||||||
arrow_symbol[point] = center + QPointF(up_arrow_x * size, up_arrow_y * size);
|
|
||||||
break;
|
|
||||||
case Direction::Left:
|
|
||||||
arrow_symbol[point] = center + QPointF(up_arrow_y * size, up_arrow_x * size);
|
|
||||||
break;
|
|
||||||
case Direction::Right:
|
|
||||||
arrow_symbol[point] = center + QPointF(-up_arrow_y * size, up_arrow_x * size);
|
|
||||||
break;
|
|
||||||
case Direction::Down:
|
|
||||||
arrow_symbol[point] = center + QPointF(up_arrow_x * size, -up_arrow_y * size);
|
|
||||||
break;
|
|
||||||
case Direction::None:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawPolygon(p, arrow_symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
void CommonShapes::DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon) {
|
|
||||||
p.drawPolygon(polygon.data(), static_cast<int>(polygon.size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonShapes::DrawCircle(QPainter& p, const QPointF center, float size) {
|
|
||||||
p.drawEllipse(center, size, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonShapes::DrawRectangle(QPainter& p, const QPointF center, float width, float height) {
|
|
||||||
const QRectF rect = QRectF(center.x() - (width / 2), center.y() - (height / 2), width, height);
|
|
||||||
p.drawRect(rect);
|
|
||||||
}
|
|
||||||
void CommonShapes::DrawRoundRectangle(QPainter& p, const QPointF center, float width, float height,
|
|
||||||
float round) {
|
|
||||||
const QRectF rect = QRectF(center.x() - (width / 2), center.y() - (height / 2), width, height);
|
|
||||||
p.drawRoundedRect(rect, round, round);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonShapes::DrawText(QPainter& p, const QPointF center, float text_size,
|
|
||||||
const QString& text) {
|
|
||||||
SetTextFont(p, text_size);
|
|
||||||
const QFontMetrics fm(p.font());
|
|
||||||
const QPointF offset = {fm.horizontalAdvance(text) / 2.0f, -text_size / 2.0f};
|
|
||||||
p.drawText(center - offset, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CommonShapes::SetTextFont(QPainter& p, float text_size, const QString& font_family) {
|
|
||||||
QFont font = p.font();
|
|
||||||
font.setPointSizeF(text_size);
|
|
||||||
font.setFamily(font_family);
|
|
||||||
p.setFont(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr std::array<float, 13 * 2> symbol_a = {
|
|
||||||
-1.085f, -5.2f, 1.085f, -5.2f, 5.085f, 5.0f, 2.785f, 5.0f, 1.785f,
|
|
||||||
2.65f, -1.785f, 2.65f, -2.785f, 5.0f, -5.085f, 5.0f, -1.4f, 1.0f,
|
|
||||||
0.0f, -2.8f, 1.4f, 1.0f, -1.4f, 1.0f, -5.085f, 5.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 134 * 2> symbol_b = {
|
|
||||||
-4.0f, 0.0f, -4.0f, 0.0f, -4.0f, -0.1f, -3.8f, -5.1f, 1.8f, -5.0f, 2.3f, -4.9f, 2.6f,
|
|
||||||
-4.8f, 2.8f, -4.7f, 2.9f, -4.6f, 3.1f, -4.5f, 3.2f, -4.4f, 3.4f, -4.3f, 3.4f, -4.2f,
|
|
||||||
3.5f, -4.1f, 3.7f, -4.0f, 3.7f, -3.9f, 3.8f, -3.8f, 3.8f, -3.7f, 3.9f, -3.6f, 3.9f,
|
|
||||||
-3.5f, 4.0f, -3.4f, 4.0f, -3.3f, 4.1f, -3.1f, 4.1f, -3.0f, 4.0f, -2.0f, 4.0f, -1.9f,
|
|
||||||
3.9f, -1.7f, 3.9f, -1.6f, 3.8f, -1.5f, 3.8f, -1.4f, 3.7f, -1.3f, 3.7f, -1.2f, 3.6f,
|
|
||||||
-1.1f, 3.6f, -1.0f, 3.5f, -0.9f, 3.3f, -0.8f, 3.3f, -0.7f, 3.2f, -0.6f, 3.0f, -0.5f,
|
|
||||||
2.9f, -0.4f, 2.7f, -0.3f, 2.9f, -0.2f, 3.2f, -0.1f, 3.3f, 0.0f, 3.5f, 0.1f, 3.6f,
|
|
||||||
0.2f, 3.8f, 0.3f, 3.9f, 0.4f, 4.0f, 0.6f, 4.1f, 0.7f, 4.3f, 0.8f, 4.3f, 0.9f,
|
|
||||||
4.4f, 1.0f, 4.4f, 1.1f, 4.5f, 1.3f, 4.5f, 1.4f, 4.6f, 1.6f, 4.6f, 1.7f, 4.5f,
|
|
||||||
2.8f, 4.5f, 2.9f, 4.4f, 3.1f, 4.4f, 3.2f, 4.3f, 3.4f, 4.3f, 3.5f, 4.2f, 3.6f,
|
|
||||||
4.2f, 3.7f, 4.1f, 3.8f, 4.1f, 3.9f, 4.0f, 4.0f, 3.9f, 4.2f, 3.8f, 4.3f, 3.6f,
|
|
||||||
4.4f, 3.6f, 4.5f, 3.4f, 4.6f, 3.3f, 4.7f, 3.1f, 4.8f, 2.8f, 4.9f, 2.6f, 5.0f,
|
|
||||||
2.1f, 5.1f, -4.0f, 5.0f, -4.0f, 4.9f,
|
|
||||||
|
|
||||||
-4.0f, 0.0f, 1.1f, 3.4f, 1.1f, 3.4f, 1.5f, 3.3f, 1.8f, 3.2f, 2.0f, 3.1f, 2.1f,
|
|
||||||
3.0f, 2.3f, 2.9f, 2.3f, 2.8f, 2.4f, 2.7f, 2.4f, 2.6f, 2.5f, 2.3f, 2.5f, 2.2f,
|
|
||||||
2.4f, 1.7f, 2.4f, 1.6f, 2.3f, 1.4f, 2.3f, 1.3f, 2.2f, 1.2f, 2.2f, 1.1f, 2.1f,
|
|
||||||
1.0f, 1.9f, 0.9f, 1.6f, 0.8f, 1.4f, 0.7f, -1.9f, 0.6f, -1.9f, 0.7f, -1.8f, 3.4f,
|
|
||||||
1.1f, 3.4f, -4.0f, 0.0f,
|
|
||||||
|
|
||||||
0.3f, -1.1f, 0.3f, -1.1f, 1.3f, -1.2f, 1.5f, -1.3f, 1.8f, -1.4f, 1.8f, -1.5f, 1.9f,
|
|
||||||
-1.6f, 2.0f, -1.8f, 2.0f, -1.9f, 2.1f, -2.0f, 2.1f, -2.1f, 2.0f, -2.7f, 2.0f, -2.8f,
|
|
||||||
1.9f, -2.9f, 1.9f, -3.0f, 1.8f, -3.1f, 1.6f, -3.2f, 1.6f, -3.3f, 1.3f, -3.4f, -1.9f,
|
|
||||||
-3.3f, -1.9f, -3.2f, -1.8f, -1.0f, 0.2f, -1.1f, 0.3f, -1.1f, -4.0f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 9 * 2> symbol_y = {
|
|
||||||
-4.79f, -4.9f, -2.44f, -4.9f, 0.0f, -0.9f, 2.44f, -4.9f, 4.79f,
|
|
||||||
-4.9f, 1.05f, 1.0f, 1.05f, 5.31f, -1.05f, 5.31f, -1.05f, 1.0f,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 12 * 2> symbol_x = {
|
|
||||||
-4.4f, -5.0f, -2.0f, -5.0f, 0.0f, -1.7f, 2.0f, -5.0f, 4.4f, -5.0f, 1.2f, 0.0f,
|
|
||||||
4.4f, 5.0f, 2.0f, 5.0f, 0.0f, 1.7f, -2.0f, 5.0f, -4.4f, 5.0f, -1.2f, 0.0f,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 7 * 2> symbol_l = {
|
|
||||||
2.4f, -3.23f, 2.4f, 2.1f, 5.43f, 2.1f, 5.43f, 3.22f, 0.98f, 3.22f, 0.98f, -3.23f, 2.4f, -3.23f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 98 * 2> symbol_r = {
|
|
||||||
1.0f, 0.0f, 1.0f, -0.1f, 1.1f, -3.3f, 4.3f, -3.2f, 5.1f, -3.1f, 5.4f, -3.0f, 5.6f, -2.9f,
|
|
||||||
5.7f, -2.8f, 5.9f, -2.7f, 5.9f, -2.6f, 6.0f, -2.5f, 6.1f, -2.3f, 6.2f, -2.2f, 6.2f, -2.1f,
|
|
||||||
6.3f, -2.0f, 6.3f, -1.9f, 6.2f, -0.8f, 6.2f, -0.7f, 6.1f, -0.6f, 6.1f, -0.5f, 6.0f, -0.4f,
|
|
||||||
6.0f, -0.3f, 5.9f, -0.2f, 5.7f, -0.1f, 5.7f, 0.0f, 5.6f, 0.1f, 5.4f, 0.2f, 5.1f, 0.3f,
|
|
||||||
4.7f, 0.4f, 4.7f, 0.5f, 4.9f, 0.6f, 5.0f, 0.7f, 5.2f, 0.8f, 5.2f, 0.9f, 5.3f, 1.0f,
|
|
||||||
5.5f, 1.1f, 5.5f, 1.2f, 5.6f, 1.3f, 5.7f, 1.5f, 5.8f, 1.6f, 5.9f, 1.8f, 6.0f, 1.9f,
|
|
||||||
6.1f, 2.1f, 6.2f, 2.2f, 6.2f, 2.3f, 6.3f, 2.4f, 6.4f, 2.6f, 6.5f, 2.7f, 6.6f, 2.9f,
|
|
||||||
6.7f, 3.0f, 6.7f, 3.1f, 6.8f, 3.2f, 6.8f, 3.3f, 5.3f, 3.2f, 5.2f, 3.1f, 5.2f, 3.0f,
|
|
||||||
5.1f, 2.9f, 5.0f, 2.7f, 4.9f, 2.6f, 4.8f, 2.4f, 4.7f, 2.3f, 4.6f, 2.1f, 4.5f, 2.0f,
|
|
||||||
4.4f, 1.8f, 4.3f, 1.7f, 4.1f, 1.4f, 4.0f, 1.3f, 3.9f, 1.1f, 3.8f, 1.0f, 3.6f, 0.9f,
|
|
||||||
3.6f, 0.8f, 3.5f, 0.7f, 3.3f, 0.6f, 2.9f, 0.5f, 2.3f, 0.6f, 2.3f, 0.7f, 2.2f, 3.3f,
|
|
||||||
1.0f, 3.2f, 1.0f, 3.1f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
4.2f, -0.5f, 4.4f, -0.6f, 4.7f, -0.7f, 4.8f, -0.8f, 4.9f, -1.0f, 5.0f, -1.1f, 5.0f, -1.2f,
|
|
||||||
4.9f, -1.7f, 4.9f, -1.8f, 4.8f, -1.9f, 4.8f, -2.0f, 4.6f, -2.1f, 4.3f, -2.2f, 2.3f, -2.1f,
|
|
||||||
2.3f, -2.0f, 2.4f, -0.5f, 4.2f, -0.5f, 1.0f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 18 * 2> symbol_zl = {
|
|
||||||
-2.6f, -2.13f, -5.6f, -2.13f, -5.6f, -3.23f, -0.8f, -3.23f, -0.8f, -2.13f, -4.4f, 2.12f,
|
|
||||||
-0.7f, 2.12f, -0.7f, 3.22f, -6.0f, 3.22f, -6.0f, 2.12f, 2.4f, -3.23f, 2.4f, 2.1f,
|
|
||||||
5.43f, 2.1f, 5.43f, 3.22f, 0.98f, 3.22f, 0.98f, -3.23f, 2.4f, -3.23f, -6.0f, 2.12f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 57 * 2> symbol_sl = {
|
|
||||||
-3.0f, -3.65f, -2.76f, -4.26f, -2.33f, -4.76f, -1.76f, -5.09f, -1.13f, -5.26f, -0.94f,
|
|
||||||
-4.77f, -0.87f, -4.11f, -1.46f, -3.88f, -1.91f, -3.41f, -2.05f, -2.78f, -1.98f, -2.13f,
|
|
||||||
-1.59f, -1.61f, -0.96f, -1.53f, -0.56f, -2.04f, -0.38f, -2.67f, -0.22f, -3.31f, 0.0f,
|
|
||||||
-3.93f, 0.34f, -4.49f, 0.86f, -4.89f, 1.49f, -5.05f, 2.14f, -4.95f, 2.69f, -4.6f,
|
|
||||||
3.07f, -4.07f, 3.25f, -3.44f, 3.31f, -2.78f, 3.25f, -2.12f, 3.07f, -1.49f, 2.7f,
|
|
||||||
-0.95f, 2.16f, -0.58f, 1.52f, -0.43f, 1.41f, -0.99f, 1.38f, -1.65f, 1.97f, -1.91f,
|
|
||||||
2.25f, -2.49f, 2.25f, -3.15f, 1.99f, -3.74f, 1.38f, -3.78f, 1.06f, -3.22f, 0.88f,
|
|
||||||
-2.58f, 0.71f, -1.94f, 0.49f, -1.32f, 0.13f, -0.77f, -0.4f, -0.4f, -1.04f, -0.25f,
|
|
||||||
-1.69f, -0.32f, -2.28f, -0.61f, -2.73f, -1.09f, -2.98f, -1.69f, -3.09f, -2.34f,
|
|
||||||
|
|
||||||
3.23f, 2.4f, -2.1f, 2.4f, -2.1f, 5.43f, -3.22f, 5.43f, -3.22f, 0.98f, 3.23f,
|
|
||||||
0.98f, 3.23f, 2.4f, -3.09f, -2.34f,
|
|
||||||
};
|
|
||||||
constexpr std::array<float, 109 * 2> symbol_zr = {
|
|
||||||
-2.6f, -2.13f, -5.6f, -2.13f, -5.6f, -3.23f, -0.8f, -3.23f, -0.8f, -2.13f, -4.4f, 2.12f, -0.7f,
|
|
||||||
2.12f, -0.7f, 3.22f, -6.0f, 3.22f, -6.0f, 2.12f,
|
|
||||||
|
|
||||||
1.0f, 0.0f, 1.0f, -0.1f, 1.1f, -3.3f, 4.3f, -3.2f, 5.1f, -3.1f, 5.4f, -3.0f, 5.6f,
|
|
||||||
-2.9f, 5.7f, -2.8f, 5.9f, -2.7f, 5.9f, -2.6f, 6.0f, -2.5f, 6.1f, -2.3f, 6.2f, -2.2f,
|
|
||||||
6.2f, -2.1f, 6.3f, -2.0f, 6.3f, -1.9f, 6.2f, -0.8f, 6.2f, -0.7f, 6.1f, -0.6f, 6.1f,
|
|
||||||
-0.5f, 6.0f, -0.4f, 6.0f, -0.3f, 5.9f, -0.2f, 5.7f, -0.1f, 5.7f, 0.0f, 5.6f, 0.1f,
|
|
||||||
5.4f, 0.2f, 5.1f, 0.3f, 4.7f, 0.4f, 4.7f, 0.5f, 4.9f, 0.6f, 5.0f, 0.7f, 5.2f,
|
|
||||||
0.8f, 5.2f, 0.9f, 5.3f, 1.0f, 5.5f, 1.1f, 5.5f, 1.2f, 5.6f, 1.3f, 5.7f, 1.5f,
|
|
||||||
5.8f, 1.6f, 5.9f, 1.8f, 6.0f, 1.9f, 6.1f, 2.1f, 6.2f, 2.2f, 6.2f, 2.3f, 6.3f,
|
|
||||||
2.4f, 6.4f, 2.6f, 6.5f, 2.7f, 6.6f, 2.9f, 6.7f, 3.0f, 6.7f, 3.1f, 6.8f, 3.2f,
|
|
||||||
6.8f, 3.3f, 5.3f, 3.2f, 5.2f, 3.1f, 5.2f, 3.0f, 5.1f, 2.9f, 5.0f, 2.7f, 4.9f,
|
|
||||||
2.6f, 4.8f, 2.4f, 4.7f, 2.3f, 4.6f, 2.1f, 4.5f, 2.0f, 4.4f, 1.8f, 4.3f, 1.7f,
|
|
||||||
4.1f, 1.4f, 4.0f, 1.3f, 3.9f, 1.1f, 3.8f, 1.0f, 3.6f, 0.9f, 3.6f, 0.8f, 3.5f,
|
|
||||||
0.7f, 3.3f, 0.6f, 2.9f, 0.5f, 2.3f, 0.6f, 2.3f, 0.7f, 2.2f, 3.3f, 1.0f, 3.2f,
|
|
||||||
1.0f, 3.1f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
4.2f, -0.5f, 4.4f, -0.6f, 4.7f, -0.7f, 4.8f, -0.8f, 4.9f, -1.0f, 5.0f, -1.1f, 5.0f,
|
|
||||||
-1.2f, 4.9f, -1.7f, 4.9f, -1.8f, 4.8f, -1.9f, 4.8f, -2.0f, 4.6f, -2.1f, 4.3f, -2.2f,
|
|
||||||
2.3f, -2.1f, 2.3f, -2.0f, 2.4f, -0.5f, 4.2f, -0.5f, 1.0f, 0.0f, -6.0f, 2.12f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 148 * 2> symbol_sr = {
|
|
||||||
-3.0f, -3.65f, -2.76f, -4.26f, -2.33f, -4.76f, -1.76f, -5.09f, -1.13f, -5.26f, -0.94f, -4.77f,
|
|
||||||
-0.87f, -4.11f, -1.46f, -3.88f, -1.91f, -3.41f, -2.05f, -2.78f, -1.98f, -2.13f, -1.59f, -1.61f,
|
|
||||||
-0.96f, -1.53f, -0.56f, -2.04f, -0.38f, -2.67f, -0.22f, -3.31f, 0.0f, -3.93f, 0.34f, -4.49f,
|
|
||||||
0.86f, -4.89f, 1.49f, -5.05f, 2.14f, -4.95f, 2.69f, -4.6f, 3.07f, -4.07f, 3.25f, -3.44f,
|
|
||||||
3.31f, -2.78f, 3.25f, -2.12f, 3.07f, -1.49f, 2.7f, -0.95f, 2.16f, -0.58f, 1.52f, -0.43f,
|
|
||||||
1.41f, -0.99f, 1.38f, -1.65f, 1.97f, -1.91f, 2.25f, -2.49f, 2.25f, -3.15f, 1.99f, -3.74f,
|
|
||||||
1.38f, -3.78f, 1.06f, -3.22f, 0.88f, -2.58f, 0.71f, -1.94f, 0.49f, -1.32f, 0.13f, -0.77f,
|
|
||||||
-0.4f, -0.4f, -1.04f, -0.25f, -1.69f, -0.32f, -2.28f, -0.61f, -2.73f, -1.09f, -2.98f, -1.69f,
|
|
||||||
-3.09f, -2.34f,
|
|
||||||
|
|
||||||
-1.0f, 0.0f, 0.1f, 1.0f, 3.3f, 1.1f, 3.2f, 4.3f, 3.1f, 5.1f, 3.0f, 5.4f,
|
|
||||||
2.9f, 5.6f, 2.8f, 5.7f, 2.7f, 5.9f, 2.6f, 5.9f, 2.5f, 6.0f, 2.3f, 6.1f,
|
|
||||||
2.2f, 6.2f, 2.1f, 6.2f, 2.0f, 6.3f, 1.9f, 6.3f, 0.8f, 6.2f, 0.7f, 6.2f,
|
|
||||||
0.6f, 6.1f, 0.5f, 6.1f, 0.4f, 6.0f, 0.3f, 6.0f, 0.2f, 5.9f, 0.1f, 5.7f,
|
|
||||||
0.0f, 5.7f, -0.1f, 5.6f, -0.2f, 5.4f, -0.3f, 5.1f, -0.4f, 4.7f, -0.5f, 4.7f,
|
|
||||||
-0.6f, 4.9f, -0.7f, 5.0f, -0.8f, 5.2f, -0.9f, 5.2f, -1.0f, 5.3f, -1.1f, 5.5f,
|
|
||||||
-1.2f, 5.5f, -1.3f, 5.6f, -1.5f, 5.7f, -1.6f, 5.8f, -1.8f, 5.9f, -1.9f, 6.0f,
|
|
||||||
-2.1f, 6.1f, -2.2f, 6.2f, -2.3f, 6.2f, -2.4f, 6.3f, -2.6f, 6.4f, -2.7f, 6.5f,
|
|
||||||
-2.9f, 6.6f, -3.0f, 6.7f, -3.1f, 6.7f, -3.2f, 6.8f, -3.3f, 6.8f, -3.2f, 5.3f,
|
|
||||||
-3.1f, 5.2f, -3.0f, 5.2f, -2.9f, 5.1f, -2.7f, 5.0f, -2.6f, 4.9f, -2.4f, 4.8f,
|
|
||||||
-2.3f, 4.7f, -2.1f, 4.6f, -2.0f, 4.5f, -1.8f, 4.4f, -1.7f, 4.3f, -1.4f, 4.1f,
|
|
||||||
-1.3f, 4.0f, -1.1f, 3.9f, -1.0f, 3.8f, -0.9f, 3.6f, -0.8f, 3.6f, -0.7f, 3.5f,
|
|
||||||
-0.6f, 3.3f, -0.5f, 2.9f, -0.6f, 2.3f, -0.7f, 2.3f, -3.3f, 2.2f, -3.2f, 1.0f,
|
|
||||||
-3.1f, 1.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
0.5f, 4.2f, 0.6f, 4.4f, 0.7f, 4.7f, 0.8f, 4.8f, 1.0f, 4.9f, 1.1f, 5.0f,
|
|
||||||
1.2f, 5.0f, 1.7f, 4.9f, 1.8f, 4.9f, 1.9f, 4.8f, 2.0f, 4.8f, 2.1f, 4.6f,
|
|
||||||
2.2f, 4.3f, 2.1f, 2.3f, 2.0f, 2.3f, 0.5f, 2.4f, 0.5f, 4.2f, -0.0f, 1.0f,
|
|
||||||
-3.09f, -2.34f,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 30 * 2> symbol_c = {
|
|
||||||
2.86f, 7.57f, 0.99f, 7.94f, -0.91f, 7.87f, -2.73f, 7.31f, -4.23f, 6.14f, -5.2f, 4.51f,
|
|
||||||
-5.65f, 2.66f, -5.68f, 0.75f, -5.31f, -1.12f, -4.43f, -2.81f, -3.01f, -4.08f, -1.24f, -4.78f,
|
|
||||||
0.66f, -4.94f, 2.54f, -4.67f, 4.33f, -4.0f, 4.63f, -2.27f, 3.37f, -2.7f, 1.6f, -3.4f,
|
|
||||||
-0.3f, -3.5f, -2.09f, -2.87f, -3.34f, -1.45f, -3.91f, 0.37f, -3.95f, 2.27f, -3.49f, 4.12f,
|
|
||||||
-2.37f, 5.64f, -0.65f, 6.44f, 1.25f, 6.47f, 3.06f, 5.89f, 4.63f, 4.92f, 4.63f, 6.83f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 6 * 2> symbol_charging = {
|
|
||||||
6.5f, -1.0f, 1.0f, -1.0f, 1.0f, -3.0f, -6.5f, 1.0f, -1.0f, 1.0f, -1.0f, 3.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 12 * 2> house = {
|
|
||||||
-1.3f, 0.0f, -0.93f, 0.0f, -0.93f, 1.15f, 0.93f, 1.15f, 0.93f, 0.0f, 1.3f, 0.0f,
|
|
||||||
0.0f, -1.2f, -1.3f, 0.0f, -0.43f, 0.0f, -0.43f, .73f, 0.43f, .73f, 0.43f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 11 * 2> up_arrow_button = {
|
|
||||||
9.1f, -9.1f, 9.1f, -30.0f, 8.1f, -30.1f, 7.7f, -30.1f, -8.6f, -30.0f, -9.0f,
|
|
||||||
-29.8f, -9.3f, -29.5f, -9.5f, -29.1f, -9.1f, -28.7f, -9.1f, -9.1f, 0.0f, 0.6f,
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr std::array<float, 3 * 2> up_arrow_symbol = {
|
|
||||||
0.0f, -3.0f, -3.0f, 2.0f, 3.0f, 2.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ControllerViewer
|
|
@ -1,65 +0,0 @@
|
|||||||
// Copyright 2020 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <QColor>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
#include "common\common_types.h"
|
|
||||||
|
|
||||||
namespace Common::Input {
|
|
||||||
enum class BatteryLevel : u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ControllerViewer {
|
|
||||||
|
|
||||||
// Widget for representing controller animations
|
|
||||||
class CommonShapes {
|
|
||||||
|
|
||||||
enum class Direction : std::size_t {
|
|
||||||
None,
|
|
||||||
Up,
|
|
||||||
Right,
|
|
||||||
Down,
|
|
||||||
Left,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Symbol {
|
|
||||||
House,
|
|
||||||
A,
|
|
||||||
B,
|
|
||||||
X,
|
|
||||||
Y,
|
|
||||||
L,
|
|
||||||
R,
|
|
||||||
C,
|
|
||||||
SL,
|
|
||||||
ZL,
|
|
||||||
ZR,
|
|
||||||
SR,
|
|
||||||
Charging,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Draw battery functions
|
|
||||||
void DrawBattery(QPainter& p, QPointF center, Common::Input::BatteryLevel battery,
|
|
||||||
QColor outline, QColor battery_color, QColor charging_outline,
|
|
||||||
QColor charging_color);
|
|
||||||
|
|
||||||
// Draw icon functions
|
|
||||||
void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);
|
|
||||||
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"));
|
|
||||||
};
|
|
||||||
} // namespace ControllerViewer
|
|
@ -1,77 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <QColor>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
#include "common/input.h"
|
|
||||||
#include "common/settings_input.h"
|
|
||||||
#include "core/hid/emulated_controller.h"
|
|
||||||
#include "core/hid/hid_types.h"
|
|
||||||
|
|
||||||
namespace ControllerViewer {
|
|
||||||
|
|
||||||
using AnalogParam = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>;
|
|
||||||
using ButtonParam = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
|
|
||||||
|
|
||||||
enum class Theme {
|
|
||||||
White,
|
|
||||||
Dark,
|
|
||||||
Midnight,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Widget for representing controller animations
|
|
||||||
class ControllerBase {
|
|
||||||
struct ColorMapping {
|
|
||||||
QColor outline{};
|
|
||||||
QColor primary{};
|
|
||||||
QColor left{};
|
|
||||||
QColor right{};
|
|
||||||
QColor button{};
|
|
||||||
QColor button2{};
|
|
||||||
QColor font{};
|
|
||||||
QColor font2{};
|
|
||||||
QColor highlight{};
|
|
||||||
QColor highlight2{};
|
|
||||||
QColor transparent{};
|
|
||||||
QColor indicator{};
|
|
||||||
QColor indicator2{};
|
|
||||||
QColor led_on{};
|
|
||||||
QColor led_off{};
|
|
||||||
QColor slider{};
|
|
||||||
QColor slider_button{};
|
|
||||||
QColor slider_arrow{};
|
|
||||||
QColor deadzone{};
|
|
||||||
QColor charging{};
|
|
||||||
};
|
|
||||||
|
|
||||||
void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
|
|
||||||
void DrawJoystickProperties(QPainter& p, QPointF center,
|
|
||||||
const Common::Input::AnalogProperties& properties);
|
|
||||||
|
|
||||||
bool is_controller_set{};
|
|
||||||
bool is_connected{};
|
|
||||||
bool needs_redraw{};
|
|
||||||
Core::HID::NpadStyleIndex controller_type;
|
|
||||||
|
|
||||||
bool mapping_active{};
|
|
||||||
int blink_counter{};
|
|
||||||
int callback_key;
|
|
||||||
QColor button_color{};
|
|
||||||
ColorMapping colors{};
|
|
||||||
Core::HID::LedPattern led_pattern{0, 0, 0, 0};
|
|
||||||
std::size_t player_index{};
|
|
||||||
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{};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ControllerViewer
|
|
@ -1,112 +0,0 @@
|
|||||||
// Copyright 2022 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "core/hid/emulated_controller.h"
|
|
||||||
#include "yuzu/util/controller_viewer/controller_viewer.h"
|
|
||||||
|
|
||||||
namespace ControllerViewer {
|
|
||||||
ControllerViewer::ControllerViewer(QWidget* parent) : QFrame(parent) {
|
|
||||||
is_controller_set = false;
|
|
||||||
QTimer* timer = new QTimer(this);
|
|
||||||
connect(timer, &QTimer::timeout, this, QOverload<>::of(&ControllerViewer::UpdateInput));
|
|
||||||
|
|
||||||
// refresh at 60hz
|
|
||||||
timer->start(16);
|
|
||||||
}
|
|
||||||
|
|
||||||
ControllerViewer::~ControllerViewer() {
|
|
||||||
UnloadController();
|
|
||||||
};
|
|
||||||
|
|
||||||
void ControllerViewer::SetController(Core::HID::EmulatedController* controller_) {
|
|
||||||
UnloadController();
|
|
||||||
is_controller_set = true;
|
|
||||||
controller = controller_;
|
|
||||||
Core::HID::ControllerUpdateCallback engine_callback{
|
|
||||||
.on_change = [this](Core::HID::ControllerTriggerType type) { ControllerUpdate(type); },
|
|
||||||
.is_npad_service = false,
|
|
||||||
};
|
|
||||||
callback_key = controller->SetCallback(engine_callback);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::All);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::UnloadController() {
|
|
||||||
if (is_controller_set) {
|
|
||||||
controller->DeleteCallback(callback_key);
|
|
||||||
is_controller_set = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::BeginMappingButton(std::size_t button_id) {
|
|
||||||
controller_view.BeginMappingButton(button_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::BeginMappingAnalog(std::size_t stick_id) {
|
|
||||||
controller_view.BeginMappingAnalog(stick_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::EndMapping() {
|
|
||||||
controller_view.EndMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::UpdateColors() {
|
|
||||||
if (QIcon::themeName().contains(QStringLiteral("dark"))) {
|
|
||||||
controller_view.UpdateColors(Theme::Midnight);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (QIcon::themeName().contains(QStringLiteral("midnight"))) {
|
|
||||||
controller_view.UpdateColors(Theme::Midnight);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
controller_view.UpdateColors(Theme::White);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::ResetInputs() {
|
|
||||||
controller_view.ResetInputs();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::ControllerUpdate(Core::HID::ControllerTriggerType type) {
|
|
||||||
if (type == Core::HID::ControllerTriggerType::All) {
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Color);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Type);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Connected);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Button);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Stick);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Trigger);
|
|
||||||
ControllerUpdate(Core::HID::ControllerTriggerType::Battery);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case Core::HID::ControllerTriggerType::Type:
|
|
||||||
controller_type = controller->GetNpadStyleIndex(true);
|
|
||||||
needs_redraw = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
controller_view.ControllerUpdate(type);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::UpdateInput() {
|
|
||||||
controller_view.UpdateInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ControllerViewer::paintEvent(QPaintEvent* event) {
|
|
||||||
QFrame::paintEvent(event);
|
|
||||||
QPainter p(this);
|
|
||||||
p.setRenderHint(QPainter::Antialiasing);
|
|
||||||
const QPointF center = rect().center();
|
|
||||||
|
|
||||||
controller_view.DrawController(p, center);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ControllerViewer
|
|
@ -1,64 +0,0 @@
|
|||||||
// Copyright 2022 yuzu Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
#include "common/input.h"
|
|
||||||
#include "common/settings_input.h"
|
|
||||||
#include "core/hid/emulated_controller.h"
|
|
||||||
#include "core/hid/hid_types.h"
|
|
||||||
#include "yuzu/util/controller_viewer/controller_base.h"
|
|
||||||
|
|
||||||
namespace ControllerViewer {
|
|
||||||
|
|
||||||
// Widget for representing controller animations
|
|
||||||
class ControllerViewer : public QFrame {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ControllerViewer(QWidget* parent);
|
|
||||||
~ControllerViewer() override;
|
|
||||||
|
|
||||||
// Sets the emulated controller to be displayed
|
|
||||||
void SetController(Core::HID::EmulatedController* controller);
|
|
||||||
|
|
||||||
// Disables events from the emulated controller
|
|
||||||
void UnloadController();
|
|
||||||
|
|
||||||
// Starts blinking animation at the button specified
|
|
||||||
void BeginMappingButton(std::size_t button_id);
|
|
||||||
|
|
||||||
// Starts moving animation at the stick specified
|
|
||||||
void BeginMappingAnalog(std::size_t stick_id);
|
|
||||||
|
|
||||||
// Stops any ongoing animation
|
|
||||||
void EndMapping();
|
|
||||||
|
|
||||||
// Handles emulated controller events
|
|
||||||
void ControllerUpdate(Core::HID::ControllerTriggerType type);
|
|
||||||
|
|
||||||
// Updates input on sheduled interval
|
|
||||||
void UpdateInput();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent* event) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void UpdateColors();
|
|
||||||
void ResetInputs();
|
|
||||||
|
|
||||||
bool is_controller_set{};
|
|
||||||
bool is_connected{};
|
|
||||||
bool needs_redraw{};
|
|
||||||
|
|
||||||
int callback_key;
|
|
||||||
ControllerBase controller_view;
|
|
||||||
Core::HID::EmulatedController* controller;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ControllerViewer
|
|
File diff suppressed because it is too large
Load Diff
@ -1,28 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <QFrame>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
#include "util\controller_viewer\controller_base.h"
|
|
||||||
|
|
||||||
// Widget for representing controller animations
|
|
||||||
class ProController : public PlayerControllerBase {
|
|
||||||
void UpdateColors();
|
|
||||||
void ResetInputs();
|
|
||||||
|
|
||||||
void DrawProController(QPainter& p, QPointF center);
|
|
||||||
|
|
||||||
void DrawGCBody(QPainter& p, QPointF center);
|
|
||||||
|
|
||||||
// Draw triggers functions
|
|
||||||
void DrawProTriggers(QPainter& p, QPointF center,
|
|
||||||
const Common::Input::ButtonStatus& left_pressed,
|
|
||||||
const Common::Input::ButtonStatus& right_pressed);
|
|
||||||
|
|
||||||
void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
|
|
||||||
const Common::Input::ButtonStatus& pressed);
|
|
||||||
};
|
|
Reference in New Issue
Block a user