mirror of https://github.com/mgba-emu/mgba.git
Qt: Allow keys and axes to be bound at the same time
This commit is contained in:
parent
500eeb7ee3
commit
a08f092913
|
@ -253,14 +253,11 @@ void GBAKeyEditor::lookupAxes(const GBAInputMap* map) {
|
|||
|
||||
void GBAKeyEditor::bindKey(const KeyEditor* keyEditor, GBAKey key) {
|
||||
#ifdef BUILD_SDL
|
||||
if (keyEditor->direction() != GamepadAxisEvent::NEUTRAL) {
|
||||
m_controller->bindAxis(m_type, keyEditor->value(), keyEditor->direction(), key);
|
||||
} else {
|
||||
#endif
|
||||
m_controller->bindKey(m_type, keyEditor->value(), key);
|
||||
#ifdef BUILD_SDL
|
||||
if (m_type == SDL_BINDING_BUTTON) {
|
||||
m_controller->bindAxis(m_type, keyEditor->axis(), keyEditor->direction(), key);
|
||||
}
|
||||
#endif
|
||||
m_controller->bindKey(m_type, keyEditor->value(), key);
|
||||
}
|
||||
|
||||
bool GBAKeyEditor::findFocus() {
|
||||
|
|
|
@ -15,22 +15,20 @@ using namespace QGBA;
|
|||
KeyEditor::KeyEditor(QWidget* parent)
|
||||
: QLineEdit(parent)
|
||||
, m_direction(GamepadAxisEvent::NEUTRAL)
|
||||
, m_key(-1)
|
||||
, m_axis(-1)
|
||||
, m_button(false)
|
||||
{
|
||||
setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
void KeyEditor::setValue(int key) {
|
||||
m_key = key;
|
||||
if (m_button) {
|
||||
if (key < 0) {
|
||||
clear();
|
||||
} else {
|
||||
setText(QString::number(key));
|
||||
}
|
||||
updateButtonText();
|
||||
} else {
|
||||
setText(QKeySequence(key).toString(QKeySequence::NativeText));
|
||||
}
|
||||
m_key = key;
|
||||
emit valueChanged(key);
|
||||
}
|
||||
|
||||
|
@ -41,15 +39,14 @@ void KeyEditor::setValueKey(int key) {
|
|||
|
||||
void KeyEditor::setValueButton(int button) {
|
||||
m_button = true;
|
||||
m_direction = GamepadAxisEvent::NEUTRAL;
|
||||
setValue(button);
|
||||
}
|
||||
|
||||
void KeyEditor::setValueAxis(int axis, int32_t value) {
|
||||
m_button = true;
|
||||
m_key = axis;
|
||||
m_axis = axis;
|
||||
m_direction = value < 0 ? GamepadAxisEvent::NEGATIVE : GamepadAxisEvent::POSITIVE;
|
||||
setText((value < 0 ? "-" : "+") + QString::number(axis));
|
||||
updateButtonText();
|
||||
emit axisChanged(axis, m_direction);
|
||||
}
|
||||
|
||||
|
@ -85,3 +82,18 @@ bool KeyEditor::event(QEvent* event) {
|
|||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void KeyEditor::updateButtonText() {
|
||||
QStringList text;
|
||||
if (m_key >= 0) {
|
||||
text.append(QString::number(m_key));
|
||||
}
|
||||
if (m_direction != GamepadAxisEvent::NEUTRAL) {
|
||||
text.append((m_direction == GamepadAxisEvent::NEGATIVE ? "-" : "+") + QString::number(m_axis));
|
||||
}
|
||||
if (text.isEmpty()) {
|
||||
setText(tr("---"));
|
||||
} else {
|
||||
setText(text.join("/"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
int value() const { return m_key; }
|
||||
|
||||
GamepadAxisEvent::Direction direction() const { return m_direction; }
|
||||
int axis() const { return m_axis; }
|
||||
|
||||
virtual QSize sizeHint() const override;
|
||||
|
||||
|
@ -38,7 +39,10 @@ protected:
|
|||
virtual bool event(QEvent* event) override;
|
||||
|
||||
private:
|
||||
void updateButtonText();
|
||||
|
||||
int m_key;
|
||||
int m_axis;
|
||||
bool m_button;
|
||||
GamepadAxisEvent::Direction m_direction;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue