all repos — mgba @ 61fc28e03e4f4c352a11bc27b4baa463af0b1e8c

mGBA Game Boy Advance Emulator

Qt: Ensure holding down a button while mapping only takes effect once
Jeffrey Pfau jeffrey@endrift.com
Thu, 18 Dec 2014 01:20:37 -0800
commit

61fc28e03e4f4c352a11bc27b4baa463af0b1e8c

parent

e80cf92eeee2469823ef3187299fde115890340a

2 files changed, 26 insertions(+), 13 deletions(-)

jump to
M src/platform/qt/GBAKeyEditor.cppsrc/platform/qt/GBAKeyEditor.cpp

@@ -25,6 +25,7 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* parent)

: QWidget(parent) , m_type(type) , m_controller(controller) + , m_gamepadTimer(nullptr) { setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint); setMinimumSize(300, 300);

@@ -112,8 +113,11 @@

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 @@ }

#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
M src/platform/qt/GBAKeyEditor.hsrc/platform/qt/GBAKeyEditor.h

@@ -8,11 +8,14 @@ #define QGBA_GBA_KEY_EDITOR

#include <QList> #include <QPicture> +#include <QSet> #include <QWidget> extern "C" { #include "gba-input.h" } + +class QTimer; namespace QGBA {

@@ -69,6 +72,12 @@ KeyEditor* m_keyL;

KeyEditor* m_keyR; 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;