summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar german2021-01-12 21:09:59 -0600
committerGravatar german2021-02-06 09:43:41 -0600
commit481cd86722f7070b6a63f2b95c1e8bceb518eee7 (patch)
tree5ec35ba24ca028b381f80963d40c2ed375229b84 /src
parentMerge pull request #5326 from german77/hidUpdate1 (diff)
downloadyuzu-481cd86722f7070b6a63f2b95c1e8bceb518eee7.tar.gz
yuzu-481cd86722f7070b6a63f2b95c1e8bceb518eee7.tar.xz
yuzu-481cd86722f7070b6a63f2b95c1e8bceb518eee7.zip
Make settings controller image change with controller input
Diffstat (limited to 'src')
-rw-r--r--src/core/frontend/input.h11
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp10
-rw-r--r--src/input_common/sdl/sdl_impl.cpp10
-rw-r--r--src/yuzu/CMakeLists.txt2
-rw-r--r--src/yuzu/configuration/configure_input_player.cpp101
-rw-r--r--src/yuzu/configuration/configure_input_player.h2
-rw-r--r--src/yuzu/configuration/configure_input_player.ui74
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.cpp1784
-rw-r--r--src/yuzu/configuration/configure_input_player_widget.h157
9 files changed, 2076 insertions, 75 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h
index f014dfea3..88ebc6497 100644
--- a/src/core/frontend/input.h
+++ b/src/core/frontend/input.h
@@ -21,6 +21,11 @@ enum class AnalogDirection : u8 {
21 UP, 21 UP,
22 DOWN, 22 DOWN,
23}; 23};
24struct AnalogProperties {
25 float deadzone;
26 float range;
27 float threshold;
28};
24 29
25/// An abstract class template for an input device (a button, an analog input, etc.). 30/// An abstract class template for an input device (a button, an analog input, etc.).
26template <typename StatusType> 31template <typename StatusType>
@@ -30,6 +35,12 @@ public:
30 virtual StatusType GetStatus() const { 35 virtual StatusType GetStatus() const {
31 return {}; 36 return {};
32 } 37 }
38 virtual StatusType GetRawStatus() const {
39 return GetStatus();
40 }
41 virtual AnalogProperties GetAnalogProperties() const {
42 return {};
43 }
33 virtual bool GetAnalogDirectionStatus([[maybe_unused]] AnalogDirection direction) const { 44 virtual bool GetAnalogDirectionStatus([[maybe_unused]] AnalogDirection direction) const {
34 return {}; 45 return {};
35 } 46 }
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index 9670bdeb2..1b6ded8d6 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -185,6 +185,16 @@ public:
185 return {0.0f, 0.0f}; 185 return {0.0f, 0.0f};
186 } 186 }
187 187
188 std::tuple<float, float> GetRawStatus() const override {
189 const float x = GetAxis(axis_x);
190 const float y = GetAxis(axis_y);
191 return {x, y};
192 }
193
194 Input::AnalogProperties GetAnalogProperties() const override {
195 return {deadzone, range, 0.5f};
196 }
197
188 bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { 198 bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override {
189 const auto [x, y] = GetStatus(); 199 const auto [x, y] = GetStatus();
190 const float directional_deadzone = 0.5f; 200 const float directional_deadzone = 0.5f;
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 1b5750937..f67de37e3 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -377,6 +377,16 @@ public:
377 return {}; 377 return {};
378 } 378 }
379 379
380 std::tuple<float, float> GetRawStatus() const override {
381 const float x = joystick->GetAxis(axis_x, range);
382 const float y = joystick->GetAxis(axis_y, range);
383 return {x, -y};
384 }
385
386 Input::AnalogProperties GetAnalogProperties() const override {
387 return {deadzone, range, 0.5f};
388 }
389
380 bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { 390 bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override {
381 const auto [x, y] = GetStatus(); 391 const auto [x, y] = GetStatus();
382 const float directional_deadzone = 0.5f; 392 const float directional_deadzone = 0.5f;
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index e1bab2112..6802be295 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -71,6 +71,8 @@ add_executable(yuzu
71 configuration/configure_input_player.cpp 71 configuration/configure_input_player.cpp
72 configuration/configure_input_player.h 72 configuration/configure_input_player.h
73 configuration/configure_input_player.ui 73 configuration/configure_input_player.ui
74 configuration/configure_input_player_widget.cpp
75 configuration/configure_input_player_widget.h
74 configuration/configure_input_profile_dialog.cpp 76 configuration/configure_input_profile_dialog.cpp
75 configuration/configure_input_profile_dialog.h 77 configuration/configure_input_profile_dialog.h
76 configuration/configure_input_profile_dialog.ui 78 configuration/configure_input_profile_dialog.ui
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp
index b40d7c5e2..c9d19c948 100644
--- a/src/yuzu/configuration/configure_input_player.cpp
+++ b/src/yuzu/configuration/configure_input_player.cpp
@@ -23,6 +23,7 @@
23#include "ui_configure_input_player.h" 23#include "ui_configure_input_player.h"
24#include "yuzu/configuration/config.h" 24#include "yuzu/configuration/config.h"
25#include "yuzu/configuration/configure_input_player.h" 25#include "yuzu/configuration/configure_input_player.h"
26#include "yuzu/configuration/configure_input_player_widget.h"
26#include "yuzu/configuration/configure_vibration.h" 27#include "yuzu/configuration/configure_vibration.h"
27#include "yuzu/configuration/input_profiles.h" 28#include "yuzu/configuration/input_profiles.h"
28#include "yuzu/util/limitable_input_dialog.h" 29#include "yuzu/util/limitable_input_dialog.h"
@@ -254,11 +255,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
254 analog_map_range_groupbox = {ui->buttonLStickRangeGroup, ui->buttonRStickRangeGroup}; 255 analog_map_range_groupbox = {ui->buttonLStickRangeGroup, ui->buttonRStickRangeGroup};
255 analog_map_range_spinbox = {ui->spinboxLStickRange, ui->spinboxRStickRange}; 256 analog_map_range_spinbox = {ui->spinboxLStickRange, ui->spinboxRStickRange};
256 257
257 const auto ConfigureButtonClick = [&](QPushButton* button, Common::ParamPackage* param, 258 const auto ConfigureButtonClick = [&](QPushButton* button, std::size_t button_id,
258 int default_val, InputCommon::Polling::DeviceType type) { 259 Common::ParamPackage* param, int default_val,
260 InputCommon::Polling::DeviceType type) {
259 connect(button, &QPushButton::clicked, [=, this] { 261 connect(button, &QPushButton::clicked, [=, this] {
260 HandleClick( 262 HandleClick(
261 button, 263 button, button_id,
262 [=, this](Common::ParamPackage params) { 264 [=, this](Common::ParamPackage params) {
263 // Workaround for ZL & ZR for analog triggers like on XBOX 265 // Workaround for ZL & ZR for analog triggers like on XBOX
264 // controllers. Analog triggers (from controllers like the XBOX 266 // controllers. Analog triggers (from controllers like the XBOX
@@ -286,12 +288,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
286 continue; 288 continue;
287 } 289 }
288 290
289 ConfigureButtonClick(button_map[button_id], &buttons_param[button_id], 291 ConfigureButtonClick(button_map[button_id], button_id, &buttons_param[button_id],
290 Config::default_buttons[button_id], 292 Config::default_buttons[button_id],
291 InputCommon::Polling::DeviceType::Button); 293 InputCommon::Polling::DeviceType::Button);
292 294
293 button->setContextMenuPolicy(Qt::CustomContextMenu); 295 button->setContextMenuPolicy(Qt::CustomContextMenu);
294
295 connect(button, &QPushButton::customContextMenuRequested, 296 connect(button, &QPushButton::customContextMenuRequested,
296 [=, this](const QPoint& menu_location) { 297 [=, this](const QPoint& menu_location) {
297 QMenu context_menu; 298 QMenu context_menu;
@@ -300,6 +301,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
300 button_map[button_id]->setText(tr("[not set]")); 301 button_map[button_id]->setText(tr("[not set]"));
301 }); 302 });
302 context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); 303 context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
304 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
303 }); 305 });
304 } 306 }
305 307
@@ -309,7 +311,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
309 continue; 311 continue;
310 } 312 }
311 313
312 ConfigureButtonClick(motion_map[motion_id], &motions_param[motion_id], 314 ConfigureButtonClick(motion_map[motion_id], motion_id, &motions_param[motion_id],
313 Config::default_motions[motion_id], 315 Config::default_motions[motion_id],
314 InputCommon::Polling::DeviceType::Motion); 316 InputCommon::Polling::DeviceType::Motion);
315 317
@@ -348,7 +350,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
348 } 350 }
349 } 351 }
350 HandleClick( 352 HandleClick(
351 analog_map_buttons[analog_id][sub_button_id], 353 analog_map_buttons[analog_id][sub_button_id], analog_id,
352 [=, this](const Common::ParamPackage& params) { 354 [=, this](const Common::ParamPackage& params) {
353 SetAnalogParam(params, analogs_param[analog_id], 355 SetAnalogParam(params, analogs_param[analog_id],
354 analog_sub_buttons[sub_button_id]); 356 analog_sub_buttons[sub_button_id]);
@@ -358,41 +360,43 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
358 360
359 analog_button->setContextMenuPolicy(Qt::CustomContextMenu); 361 analog_button->setContextMenuPolicy(Qt::CustomContextMenu);
360 362
361 connect(analog_button, &QPushButton::customContextMenuRequested, 363 connect(
362 [=, this](const QPoint& menu_location) { 364 analog_button, &QPushButton::customContextMenuRequested,
363 QMenu context_menu; 365 [=, this](const QPoint& menu_location) {
364 context_menu.addAction(tr("Clear"), [&] { 366 QMenu context_menu;
365 analogs_param[analog_id].Clear(); 367 context_menu.addAction(tr("Clear"), [&] {
366 analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); 368 analogs_param[analog_id].Clear();
367 }); 369 analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
368 context_menu.addAction(tr("Invert axis"), [&] { 370 });
369 if (sub_button_id == 2 || sub_button_id == 3) { 371 context_menu.addAction(tr("Invert axis"), [&] {
370 const bool invert_value = 372 if (sub_button_id == 2 || sub_button_id == 3) {
371 analogs_param[analog_id].Get("invert_x", "+") == "-"; 373 const bool invert_value =
372 const std::string invert_str = invert_value ? "+" : "-"; 374 analogs_param[analog_id].Get("invert_x", "+") == "-";
373 analogs_param[analog_id].Set("invert_x", invert_str); 375 const std::string invert_str = invert_value ? "+" : "-";
374 } 376 analogs_param[analog_id].Set("invert_x", invert_str);
375 if (sub_button_id == 0 || sub_button_id == 1) { 377 }
376 const bool invert_value = 378 if (sub_button_id == 0 || sub_button_id == 1) {
377 analogs_param[analog_id].Get("invert_y", "+") == "-"; 379 const bool invert_value =
378 const std::string invert_str = invert_value ? "+" : "-"; 380 analogs_param[analog_id].Get("invert_y", "+") == "-";
379 analogs_param[analog_id].Set("invert_y", invert_str); 381 const std::string invert_str = invert_value ? "+" : "-";
380 } 382 analogs_param[analog_id].Set("invert_y", invert_str);
381 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; 383 }
382 ++sub_button_id) { 384 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM;
383 analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText( 385 ++sub_button_id) {
384 analogs_param[analog_id], analog_sub_buttons[sub_button_id])); 386 analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText(
385 } 387 analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
386 }); 388 }
387 context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
388 menu_location));
389 }); 389 });
390 context_menu.exec(
391 analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location));
392 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
393 });
390 } 394 }
391 395
392 // Handle clicks for the modifier buttons as well. 396 // Handle clicks for the modifier buttons as well.
393 connect(analog_map_modifier_button[analog_id], &QPushButton::clicked, [=, this] { 397 connect(analog_map_modifier_button[analog_id], &QPushButton::clicked, [=, this] {
394 HandleClick( 398 HandleClick(
395 analog_map_modifier_button[analog_id], 399 analog_map_modifier_button[analog_id], analog_id,
396 [=, this](const Common::ParamPackage& params) { 400 [=, this](const Common::ParamPackage& params) {
397 analogs_param[analog_id].Set("modifier", params.Serialize()); 401 analogs_param[analog_id].Set("modifier", params.Serialize());
398 }, 402 },
@@ -416,12 +420,14 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
416 [=, this] { 420 [=, this] {
417 const auto spinbox_value = analog_map_range_spinbox[analog_id]->value(); 421 const auto spinbox_value = analog_map_range_spinbox[analog_id]->value();
418 analogs_param[analog_id].Set("range", spinbox_value / 100.0f); 422 analogs_param[analog_id].Set("range", spinbox_value / 100.0f);
423 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
419 }); 424 });
420 425
421 connect(analog_map_deadzone_slider[analog_id], &QSlider::valueChanged, [=, this] { 426 connect(analog_map_deadzone_slider[analog_id], &QSlider::valueChanged, [=, this] {
422 const auto slider_value = analog_map_deadzone_slider[analog_id]->value(); 427 const auto slider_value = analog_map_deadzone_slider[analog_id]->value();
423 analog_map_deadzone_label[analog_id]->setText(tr("Deadzone: %1%").arg(slider_value)); 428 analog_map_deadzone_label[analog_id]->setText(tr("Deadzone: %1%").arg(slider_value));
424 analogs_param[analog_id].Set("deadzone", slider_value / 100.0f); 429 analogs_param[analog_id].Set("deadzone", slider_value / 100.0f);
430 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
425 }); 431 });
426 432
427 connect(analog_map_modifier_slider[analog_id], &QSlider::valueChanged, [=, this] { 433 connect(analog_map_modifier_slider[analog_id], &QSlider::valueChanged, [=, this] {
@@ -433,8 +439,10 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
433 } 439 }
434 440
435 // Player Connected checkbox 441 // Player Connected checkbox
436 connect(ui->groupConnectedController, &QGroupBox::toggled, 442 connect(ui->groupConnectedController, &QGroupBox::toggled, [this](bool checked) {
437 [this](bool checked) { emit Connected(checked); }); 443 emit Connected(checked);
444 ui->controllerFrame->SetConnectedStatus(checked);
445 });
438 446
439 if (player_index == 0) { 447 if (player_index == 0) {
440 connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), 448 connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged),
@@ -553,6 +561,8 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
553 561
554 // TODO(wwylele): enable this when we actually emulate it 562 // TODO(wwylele): enable this when we actually emulate it
555 ui->buttonHome->setEnabled(false); 563 ui->buttonHome->setEnabled(false);
564 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
565 ui->controllerFrame->SetConnectedStatus(ui->groupConnectedController->isChecked());
556} 566}
557 567
558ConfigureInputPlayer::~ConfigureInputPlayer() = default; 568ConfigureInputPlayer::~ConfigureInputPlayer() = default;
@@ -875,6 +885,7 @@ void ConfigureInputPlayer::UpdateUI() {
875 modifier_label->setVisible(!is_controller); 885 modifier_label->setVisible(!is_controller);
876 modifier_slider->setVisible(!is_controller); 886 modifier_slider->setVisible(!is_controller);
877 range_groupbox->setVisible(is_controller); 887 range_groupbox->setVisible(is_controller);
888 ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
878 } 889 }
879} 890}
880 891
@@ -991,8 +1002,8 @@ void ConfigureInputPlayer::UpdateControllerIcon() {
991 return QString{}; 1002 return QString{};
992 } 1003 }
993 }(); 1004 }();
994 1005 ui->controllerFrame->SetControllerType(
995 ui->controllerFrame->setStyleSheet(stylesheet.arg(theme)); 1006 GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()));
996} 1007}
997 1008
998void ConfigureInputPlayer::UpdateControllerAvailableButtons() { 1009void ConfigureInputPlayer::UpdateControllerAvailableButtons() {
@@ -1129,7 +1140,8 @@ void ConfigureInputPlayer::UpdateMappingWithDefaults() {
1129} 1140}
1130 1141
1131void ConfigureInputPlayer::HandleClick( 1142void ConfigureInputPlayer::HandleClick(
1132 QPushButton* button, std::function<void(const Common::ParamPackage&)> new_input_setter, 1143 QPushButton* button, std::size_t button_id,
1144 std::function<void(const Common::ParamPackage&)> new_input_setter,
1133 InputCommon::Polling::DeviceType type) { 1145 InputCommon::Polling::DeviceType type) {
1134 if (button == ui->buttonMotionLeft || button == ui->buttonMotionRight) { 1146 if (button == ui->buttonMotionLeft || button == ui->buttonMotionRight) {
1135 button->setText(tr("Shake!")); 1147 button->setText(tr("Shake!"));
@@ -1173,6 +1185,12 @@ void ConfigureInputPlayer::HandleClick(
1173 input_subsystem->GetMouseTouch()->BeginConfiguration(); 1185 input_subsystem->GetMouseTouch()->BeginConfiguration();
1174 } 1186 }
1175 1187
1188 if (type == InputCommon::Polling::DeviceType::Button) {
1189 ui->controllerFrame->BeginMappingButton(button_id);
1190 } else if (type == InputCommon::Polling::DeviceType::AnalogPreferred) {
1191 ui->controllerFrame->BeginMappingAnalog(button_id);
1192 }
1193
1176 timeout_timer->start(2500); // Cancel after 2.5 seconds 1194 timeout_timer->start(2500); // Cancel after 2.5 seconds
1177 poll_timer->start(50); // Check for new inputs every 50ms 1195 poll_timer->start(50); // Check for new inputs every 50ms
1178} 1196}
@@ -1203,6 +1221,7 @@ void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params,
1203 1221
1204 UpdateUI(); 1222 UpdateUI();
1205 UpdateInputDeviceCombobox(); 1223 UpdateInputDeviceCombobox();
1224 ui->controllerFrame->EndMapping();
1206 1225
1207 input_setter = std::nullopt; 1226 input_setter = std::nullopt;
1208} 1227}
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h
index c4ae50de7..da2b89136 100644
--- a/src/yuzu/configuration/configure_input_player.h
+++ b/src/yuzu/configuration/configure_input_player.h
@@ -106,7 +106,7 @@ private:
106 void LoadConfiguration(); 106 void LoadConfiguration();
107 107
108 /// Called when the button was pressed. 108 /// Called when the button was pressed.
109 void HandleClick(QPushButton* button, 109 void HandleClick(QPushButton* button, std::size_t button_id,
110 std::function<void(const Common::ParamPackage&)> new_input_setter, 110 std::function<void(const Common::ParamPackage&)> new_input_setter,
111 InputCommon::Polling::DeviceType type); 111 InputCommon::Polling::DeviceType type);
112 112
diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui
index 1e78b4c10..e76aa484f 100644
--- a/src/yuzu/configuration/configure_input_player.ui
+++ b/src/yuzu/configuration/configure_input_player.ui
@@ -1964,39 +1964,39 @@
1964 </item> 1964 </item>
1965 </layout> 1965 </layout>
1966 </item> 1966 </item>
1967 <item> 1967 <item>
1968 <widget class="QFrame" name="controllerFrame"> 1968 <widget class="PlayerControlPreview" name="controllerFrame">
1969 <property name="sizePolicy"> 1969 <property name="sizePolicy">
1970 <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> 1970 <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
1971 <horstretch>0</horstretch> 1971 <horstretch>0</horstretch>
1972 <verstretch>0</verstretch> 1972 <verstretch>0</verstretch>
1973 </sizepolicy> 1973 </sizepolicy>
1974 </property> 1974 </property>
1975 <property name="font"> 1975 <property name="font">
1976 <font> 1976 <font>
1977 <weight>75</weight> 1977 <weight>75</weight>
1978 <bold>true</bold> 1978 <bold>true</bold>
1979 </font> 1979 </font>
1980 </property> 1980 </property>
1981 <property name="styleSheet"> 1981 <property name="styleSheet">
1982 <string notr="true">image: url(:/controller/pro);</string> 1982 <string notr="true">image: url(:/controller/pro);</string>
1983 </property> 1983 </property>
1984 <layout class="QVBoxLayout" name="verticalLayout_4"> 1984 <layout class="QVBoxLayout" name="verticalLayout_4">
1985 <property name="leftMargin"> 1985 <property name="leftMargin">
1986 <number>0</number> 1986 <number>0</number>
1987 </property> 1987 </property>
1988 <property name="topMargin"> 1988 <property name="topMargin">
1989 <number>0</number> 1989 <number>0</number>
1990 </property> 1990 </property>
1991 <property name="rightMargin"> 1991 <property name="rightMargin">
1992 <number>0</number> 1992 <number>0</number>
1993 </property> 1993 </property>
1994 <property name="bottomMargin"> 1994 <property name="bottomMargin">
1995 <number>0</number> 1995 <number>0</number>
1996 </property> 1996 </property>
1997 </layout> 1997 </layout>
1998 </widget> 1998 </widget>
1999 </item> 1999 </item>
2000 <item> 2000 <item>
2001 <layout class="QHBoxLayout" name="miscButtons"> 2001 <layout class="QHBoxLayout" name="miscButtons">
2002 <property name="spacing"> 2002 <property name="spacing">
@@ -3087,6 +3087,14 @@
3087 </item> 3087 </item>
3088 </layout> 3088 </layout>
3089 </widget> 3089 </widget>
3090 <customwidgets>
3091 <customwidget>
3092 <class>PlayerControlPreview</class>
3093 <extends>QFrame</extends>
3094 <header>yuzu/configuration/configure_input_player_widget.h</header>
3095 <container>1</container>
3096 </customwidget>
3097 </customwidgets>
3090 <resources> 3098 <resources>
3091 <include location="../../../dist/icons/controller/controller.qrc"/> 3099 <include location="../../../dist/icons/controller/controller.qrc"/>
3092 </resources> 3100 </resources>
diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp
new file mode 100644
index 000000000..016066533
--- /dev/null
+++ b/src/yuzu/configuration/configure_input_player_widget.cpp
@@ -0,0 +1,1784 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <QMenu>
7#include <QPainter>
8#include <QTimer>
9#include "yuzu/configuration/configure_input_player_widget.h"
10
11PlayerControlPreview::PlayerControlPreview(QWidget* parent) : QFrame(parent) {
12 UpdateColors();
13 QTimer* timer = new QTimer(this);
14 connect(timer, &QTimer::timeout, this, QOverload<>::of(&PlayerControlPreview::update));
15
16 // refresh at 40hz
17 timer->start(25);
18}
19
20PlayerControlPreview::~PlayerControlPreview() = default;
21
22void PlayerControlPreview::SetPlayerInput(std::size_t index, const ButtonParam& buttons_param,
23 const AnalogParam& analogs_param) {
24 player_index = index;
25 Settings::ButtonsRaw buttonss;
26 Settings::AnalogsRaw analogs;
27 std::transform(buttons_param.begin(), buttons_param.end(), buttonss.begin(),
28 [](const Common::ParamPackage& param) { return param.Serialize(); });
29 std::transform(analogs_param.begin(), analogs_param.end(), analogs.begin(),
30 [](const Common::ParamPackage& param) { return param.Serialize(); });
31
32 std::transform(buttonss.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
33 buttonss.begin() + Settings::NativeButton::BUTTON_NS_END, buttons.begin(),
34 Input::CreateDevice<Input::ButtonDevice>);
35 std::transform(analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN,
36 analogs.begin() + Settings::NativeAnalog::STICK_HID_END, sticks.begin(),
37 Input::CreateDevice<Input::AnalogDevice>);
38 UpdateColors();
39}
40
41PlayerControlPreview::LedPattern PlayerControlPreview::GetColorPattern(std::size_t index,
42 bool player_on) {
43 if (!player_on) {
44 return {0, 0, 0, 0};
45 }
46
47 switch (index) {
48 case 0:
49 return {1, 0, 0, 0};
50 case 1:
51 return {1, 1, 0, 0};
52 case 2:
53 return {1, 1, 1, 0};
54 case 3:
55 return {1, 1, 1, 1};
56 case 4:
57 return {1, 0, 0, 1};
58 case 5:
59 return {1, 0, 1, 0};
60 case 6:
61 return {1, 0, 1, 1};
62 case 7:
63 return {0, 1, 1, 0};
64 default:
65 return {0, 0, 0, 0};
66 }
67}
68
69void PlayerControlPreview::SetConnectedStatus(bool checked) {
70 LedPattern led_pattern = GetColorPattern(player_index, checked);
71
72 led_color[0] = led_pattern.position1 ? colors.led_on : colors.led_off;
73 led_color[1] = led_pattern.position2 ? colors.led_on : colors.led_off;
74 led_color[2] = led_pattern.position3 ? colors.led_on : colors.led_off;
75 led_color[3] = led_pattern.position4 ? colors.led_on : colors.led_off;
76}
77
78void PlayerControlPreview::SetControllerType(const Settings::ControllerType type) {
79 controller_type = type;
80 UpdateColors();
81}
82
83void PlayerControlPreview::BeginMappingButton(std::size_t index) {
84 button_mapping_index = index;
85 mapping_active = true;
86}
87
88void PlayerControlPreview::BeginMappingAnalog(std::size_t index) {
89 button_mapping_index = Settings::NativeButton::LStick + index;
90 analog_mapping_index = index;
91 mapping_active = true;
92}
93
94void PlayerControlPreview::EndMapping() {
95 button_mapping_index = Settings::NativeButton::BUTTON_NS_END;
96 analog_mapping_index = Settings::NativeAnalog::NumAnalogs;
97 mapping_active = false;
98 blink_counter = 0;
99}
100
101void PlayerControlPreview::UpdateColors() {
102 if (QIcon::themeName().contains(QStringLiteral("dark")) ||
103 QIcon::themeName().contains(QStringLiteral("midnight"))) {
104 colors.primary = QColor(204, 204, 204);
105 colors.button = QColor(35, 38, 41);
106 colors.button2 = QColor(26, 27, 30);
107 colors.slider_arrow = QColor(14, 15, 18);
108 colors.font2 = QColor(255, 255, 255);
109 colors.indicator = QColor(170, 238, 255);
110 colors.deadzone = QColor(204, 136, 136);
111 colors.slider_button = colors.button;
112 }
113
114 if (QIcon::themeName().contains(QStringLiteral("dark"))) {
115 colors.outline = QColor(160, 160, 160);
116 } else if (QIcon::themeName().contains(QStringLiteral("midnight"))) {
117 colors.outline = QColor(145, 145, 145);
118 } else {
119 colors.outline = QColor(0, 0, 0);
120 colors.primary = QColor(225, 225, 225);
121 colors.button = QColor(109, 111, 114);
122 colors.button2 = QColor(109, 111, 114);
123 colors.button2 = QColor(77, 80, 84);
124 colors.slider_arrow = QColor(65, 68, 73);
125 colors.font2 = QColor(0, 0, 0);
126 colors.indicator = QColor(0, 0, 200);
127 colors.deadzone = QColor(170, 0, 0);
128 colors.slider_button = QColor(153, 149, 149);
129 }
130
131 // Constant colors
132 colors.highlight = QColor(170, 0, 0);
133 colors.highlight2 = QColor(119, 0, 0);
134 colors.slider = QColor(103, 106, 110);
135 colors.transparent = QColor(0, 0, 0, 0);
136 colors.font = QColor(255, 255, 255);
137 colors.led_on = QColor(255, 255, 0);
138 colors.led_off = QColor(170, 238, 255);
139
140 colors.left = colors.primary;
141 colors.right = colors.primary;
142 // Possible alternative to set colors from settings
143 // colors.left = QColor(Settings::values.players.GetValue()[player_index].body_color_left);
144 // colors.right = QColor(Settings::values.players.GetValue()[player_index].body_color_right);
145}
146
147void PlayerControlPreview::paintEvent(QPaintEvent* event) {
148 QFrame::paintEvent(event);
149 QPainter p(this);
150 p.setRenderHint(QPainter::Antialiasing);
151 const QPointF center = rect().center();
152
153 const auto& button_state = buttons;
154 for (std::size_t index = 0; index < button_values.size(); ++index) {
155 bool value = false;
156 if (index < Settings::NativeButton::BUTTON_NS_END) {
157 value = button_state[index]->GetStatus();
158 }
159 bool blink = mapping_active && index == button_mapping_index;
160 if (analog_mapping_index == Settings::NativeAnalog::NUM_STICKS_HID) {
161 blink &= blink_counter > 12;
162 }
163 button_values[index] = value || blink;
164 }
165
166 const auto& analog_state = sticks;
167 for (std::size_t index = 0; index < axis_values.size(); ++index) {
168 const auto [stick_x_f, stick_y_f] = analog_state[index]->GetStatus();
169 const auto [stick_x_rf, stick_y_rf] = analog_state[index]->GetRawStatus();
170 axis_values[index].properties = analog_state[index]->GetAnalogProperties();
171 axis_values[index].value = QPointF(stick_x_f, -stick_y_f);
172 axis_values[index].raw_value = QPointF(stick_x_rf, -stick_y_rf);
173
174 const bool blink_analog = mapping_active && index == analog_mapping_index;
175 if (blink_analog) {
176 axis_values[index].value =
177 QPointF(blink_counter < 12 ? -blink_counter / 12.0f : 0,
178 blink_counter > 12 ? -(blink_counter - 12) / 12.0f : 0);
179 }
180 }
181 switch (controller_type) {
182 case Settings::ControllerType::Handheld:
183 DrawHandheldController(p, center);
184 break;
185 case Settings::ControllerType::DualJoyconDetached:
186 DrawDualController(p, center);
187 break;
188 case Settings::ControllerType::LeftJoycon:
189 DrawLeftController(p, center);
190 break;
191 case Settings::ControllerType::RightJoycon:
192 DrawRightController(p, center);
193 break;
194 case Settings::ControllerType::ProController:
195 default:
196 DrawProController(p, center);
197 break;
198 }
199 if (mapping_active) {
200 blink_counter = (blink_counter + 1) % 24;
201 }
202}
203
204void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) {
205 {
206 using namespace Settings::NativeButton;
207
208 // Sideview left joystick
209 DrawJoystickSideview(p, center + QPoint(142, -69),
210 -axis_values[Settings::NativeAnalog::LStick].value.y(), 1.15f,
211 button_values[LStick]);
212
213 // Left trigger
214 p.setPen(colors.outline);
215 button_color = colors.button;
216 DrawLeftTriggers(p, center, button_values[L]);
217 DrawRoundButton(p, center + QPoint(151, -146), button_values[L], 8, 4, Direction::Down);
218 DrawLeftZTriggers(p, center, button_values[ZL]);
219
220 // Sideview D-pad buttons
221 DrawRoundButton(p, center + QPoint(135, 14), button_values[DLeft], 5, 11, Direction::Right);
222 DrawRoundButton(p, center + QPoint(135, 36), button_values[DDown], 5, 11, Direction::Right);
223 DrawRoundButton(p, center + QPoint(135, -10), button_values[DUp], 5, 11, Direction::Right);
224 DrawRoundButton(p, center + QPoint(135, 14), button_values[DRight], 5, 11,
225 Direction::Right);
226 DrawRoundButton(p, center + QPoint(135, 71), button_values[Screenshot], 3, 8,
227 Direction::Right, 1);
228
229 // Sideview minus button
230 DrawRoundButton(p, center + QPoint(135, -118), button_values[Minus], 4, 2.66f,
231 Direction::Right, 1);
232
233 // Sideview SL and SR buttons
234 button_color = colors.slider_button;
235 DrawRoundButton(p, center + QPoint(59, 52), button_values[SR], 5, 12, Direction::Left);
236 DrawRoundButton(p, center + QPoint(59, -69), button_values[SL], 5, 12, Direction::Left);
237 }
238
239 DrawLeftBody(p, center);
240
241 { // Draw joysticks
242 using namespace Settings::NativeAnalog;
243 DrawJoystick(p, center + QPointF(9, -69) + (axis_values[LStick].value * 8), 1.8f,
244 button_values[Settings::NativeButton::LStick]);
245 DrawRawJoystick(p, rect().bottomLeft() + QPointF(45, -45), axis_values[LStick].raw_value,
246 axis_values[LStick].properties);
247 }
248
249 using namespace Settings::NativeButton;
250
251 // D-pad constants
252 const QPointF dpad_center = center + QPoint(9, 14);
253 const int dpad_distance = 23;
254 const int dpad_radius = 11;
255 const float dpad_arrow_size = 1.2f;
256
257 // D-pad buttons
258 p.setPen(colors.outline);
259 button_color = colors.button;
260 DrawCircleButton(p, dpad_center + QPoint(dpad_distance, 0), button_values[DRight], dpad_radius);
261 DrawCircleButton(p, dpad_center + QPoint(0, dpad_distance), button_values[DDown], dpad_radius);
262 DrawCircleButton(p, dpad_center + QPoint(0, -dpad_distance), button_values[DUp], dpad_radius);
263 DrawCircleButton(p, dpad_center + QPoint(-dpad_distance, 0), button_values[DLeft], dpad_radius);
264
265 // D-pad arrows
266 p.setPen(colors.font2);
267 p.setBrush(colors.font2);
268 DrawArrow(p, dpad_center + QPoint(dpad_distance, 0), Direction::Right, dpad_arrow_size);
269 DrawArrow(p, dpad_center + QPoint(0, dpad_distance), Direction::Down, dpad_arrow_size);
270 DrawArrow(p, dpad_center + QPoint(0, -dpad_distance), Direction::Up, dpad_arrow_size);
271 DrawArrow(p, dpad_center + QPoint(-dpad_distance, 0), Direction::Left, dpad_arrow_size);
272
273 // SR and SL buttons
274 p.setPen(colors.outline);
275 button_color = colors.slider_button;
276 DrawRoundButton(p, center + QPoint(155, 52), button_values[SR], 5.2f, 12, Direction::None, 4);
277 DrawRoundButton(p, center + QPoint(155, -69), button_values[SL], 5.2f, 12, Direction::None, 4);
278
279 // SR and SL text
280 SetTextFont(p, 5.7f);
281 p.setPen(colors.outline);
282 p.rotate(90);
283 p.drawText(QPointF(center.y() - 5, -center.x() + 3) + QPointF(52, -155), tr("SR"));
284 p.drawText(QPointF(center.y() - 5, -center.x() + 3) + QPointF(-69, -155), tr("SL"));
285 p.rotate(-90);
286
287 // Minus button
288 button_color = colors.button;
289 DrawMinusButton(p, center + QPoint(39, -118), button_values[Minus], 16);
290
291 // Screenshot button
292 DrawRoundButton(p, center + QPoint(26, 71), button_values[Screenshot], 8, 8);
293 p.setPen(colors.font2);
294 p.setBrush(colors.font2);
295 DrawCircle(p, center + QPoint(26, 71), 5);
296}
297
298void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center) {
299 {
300 using namespace Settings::NativeButton;
301
302 // Sideview right joystick
303 DrawJoystickSideview(p, center + QPoint(173 - 315, 11),
304 axis_values[Settings::NativeAnalog::RStick].value.y() + 10.0f, 1.15f,
305 button_values[Settings::NativeButton::RStick]);
306
307 // Right trigger
308 p.setPen(colors.outline);
309 button_color = colors.button;
310 DrawRightTriggers(p, center, button_values[R]);
311 DrawRoundButton(p, center + QPoint(-151, -146), button_values[R], 8, 4, Direction::Down);
312 DrawRightZTriggers(p, center, button_values[ZR]);
313
314 // Sideview face buttons
315 DrawRoundButton(p, center + QPoint(-135, -73), button_values[A], 5, 11, Direction::Left);
316 DrawRoundButton(p, center + QPoint(-135, -50), button_values[B], 5, 11, Direction::Left);
317 DrawRoundButton(p, center + QPoint(-135, -95), button_values[X], 5, 11, Direction::Left);
318 DrawRoundButton(p, center + QPoint(-135, -73), button_values[Y], 5, 11, Direction::Left);
319
320 // Sideview home and plus button
321 DrawRoundButton(p, center + QPoint(-135, 66), button_values[Home], 3, 12, Direction::Left);
322 DrawRoundButton(p, center + QPoint(-135, -118), button_values[Plus], 4, 8, Direction::Left,
323 1);
324 DrawRoundButton(p, center + QPoint(-135, -118), button_values[Plus], 4, 2.66f,
325 Direction::Left, 1);
326
327 // Sideview SL and SR buttons
328 button_color = colors.slider_button;
329 DrawRoundButton(p, center + QPoint(-59, 52), button_values[SL], 5, 11, Direction::Right);
330 DrawRoundButton(p, center + QPoint(-59, -69), button_values[SR], 5, 11, Direction::Right);
331 }
332
333 DrawRightBody(p, center);
334
335 { // Draw joysticks
336 using namespace Settings::NativeAnalog;
337 DrawJoystick(p, center + QPointF(-9, 11) + (axis_values[RStick].value * 8), 1.8f,
338 button_values[Settings::NativeButton::RStick]);
339 DrawRawJoystick(p, rect().bottomRight() + QPointF(-45, -45), axis_values[RStick].raw_value,
340 axis_values[RStick].properties);
341 }
342
343 using namespace Settings::NativeButton;
344
345 // Face buttons constants
346 const QPointF face_center = center + QPoint(-9, -73);
347 const int face_distance = 23;
348 const int face_radius = 11;
349
350 // Face buttons
351 p.setPen(colors.outline);
352 button_color = colors.button;
353 DrawCircleButton(p, face_center + QPoint(face_distance, 0), button_values[A], face_radius);
354 DrawCircleButton(p, face_center + QPoint(0, face_distance), button_values[B], face_radius);
355 DrawCircleButton(p, face_center + QPoint(0, -face_distance), button_values[X], face_radius);
356 DrawCircleButton(p, face_center + QPoint(-face_distance, 0), button_values[Y], face_radius);
357
358 // Face buttons text
359 p.setPen(colors.font);
360 DrawText(p, face_center + QPoint(face_distance, 0), 10, QStringLiteral("A"));
361 DrawText(p, face_center + QPoint(0, face_distance), 10, QStringLiteral("B"));
362 DrawText(p, face_center + QPoint(0, -face_distance), 10, QStringLiteral("X"));
363 DrawText(p, face_center + QPoint(-face_distance + 1, 1), 10, QStringLiteral("Y"));
364
365 // SR and SL buttons
366 p.setPen(colors.outline);
367 button_color = colors.slider_button;
368 DrawRoundButton(p, center + QPoint(-155, 52), button_values[SL], 5, 12, Direction::None, 4.0f);
369 DrawRoundButton(p, center + QPoint(-155, -69), button_values[SR], 5, 12, Direction::None, 4.0f);
370
371 // SR and SL text
372 SetTextFont(p, 5.7f);
373 p.setPen(colors.outline);
374 p.rotate(-90);
375 p.drawText(QPointF(-center.y() - 5, center.x() + 3) + QPointF(-52, -155), tr("SL"));
376 p.drawText(QPointF(-center.y() - 5, center.x() + 3) + QPointF(69, -155), tr("SR"));
377 p.rotate(90);
378
379 // Plus Button
380 DrawPlusButton(p, center + QPoint(-40, -118), button_values[Plus], 16);
381
382 // Home Button
383 p.setPen(colors.outline);
384 button_color = colors.slider_button;
385 DrawCircleButton(p, center + QPoint(-26, 66), button_values[Home], 12);
386 button_color = colors.button;
387 DrawCircleButton(p, center + QPoint(-26, 66), button_values[Home], 9);
388 DrawHouseIcon(p, center + QPoint(-26, 66), 5);
389}
390
391void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) {
392 {
393 using namespace Settings::NativeButton;
394
395 // Sideview joystick
396 DrawJoystickSideview(p, center + QPoint(-174, -65),
397 -axis_values[Settings::NativeAnalog::LStick].value.y(), 1.0f,
398 button_values[LStick]);
399 DrawJoystickSideview(p, center + QPoint(174, 12),
400 axis_values[Settings::NativeAnalog::RStick].value.y() + 10.0f, 1.0f,
401 button_values[RStick]);
402
403 // Left/Right trigger
404 DrawDualTriggers(p, center, button_values[L], button_values[R]);
405 DrawDualZTriggers(p, center, button_values[ZL], button_values[ZR]);
406
407 // sideview Left and Right trigger
408 p.setPen(colors.outline);
409 button_color = colors.button;
410 DrawRoundButton(p, center + QPoint(-166, -131), button_values[L], 7, 4, Direction::Down);
411 DrawRoundButton(p, center + QPoint(166, -131), button_values[R], 7, 4, Direction::Down);
412
413 // Sideview face buttons
414 DrawRoundButton(p, center + QPoint(180, -65), button_values[A], 5, 10, Direction::Left);
415 DrawRoundButton(p, center + QPoint(180, -45), button_values[B], 5, 10, Direction::Left);
416 DrawRoundButton(p, center + QPoint(180, -85), button_values[X], 5, 10, Direction::Left);
417 DrawRoundButton(p, center + QPoint(180, -65), button_values[Y], 5, 10, Direction::Left);
418
419 // Sideview D-pad buttons
420 DrawRoundButton(p, center + QPoint(-180, 12), button_values[DLeft], 5, 10,
421 Direction::Right);
422 DrawRoundButton(p, center + QPoint(-180, 33), button_values[DDown], 5, 10,
423 Direction::Right);
424 DrawRoundButton(p, center + QPoint(-180, -8), button_values[DUp], 5, 10, Direction::Right);
425 DrawRoundButton(p, center + QPoint(-180, 12), button_values[DRight], 5, 10,
426 Direction::Right);
427
428 // Sideview home and plus button
429 DrawRoundButton(p, center + QPoint(180, 60), button_values[Home], 3, 11, Direction::Left);
430 DrawRoundButton(p, center + QPoint(180, -106), button_values[Plus], 4, 7, Direction::Left,
431 1);
432 DrawRoundButton(p, center + QPoint(180, -106), button_values[Plus], 4, 2.33f,
433 Direction::Left, 1);
434
435 // Sideview screenshot and minus button
436 DrawRoundButton(p, center + QPoint(-180, 63), button_values[Screenshot], 3, 8,
437 Direction::Right, 1);
438 DrawRoundButton(p, center + QPoint(-180, -106), button_values[Minus], 4, 2.66f,
439 Direction::Right, 1);
440 }
441
442 DrawDualBody(p, center);
443
444 { // Draw joysticks
445 using namespace Settings::NativeAnalog;
446 DrawJoystick(p, center + QPointF(-65, -65) + (axis_values[LStick].value * 7), 1.62f,
447 button_values[Settings::NativeButton::LStick]);
448 DrawJoystick(p, center + QPointF(65, 12) + (axis_values[RStick].value * 7), 1.62f,
449 button_values[Settings::NativeButton::RStick]);
450 DrawRawJoystick(p, rect().bottomLeft() + QPointF(45, -45), axis_values[LStick].raw_value,
451 axis_values[LStick].properties);
452 DrawRawJoystick(p, rect().bottomRight() + QPointF(-45, -45), axis_values[RStick].raw_value,
453 axis_values[RStick].properties);
454 }
455
456 using namespace Settings::NativeButton;
457
458 // Face buttons constants
459 const QPointF face_center = center + QPoint(65, -65);
460 const int face_distance = 20;
461 const int face_radius = 10;
462 const int text_size = 10;
463
464 // Face buttons
465 p.setPen(colors.outline);
466 button_color = colors.button;
467 DrawCircleButton(p, face_center + QPoint(face_distance, 0), button_values[A], face_radius);
468 DrawCircleButton(p, face_center + QPoint(0, face_distance), button_values[B], face_radius);
469 DrawCircleButton(p, face_center + QPoint(0, -face_distance), button_values[X], face_radius);
470 DrawCircleButton(p, face_center + QPoint(-face_distance, 0), button_values[Y], face_radius);
471
472 // Face buttons text
473 p.setPen(colors.font);
474 DrawText(p, face_center + QPoint(face_distance, 0), text_size, QStringLiteral("A"));
475 DrawText(p, face_center + QPoint(0, face_distance), text_size, QStringLiteral("B"));
476 DrawText(p, face_center + QPoint(0, -face_distance), text_size, QStringLiteral("X"));
477 DrawText(p, face_center + QPointF(-face_distance + 0.5f, 1), text_size, QStringLiteral("Y"));
478
479 // D-pad constants
480 const QPointF dpad_center = center + QPoint(-65, 12);
481 const int dpad_distance = 20;
482 const int dpad_radius = 10;
483 const float dpad_arrow_size = 1.1f;
484
485 // D-pad buttons
486 p.setPen(colors.outline);
487 button_color = colors.button;
488 DrawCircleButton(p, dpad_center + QPoint(dpad_distance, 0), button_values[DRight], dpad_radius);
489 DrawCircleButton(p, dpad_center + QPoint(0, dpad_distance), button_values[DDown], dpad_radius);
490 DrawCircleButton(p, dpad_center + QPoint(0, -dpad_distance), button_values[DUp], dpad_radius);
491 DrawCircleButton(p, dpad_center + QPoint(-dpad_distance, 0), button_values[DLeft], dpad_radius);
492
493 // D-pad arrows
494 p.setPen(colors.font2);
495 p.setBrush(colors.font2);
496 DrawArrow(p, dpad_center + QPoint(dpad_distance, 0), Direction::Right, dpad_arrow_size);
497 DrawArrow(p, dpad_center + QPoint(0, dpad_distance), Direction::Down, dpad_arrow_size);
498 DrawArrow(p, dpad_center + QPoint(0, -dpad_distance), Direction::Up, dpad_arrow_size);
499 DrawArrow(p, dpad_center + QPoint(-dpad_distance, 0), Direction::Left, dpad_arrow_size);
500
501 // Minus and Plus button
502 button_color = colors.button;
503 DrawMinusButton(p, center + QPoint(-39, -106), button_values[Minus], 14);
504 DrawPlusButton(p, center + QPoint(39, -106), button_values[Plus], 14);
505
506 // Screenshot button
507 p.setPen(colors.outline);
508 DrawRoundButton(p, center + QPoint(-52, 63), button_values[Screenshot], 8, 8);
509 p.setPen(colors.font2);
510 p.setBrush(colors.font2);
511 DrawCircle(p, center + QPoint(-52, 63), 5);
512
513 // Home Button
514 p.setPen(colors.outline);
515 button_color = colors.slider_button;
516 DrawCircleButton(p, center + QPoint(50, 60), button_values[Home], 11);
517 button_color = colors.button;
518 DrawCircleButton(p, center + QPoint(50, 60), button_values[Home], 8.5f);
519 DrawHouseIcon(p, center + QPoint(50, 60), 4.2f);
520}
521
522void PlayerControlPreview::DrawHandheldController(QPainter& p, const QPointF center) {
523 DrawHandheldTriggers(p, center, button_values[Settings::NativeButton::L],
524 button_values[Settings::NativeButton::R]);
525 DrawHandheldBody(p, center);
526 { // Draw joysticks
527 using namespace Settings::NativeAnalog;
528 DrawJoystick(p, center + QPointF(-171, -41) + (axis_values[LStick].value * 4), 1.0f,
529 button_values[Settings::NativeButton::LStick]);
530 DrawJoystick(p, center + QPointF(171, 8) + (axis_values[RStick].value * 4), 1.0f,
531 button_values[Settings::NativeButton::RStick]);
532 DrawRawJoystick(p, center + QPointF(-45, 0), axis_values[LStick].raw_value,
533 axis_values[LStick].properties);
534 DrawRawJoystick(p, center + QPointF(45, 0), axis_values[RStick].raw_value,
535 axis_values[RStick].properties);
536 }
537
538 using namespace Settings::NativeButton;
539
540 // Face buttons constants
541 const QPointF face_center = center + QPoint(171, -41);
542 const int face_distance = 12;
543 const int face_radius = 6;
544 const float text_size = 5.5f;
545
546 // Face buttons
547 p.setPen(colors.outline);
548 button_color = colors.button;
549 DrawCircleButton(p, face_center + QPoint(face_distance, 0), button_values[A], face_radius);
550 DrawCircleButton(p, face_center + QPoint(0, face_distance), button_values[B], face_radius);
551 DrawCircleButton(p, face_center + QPoint(0, -face_distance), button_values[X], face_radius);
552 DrawCircleButton(p, face_center + QPoint(-face_distance, 0), button_values[Y], face_radius);
553
554 // Face buttons text
555 p.setPen(colors.font);
556 DrawText(p, face_center + QPointF(face_distance + 0.2f, 0), text_size, QStringLiteral("A"));
557 DrawText(p, face_center + QPoint(0, face_distance), text_size, QStringLiteral("B"));
558 DrawText(p, face_center + QPoint(0, -face_distance), text_size, QStringLiteral("X"));
559 DrawText(p, face_center + QPointF(-face_distance + 0.2f, 0), text_size, QStringLiteral("Y"));
560
561 // D-pad constants
562 const QPointF dpad_center = center + QPoint(-171, 8);
563 const int dpad_distance = 12;
564 const int dpad_radius = 6;
565 const float dpad_arrow_size = 0.68f;
566
567 // D-pad buttons
568 p.setPen(colors.outline);
569 button_color = colors.button;
570 DrawCircleButton(p, dpad_center + QPoint(dpad_distance, 0), button_values[DRight], dpad_radius);
571 DrawCircleButton(p, dpad_center + QPoint(0, dpad_distance), button_values[DDown], dpad_radius);
572 DrawCircleButton(p, dpad_center + QPoint(0, -dpad_distance), button_values[DUp], dpad_radius);
573 DrawCircleButton(p, dpad_center + QPoint(-dpad_distance, 0), button_values[DLeft], dpad_radius);
574
575 // D-pad arrows
576 p.setPen(colors.font2);
577 p.setBrush(colors.font2);
578 DrawArrow(p, dpad_center + QPoint(dpad_distance, 0), Direction::Right, dpad_arrow_size);
579 DrawArrow(p, dpad_center + QPoint(0, dpad_distance), Direction::Down, dpad_arrow_size);
580 DrawArrow(p, dpad_center + QPoint(0, -dpad_distance), Direction::Up, dpad_arrow_size);
581 DrawArrow(p, dpad_center + QPoint(-dpad_distance, 0), Direction::Left, dpad_arrow_size);
582
583 // ZL and ZR buttons
584 p.setPen(colors.outline);
585 DrawCircleButton(p, center + QPoint(-175, -120), button_values[ZL], 15);
586 DrawCircleButton(p, center + QPoint(175, -120), button_values[ZR], 15);
587 p.setPen(colors.font);
588 DrawText(p, center + QPoint(-175, -120), 9, QStringLiteral("ZL"));
589 DrawText(p, center + QPoint(175, -120), 9, QStringLiteral("ZR"));
590
591 // Minus and Plus button
592 p.setPen(colors.outline);
593 button_color = colors.button;
594 DrawMinusButton(p, center + QPoint(-155, -67), button_values[Minus], 8);
595 DrawPlusButton(p, center + QPoint(155, -67), button_values[Plus], 8);
596
597 // Screenshot button
598 p.setPen(colors.outline);
599 DrawRoundButton(p, center + QPoint(-162, 39), button_values[Screenshot], 5, 5);
600 p.setPen(colors.font2);
601 p.setBrush(colors.font2);
602 DrawCircle(p, center + QPoint(-162, 39), 3);
603
604 // Home Button
605 p.setPen(colors.outline);
606 button_color = colors.slider_button;
607 DrawCircleButton(p, center + QPoint(161, 37), button_values[Home], 7);
608 button_color = colors.button;
609 DrawCircleButton(p, center + QPoint(161, 37), button_values[Home], 5);
610 DrawHouseIcon(p, center + QPoint(161, 37), 2.75f);
611}
612
613void PlayerControlPreview::DrawProController(QPainter& p, const QPointF center) {
614 DrawProTriggers(p, center, button_values[Settings::NativeButton::L],
615 button_values[Settings::NativeButton::R]);
616 DrawProBody(p, center);
617 { // Draw joysticks
618 using namespace Settings::NativeAnalog;
619 DrawProJoystick(p, center + QPointF(-111, -55) + (axis_values[LStick].value * 11),
620 button_values[Settings::NativeButton::LStick]);
621 DrawProJoystick(p, center + QPointF(51, 0) + (axis_values[RStick].value * 11),
622 button_values[Settings::NativeButton::RStick]);
623 DrawRawJoystick(p, QPointF(center.x(), rect().bottom()) + QPointF(-45, -45),
624 axis_values[LStick].raw_value, axis_values[LStick].properties);
625 DrawRawJoystick(p, QPointF(center.x(), rect().bottom()) + QPointF(45, -45),
626 axis_values[RStick].raw_value, axis_values[RStick].properties);
627 }
628
629 using namespace Settings::NativeButton;
630
631 // Face buttons constants
632 const QPointF face_center = center + QPoint(105, -56);
633 const int face_distance = 31;
634 const int face_radius = 15;
635 const int text_size = 13;
636
637 // Face buttons
638 p.setPen(colors.outline);
639 button_color = colors.button;
640 DrawCircleButton(p, face_center + QPoint(face_distance, 0), button_values[A], face_radius);
641 DrawCircleButton(p, face_center + QPoint(0, face_distance), button_values[B], face_radius);
642 DrawCircleButton(p, face_center + QPoint(0, -face_distance), button_values[X], face_radius);
643 DrawCircleButton(p, face_center + QPoint(-face_distance, 0), button_values[Y], face_radius);
644
645 // Face buttons text
646 p.setPen(colors.font);
647 DrawText(p, face_center + QPoint(face_distance, 0), text_size, QStringLiteral("A"));
648 DrawText(p, face_center + QPoint(0, face_distance), text_size, QStringLiteral("B"));
649 DrawText(p, face_center + QPoint(0, -face_distance), text_size, QStringLiteral("X"));
650 DrawText(p, face_center + QPoint(-face_distance, 1), text_size, QStringLiteral("Y"));
651
652 // D-pad buttons
653 const QPointF dpad_postion = center + QPoint(-61, 0);
654 DrawArrowButton(p, dpad_postion, Direction::Up, button_values[DUp]);
655 DrawArrowButton(p, dpad_postion, Direction::Left, button_values[DLeft]);
656 DrawArrowButton(p, dpad_postion, Direction::Right, button_values[DRight]);
657 DrawArrowButton(p, dpad_postion, Direction::Down, button_values[DDown]);
658
659 // ZL and ZR buttons
660 p.setPen(colors.outline);
661 DrawCircleButton(p, center + QPoint(-175, -120), button_values[ZL], 15);
662 DrawCircleButton(p, center + QPoint(175, -120), button_values[ZR], 15);
663 p.setPen(colors.font);
664 DrawText(p, center + QPoint(-175, -120), 9, QStringLiteral("ZL"));
665 DrawText(p, center + QPoint(175, -120), 9, QStringLiteral("ZR"));
666
667 // Minus and Plus buttons
668 p.setPen(colors.outline);
669 DrawCircleButton(p, center + QPoint(-50, -86), button_values[Minus], 9);
670 DrawCircleButton(p, center + QPoint(49, -86), button_values[Plus], 9);
671 p.setPen(colors.font2);
672 p.setBrush(colors.font2);
673 DrawRectangle(p, center + QPoint(-50, -86), 8, 2);
674 DrawText(p, center + QPointF(49.5f, -86), 12, QStringLiteral("+"));
675
676 // Screenshot button
677 p.setPen(colors.outline);
678 DrawRoundButton(p, center + QPoint(-29, -56), button_values[Screenshot], 7, 7);
679 p.setPen(colors.font2);
680 p.setBrush(colors.font2);
681 DrawCircle(p, center + QPoint(-29, -56), 4.5f);
682
683 // Home Button
684 p.setPen(colors.outline);
685 button_color = colors.slider_button;
686 DrawCircleButton(p, center + QPoint(29, -56), button_values[Home], 9);
687 button_color = colors.button;
688 DrawCircleButton(p, center + QPoint(29, -56), button_values[Home], 7.1f);
689 DrawHouseIcon(p, center + QPoint(29, -56), 3.9f);
690}
691
692constexpr std::array<float, 12 * 2> house = {
693 -1.3f, 0.0f, -0.93f, 0.0f, -0.93f, 1.15f, 0.93f, 1.15f, 0.93f, 0.0f, 1.3f, 0.0f,
694 0.0f, -1.2f, -1.3f, 0.0f, -0.43f, 0.0f, -0.43f, .73f, 0.43f, .73f, 0.43f, 0.0f,
695};
696
697constexpr std::array<float, 15 * 2> up_arrow_button = {
698 -8.6f, -30.0f, -9.0f, -29.8f, -9.3f, -29.5f, -9.5f, -29.1f, -9.5f, -28.7f,
699 -9.1f, -9.1f, -8.8f, -8.8f, 0.3f, -0.3f, 0.6f, -0.6f, 9.4f, -9.8f,
700 9.4f, -10.2f, 8.9f, -29.8f, 8.5f, -30.0f, 8.1f, -30.1f, 7.7f, -30.1f,
701};
702
703constexpr std::array<float, 3 * 2> up_arrow_symbol = {
704 0.0f, -3.0f, -3.0f, 2.0f, 3.0f, 2.0f,
705};
706
707constexpr std::array<float, 13 * 2> up_arrow = {
708 9.4f, -9.8f, 9.4f, -10.2f, 8.9f, -29.8f, 8.5f, -30.0f, 8.1f,
709 -30.1f, 7.7f, -30.1f, -8.6f, -30.0f, -9.0f, -29.8f, -9.3f, -29.5f,
710 -9.5f, -29.1f, -9.5f, -28.7f, -9.1f, -9.1f, -8.8f, -8.8f,
711};
712
713constexpr std::array<float, 36 * 2> pro_left_trigger = {
714 -65.2f, -132.6f, -68.2f, -134.1f, -71.3f, -135.5f, -74.4f, -136.7f, -77.6f,
715 -137.6f, -80.9f, -138.1f, -84.3f, -138.3f, -87.6f, -138.3f, -91.0f, -138.1f,
716 -94.3f, -137.8f, -97.6f, -137.3f, -100.9f, -136.7f, -107.5f, -135.3f, -110.7f,
717 -134.5f, -120.4f, -131.8f, -123.6f, -130.8f, -126.8f, -129.7f, -129.9f, -128.5f,
718 -132.9f, -127.1f, -135.9f, -125.6f, -138.8f, -123.9f, -141.6f, -122.0f, -144.1f,
719 -119.8f, -146.3f, -117.3f, -148.4f, -114.7f, -150.4f, -112.0f, -152.3f, -109.2f,
720 -155.3f, -104.0f, -152.0f, -104.3f, -148.7f, -104.5f, -145.3f, -104.8f, -35.5f,
721 -117.2f, -38.5f, -118.7f, -41.4f, -120.3f, -44.4f, -121.8f, -50.4f, -124.9f,
722};
723
724constexpr std::array<float, 14 * 2> pro_body_top = {
725 0.0f, -115.4f, -4.4f, -116.1f, -69.7f, -131.3f, -66.4f, -131.9f, -63.1f, -132.3f,
726 -56.4f, -133.0f, -53.1f, -133.3f, -49.8f, -133.5f, -43.1f, -133.8f, -39.8f, -134.0f,
727 -36.5f, -134.1f, -16.4f, -134.4f, -13.1f, -134.4f, 0.0f, -134.1f,
728};
729
730constexpr std::array<float, 145 * 2> pro_left_handle = {
731 -178.7f, -47.5f, -179.0f, -46.1f, -179.3f, -44.6f, -182.0f, -29.8f, -182.3f, -28.4f,
732 -182.6f, -26.9f, -182.8f, -25.4f, -183.1f, -23.9f, -183.3f, -22.4f, -183.6f, -21.0f,
733 -183.8f, -19.5f, -184.1f, -18.0f, -184.3f, -16.5f, -184.6f, -15.1f, -184.8f, -13.6f,
734 -185.1f, -12.1f, -185.3f, -10.6f, -185.6f, -9.1f, -185.8f, -7.7f, -186.1f, -6.2f,
735 -186.3f, -4.7f, -186.6f, -3.2f, -186.8f, -1.7f, -187.1f, -0.3f, -187.3f, 1.2f,
736 -187.6f, 2.7f, -187.8f, 4.2f, -188.3f, 7.1f, -188.5f, 8.6f, -188.8f, 10.1f,
737 -189.0f, 11.6f, -189.3f, 13.1f, -189.5f, 14.5f, -190.0f, 17.5f, -190.2f, 19.0f,
738 -190.5f, 20.5f, -190.7f, 21.9f, -191.2f, 24.9f, -191.4f, 26.4f, -191.7f, 27.9f,
739 -191.9f, 29.3f, -192.4f, 32.3f, -192.6f, 33.8f, -193.1f, 36.8f, -193.3f, 38.2f,
740 -193.8f, 41.2f, -194.0f, 42.7f, -194.7f, 47.1f, -194.9f, 48.6f, -199.0f, 82.9f,
741 -199.1f, 84.4f, -199.1f, 85.9f, -199.2f, 87.4f, -199.2f, 88.9f, -199.1f, 94.9f,
742 -198.9f, 96.4f, -198.8f, 97.8f, -198.5f, 99.3f, -198.3f, 100.8f, -198.0f, 102.3f,
743 -197.7f, 103.7f, -197.4f, 105.2f, -197.0f, 106.7f, -196.6f, 108.1f, -195.7f, 111.0f,
744 -195.2f, 112.4f, -194.1f, 115.2f, -193.5f, 116.5f, -192.8f, 117.9f, -192.1f, 119.2f,
745 -190.6f, 121.8f, -189.8f, 123.1f, -188.9f, 124.3f, -187.0f, 126.6f, -186.0f, 127.7f,
746 -183.9f, 129.8f, -182.7f, 130.8f, -180.3f, 132.6f, -179.1f, 133.4f, -177.8f, 134.1f,
747 -176.4f, 134.8f, -175.1f, 135.5f, -173.7f, 136.0f, -169.4f, 137.3f, -167.9f, 137.7f,
748 -166.5f, 138.0f, -165.0f, 138.3f, -163.5f, 138.4f, -162.0f, 138.4f, -160.5f, 138.3f,
749 -159.0f, 138.0f, -157.6f, 137.7f, -156.1f, 137.3f, -154.7f, 136.9f, -153.2f, 136.5f,
750 -151.8f, 136.0f, -150.4f, 135.4f, -149.1f, 134.8f, -147.7f, 134.1f, -146.5f, 133.3f,
751 -145.2f, 132.5f, -144.0f, 131.6f, -142.8f, 130.6f, -141.7f, 129.6f, -139.6f, 127.5f,
752 -138.6f, 126.4f, -137.7f, 125.2f, -135.1f, 121.5f, -134.3f, 120.3f, -133.5f, 119.0f,
753 -131.9f, 116.5f, -131.1f, 115.2f, -128.8f, 111.3f, -128.0f, 110.1f, -127.2f, 108.8f,
754 -126.5f, 107.5f, -125.7f, 106.2f, -125.0f, 104.9f, -124.2f, 103.6f, -123.5f, 102.3f,
755 -122.0f, 99.6f, -121.3f, 98.3f, -115.8f, 87.7f, -115.1f, 86.4f, -114.4f, 85.0f,
756 -113.7f, 83.7f, -112.3f, 81.0f, -111.6f, 79.7f, -110.1f, 77.1f, -109.4f, 75.8f,
757 -108.0f, 73.1f, -107.2f, 71.8f, -106.4f, 70.6f, -105.7f, 69.3f, -104.8f, 68.0f,
758 -104.0f, 66.8f, -103.1f, 65.6f, -101.1f, 63.3f, -100.0f, 62.3f, -98.8f, 61.4f,
759 -97.6f, 60.6f, -97.9f, 59.5f, -98.8f, 58.3f, -101.5f, 54.6f, -102.4f, 53.4f,
760};
761
762constexpr std::array<float, 245 * 2> pro_body = {
763 -0.7f, -129.1f, -54.3f, -129.1f, -55.0f, -129.1f, -57.8f, -129.0f, -58.5f, -129.0f,
764 -60.7f, -128.9f, -61.4f, -128.9f, -62.8f, -128.8f, -63.5f, -128.8f, -65.7f, -128.7f,
765 -66.4f, -128.7f, -67.8f, -128.6f, -68.5f, -128.6f, -69.2f, -128.5f, -70.0f, -128.5f,
766 -70.7f, -128.4f, -71.4f, -128.4f, -72.1f, -128.3f, -72.8f, -128.3f, -73.5f, -128.2f,
767 -74.2f, -128.2f, -74.9f, -128.1f, -75.7f, -128.1f, -76.4f, -128.0f, -77.1f, -128.0f,
768 -77.8f, -127.9f, -78.5f, -127.9f, -79.2f, -127.8f, -80.6f, -127.7f, -81.4f, -127.6f,
769 -82.1f, -127.5f, -82.8f, -127.5f, -83.5f, -127.4f, -84.9f, -127.3f, -85.6f, -127.2f,
770 -87.0f, -127.1f, -87.7f, -127.0f, -88.5f, -126.9f, -89.2f, -126.8f, -89.9f, -126.8f,
771 -90.6f, -126.7f, -94.1f, -126.3f, -94.8f, -126.2f, -113.2f, -123.3f, -113.9f, -123.2f,
772 -114.6f, -123.0f, -115.3f, -122.9f, -116.7f, -122.6f, -117.4f, -122.5f, -118.1f, -122.3f,
773 -118.8f, -122.2f, -119.5f, -122.0f, -120.9f, -121.7f, -121.6f, -121.5f, -122.3f, -121.4f,
774 -122.9f, -121.2f, -123.6f, -121.0f, -126.4f, -120.3f, -127.1f, -120.1f, -127.8f, -119.8f,
775 -128.4f, -119.6f, -129.1f, -119.4f, -131.2f, -118.7f, -132.5f, -118.3f, -133.2f, -118.0f,
776 -133.8f, -117.7f, -134.5f, -117.4f, -135.1f, -117.2f, -135.8f, -116.9f, -136.4f, -116.5f,
777 -137.0f, -116.2f, -137.7f, -115.8f, -138.3f, -115.4f, -138.9f, -115.1f, -139.5f, -114.7f,
778 -160.0f, -100.5f, -160.5f, -100.0f, -162.5f, -97.9f, -162.9f, -97.4f, -163.4f, -96.8f,
779 -163.8f, -96.2f, -165.3f, -93.8f, -165.7f, -93.2f, -166.0f, -92.6f, -166.4f, -91.9f,
780 -166.7f, -91.3f, -167.3f, -90.0f, -167.6f, -89.4f, -167.8f, -88.7f, -168.1f, -88.0f,
781 -168.4f, -87.4f, -168.6f, -86.7f, -168.9f, -86.0f, -169.1f, -85.4f, -169.3f, -84.7f,
782 -169.6f, -84.0f, -169.8f, -83.3f, -170.2f, -82.0f, -170.4f, -81.3f, -172.8f, -72.3f,
783 -173.0f, -71.6f, -173.5f, -69.5f, -173.7f, -68.8f, -173.9f, -68.2f, -174.0f, -67.5f,
784 -174.2f, -66.8f, -174.5f, -65.4f, -174.7f, -64.7f, -174.8f, -64.0f, -175.0f, -63.3f,
785 -175.3f, -61.9f, -175.5f, -61.2f, -175.8f, -59.8f, -176.0f, -59.1f, -176.1f, -58.4f,
786 -176.3f, -57.7f, -176.6f, -56.3f, -176.8f, -55.6f, -176.9f, -54.9f, -177.1f, -54.2f,
787 -177.3f, -53.6f, -177.4f, -52.9f, -177.6f, -52.2f, -177.9f, -50.8f, -178.1f, -50.1f,
788 -178.2f, -49.4f, -178.2f, -48.7f, -177.8f, -48.1f, -177.1f, -46.9f, -176.7f, -46.3f,
789 -176.4f, -45.6f, -176.0f, -45.0f, -175.3f, -43.8f, -174.9f, -43.2f, -174.2f, -42.0f,
790 -173.4f, -40.7f, -173.1f, -40.1f, -172.7f, -39.5f, -172.0f, -38.3f, -171.6f, -37.7f,
791 -170.5f, -35.9f, -170.1f, -35.3f, -169.7f, -34.6f, -169.3f, -34.0f, -168.6f, -32.8f,
792 -168.2f, -32.2f, -166.3f, -29.2f, -165.9f, -28.6f, -163.2f, -24.4f, -162.8f, -23.8f,
793 -141.8f, 6.8f, -141.4f, 7.4f, -139.4f, 10.3f, -139.0f, 10.9f, -138.5f, 11.5f,
794 -138.1f, 12.1f, -137.3f, 13.2f, -136.9f, 13.8f, -136.0f, 15.0f, -135.6f, 15.6f,
795 -135.2f, 16.1f, -134.8f, 16.7f, -133.9f, 17.9f, -133.5f, 18.4f, -133.1f, 19.0f,
796 -131.8f, 20.7f, -131.4f, 21.3f, -130.1f, 23.0f, -129.7f, 23.6f, -128.4f, 25.3f,
797 -128.0f, 25.9f, -126.7f, 27.6f, -126.3f, 28.2f, -125.4f, 29.3f, -125.0f, 29.9f,
798 -124.1f, 31.0f, -123.7f, 31.6f, -122.8f, 32.7f, -122.4f, 33.3f, -121.5f, 34.4f,
799 -121.1f, 35.0f, -120.6f, 35.6f, -120.2f, 36.1f, -119.7f, 36.7f, -119.3f, 37.2f,
800 -118.9f, 37.8f, -118.4f, 38.4f, -118.0f, 38.9f, -117.5f, 39.5f, -117.1f, 40.0f,
801 -116.6f, 40.6f, -116.2f, 41.1f, -115.7f, 41.7f, -115.2f, 42.2f, -114.8f, 42.8f,
802 -114.3f, 43.3f, -113.9f, 43.9f, -113.4f, 44.4f, -112.4f, 45.5f, -112.0f, 46.0f,
803 -111.5f, 46.5f, -110.5f, 47.6f, -110.0f, 48.1f, -109.6f, 48.6f, -109.1f, 49.2f,
804 -108.6f, 49.7f, -107.7f, 50.8f, -107.2f, 51.3f, -105.7f, 52.9f, -105.3f, 53.4f,
805 -104.8f, 53.9f, -104.3f, 54.5f, -103.8f, 55.0f, -100.7f, 58.0f, -100.2f, 58.4f,
806 -99.7f, 58.9f, -99.1f, 59.3f, -97.2f, 60.3f, -96.5f, 60.1f, -95.9f, 59.7f,
807 -95.3f, 59.4f, -94.6f, 59.1f, -93.9f, 58.9f, -92.6f, 58.5f, -91.9f, 58.4f,
808 -91.2f, 58.2f, -90.5f, 58.1f, -89.7f, 58.0f, -89.0f, 57.9f, -86.2f, 57.6f,
809 -85.5f, 57.5f, -84.1f, 57.4f, -83.4f, 57.3f, -82.6f, 57.3f, -81.9f, 57.2f,
810 -81.2f, 57.2f, -80.5f, 57.1f, -79.8f, 57.1f, -78.4f, 57.0f, -77.7f, 57.0f,
811 -75.5f, 56.9f, -74.8f, 56.9f, -71.9f, 56.8f, -71.2f, 56.8f, 0.0f, 56.8f,
812};
813
814constexpr std::array<float, 84 * 2> left_joycon_body = {
815 -145.0f, -78.9f, -145.0f, -77.9f, -145.0f, 85.6f, -145.0f, 85.6f, -168.3f, 85.5f,
816 -169.3f, 85.4f, -171.3f, 85.1f, -172.3f, 84.9f, -173.4f, 84.7f, -174.3f, 84.5f,
817 -175.3f, 84.2f, -176.3f, 83.8f, -177.3f, 83.5f, -178.2f, 83.1f, -179.2f, 82.7f,
818 -180.1f, 82.2f, -181.0f, 81.8f, -181.9f, 81.3f, -182.8f, 80.7f, -183.7f, 80.2f,
819 -184.5f, 79.6f, -186.2f, 78.3f, -186.9f, 77.7f, -187.7f, 77.0f, -189.2f, 75.6f,
820 -189.9f, 74.8f, -190.6f, 74.1f, -191.3f, 73.3f, -191.9f, 72.5f, -192.5f, 71.6f,
821 -193.1f, 70.8f, -193.7f, 69.9f, -194.3f, 69.1f, -194.8f, 68.2f, -196.2f, 65.5f,
822 -196.6f, 64.5f, -197.0f, 63.6f, -197.4f, 62.6f, -198.1f, 60.7f, -198.4f, 59.7f,
823 -198.6f, 58.7f, -199.2f, 55.6f, -199.3f, 54.6f, -199.5f, 51.5f, -199.5f, 50.5f,
824 -199.5f, -49.4f, -199.4f, -50.5f, -199.3f, -51.5f, -199.1f, -52.5f, -198.2f, -56.5f,
825 -197.9f, -57.5f, -197.2f, -59.4f, -196.8f, -60.4f, -196.4f, -61.3f, -195.9f, -62.2f,
826 -194.3f, -64.9f, -193.7f, -65.7f, -193.1f, -66.6f, -192.5f, -67.4f, -191.8f, -68.2f,
827 -191.2f, -68.9f, -190.4f, -69.7f, -188.2f, -71.8f, -187.4f, -72.5f, -186.6f, -73.1f,
828 -185.8f, -73.8f, -185.0f, -74.4f, -184.1f, -74.9f, -183.2f, -75.5f, -182.4f, -76.0f,
829 -181.5f, -76.5f, -179.6f, -77.5f, -178.7f, -77.9f, -177.8f, -78.4f, -176.8f, -78.8f,
830 -175.9f, -79.1f, -174.9f, -79.5f, -173.9f, -79.8f, -170.9f, -80.6f, -169.9f, -80.8f,
831 -167.9f, -81.1f, -166.9f, -81.2f, -165.8f, -81.2f, -145.0f, -80.9f,
832};
833
834constexpr std::array<float, 84 * 2> left_joycon_trigger = {
835 -166.8f, -83.3f, -167.9f, -83.2f, -168.9f, -83.1f, -170.0f, -83.0f, -171.0f, -82.8f,
836 -172.1f, -82.6f, -173.1f, -82.4f, -174.2f, -82.1f, -175.2f, -81.9f, -176.2f, -81.5f,
837 -177.2f, -81.2f, -178.2f, -80.8f, -180.1f, -80.0f, -181.1f, -79.5f, -182.0f, -79.0f,
838 -183.0f, -78.5f, -183.9f, -78.0f, -184.8f, -77.4f, -185.7f, -76.9f, -186.6f, -76.3f,
839 -187.4f, -75.6f, -188.3f, -75.0f, -189.1f, -74.3f, -192.2f, -71.5f, -192.9f, -70.7f,
840 -193.7f, -69.9f, -194.3f, -69.1f, -195.0f, -68.3f, -195.6f, -67.4f, -196.8f, -65.7f,
841 -197.3f, -64.7f, -197.8f, -63.8f, -198.2f, -62.8f, -198.9f, -60.8f, -198.6f, -59.8f,
842 -197.6f, -59.7f, -196.6f, -60.0f, -195.6f, -60.5f, -194.7f, -60.9f, -193.7f, -61.4f,
843 -192.8f, -61.9f, -191.8f, -62.4f, -190.9f, -62.8f, -189.9f, -63.3f, -189.0f, -63.8f,
844 -187.1f, -64.8f, -186.2f, -65.2f, -185.2f, -65.7f, -184.3f, -66.2f, -183.3f, -66.7f,
845 -182.4f, -67.1f, -181.4f, -67.6f, -180.5f, -68.1f, -179.5f, -68.6f, -178.6f, -69.0f,
846 -177.6f, -69.5f, -176.7f, -70.0f, -175.7f, -70.5f, -174.8f, -70.9f, -173.8f, -71.4f,
847 -172.9f, -71.9f, -171.9f, -72.4f, -171.0f, -72.8f, -170.0f, -73.3f, -169.1f, -73.8f,
848 -168.1f, -74.3f, -167.2f, -74.7f, -166.2f, -75.2f, -165.3f, -75.7f, -164.3f, -76.2f,
849 -163.4f, -76.6f, -162.4f, -77.1f, -161.5f, -77.6f, -160.5f, -78.1f, -159.6f, -78.5f,
850 -158.7f, -79.0f, -157.7f, -79.5f, -156.8f, -80.0f, -155.8f, -80.4f, -154.9f, -80.9f,
851 -154.2f, -81.6f, -154.3f, -82.6f, -155.2f, -83.3f, -156.2f, -83.3f,
852};
853
854constexpr std::array<float, 70 * 2> handheld_body = {
855 -137.3f, -81.9f, -137.6f, -81.8f, -137.8f, -81.6f, -138.0f, -81.3f, -138.1f, -81.1f,
856 -138.1f, -80.8f, -138.2f, -78.7f, -138.2f, -78.4f, -138.3f, -78.1f, -138.7f, -77.3f,
857 -138.9f, -77.0f, -139.0f, -76.8f, -139.2f, -76.5f, -139.5f, -76.3f, -139.7f, -76.1f,
858 -139.9f, -76.0f, -140.2f, -75.8f, -140.5f, -75.7f, -140.7f, -75.6f, -141.0f, -75.5f,
859 -141.9f, -75.3f, -142.2f, -75.3f, -142.5f, -75.2f, -143.0f, -74.9f, -143.2f, -74.7f,
860 -143.3f, -74.4f, -143.0f, -74.1f, -143.0f, 85.3f, -143.0f, 85.6f, -142.7f, 85.8f,
861 -142.4f, 85.9f, -142.2f, 85.9f, 143.0f, 85.6f, 143.1f, 85.4f, 143.3f, 85.1f,
862 143.0f, 84.8f, 143.0f, -74.9f, 142.8f, -75.1f, 142.5f, -75.2f, 141.9f, -75.3f,
863 141.6f, -75.3f, 141.3f, -75.4f, 141.1f, -75.4f, 140.8f, -75.5f, 140.5f, -75.7f,
864 140.2f, -75.8f, 140.0f, -76.0f, 139.7f, -76.1f, 139.5f, -76.3f, 139.1f, -76.8f,
865 138.9f, -77.0f, 138.6f, -77.5f, 138.4f, -77.8f, 138.3f, -78.1f, 138.3f, -78.3f,
866 138.2f, -78.6f, 138.2f, -78.9f, 138.1f, -79.2f, 138.1f, -79.5f, 138.0f, -81.3f,
867 137.8f, -81.6f, 137.6f, -81.8f, 137.3f, -81.9f, 137.1f, -81.9f, 120.0f, -70.0f,
868 -120.0f, -70.0f, -120.0f, 70.0f, 120.0f, 70.0f, 120.0f, -70.0f, 137.1f, -81.9f,
869};
870
871constexpr std::array<float, 40 * 2> handheld_bezel = {
872 -131.4f, -75.9f, -132.2f, -75.7f, -132.9f, -75.3f, -134.2f, -74.3f, -134.7f, -73.6f,
873 -135.1f, -72.8f, -135.4f, -72.0f, -135.5f, -71.2f, -135.5f, -70.4f, -135.2f, 76.7f,
874 -134.8f, 77.5f, -134.3f, 78.1f, -133.7f, 78.8f, -133.1f, 79.2f, -132.3f, 79.6f,
875 -131.5f, 79.9f, -130.7f, 80.0f, -129.8f, 80.0f, 132.2f, 79.7f, 133.0f, 79.3f,
876 133.7f, 78.8f, 134.3f, 78.3f, 134.8f, 77.6f, 135.1f, 76.8f, 135.5f, 75.2f,
877 135.5f, 74.3f, 135.2f, -72.7f, 134.8f, -73.5f, 134.4f, -74.2f, 133.8f, -74.8f,
878 133.1f, -75.3f, 132.3f, -75.6f, 130.7f, -76.0f, 129.8f, -76.0f, -112.9f, -62.2f,
879 112.9f, -62.2f, 112.9f, 62.2f, -112.9f, 62.2f, -112.9f, -62.2f, 129.8f, -76.0f,
880};
881
882constexpr std::array<float, 47 * 2> left_joycon_slider = {
883 -23.7f, -118.2f, -23.7f, -117.3f, -23.7f, 96.6f, -22.8f, 96.6f, -21.5f, 97.2f, -21.5f,
884 98.1f, -21.2f, 106.7f, -20.8f, 107.5f, -20.1f, 108.2f, -19.2f, 108.2f, -16.4f, 108.1f,
885 -15.8f, 107.5f, -15.8f, 106.5f, -15.8f, 62.8f, -16.3f, 61.9f, -15.8f, 61.0f, -17.3f,
886 60.3f, -19.1f, 58.9f, -19.1f, 58.1f, -19.1f, 57.2f, -19.1f, 34.5f, -17.9f, 33.9f,
887 -17.2f, 33.2f, -16.6f, 32.4f, -16.2f, 31.6f, -15.8f, 30.7f, -15.8f, 29.7f, -15.8f,
888 28.8f, -15.8f, -46.4f, -16.3f, -47.3f, -15.8f, -48.1f, -17.4f, -48.8f, -19.1f, -49.4f,
889 -19.1f, -50.1f, -19.1f, -51.0f, -19.1f, -51.9f, -19.1f, -73.7f, -19.1f, -74.5f, -17.5f,
890 -75.2f, -16.4f, -76.7f, -16.0f, -77.6f, -15.8f, -78.5f, -15.8f, -79.4f, -15.8f, -80.4f,
891 -15.8f, -118.2f, -15.8f, -118.2f, -18.3f, -118.2f,
892};
893
894constexpr std::array<float, 66 * 2> left_joycon_sideview = {
895 -158.8f, -133.5f, -159.8f, -133.5f, -173.5f, -133.3f, -174.5f, -133.0f, -175.4f, -132.6f,
896 -176.2f, -132.1f, -177.0f, -131.5f, -177.7f, -130.9f, -178.3f, -130.1f, -179.4f, -128.5f,
897 -179.8f, -127.6f, -180.4f, -125.7f, -180.6f, -124.7f, -180.7f, -123.8f, -180.7f, -122.8f,
898 -180.0f, 128.8f, -179.6f, 129.7f, -179.1f, 130.5f, -177.9f, 132.1f, -177.2f, 132.7f,
899 -176.4f, 133.3f, -175.6f, 133.8f, -174.7f, 134.3f, -173.8f, 134.6f, -172.8f, 134.8f,
900 -170.9f, 135.0f, -169.9f, 135.0f, -156.1f, 134.8f, -155.2f, 134.6f, -154.2f, 134.3f,
901 -153.3f, 134.0f, -152.4f, 133.6f, -151.6f, 133.1f, -150.7f, 132.6f, -149.9f, 132.0f,
902 -149.2f, 131.4f, -148.5f, 130.7f, -147.1f, 129.2f, -146.5f, 128.5f, -146.0f, 127.7f,
903 -145.5f, 126.8f, -145.0f, 126.0f, -144.6f, 125.1f, -144.2f, 124.1f, -143.9f, 123.2f,
904 -143.7f, 122.2f, -143.6f, 121.3f, -143.5f, 120.3f, -143.5f, 119.3f, -144.4f, -123.4f,
905 -144.8f, -124.3f, -145.3f, -125.1f, -145.8f, -126.0f, -146.3f, -126.8f, -147.0f, -127.5f,
906 -147.6f, -128.3f, -148.3f, -129.0f, -149.0f, -129.6f, -149.8f, -130.3f, -150.6f, -130.8f,
907 -151.4f, -131.4f, -152.2f, -131.9f, -153.1f, -132.3f, -155.9f, -133.3f, -156.8f, -133.5f,
908 -157.8f, -133.5f,
909};
910
911constexpr std::array<float, 40 * 2> left_joycon_body_trigger = {
912 -146.1f, -124.3f, -146.0f, -122.0f, -145.8f, -119.7f, -145.7f, -117.4f, -145.4f, -112.8f,
913 -145.3f, -110.5f, -145.0f, -105.9f, -144.9f, -103.6f, -144.6f, -99.1f, -144.5f, -96.8f,
914 -144.5f, -89.9f, -144.5f, -87.6f, -144.5f, -83.0f, -144.5f, -80.7f, -144.5f, -80.3f,
915 -142.4f, -82.4f, -141.4f, -84.5f, -140.2f, -86.4f, -138.8f, -88.3f, -137.4f, -90.1f,
916 -134.5f, -93.6f, -133.0f, -95.3f, -130.0f, -98.8f, -128.5f, -100.6f, -127.1f, -102.4f,
917 -125.8f, -104.3f, -124.7f, -106.3f, -123.9f, -108.4f, -125.1f, -110.2f, -127.4f, -110.3f,
918 -129.7f, -110.3f, -134.2f, -110.5f, -136.4f, -111.4f, -138.1f, -112.8f, -139.4f, -114.7f,
919 -140.5f, -116.8f, -141.4f, -118.9f, -143.3f, -123.1f, -144.6f, -124.9f, -146.2f, -126.0f,
920};
921
922constexpr std::array<float, 42 * 2> left_joycon_sideview_zl = {
923 -148.9f, -128.2f, -148.7f, -126.6f, -148.4f, -124.9f, -148.2f, -123.3f, -147.9f, -121.7f,
924 -147.7f, -120.1f, -147.4f, -118.5f, -147.2f, -116.9f, -146.9f, -115.3f, -146.4f, -112.1f,
925 -146.1f, -110.5f, -145.9f, -108.9f, -145.6f, -107.3f, -144.2f, -107.3f, -142.6f, -107.5f,
926 -141.0f, -107.8f, -137.8f, -108.3f, -136.2f, -108.6f, -131.4f, -109.4f, -129.8f, -109.7f,
927 -125.6f, -111.4f, -124.5f, -112.7f, -123.9f, -114.1f, -123.8f, -115.8f, -123.8f, -117.4f,
928 -123.9f, -120.6f, -124.5f, -122.1f, -125.8f, -123.1f, -127.4f, -123.4f, -129.0f, -123.6f,
929 -130.6f, -124.0f, -132.1f, -124.4f, -133.7f, -124.8f, -135.3f, -125.3f, -136.8f, -125.9f,
930 -138.3f, -126.4f, -139.9f, -126.9f, -141.4f, -127.5f, -142.9f, -128.0f, -144.5f, -128.5f,
931 -146.0f, -129.0f, -147.6f, -129.4f,
932};
933
934constexpr std::array<float, 72 * 2> left_joystick_sideview = {
935 -14.7f, -3.8f, -15.2f, -5.6f, -15.2f, -7.6f, -15.5f, -17.6f, -17.4f, -18.3f, -19.4f, -18.2f,
936 -21.3f, -17.6f, -22.8f, -16.4f, -23.4f, -14.5f, -23.4f, -12.5f, -24.1f, -8.6f, -24.8f, -6.7f,
937 -25.3f, -4.8f, -25.7f, -2.8f, -25.9f, -0.8f, -26.0f, 1.2f, -26.0f, 3.2f, -25.8f, 5.2f,
938 -25.5f, 7.2f, -25.0f, 9.2f, -24.4f, 11.1f, -23.7f, 13.0f, -23.4f, 14.9f, -23.4f, 16.9f,
939 -23.3f, 18.9f, -22.0f, 20.5f, -20.2f, 21.3f, -18.3f, 21.6f, -16.3f, 21.4f, -15.3f, 19.9f,
940 -15.3f, 17.8f, -15.2f, 7.8f, -13.5f, 6.4f, -12.4f, 7.2f, -11.4f, 8.9f, -10.2f, 10.5f,
941 -8.7f, 11.8f, -7.1f, 13.0f, -5.3f, 14.0f, -3.5f, 14.7f, -1.5f, 15.0f, 0.5f, 15.0f,
942 2.5f, 14.7f, 4.4f, 14.2f, 6.3f, 13.4f, 8.0f, 12.4f, 9.6f, 11.1f, 10.9f, 9.6f,
943 12.0f, 7.9f, 12.7f, 6.0f, 13.2f, 4.1f, 13.3f, 2.1f, 13.2f, 0.1f, 12.9f, -1.9f,
944 12.2f, -3.8f, 11.3f, -5.6f, 10.2f, -7.2f, 8.8f, -8.6f, 7.1f, -9.8f, 5.4f, -10.8f,
945 3.5f, -11.5f, 1.5f, -11.9f, -0.5f, -12.0f, -2.5f, -11.8f, -4.4f, -11.3f, -6.2f, -10.4f,
946 -8.0f, -9.4f, -9.6f, -8.2f, -10.9f, -6.7f, -11.9f, -4.9f, -12.8f, -3.2f, -13.5f, -3.8f,
947};
948
949void PlayerControlPreview::DrawProBody(QPainter& p, const QPointF center) {
950 std::array<QPointF, pro_left_handle.size() / 2> qleft_handle;
951 std::array<QPointF, pro_left_handle.size() / 2> qright_handle;
952 std::array<QPointF, pro_body.size()> qbody;
953 constexpr int radius1 = 30;
954
955 for (std::size_t point = 0; point < pro_left_handle.size() / 2; ++point) {
956 qleft_handle[point] =
957 center + QPointF(pro_left_handle[point * 2], pro_left_handle[point * 2 + 1]);
958 qright_handle[point] =
959 center + QPointF(-pro_left_handle[point * 2], pro_left_handle[point * 2 + 1]);
960 }
961 for (std::size_t point = 0; point < pro_body.size() / 2; ++point) {
962 qbody[point] = center + QPointF(pro_body[point * 2], pro_body[point * 2 + 1]);
963 qbody[pro_body.size() - 1 - point] =
964 center + QPointF(-pro_body[point * 2], pro_body[point * 2 + 1]);
965 }
966
967 // Draw left handle body
968 p.setPen(colors.outline);
969 p.setBrush(colors.left);
970 DrawPolygon(p, qleft_handle);
971
972 // Draw right handle body
973 p.setBrush(colors.right);
974 DrawPolygon(p, qright_handle);
975
976 // Draw body
977 p.setBrush(colors.primary);
978 DrawPolygon(p, qbody);
979
980 // Draw joycon circles
981 p.setBrush(colors.transparent);
982 p.drawEllipse(center + QPoint(-111, -55), radius1, radius1);
983 p.drawEllipse(center + QPoint(51, 0), radius1, radius1);
984}
985
986void PlayerControlPreview::DrawHandheldBody(QPainter& p, const QPointF center) {
987 const std::size_t body_outline_end = handheld_body.size() / 2 - 6;
988 const std::size_t bezel_outline_end = handheld_bezel.size() / 2 - 6;
989 const std::size_t bezel_inline_size = 4;
990 const std::size_t bezel_inline_start = 35;
991 std::array<QPointF, left_joycon_body.size() / 2> left_joycon;
992 std::array<QPointF, left_joycon_body.size() / 2> right_joycon;
993 std::array<QPointF, handheld_body.size() / 2> qhandheld_body;
994 std::array<QPointF, body_outline_end> qhandheld_body_outline;
995 std::array<QPointF, handheld_bezel.size() / 2> qhandheld_bezel;
996 std::array<QPointF, bezel_inline_size> qhandheld_bezel_inline;
997 std::array<QPointF, bezel_outline_end> qhandheld_bezel_outline;
998
999 for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
1000 left_joycon[point] =
1001 center + QPointF(left_joycon_body[point * 2], left_joycon_body[point * 2 + 1]);
1002 right_joycon[point] =
1003 center + QPointF(-left_joycon_body[point * 2], left_joycon_body[point * 2 + 1]);
1004 }
1005 for (std::size_t point = 0; point < body_outline_end; ++point) {
1006 qhandheld_body_outline[point] =
1007 center + QPointF(handheld_body[point * 2], handheld_body[point * 2 + 1]);
1008 }
1009 for (std::size_t point = 0; point < handheld_body.size() / 2; ++point) {
1010 qhandheld_body[point] =
1011 center + QPointF(handheld_body[point * 2], handheld_body[point * 2 + 1]);
1012 }
1013 for (std::size_t point = 0; point < handheld_bezel.size() / 2; ++point) {
1014 qhandheld_bezel[point] =
1015 center + QPointF(handheld_bezel[point * 2], handheld_bezel[point * 2 + 1]);
1016 }
1017 for (std::size_t point = 0; point < bezel_outline_end; ++point) {
1018 qhandheld_bezel_outline[point] =
1019 center + QPointF(handheld_bezel[point * 2], handheld_bezel[point * 2 + 1]);
1020 }
1021 for (std::size_t point = 0; point < bezel_inline_size; ++point) {
1022 qhandheld_bezel_inline[point] =
1023 center + QPointF(handheld_bezel[(point + bezel_inline_start) * 2],
1024 handheld_bezel[(point + bezel_inline_start) * 2 + 1]);
1025 }
1026
1027 // Draw left joycon
1028 p.setPen(colors.outline);
1029 p.setBrush(colors.left);
1030 DrawPolygon(p, left_joycon);
1031
1032 // Draw right joycon
1033 p.setPen(colors.outline);
1034 p.setBrush(colors.right);
1035 DrawPolygon(p, right_joycon);
1036
1037 // Draw handheld body
1038 p.setPen(colors.transparent);
1039 p.setBrush(colors.primary);
1040 DrawPolygon(p, qhandheld_body);
1041 p.setPen(colors.outline);
1042 p.setBrush(colors.transparent);
1043 DrawPolygon(p, qhandheld_body_outline);
1044
1045 // Draw Handheld bezel
1046 p.setPen(colors.transparent);
1047 p.setBrush(colors.button);
1048 DrawPolygon(p, qhandheld_bezel);
1049 p.setPen(colors.outline);
1050 p.setBrush(colors.transparent);
1051 DrawPolygon(p, qhandheld_bezel_outline);
1052 DrawPolygon(p, qhandheld_bezel_inline);
1053}
1054
1055void PlayerControlPreview::DrawDualBody(QPainter& p, const QPointF center) {
1056 std::array<QPointF, left_joycon_body.size() / 2> left_joycon;
1057 std::array<QPointF, left_joycon_body.size() / 2> right_joycon;
1058 std::array<QPointF, left_joycon_sideview.size() / 2> qleft_joycon_sideview;
1059 std::array<QPointF, left_joycon_sideview.size() / 2> qright_joycon_sideview;
1060 std::array<QPointF, left_joycon_body_trigger.size() / 2> qleft_joycon_trigger;
1061 std::array<QPointF, left_joycon_body_trigger.size() / 2> qright_joycon_trigger;
1062 std::array<QPointF, left_joycon_slider.size() / 2> qleft_joycon_slider;
1063 std::array<QPointF, left_joycon_slider.size() / 2> qright_joycon_slider;
1064 constexpr float size = 1.61f;
1065 constexpr float offset = 209.3;
1066
1067 for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
1068 left_joycon[point] = center + QPointF(left_joycon_body[point * 2] * size + offset,
1069 left_joycon_body[point * 2 + 1] * size - 1);
1070 right_joycon[point] = center + QPointF(-left_joycon_body[point * 2] * size - offset,
1071 left_joycon_body[point * 2 + 1] * size - 1);
1072 }
1073 for (std::size_t point = 0; point < left_joycon_sideview.size() / 2; ++point) {
1074 qleft_joycon_sideview[point] = center + QPointF(left_joycon_sideview[point * 2],
1075 left_joycon_sideview[point * 2 + 1] + 2);
1076 qright_joycon_sideview[point] = center + QPointF(-left_joycon_sideview[point * 2],
1077 left_joycon_sideview[point * 2 + 1] + 2);
1078 }
1079 for (std::size_t point = 0; point < left_joycon_slider.size() / 2; ++point) {
1080 qleft_joycon_slider[point] =
1081 center + QPointF(left_joycon_slider[point * 2], left_joycon_slider[point * 2 + 1]);
1082 qright_joycon_slider[point] =
1083 center + QPointF(-left_joycon_slider[point * 2], left_joycon_slider[point * 2 + 1]);
1084 }
1085 for (std::size_t point = 0; point < left_joycon_body_trigger.size() / 2; ++point) {
1086 qleft_joycon_trigger[point] = center + QPointF(left_joycon_body_trigger[point * 2],
1087 left_joycon_body_trigger[point * 2 + 1] + 2);
1088 qright_joycon_trigger[point] =
1089 center + QPointF(-left_joycon_body_trigger[point * 2],
1090 left_joycon_body_trigger[point * 2 + 1] + 2);
1091 }
1092
1093 // right joycon boddy
1094 p.setPen(colors.outline);
1095 p.setBrush(colors.right);
1096 DrawPolygon(p, right_joycon);
1097 DrawPolygon(p, qright_joycon_trigger);
1098
1099 // Left joycon boddy
1100 p.setPen(colors.outline);
1101 p.setBrush(colors.left);
1102 DrawPolygon(p, left_joycon);
1103 DrawPolygon(p, qleft_joycon_trigger);
1104
1105 // Right Slider release button
1106 p.setBrush(colors.button);
1107 DrawRoundRectangle(p, center + QPoint(145, -100), 12, 12, 2);
1108
1109 // Left Slider release button
1110 p.setBrush(colors.button);
1111 DrawRoundRectangle(p, center + QPoint(-145, -100), 12, 12, 2);
1112
1113 // Right SR and SL sideview buttons
1114 p.setPen(colors.outline);
1115 p.setBrush(colors.slider_button);
1116 DrawRoundRectangle(p, center + QPoint(19, 47), 7, 22, 1);
1117 DrawRoundRectangle(p, center + QPoint(19, -62), 7, 22, 1);
1118
1119 // Left SR and SL sideview buttons
1120 DrawRoundRectangle(p, center + QPoint(-19, 47), 7, 22, 1);
1121 DrawRoundRectangle(p, center + QPoint(-19, -62), 7, 22, 1);
1122
1123 // Right Sideview body
1124 p.setBrush(colors.right);
1125 DrawPolygon(p, qright_joycon_sideview);
1126 p.setBrush(colors.slider);
1127 DrawPolygon(p, qright_joycon_slider);
1128
1129 // Left Sideview body
1130 p.setBrush(colors.left);
1131 DrawPolygon(p, qleft_joycon_sideview);
1132 p.setBrush(colors.slider);
1133 DrawPolygon(p, qleft_joycon_slider);
1134
1135 const QPointF right_sideview_center = QPointF(162.5f, 0) + center;
1136 const QPointF left_sideview_center = QPointF(-162.5f, 0) + center;
1137
1138 // right sideview slider body
1139 p.setBrush(colors.slider);
1140 DrawRoundRectangle(p, right_sideview_center + QPointF(0, -6), 26, 227, 3);
1141 p.setBrush(colors.button2);
1142 DrawRoundRectangle(p, right_sideview_center + QPointF(0, 85), 20.2f, 40.2f, 3);
1143
1144 // left sideview slider body
1145 p.setBrush(colors.slider);
1146 DrawRoundRectangle(p, left_sideview_center + QPointF(0, -6), 26, 227, 3);
1147 p.setBrush(colors.button2);
1148 DrawRoundRectangle(p, left_sideview_center + QPointF(0, 85), 20.2f, 40.2f, 3);
1149
1150 // Right Slider decorations
1151 p.setPen(colors.outline);
1152 p.setBrush(colors.slider_arrow);
1153 DrawArrow(p, right_sideview_center + QPoint(0, 73), Direction::Down, 2.1f);
1154 DrawArrow(p, right_sideview_center + QPoint(0, 85), Direction::Down, 2.1f);
1155 DrawArrow(p, right_sideview_center + QPoint(0, 97), Direction::Down, 2.1f);
1156 DrawCircle(p, right_sideview_center + QPointF(0, 17), 3.8f);
1157
1158 // Left Slider decorations
1159 DrawArrow(p, left_sideview_center + QPoint(0, 73), Direction::Down, 2.1f);
1160 DrawArrow(p, left_sideview_center + QPoint(0, 85), Direction::Down, 2.1f);
1161 DrawArrow(p, left_sideview_center + QPoint(0, 97), Direction::Down, 2.1f);
1162 DrawCircle(p, left_sideview_center + QPointF(0, 17), 3.8f);
1163
1164 // Right SR and SL buttons
1165 p.setPen(colors.outline);
1166 p.setBrush(colors.slider_button);
1167 DrawRoundRectangle(p, right_sideview_center + QPoint(0, 47), 10, 22, 3.6f);
1168 DrawRoundRectangle(p, right_sideview_center + QPoint(0, -62), 10, 22, 3.6f);
1169
1170 // Left SR and SL buttons
1171 DrawRoundRectangle(p, left_sideview_center + QPoint(0, 47), 10, 22, 3.6f);
1172 DrawRoundRectangle(p, left_sideview_center + QPoint(0, -62), 10, 22, 3.6f);
1173
1174 // Right SR and SL text
1175 SetTextFont(p, 5.5f);
1176 p.setPen(colors.outline);
1177 p.rotate(-90);
1178 p.drawText(QPointF(-center.y() - 5, center.x() + 3) + QPointF(-47, 162.5f), tr("SL"));
1179 p.drawText(QPointF(-center.y() - 5, center.x() + 3) + QPointF(62, 162.5f), tr("SR"));
1180 p.rotate(90);
1181
1182 // Left SR and SL text
1183 p.rotate(90);
1184 p.drawText(QPointF(center.y() - 5, -center.x() + 3) + QPointF(47, 162.5f), tr("SR"));
1185 p.drawText(QPointF(center.y() - 5, -center.x() + 3) + QPointF(-62, 162.5f), tr("SL"));
1186 p.rotate(-90);
1187
1188 // LED indicators
1189 const float led_size = 5.0f;
1190 const QPointF left_led_position = left_sideview_center + QPointF(0, -33);
1191 const QPointF right_led_position = right_sideview_center + QPointF(0, -33);
1192 int led_count = 0;
1193 for (const auto color : led_color) {
1194 p.setBrush(color);
1195 DrawRectangle(p, left_led_position + QPointF(0, 11 * led_count), led_size, led_size);
1196 DrawRectangle(p, right_led_position + QPointF(0, 11 * led_count), led_size, led_size);
1197 led_count++;
1198 }
1199}
1200
1201void PlayerControlPreview::DrawLeftBody(QPainter& p, const QPointF center) {
1202 std::array<QPointF, left_joycon_body.size() / 2> left_joycon;
1203 std::array<QPointF, left_joycon_sideview.size() / 2> qleft_joycon_sideview;
1204 std::array<QPointF, left_joycon_body_trigger.size() / 2> qleft_joycon_trigger;
1205 std::array<QPointF, left_joycon_slider.size() / 2> qleft_joycon_slider;
1206 constexpr float size = 1.78f;
1207 constexpr float size2 = 1.1115f;
1208 constexpr float offset = 312.39f;
1209 constexpr float offset2 = 335;
1210
1211 for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
1212 left_joycon[point] = center + QPointF(left_joycon_body[point * 2] * size + offset,
1213 left_joycon_body[point * 2 + 1] * size - 1);
1214 }
1215
1216 for (std::size_t point = 0; point < left_joycon_sideview.size() / 2; ++point) {
1217 qleft_joycon_sideview[point] =
1218 center + QPointF(left_joycon_sideview[point * 2] * size2 + offset2,
1219 left_joycon_sideview[point * 2 + 1] * size2 + 2);
1220 }
1221 for (std::size_t point = 0; point < left_joycon_slider.size() / 2; ++point) {
1222 qleft_joycon_slider[point] = center + QPointF(left_joycon_slider[point * 2] * size2 + 81,
1223 left_joycon_slider[point * 2 + 1] * size2);
1224 }
1225 for (std::size_t point = 0; point < left_joycon_body_trigger.size() / 2; ++point) {
1226 qleft_joycon_trigger[point] =
1227 center + QPointF(left_joycon_body_trigger[point * 2] * size2 + offset2,
1228 left_joycon_body_trigger[point * 2 + 1] * size2 + 2);
1229 }
1230
1231 // Joycon boddy
1232 p.setPen(colors.outline);
1233 p.setBrush(colors.left);
1234 DrawPolygon(p, left_joycon);
1235 DrawPolygon(p, qleft_joycon_trigger);
1236
1237 // Slider release button
1238 p.setBrush(colors.button);
1239 DrawRoundRectangle(p, center + QPoint(175, -110), 12, 14, 2);
1240
1241 // Sideview body
1242 p.setBrush(colors.left);
1243 DrawPolygon(p, qleft_joycon_sideview);
1244 p.setBrush(colors.slider);
1245 DrawPolygon(p, qleft_joycon_slider);
1246
1247 const QPointF sideview_center = QPointF(155, 0) + center;
1248
1249 // Sideview slider body
1250 p.setBrush(colors.slider);
1251 DrawRoundRectangle(p, sideview_center + QPointF(0, -5), 28, 253, 3);
1252 p.setBrush(colors.button2);
1253 DrawRoundRectangle(p, sideview_center + QPointF(0, 97), 22.44f, 44.66f, 3);
1254
1255 // Slider decorations
1256 p.setPen(colors.outline);
1257 p.setBrush(colors.slider_arrow);
1258 DrawArrow(p, sideview_center + QPoint(0, 83), Direction::Down, 2.2f);
1259 DrawArrow(p, sideview_center + QPoint(0, 96), Direction::Down, 2.2f);
1260 DrawArrow(p, sideview_center + QPoint(0, 109), Direction::Down, 2.2f);
1261 DrawCircle(p, sideview_center + QPointF(0, 19), 4.44f);
1262
1263 // LED indicators
1264 const float led_size = 5.0f;
1265 const QPointF led_position = sideview_center + QPointF(0, -36);
1266 int led_count = 0;
1267 for (const auto color : led_color) {
1268 p.setBrush(color);
1269 DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
1270 }
1271}
1272
1273void PlayerControlPreview::DrawRightBody(QPainter& p, const QPointF center) {
1274 std::array<QPointF, left_joycon_body.size() / 2> right_joycon;
1275 std::array<QPointF, left_joycon_sideview.size() / 2> qright_joycon_sideview;
1276 std::array<QPointF, left_joycon_body_trigger.size() / 2> qright_joycon_trigger;
1277 std::array<QPointF, left_joycon_slider.size() / 2> qright_joycon_slider;
1278 constexpr float size = 1.78f;
1279 constexpr float size2 = 1.1115f;
1280 constexpr float offset = 312.39f;
1281 constexpr float offset2 = 335;
1282
1283 for (std::size_t point = 0; point < left_joycon_body.size() / 2; ++point) {
1284 right_joycon[point] = center + QPointF(-left_joycon_body[point * 2] * size - offset,
1285 left_joycon_body[point * 2 + 1] * size - 1);
1286 }
1287
1288 for (std::size_t point = 0; point < left_joycon_sideview.size() / 2; ++point) {
1289 qright_joycon_sideview[point] =
1290 center + QPointF(-left_joycon_sideview[point * 2] * size2 - offset2,
1291 left_joycon_sideview[point * 2 + 1] * size2 + 2);
1292 }
1293 for (std::size_t point = 0; point < left_joycon_body_trigger.size() / 2; ++point) {
1294 qright_joycon_trigger[point] =
1295 center + QPointF(-left_joycon_body_trigger[point * 2] * size2 - offset2,
1296 left_joycon_body_trigger[point * 2 + 1] * size2 + 2);
1297 }
1298 for (std::size_t point = 0; point < left_joycon_slider.size() / 2; ++point) {
1299 qright_joycon_slider[point] = center + QPointF(-left_joycon_slider[point * 2] * size2 - 81,
1300 left_joycon_slider[point * 2 + 1] * size2);
1301 }
1302
1303 // Joycon boddy
1304 p.setPen(colors.outline);
1305 p.setBrush(colors.left);
1306 DrawPolygon(p, right_joycon);
1307 DrawPolygon(p, qright_joycon_trigger);
1308
1309 // Slider release button
1310 p.setBrush(colors.button);
1311 DrawRoundRectangle(p, center + QPoint(-175, -110), 12, 14, 2);
1312
1313 // Sideview body
1314 p.setBrush(colors.left);
1315 DrawPolygon(p, qright_joycon_sideview);
1316 p.setBrush(colors.slider);
1317 DrawPolygon(p, qright_joycon_slider);
1318
1319 const QPointF sideview_center = QPointF(-155, 0) + center;
1320
1321 // Sideview slider body
1322 p.setBrush(colors.slider);
1323 DrawRoundRectangle(p, sideview_center + QPointF(0, -5), 28, 253, 3);
1324 p.setBrush(colors.button2);
1325 DrawRoundRectangle(p, sideview_center + QPointF(0, 97), 22.44f, 44.66f, 3);
1326
1327 // Slider decorations
1328 p.setPen(colors.outline);
1329 p.setBrush(colors.slider_arrow);
1330 DrawArrow(p, sideview_center + QPoint(0, 83), Direction::Down, 2.2f);
1331 DrawArrow(p, sideview_center + QPoint(0, 96), Direction::Down, 2.2f);
1332 DrawArrow(p, sideview_center + QPoint(0, 109), Direction::Down, 2.2f);
1333 DrawCircle(p, sideview_center + QPointF(0, 19), 4.44f);
1334
1335 // LED indicators
1336 const float led_size = 5.0f;
1337 const QPointF led_position = sideview_center + QPointF(0, -36);
1338 int led_count = 0;
1339 for (const auto color : led_color) {
1340 p.setBrush(color);
1341 DrawRectangle(p, led_position + QPointF(0, 12 * led_count++), led_size, led_size);
1342 }
1343}
1344
1345void PlayerControlPreview::DrawProTriggers(QPainter& p, const QPointF center, bool left_pressed,
1346 bool right_pressed) {
1347 std::array<QPointF, pro_left_trigger.size() / 2> qleft_trigger;
1348 std::array<QPointF, pro_left_trigger.size() / 2> qright_trigger;
1349 std::array<QPointF, pro_body_top.size()> qbody_top;
1350
1351 for (std::size_t point = 0; point < pro_left_trigger.size() / 2; ++point) {
1352 qleft_trigger[point] =
1353 center + QPointF(pro_left_trigger[point * 2],
1354 pro_left_trigger[point * 2 + 1] + (left_pressed ? 2 : 0));
1355 qright_trigger[point] =
1356 center + QPointF(-pro_left_trigger[point * 2],
1357 pro_left_trigger[point * 2 + 1] + (right_pressed ? 2 : 0));
1358 }
1359
1360 for (std::size_t point = 0; point < pro_body_top.size() / 2; ++point) {
1361 qbody_top[pro_body_top.size() - 1 - point] =
1362 center + QPointF(-pro_body_top[point * 2], pro_body_top[point * 2 + 1]);
1363 qbody_top[point] = center + QPointF(pro_body_top[point * 2], pro_body_top[point * 2 + 1]);
1364 }
1365
1366 // Pro body detail
1367 p.setPen(colors.outline);
1368 p.setBrush(colors.primary);
1369 DrawPolygon(p, qbody_top);
1370
1371 // Left trigger
1372 p.setBrush(left_pressed ? colors.highlight : colors.button);
1373 DrawPolygon(p, qleft_trigger);
1374
1375 // Right trigger
1376 p.setBrush(right_pressed ? colors.highlight : colors.button);
1377 DrawPolygon(p, qright_trigger);
1378}
1379
1380void PlayerControlPreview::DrawHandheldTriggers(QPainter& p, const QPointF center,
1381 bool left_pressed, bool right_pressed) {
1382 std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
1383 std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
1384
1385 for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
1386 qleft_trigger[point] =
1387 center + QPointF(left_joycon_trigger[point * 2],
1388 left_joycon_trigger[point * 2 + 1] + (left_pressed ? 0.5f : 0));
1389 qright_trigger[point] =
1390 center + QPointF(-left_joycon_trigger[point * 2],
1391 left_joycon_trigger[point * 2 + 1] + (right_pressed ? 0.5f : 0));
1392 }
1393
1394 // Left trigger
1395 p.setPen(colors.outline);
1396 p.setBrush(left_pressed ? colors.highlight : colors.button);
1397 DrawPolygon(p, qleft_trigger);
1398
1399 // Right trigger
1400 p.setBrush(right_pressed ? colors.highlight : colors.button);
1401 DrawPolygon(p, qright_trigger);
1402}
1403
1404void PlayerControlPreview::DrawDualTriggers(QPainter& p, const QPointF center, bool left_pressed,
1405 bool right_pressed) {
1406 std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
1407 std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
1408 constexpr float size = 1.62f;
1409 constexpr float offset = 210.6f;
1410 for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
1411 qleft_trigger[point] =
1412 center + QPointF(left_joycon_trigger[point * 2] * size + offset,
1413 left_joycon_trigger[point * 2 + 1] * size + (left_pressed ? 0.5f : 0));
1414 qright_trigger[point] = center + QPointF(-left_joycon_trigger[point * 2] * size - offset,
1415 left_joycon_trigger[point * 2 + 1] * size +
1416 (right_pressed ? 0.5f : 0));
1417 }
1418
1419 // Left trigger
1420 p.setPen(colors.outline);
1421 p.setBrush(left_pressed ? colors.highlight : colors.button);
1422 DrawPolygon(p, qleft_trigger);
1423
1424 // Right trigger
1425 p.setBrush(right_pressed ? colors.highlight : colors.button);
1426 DrawPolygon(p, qright_trigger);
1427}
1428
1429void PlayerControlPreview::DrawDualZTriggers(QPainter& p, const QPointF center, bool left_pressed,
1430 bool right_pressed) {
1431 std::array<QPointF, left_joycon_sideview_zl.size() / 2> qleft_trigger;
1432 std::array<QPointF, left_joycon_sideview_zl.size() / 2> qright_trigger;
1433
1434 for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
1435 qleft_trigger[point] =
1436 center + QPointF(left_joycon_sideview_zl[point * 2],
1437 left_joycon_sideview_zl[point * 2 + 1] + (left_pressed ? 2.5f : 2.0f));
1438 qright_trigger[point] = center + QPointF(-left_joycon_sideview_zl[point * 2],
1439 left_joycon_sideview_zl[point * 2 + 1] +
1440 (right_pressed ? 2.5f : 2.0f));
1441 }
1442
1443 p.setPen(colors.outline);
1444 p.setBrush(left_pressed ? colors.highlight : colors.button);
1445 DrawPolygon(p, qleft_trigger);
1446 p.setBrush(right_pressed ? colors.highlight : colors.button);
1447 DrawPolygon(p, qright_trigger);
1448 p.drawArc(center.x() - 159, center.y() - 183 + (left_pressed ? 0.5f : 0), 70, 70, 225 * 16,
1449 44 * 16);
1450 p.drawArc(center.x() + 90, center.y() - 183 + (right_pressed ? 0.5f : 0), 70, 70, 271 * 16,
1451 44 * 16);
1452}
1453
1454void PlayerControlPreview::DrawLeftTriggers(QPainter& p, const QPointF center, bool left_pressed) {
1455 std::array<QPointF, left_joycon_trigger.size() / 2> qleft_trigger;
1456 constexpr float size = 1.78f;
1457 constexpr float offset = 311.5f;
1458
1459 for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
1460 qleft_trigger[point] = center + QPointF(left_joycon_trigger[point * 2] * size + offset,
1461 left_joycon_trigger[point * 2 + 1] * size -
1462 (left_pressed ? 0.5f : 1.0f));
1463 }
1464
1465 p.setPen(colors.outline);
1466 p.setBrush(left_pressed ? colors.highlight : colors.button);
1467 DrawPolygon(p, qleft_trigger);
1468}
1469
1470void PlayerControlPreview::DrawLeftZTriggers(QPainter& p, const QPointF center, bool left_pressed) {
1471 std::array<QPointF, left_joycon_sideview_zl.size() / 2> qleft_trigger;
1472 constexpr float size = 1.1115f;
1473 constexpr float offset2 = 335;
1474
1475 for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
1476 qleft_trigger[point] = center + QPointF(left_joycon_sideview_zl[point * 2] * size + offset2,
1477 left_joycon_sideview_zl[point * 2 + 1] * size +
1478 (left_pressed ? 1.5f : 1.0f));
1479 }
1480
1481 p.setPen(colors.outline);
1482 p.setBrush(left_pressed ? colors.highlight : colors.button);
1483 DrawPolygon(p, qleft_trigger);
1484 p.drawArc(center.x() + 158, center.y() + (left_pressed ? -203.5f : -204.0f), 77, 77, 225 * 16,
1485 44 * 16);
1486}
1487
1488void PlayerControlPreview::DrawRightTriggers(QPainter& p, const QPointF center,
1489 bool right_pressed) {
1490 std::array<QPointF, left_joycon_trigger.size() / 2> qright_trigger;
1491 constexpr float size = 1.78f;
1492 constexpr float offset = 311.5f;
1493
1494 for (std::size_t point = 0; point < left_joycon_trigger.size() / 2; ++point) {
1495 qright_trigger[point] = center + QPointF(-left_joycon_trigger[point * 2] * size - offset,
1496 left_joycon_trigger[point * 2 + 1] * size -
1497 (right_pressed ? 0.5f : 1.0f));
1498 }
1499
1500 p.setPen(colors.outline);
1501 p.setBrush(right_pressed ? colors.highlight : colors.button);
1502 DrawPolygon(p, qright_trigger);
1503}
1504
1505void PlayerControlPreview::DrawRightZTriggers(QPainter& p, const QPointF center,
1506 bool right_pressed) {
1507 std::array<QPointF, left_joycon_sideview_zl.size() / 2> qright_trigger;
1508 constexpr float size = 1.1115f;
1509 constexpr float offset2 = 335;
1510
1511 for (std::size_t point = 0; point < left_joycon_sideview_zl.size() / 2; ++point) {
1512 qright_trigger[point] =
1513 center +
1514 QPointF(-left_joycon_sideview_zl[point * 2] * size - offset2,
1515 left_joycon_sideview_zl[point * 2 + 1] * size + (right_pressed ? 0.5f : 0) + 1);
1516 }
1517
1518 p.setPen(colors.outline);
1519 p.setBrush(right_pressed ? colors.highlight : colors.button);
1520 DrawPolygon(p, qright_trigger);
1521 p.drawArc(center.x() - 236, center.y() + (right_pressed ? -203.5f : -204.0f), 77, 77, 271 * 16,
1522 44 * 16);
1523}
1524
1525void PlayerControlPreview::DrawJoystick(QPainter& p, const QPointF center, float size,
1526 bool pressed) {
1527 const float radius1 = 13.0f * size;
1528 const float radius2 = 9.0f * size;
1529
1530 // Outer circle
1531 p.setPen(colors.outline);
1532 p.setBrush(pressed ? colors.highlight : colors.button);
1533 DrawCircle(p, center, radius1);
1534
1535 // Cross
1536 p.drawLine(center - QPoint(radius1, 0), center + QPoint(radius1, 0));
1537 p.drawLine(center - QPoint(0, radius1), center + QPoint(0, radius1));
1538
1539 // Inner circle
1540 p.setBrush(pressed ? colors.highlight2 : colors.button2);
1541 DrawCircle(p, center, radius2);
1542}
1543
1544void PlayerControlPreview::DrawJoystickSideview(QPainter& p, const QPointF center, float angle,
1545 float size, bool pressed) {
1546 QVector<QPointF> joystick;
1547 joystick.reserve(left_joystick_sideview.size() / 2);
1548
1549 for (std::size_t point = 0; point < left_joystick_sideview.size() / 2; ++point) {
1550 joystick.append(QPointF(left_joystick_sideview[point * 2] * size + (pressed ? 1 : 0),
1551 left_joystick_sideview[point * 2 + 1] * size - 1));
1552 }
1553
1554 // Rotate joystick
1555 QTransform t;
1556 t.translate(center.x(), center.y());
1557 t.rotate(18 * angle);
1558 QPolygonF p2 = t.map(QPolygonF(joystick));
1559
1560 // Draw joystick
1561 p.setPen(colors.outline);
1562 p.setBrush(pressed ? colors.highlight : colors.button);
1563 p.drawPolygon(p2);
1564 p.drawLine(p2.at(1), p2.at(30));
1565 p.drawLine(p2.at(32), p2.at(71));
1566}
1567
1568void PlayerControlPreview::DrawProJoystick(QPainter& p, const QPointF center, bool pressed) {
1569 // Outer circle
1570 p.setPen(colors.outline);
1571 p.setBrush(pressed ? colors.highlight : colors.button);
1572 DrawCircle(p, center, 24.0f);
1573
1574 // Inner circle
1575 p.setBrush(pressed ? colors.highlight2 : colors.button2);
1576 DrawCircle(p, center, 17.0f);
1577}
1578
1579void PlayerControlPreview::DrawRawJoystick(QPainter& p, const QPointF center, const QPointF value,
1580 const Input::AnalogProperties properties) {
1581 constexpr float size = 45.0f;
1582 const float range = size * properties.range;
1583 const float deadzone = size * properties.deadzone;
1584
1585 // Outer box
1586 p.setPen(colors.outline);
1587 p.setBrush(colors.transparent);
1588 p.drawRect(center.x() - size, center.y() - size, size * 2, size * 2);
1589
1590 // Max range zone circle
1591 QPen pen = p.pen();
1592 pen.setStyle(Qt::DotLine);
1593 p.setPen(pen);
1594 DrawCircle(p, center, range);
1595
1596 // Deadzone circle
1597 pen.setColor(colors.deadzone);
1598 p.setPen(pen);
1599 DrawCircle(p, center, deadzone);
1600
1601 // Dot pointer
1602 p.setPen(colors.indicator);
1603 p.setBrush(colors.indicator);
1604 DrawCircle(p, center + (value * range), 2);
1605}
1606
1607void PlayerControlPreview::DrawRoundButton(QPainter& p, QPointF center, bool pressed, float width,
1608 float height, Direction direction, float radius) {
1609 p.setBrush(button_color);
1610 if (pressed) {
1611 switch (direction) {
1612 case Direction::Left:
1613 center.setX(center.x() - 1);
1614 break;
1615 case Direction::Right:
1616 center.setX(center.x() + 1);
1617 break;
1618 case Direction::Down:
1619 center.setY(center.y() + 1);
1620 break;
1621 case Direction::Up:
1622 center.setY(center.y() + 1);
1623 break;
1624 case Direction::None:
1625 break;
1626 }
1627 p.setBrush(colors.highlight);
1628 }
1629 QRectF rect = {center.x() - width, center.y() - height, width * 2.0f, height * 2.0f};
1630 p.drawRoundedRect(rect, radius, radius);
1631}
1632void PlayerControlPreview::DrawMinusButton(QPainter& p, const QPointF center, bool pressed,
1633 int button_size) {
1634 p.setPen(colors.outline);
1635 p.setBrush(pressed ? colors.highlight : colors.button);
1636 DrawRectangle(p, center, button_size, button_size / 3.0f);
1637}
1638void PlayerControlPreview::DrawPlusButton(QPainter& p, const QPointF center, bool pressed,
1639 int button_size) {
1640 // Draw outer line
1641 p.setPen(colors.outline);
1642 p.setBrush(pressed ? colors.highlight : colors.button);
1643 DrawRectangle(p, center, button_size, button_size / 3.0f);
1644 DrawRectangle(p, center, button_size / 3.0f, button_size);
1645
1646 // Scale down size
1647 button_size *= 0.88f;
1648
1649 // Draw inner color
1650 p.setPen(colors.transparent);
1651 DrawRectangle(p, center, button_size, button_size / 3.0f);
1652 DrawRectangle(p, center, button_size / 3.0f, button_size);
1653}
1654
1655void PlayerControlPreview::DrawCircleButton(QPainter& p, const QPointF center, bool pressed,
1656 int button_size) {
1657 p.setBrush(button_color);
1658 if (pressed) {
1659 p.setBrush(colors.highlight);
1660 }
1661 p.drawEllipse(center, button_size, button_size);
1662}
1663void PlayerControlPreview::DrawArrowButton(QPainter& p, const QPointF center,
1664 const Direction direction, bool pressed) {
1665
1666 std::array<QPointF, up_arrow_button.size() / 2> arrow_button;
1667 QPoint offset;
1668
1669 for (std::size_t point = 0; point < up_arrow_button.size() / 2; ++point) {
1670 switch (direction) {
1671 case Direction::Up:
1672 arrow_button[point] =
1673 center + QPointF(up_arrow_button[point * 2], up_arrow_button[point * 2 + 1]);
1674 offset = QPoint(0, -20);
1675 break;
1676 case Direction::Left:
1677 arrow_button[point] =
1678 center + QPointF(up_arrow_button[point * 2 + 1], up_arrow_button[point * 2]);
1679 offset = QPoint(-20, 0);
1680 break;
1681 case Direction::Right:
1682 arrow_button[point] =
1683 center + QPointF(-up_arrow_button[point * 2 + 1], up_arrow_button[point * 2]);
1684 offset = QPoint(20, 0);
1685 break;
1686 case Direction::Down:
1687 arrow_button[point] =
1688 center + QPointF(up_arrow_button[point * 2], -up_arrow_button[point * 2 + 1]);
1689 offset = QPoint(0, 20);
1690 break;
1691 case Direction::None:
1692 break;
1693 }
1694 }
1695
1696 // Draw arrow button
1697 p.setPen(colors.outline);
1698 p.setBrush(pressed ? colors.highlight : colors.button);
1699 DrawPolygon(p, arrow_button);
1700
1701 // Draw arrow icon
1702 p.setPen(colors.font2);
1703 p.setBrush(colors.font2);
1704 DrawArrow(p, center + offset, direction, 1.0f);
1705}
1706
1707void PlayerControlPreview::DrawHouseIcon(QPainter& p, const QPointF center, float icon_size) {
1708 std::array<QPointF, house.size() / 2> house_icon;
1709
1710 for (std::size_t point = 0; point < house.size() / 2; ++point) {
1711 house_icon[point] = center + QPointF(house[point * 2] * icon_size,
1712 (house[point * 2 + 1] - 0.025f) * icon_size);
1713 }
1714
1715 p.setPen(colors.transparent);
1716 p.setBrush(colors.font2);
1717 p.drawPolygon(house_icon.data(), static_cast<int>(house_icon.size()));
1718}
1719
1720void PlayerControlPreview::DrawArrow(QPainter& p, const QPointF center, const Direction direction,
1721 float size) {
1722
1723 std::array<QPointF, up_arrow_symbol.size() / 2> arrow_symbol;
1724
1725 for (std::size_t point = 0; point < up_arrow_symbol.size() / 2; ++point) {
1726 switch (direction) {
1727 case Direction::Up:
1728 arrow_symbol[point] = center + QPointF(up_arrow_symbol[point * 2] * size,
1729 up_arrow_symbol[point * 2 + 1] * size);
1730 break;
1731 case Direction::Left:
1732 arrow_symbol[point] = center + QPointF(up_arrow_symbol[point * 2 + 1] * size,
1733 up_arrow_symbol[point * 2] * size);
1734 break;
1735 case Direction::Right:
1736 arrow_symbol[point] = center + QPointF(-up_arrow_symbol[point * 2 + 1] * size,
1737 up_arrow_symbol[point * 2] * size);
1738 break;
1739 case Direction::Down:
1740 arrow_symbol[point] = center + QPointF(up_arrow_symbol[point * 2] * size,
1741 -up_arrow_symbol[point * 2 + 1] * size);
1742 break;
1743 case Direction::None:
1744 break;
1745 }
1746 }
1747
1748 DrawPolygon(p, arrow_symbol);
1749}
1750
1751template <size_t N>
1752void PlayerControlPreview::DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon) {
1753 p.drawPolygon(polygon.data(), static_cast<int>(polygon.size()));
1754}
1755
1756void PlayerControlPreview::DrawCircle(QPainter& p, const QPointF center, float size) {
1757 p.drawEllipse(center, size, size);
1758}
1759
1760void PlayerControlPreview::DrawRectangle(QPainter& p, const QPointF center, float width,
1761 float height) {
1762 const QRectF rect = QRectF(center.x() - (width / 2), center.y() - (height / 2), width, height);
1763 p.drawRect(rect);
1764}
1765void PlayerControlPreview::DrawRoundRectangle(QPainter& p, const QPointF center, float width,
1766 float height, float round) {
1767 const QRectF rect = QRectF(center.x() - (width / 2), center.y() - (height / 2), width, height);
1768 p.drawRoundedRect(rect, round, round);
1769}
1770
1771void PlayerControlPreview::DrawText(QPainter& p, const QPointF center, float text_size,
1772 const QString& text) {
1773 SetTextFont(p, text_size);
1774 const QFontMetrics fm(p.font());
1775 const QPointF offset = {fm.width(text) / 2.0f, -text_size / 2.0f};
1776 p.drawText(center - offset, text);
1777}
1778
1779void PlayerControlPreview::SetTextFont(QPainter& p, float text_size, const QString& font_family) {
1780 QFont font = p.font();
1781 font.setPointSizeF(text_size);
1782 font.setFamily(font_family);
1783 p.setFont(font);
1784}
diff --git a/src/yuzu/configuration/configure_input_player_widget.h b/src/yuzu/configuration/configure_input_player_widget.h
new file mode 100644
index 000000000..4122e3abd
--- /dev/null
+++ b/src/yuzu/configuration/configure_input_player_widget.h
@@ -0,0 +1,157 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <QFrame>
9#include <QPointer>
10#include "core/frontend/input.h"
11#include "core/settings.h"
12
13class QLabel;
14
15using AnalogParam = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>;
16using ButtonParam = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
17
18// Widget for representing controller animations
19class PlayerControlPreview : public QFrame {
20 Q_OBJECT
21
22public:
23 explicit PlayerControlPreview(QWidget* parent);
24 ~PlayerControlPreview() override;
25
26 void SetPlayerInput(std::size_t index, const ButtonParam& buttons_param,
27 const AnalogParam& analogs_param);
28 void SetConnectedStatus(bool checked);
29 void SetControllerType(Settings::ControllerType type);
30 void BeginMappingButton(std::size_t button_id);
31 void BeginMappingAnalog(std::size_t button_id);
32 void EndMapping();
33
34protected:
35 void paintEvent(QPaintEvent* event) override;
36
37private:
38 enum class Direction : std::size_t {
39 None,
40 Up,
41 Right,
42 Down,
43 Left,
44 };
45
46 struct AxisValue {
47 QPointF value{};
48 QPointF raw_value{};
49 Input::AnalogProperties properties{};
50 int size{};
51 QPoint offset{};
52 bool active{};
53 };
54
55 struct LedPattern {
56 bool position1;
57 bool position2;
58 bool position3;
59 bool position4;
60 };
61
62 struct ColorMapping {
63 QColor outline{};
64 QColor primary{};
65 QColor left{};
66 QColor right{};
67 QColor button{};
68 QColor button2{};
69 QColor font{};
70 QColor font2{};
71 QColor highlight{};
72 QColor highlight2{};
73 QColor transparent{};
74 QColor indicator{};
75 QColor led_on{};
76 QColor led_off{};
77 QColor slider{};
78 QColor slider_button{};
79 QColor slider_arrow{};
80 QColor deadzone{};
81 };
82
83 static LedPattern GetColorPattern(std::size_t index, bool player_on);
84 void UpdateColors();
85
86 // Draw controller functions
87 void DrawHandheldController(QPainter& p, QPointF center);
88 void DrawDualController(QPainter& p, QPointF center);
89 void DrawLeftController(QPainter& p, QPointF center);
90 void DrawRightController(QPainter& p, QPointF center);
91 void DrawProController(QPainter& p, QPointF center);
92
93 // Draw body functions
94 void DrawHandheldBody(QPainter& p, QPointF center);
95 void DrawDualBody(QPainter& p, QPointF center);
96 void DrawLeftBody(QPainter& p, QPointF center);
97 void DrawRightBody(QPainter& p, QPointF center);
98 void DrawProBody(QPainter& p, QPointF center);
99
100 // Draw triggers functions
101 void DrawProTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
102 void DrawHandheldTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
103 void DrawDualTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
104 void DrawDualZTriggers(QPainter& p, QPointF center, bool left_pressed, bool right_pressed);
105 void DrawLeftTriggers(QPainter& p, QPointF center, bool left_pressed);
106 void DrawLeftZTriggers(QPainter& p, QPointF center, bool left_pressed);
107 void DrawRightTriggers(QPainter& p, QPointF center, bool right_pressed);
108 void DrawRightZTriggers(QPainter& p, QPointF center, bool right_pressed);
109
110 // Draw joystick functions
111 void DrawJoystick(QPainter& p, QPointF center, float size, bool pressed);
112 void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size, bool pressed);
113 void DrawRawJoystick(QPainter& p, QPointF center, const QPointF value,
114 const Input::AnalogProperties properties);
115 void DrawProJoystick(QPainter& p, QPointF center, bool pressed);
116
117 // Draw button functions
118 void DrawCircleButton(QPainter& p, QPointF center, bool pressed, int button_size);
119 void DrawRoundButton(QPainter& p, QPointF center, bool pressed, float width, float height,
120 Direction direction = Direction::None, float radius = 2);
121 void DrawMinusButton(QPainter& p, QPointF center, bool pressed, int button_size);
122 void DrawPlusButton(QPainter& p, QPointF center, bool pressed, int button_size);
123 void DrawArrowButton(QPainter& p, QPointF center, Direction direction, bool pressed);
124
125 // Draw icon functions
126 void DrawHouseIcon(QPainter& p, QPointF center, float icon_size);
127 void DrawArrow(QPainter& p, QPointF center, Direction direction, float size);
128
129 // Draw primitive types
130 template <size_t N>
131 void DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon);
132 void DrawCircle(QPainter& p, QPointF center, float size);
133 void DrawRectangle(QPainter& p, QPointF center, float width, float height);
134 void DrawRoundRectangle(QPainter& p, QPointF center, float width, float height, float round);
135 void DrawText(QPainter& p, QPointF center, float text_size, const QString& text);
136 void SetTextFont(QPainter& p, float text_size,
137 const QString& font_family = QStringLiteral("sans-serif"));
138
139 using ButtonArray =
140 std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::BUTTON_NS_END>;
141 using StickArray =
142 std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>;
143
144 bool mapping_active{};
145 int blink_counter{};
146 QColor button_color{};
147 ColorMapping colors{};
148 std::array<QColor, 4> led_color{};
149 ButtonArray buttons{};
150 StickArray sticks{};
151 std::size_t player_index{};
152 std::size_t button_mapping_index{Settings::NativeButton::BUTTON_NS_END};
153 std::size_t analog_mapping_index{Settings::NativeAnalog::NUM_STICKS_HID};
154 std::array<AxisValue, Settings::NativeAnalog::NUM_STICKS_HID> axis_values{};
155 std::array<bool, Settings::NativeButton::NumButtons> button_values{};
156 Settings::ControllerType controller_type{Settings::ControllerType::ProController};
157};