configure_input.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2016 Citra 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 <functional>
  7. #include <memory>
  8. #include <string>
  9. #include <unordered_map>
  10. #include <QKeyEvent>
  11. #include <QWidget>
  12. #include <boost/optional.hpp>
  13. #include "common/param_package.h"
  14. #include "core/settings.h"
  15. #include "input_common/main.h"
  16. #include "ui_configure_input.h"
  17. class QPushButton;
  18. class QString;
  19. class QTimer;
  20. namespace Ui {
  21. class ConfigureInput;
  22. }
  23. class ConfigureInput : public QWidget {
  24. Q_OBJECT
  25. public:
  26. explicit ConfigureInput(QWidget* parent = nullptr);
  27. /// Save all button configurations to settings file
  28. void applyConfiguration();
  29. private:
  30. std::unique_ptr<Ui::ConfigureInput> ui;
  31. std::unique_ptr<QTimer> timeout_timer;
  32. std::unique_ptr<QTimer> poll_timer;
  33. /// This will be the the setting function when an input is awaiting configuration.
  34. boost::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
  35. std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
  36. std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
  37. static constexpr int ANALOG_SUB_BUTTONS_NUM = 5;
  38. /// Each button input is represented by a QPushButton.
  39. std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
  40. /// A group of five QPushButtons represent one analog input. The buttons each represent up,
  41. /// down, left, right, and modifier, respectively.
  42. std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
  43. analog_map_buttons;
  44. /// Analog inputs are also represented each with a single button, used to configure with an
  45. /// actual analog stick
  46. std::array<QPushButton*, Settings::NativeAnalog::NumAnalogs> analog_map_stick;
  47. static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
  48. std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
  49. /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
  50. /// keyboard events are ignored.
  51. bool want_keyboard_keys = false;
  52. /// Load configuration settings.
  53. void loadConfiguration();
  54. /// Restore all buttons to their default values.
  55. void restoreDefaults();
  56. /// Clear all input configuration
  57. void ClearAll();
  58. /// Update UI to reflect current configuration.
  59. void updateButtonLabels();
  60. /// Called when the button was pressed.
  61. void handleClick(QPushButton* button,
  62. std::function<void(const Common::ParamPackage&)> new_input_setter,
  63. InputCommon::Polling::DeviceType type);
  64. /// Finish polling and configure input using the input_setter
  65. void setPollingResult(const Common::ParamPackage& params, bool abort);
  66. /// Handle key press events.
  67. void keyPressEvent(QKeyEvent* event) override;
  68. };