2020-01-05 02:46:03 +00:00
|
|
|
#pragma once
|
2020-08-29 12:19:28 +00:00
|
|
|
#include "core/controller.h"
|
2020-01-05 02:46:03 +00:00
|
|
|
#include "core/types.h"
|
|
|
|
#include <QtWidgets/QPushButton>
|
2020-08-29 12:19:28 +00:00
|
|
|
#include <optional>
|
2020-01-05 02:46:03 +00:00
|
|
|
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
class QtHostInterface;
|
|
|
|
|
2020-02-17 15:06:11 +00:00
|
|
|
class InputBindingWidget : public QPushButton
|
2020-01-05 02:46:03 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-21 09:49:04 +00:00
|
|
|
InputBindingWidget(QtHostInterface* host_interface, std::string section_name, std::string key_name, QWidget* parent);
|
2020-02-17 15:06:11 +00:00
|
|
|
~InputBindingWidget();
|
2020-01-05 02:46:03 +00:00
|
|
|
|
2020-03-21 14:50:09 +00:00
|
|
|
ALWAYS_INLINE InputBindingWidget* getNextWidget() const { return m_next_widget; }
|
|
|
|
ALWAYS_INLINE void setNextWidget(InputBindingWidget* widget) { m_next_widget = widget; }
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
2020-11-15 13:56:52 +00:00
|
|
|
void bindToControllerAxis(int controller_index, int axis_index, bool inverted,
|
|
|
|
std::optional<bool> half_axis_positive);
|
2020-08-29 12:19:28 +00:00
|
|
|
void bindToControllerButton(int controller_index, int button_index);
|
2020-11-15 13:56:52 +00:00
|
|
|
void bindToControllerHat(int controller_index, int hat_index, const QString& hat_direction);
|
2020-03-21 14:50:09 +00:00
|
|
|
void beginRebindAll();
|
|
|
|
void clearBinding();
|
2020-04-14 15:44:16 +00:00
|
|
|
void reloadBinding();
|
2020-01-05 02:46:03 +00:00
|
|
|
|
2020-02-17 15:06:11 +00:00
|
|
|
protected Q_SLOTS:
|
2020-04-26 07:23:42 +00:00
|
|
|
void onClicked();
|
2020-01-05 02:46:03 +00:00
|
|
|
void onInputListenTimerTimeout();
|
|
|
|
|
2020-02-17 15:06:11 +00:00
|
|
|
protected:
|
2020-03-21 14:50:09 +00:00
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
TIMEOUT_FOR_SINGLE_BINDING = 5,
|
|
|
|
TIMEOUT_FOR_ALL_BINDING = 10
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual bool eventFilter(QObject* watched, QEvent* event) override;
|
2020-07-22 16:35:15 +00:00
|
|
|
virtual bool event(QEvent* event) override;
|
2020-03-21 14:50:09 +00:00
|
|
|
virtual void mouseReleaseEvent(QMouseEvent* e) override;
|
|
|
|
|
|
|
|
virtual void startListeningForInput(u32 timeout_in_seconds);
|
2020-02-17 15:06:11 +00:00
|
|
|
virtual void stopListeningForInput();
|
2020-07-22 16:35:15 +00:00
|
|
|
virtual void openDialog();
|
2020-02-17 15:06:11 +00:00
|
|
|
|
2020-01-05 02:46:03 +00:00
|
|
|
bool isListeningForInput() const { return m_input_listen_timer != nullptr; }
|
2020-01-06 05:14:47 +00:00
|
|
|
void setNewBinding();
|
2020-07-22 16:35:15 +00:00
|
|
|
void updateText();
|
2020-01-05 02:46:03 +00:00
|
|
|
|
|
|
|
QtHostInterface* m_host_interface;
|
2020-07-21 09:49:04 +00:00
|
|
|
std::string m_section_name;
|
|
|
|
std::string m_key_name;
|
2020-07-22 16:35:15 +00:00
|
|
|
std::vector<std::string> m_bindings;
|
2020-07-21 09:49:04 +00:00
|
|
|
std::string m_new_binding_value;
|
2020-01-05 02:46:03 +00:00
|
|
|
QTimer* m_input_listen_timer = nullptr;
|
|
|
|
u32 m_input_listen_remaining_seconds = 0;
|
2020-03-21 14:50:09 +00:00
|
|
|
|
|
|
|
InputBindingWidget* m_next_widget = nullptr;
|
|
|
|
bool m_is_binding_all = false;
|
2020-01-05 02:46:03 +00:00
|
|
|
};
|
2020-02-17 15:06:11 +00:00
|
|
|
|
|
|
|
class InputButtonBindingWidget : public InputBindingWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-22 16:35:15 +00:00
|
|
|
InputButtonBindingWidget(QtHostInterface* host_interface, std::string section_name, std::string key_name,
|
|
|
|
QWidget* parent);
|
2020-02-17 15:06:11 +00:00
|
|
|
~InputButtonBindingWidget();
|
|
|
|
|
|
|
|
protected:
|
2020-03-21 14:50:09 +00:00
|
|
|
void startListeningForInput(u32 timeout_in_seconds) override;
|
2020-02-17 15:06:11 +00:00
|
|
|
void stopListeningForInput() override;
|
2020-07-22 16:35:15 +00:00
|
|
|
void openDialog() override;
|
2020-02-17 15:06:11 +00:00
|
|
|
void hookControllerInput();
|
|
|
|
void unhookControllerInput();
|
|
|
|
};
|
|
|
|
|
|
|
|
class InputAxisBindingWidget : public InputBindingWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-22 16:35:15 +00:00
|
|
|
InputAxisBindingWidget(QtHostInterface* host_interface, std::string section_name, std::string key_name,
|
2020-08-29 12:19:28 +00:00
|
|
|
Controller::AxisType axis_type, QWidget* parent);
|
2020-02-17 15:06:11 +00:00
|
|
|
~InputAxisBindingWidget();
|
|
|
|
|
|
|
|
protected:
|
2020-08-29 12:19:28 +00:00
|
|
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
2020-03-21 14:50:09 +00:00
|
|
|
void startListeningForInput(u32 timeout_in_seconds) override;
|
2020-02-17 15:06:11 +00:00
|
|
|
void stopListeningForInput() override;
|
2020-07-22 16:35:15 +00:00
|
|
|
void openDialog() override;
|
2020-02-17 15:06:11 +00:00
|
|
|
void hookControllerInput();
|
|
|
|
void unhookControllerInput();
|
2020-08-29 12:19:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Controller::AxisType m_axis_type;
|
2020-02-17 15:06:11 +00:00
|
|
|
};
|
2020-04-14 06:35:04 +00:00
|
|
|
|
|
|
|
class InputRumbleBindingWidget : public InputBindingWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-07-22 16:35:15 +00:00
|
|
|
InputRumbleBindingWidget(QtHostInterface* host_interface, std::string section_name, std::string key_name,
|
|
|
|
QWidget* parent);
|
2020-04-14 06:35:04 +00:00
|
|
|
~InputRumbleBindingWidget();
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void bindToControllerRumble(int controller_index);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void startListeningForInput(u32 timeout_in_seconds) override;
|
|
|
|
void stopListeningForInput() override;
|
|
|
|
void hookControllerInput();
|
|
|
|
void unhookControllerInput();
|
|
|
|
};
|