Qt: Ensure holding down a button while mapping only takes effect once

This commit is contained in:
Jeffrey Pfau 2014-12-18 01:20:37 -08:00
parent e80cf92eee
commit 61fc28e03e
2 changed files with 26 additions and 13 deletions

View File

@ -25,6 +25,7 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* paren
: QWidget(parent)
, m_type(type)
, m_controller(controller)
, m_gamepadTimer(nullptr)
{
setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint);
setMinimumSize(300, 300);
@ -112,8 +113,11 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* paren
setAll->setFocus();
#ifdef BUILD_SDL
if (type == SDL_BINDING_BUTTON) {\
QTimer::singleShot(50, this, SLOT(testGamepad()));
if (type == SDL_BINDING_BUTTON) {
m_gamepadTimer = new QTimer(this);
connect(m_gamepadTimer, SIGNAL(timeout()), this, SLOT(testGamepad()));
m_gamepadTimer->setInterval(50);
m_gamepadTimer->start();
}
#endif
}
@ -217,29 +221,29 @@ void GBAKeyEditor::bindKey(const KeyEditor* keyEditor, GBAKey key) {
#ifdef BUILD_SDL
void GBAKeyEditor::testGamepad() {
m_gamepadTimer->setInterval(50);
if (m_currentKey == m_keyOrder.end() || !*m_currentKey) {
QTimer::singleShot(50, this, SLOT(testGamepad()));
return;
}
KeyEditor* focused = *m_currentKey;
QSet<QPair<int, int32_t>> activeAxes = m_controller->activeGamepadAxes();
auto activeAxes = m_controller->activeGamepadAxes();
auto oldAxes = m_activeAxes;
m_activeAxes = activeAxes;
activeAxes.subtract(oldAxes);
if (!activeAxes.empty()) {
focused->setValueAxis(activeAxes.begin()->first, activeAxes.begin()->second);
QTimer::singleShot(200, this, SLOT(testGamepad()));
return;
}
QSet<int> activeKeys = m_controller->activeGamepadButtons();
if (!activeKeys.empty()) {
focused->setValueButton(*activeKeys.begin());
QTimer::singleShot(200, this, SLOT(testGamepad()));
auto activeButtons = m_controller->activeGamepadButtons();
auto oldButtons = m_activeButtons;
m_activeButtons = activeButtons;
activeButtons.subtract(oldButtons);
if (!activeButtons.empty()) {
focused->setValueButton(*activeButtons.begin());
return;
}
QTimer::singleShot(50, this, SLOT(testGamepad()));
}
#endif

View File

@ -8,12 +8,15 @@
#include <QList>
#include <QPicture>
#include <QSet>
#include <QWidget>
extern "C" {
#include "gba-input.h"
}
class QTimer;
namespace QGBA {
class InputController;
@ -70,6 +73,12 @@ private:
QList<KeyEditor*> m_keyOrder;
QList<KeyEditor*>::iterator m_currentKey;
#ifdef BUILD_SDL
QSet<int> m_activeButtons;
QSet<QPair<int, int32_t>> m_activeAxes;
QTimer* m_gamepadTimer;
#endif
uint32_t m_type;
InputController* m_controller;