configure_input_player_widget.h 9.2 KB

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