configure_input_player_widget.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <QFrame>
  6. #include <QPointer>
  7. #include "common/input.h"
  8. #include "common/settings_input.h"
  9. #include "core/hid/emulated_controller.h"
  10. #include "core/hid/hid_types.h"
  11. class QLabel;
  12. using AnalogParam = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>;
  13. using ButtonParam = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
  14. // Widget for representing controller animations
  15. class PlayerControlPreview : public QFrame {
  16. Q_OBJECT
  17. public:
  18. explicit PlayerControlPreview(QWidget* parent);
  19. ~PlayerControlPreview() override;
  20. // Sets the emulated controller to be displayed
  21. void SetController(Core::HID::EmulatedController* controller);
  22. // Disables events from the emulated controller
  23. void UnloadController();
  24. // Starts blinking animation at the button specified
  25. void BeginMappingButton(std::size_t button_id);
  26. // Starts moving animation at the stick specified
  27. void BeginMappingAnalog(std::size_t stick_id);
  28. // Stops any ongoing animation
  29. void EndMapping();
  30. // Handles emulated controller events
  31. void ControllerUpdate(Core::HID::ControllerTriggerType type);
  32. // Updates input on sheduled interval
  33. void UpdateInput();
  34. protected:
  35. void paintEvent(QPaintEvent* event) override;
  36. private:
  37. enum class Direction : std::size_t {
  38. None,
  39. Up,
  40. Right,
  41. Down,
  42. Left,
  43. };
  44. enum class Symbol {
  45. House,
  46. A,
  47. B,
  48. X,
  49. Y,
  50. L,
  51. R,
  52. C,
  53. SL,
  54. ZL,
  55. ZR,
  56. SR,
  57. Charging,
  58. };
  59. struct ColorMapping {
  60. QColor outline{};
  61. QColor primary{};
  62. QColor left{};
  63. QColor right{};
  64. QColor button{};
  65. QColor button2{};
  66. QColor font{};
  67. QColor font2{};
  68. QColor highlight{};
  69. QColor highlight2{};
  70. QColor transparent{};
  71. QColor indicator{};
  72. QColor indicator2{};
  73. QColor led_on{};
  74. QColor led_off{};
  75. QColor slider{};
  76. QColor slider_button{};
  77. QColor slider_arrow{};
  78. QColor deadzone{};
  79. QColor charging{};
  80. };
  81. void UpdateColors();
  82. void ResetInputs();
  83. // Draw controller functions
  84. void DrawHandheldController(QPainter& p, QPointF center);
  85. void DrawDualController(QPainter& p, QPointF center);
  86. void DrawLeftController(QPainter& p, QPointF center);
  87. void DrawRightController(QPainter& p, QPointF center);
  88. void DrawProController(QPainter& p, QPointF center);
  89. void DrawGCController(QPainter& p, QPointF center);
  90. // Draw body functions
  91. void DrawHandheldBody(QPainter& p, QPointF center);
  92. void DrawDualBody(QPainter& p, QPointF center);
  93. void DrawLeftBody(QPainter& p, QPointF center);
  94. void DrawRightBody(QPainter& p, QPointF center);
  95. void DrawProBody(QPainter& p, QPointF center);
  96. void DrawGCBody(QPainter& p, QPointF center);
  97. // Draw triggers functions
  98. void DrawProTriggers(QPainter& p, QPointF center,
  99. const Common::Input::ButtonStatus& left_pressed,
  100. const Common::Input::ButtonStatus& right_pressed);
  101. void DrawGCTriggers(QPainter& p, QPointF center, Common::Input::TriggerStatus left_trigger,
  102. Common::Input::TriggerStatus right_trigger);
  103. void DrawHandheldTriggers(QPainter& p, QPointF center,
  104. const Common::Input::ButtonStatus& left_pressed,
  105. const Common::Input::ButtonStatus& right_pressed);
  106. void DrawDualTriggers(QPainter& p, QPointF center,
  107. const Common::Input::ButtonStatus& left_pressed,
  108. const Common::Input::ButtonStatus& right_pressed);
  109. void DrawDualTriggersTopView(QPainter& p, QPointF center,
  110. const Common::Input::ButtonStatus& left_pressed,
  111. const Common::Input::ButtonStatus& right_pressed);
  112. void DrawDualZTriggersTopView(QPainter& p, QPointF center,
  113. const Common::Input::ButtonStatus& left_pressed,
  114. const Common::Input::ButtonStatus& right_pressed);
  115. void DrawLeftTriggers(QPainter& p, QPointF center,
  116. const Common::Input::ButtonStatus& left_pressed);
  117. void DrawLeftZTriggers(QPainter& p, QPointF center,
  118. const Common::Input::ButtonStatus& left_pressed);
  119. void DrawLeftTriggersTopView(QPainter& p, QPointF center,
  120. const Common::Input::ButtonStatus& left_pressed);
  121. void DrawLeftZTriggersTopView(QPainter& p, QPointF center,
  122. const Common::Input::ButtonStatus& left_pressed);
  123. void DrawRightTriggers(QPainter& p, QPointF center,
  124. const Common::Input::ButtonStatus& right_pressed);
  125. void DrawRightZTriggers(QPainter& p, QPointF center,
  126. const Common::Input::ButtonStatus& right_pressed);
  127. void DrawRightTriggersTopView(QPainter& p, QPointF center,
  128. const Common::Input::ButtonStatus& right_pressed);
  129. void DrawRightZTriggersTopView(QPainter& p, QPointF center,
  130. const Common::Input::ButtonStatus& right_pressed);
  131. // Draw joystick functions
  132. void DrawJoystick(QPainter& p, QPointF center, float size,
  133. const Common::Input::ButtonStatus& pressed);
  134. void DrawJoystickSideview(QPainter& p, QPointF center, float angle, float size,
  135. const Common::Input::ButtonStatus& pressed);
  136. void DrawRawJoystick(QPainter& p, QPointF center_left, QPointF center_right);
  137. void DrawJoystickProperties(QPainter& p, QPointF center,
  138. const Common::Input::AnalogProperties& properties);
  139. void DrawJoystickDot(QPainter& p, QPointF center, const Common::Input::StickStatus& stick,
  140. bool raw);
  141. void DrawProJoystick(QPainter& p, QPointF center, QPointF offset, float scalar,
  142. const Common::Input::ButtonStatus& pressed);
  143. void DrawGCJoystick(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
  144. // Draw button functions
  145. void DrawCircleButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
  146. float button_size);
  147. void DrawRoundButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
  148. float width, float height, Direction direction = Direction::None,
  149. float radius = 2);
  150. void DrawMinusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
  151. int button_size);
  152. void DrawPlusButton(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed,
  153. int button_size);
  154. void DrawGCButtonX(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
  155. void DrawGCButtonY(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
  156. void DrawGCButtonZ(QPainter& p, QPointF center, const Common::Input::ButtonStatus& pressed);
  157. void DrawArrowButtonOutline(QPainter& p, const QPointF center, float size = 1.0f);
  158. void DrawArrowButton(QPainter& p, QPointF center, Direction direction,
  159. const Common::Input::ButtonStatus& pressed, float size = 1.0f);
  160. void DrawTriggerButton(QPainter& p, QPointF center, Direction direction,
  161. const Common::Input::ButtonStatus& pressed);
  162. // Draw battery functions
  163. void DrawBattery(QPainter& p, QPointF center, Common::Input::BatteryLevel battery);
  164. // Draw icon functions
  165. void DrawSymbol(QPainter& p, QPointF center, Symbol symbol, float icon_size);
  166. void DrawArrow(QPainter& p, QPointF center, Direction direction, float size);
  167. // Draw primitive types
  168. template <size_t N>
  169. void DrawPolygon(QPainter& p, const std::array<QPointF, N>& polygon);
  170. void DrawCircle(QPainter& p, QPointF center, float size);
  171. void DrawRectangle(QPainter& p, QPointF center, float width, float height);
  172. void DrawRoundRectangle(QPainter& p, QPointF center, float width, float height, float round);
  173. void DrawText(QPainter& p, QPointF center, float text_size, const QString& text);
  174. void SetTextFont(QPainter& p, float text_size,
  175. const QString& font_family = QStringLiteral("sans-serif"));
  176. bool is_controller_set{};
  177. bool is_connected{};
  178. bool needs_redraw{};
  179. Core::HID::NpadStyleIndex controller_type;
  180. bool mapping_active{};
  181. int blink_counter{};
  182. int callback_key;
  183. QColor button_color{};
  184. ColorMapping colors{};
  185. Core::HID::LedPattern led_pattern{0, 0, 0, 0};
  186. std::size_t player_index{};
  187. Core::HID::EmulatedController* controller;
  188. std::size_t button_mapping_index{Settings::NativeButton::NumButtons};
  189. std::size_t analog_mapping_index{Settings::NativeAnalog::NumAnalogs};
  190. Core::HID::ButtonValues button_values{};
  191. Core::HID::SticksValues stick_values{};
  192. Core::HID::TriggerValues trigger_values{};
  193. Core::HID::BatteryValues battery_values{};
  194. };