configure_ringcon.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <functional>
  5. #include <memory>
  6. #include <QDialog>
  7. namespace InputCommon {
  8. class InputSubsystem;
  9. } // namespace InputCommon
  10. namespace Core::HID {
  11. class HIDCore;
  12. class EmulatedController;
  13. } // namespace Core::HID
  14. namespace Ui {
  15. class ConfigureRingController;
  16. } // namespace Ui
  17. class ConfigureRingController : public QDialog {
  18. Q_OBJECT
  19. public:
  20. explicit ConfigureRingController(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_,
  21. Core::HID::HIDCore& hid_core_);
  22. ~ConfigureRingController() override;
  23. void ApplyConfiguration();
  24. private:
  25. void changeEvent(QEvent* event) override;
  26. void RetranslateUI();
  27. void UpdateUI();
  28. /// Load configuration settings.
  29. void LoadConfiguration();
  30. /// Restore all buttons to their default values.
  31. void RestoreDefaults();
  32. /// Sets current polling mode to ring input
  33. void EnableRingController();
  34. // Handles emulated controller events
  35. void ControllerUpdate(Core::HID::ControllerTriggerType type);
  36. /// Called when the button was pressed.
  37. void HandleClick(QPushButton* button,
  38. std::function<void(const Common::ParamPackage&)> new_input_setter,
  39. InputCommon::Polling::InputType type);
  40. /// Finish polling and configure input using the input_setter.
  41. void SetPollingResult(const Common::ParamPackage& params, bool abort);
  42. /// Checks whether a given input can be accepted.
  43. bool IsInputAcceptable(const Common::ParamPackage& params) const;
  44. /// Handle mouse button press events.
  45. void mousePressEvent(QMouseEvent* event) override;
  46. /// Handle key press events.
  47. void keyPressEvent(QKeyEvent* event) override;
  48. QString ButtonToText(const Common::ParamPackage& param);
  49. QString AnalogToText(const Common::ParamPackage& param, const std::string& dir);
  50. static constexpr int ANALOG_SUB_BUTTONS_NUM = 2;
  51. // A group of four QPushButtons represent one analog input. The buttons each represent left,
  52. // right, respectively.
  53. std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM> analog_map_buttons;
  54. static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
  55. std::unique_ptr<QTimer> timeout_timer;
  56. std::unique_ptr<QTimer> poll_timer;
  57. /// This will be the the setting function when an input is awaiting configuration.
  58. std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
  59. InputCommon::InputSubsystem* input_subsystem;
  60. Core::HID::EmulatedController* emulated_controller;
  61. bool is_ring_enabled{};
  62. bool is_controller_set{};
  63. int callback_key;
  64. std::unique_ptr<Ui::ConfigureRingController> ui;
  65. };