Qt: These return multiple keys

This commit is contained in:
Vicki Pfau 2023-01-26 16:18:10 -08:00
parent 0cfec878c8
commit 6b63e42146
4 changed files with 28 additions and 10 deletions

View File

@ -495,15 +495,15 @@ void InputController::testGamepad(uint32_t type) {
for (auto& hat : activeHats) { for (auto& hat : activeHats) {
GamepadHatEvent* event = new GamepadHatEvent(GamepadHatEvent::Down(), hat.first, hat.second, type, this); GamepadHatEvent* event = new GamepadHatEvent(GamepadHatEvent::Down(), hat.first, hat.second, type, this);
postPendingEvent(event->platformKey()); postPendingEvents(event->platformKeys());
sendGamepadEvent(event); sendGamepadEvent(event);
if (!event->isAccepted()) { if (!event->isAccepted()) {
clearPendingEvent(event->platformKey()); clearPendingEvents(event->platformKeys());
} }
} }
for (auto& hat : oldHats) { for (auto& hat : oldHats) {
GamepadHatEvent* event = new GamepadHatEvent(GamepadHatEvent::Up(), hat.first, hat.second, type, this); GamepadHatEvent* event = new GamepadHatEvent(GamepadHatEvent::Up(), hat.first, hat.second, type, this);
clearPendingEvent(event->platformKey()); clearPendingEvents(event->platformKeys());
sendGamepadEvent(event); sendGamepadEvent(event);
} }
} }
@ -529,6 +529,22 @@ void InputController::clearPendingEvent(int key) {
m_pendingEvents.remove(key); m_pendingEvents.remove(key);
} }
void InputController::postPendingEvents(int keys) {
for (int i = 0; keys; ++i, keys >>= 1) {
if (keys & 1) {
m_pendingEvents.insert(i);
}
}
}
void InputController::clearPendingEvents(int keys) {
for (int i = 0; keys; ++i, keys >>= 1) {
if (keys & 1) {
m_pendingEvents.remove(i);
}
}
}
bool InputController::hasPendingEvent(int key) const { bool InputController::hasPendingEvent(int key) const {
return m_pendingEvents.contains(key); return m_pendingEvents.contains(key);
} }

View File

@ -128,9 +128,11 @@ private slots:
void teardownCam(); void teardownCam();
private: private:
void postPendingEvent(int); void postPendingEvent(int key);
void clearPendingEvent(int); void clearPendingEvent(int key);
bool hasPendingEvent(int) const; void postPendingEvents(int keys);
void clearPendingEvents(int keys);
bool hasPendingEvent(int key) const;
void sendGamepadEvent(QEvent*); void sendGamepadEvent(QEvent*);
Gamepad* gamepad(uint32_t type); Gamepad* gamepad(uint32_t type);

View File

@ -16,11 +16,11 @@ GamepadHatEvent::GamepadHatEvent(QEvent::Type pressType, int hatId, Direction di
: QEvent(pressType) : QEvent(pressType)
, m_hatId(hatId) , m_hatId(hatId)
, m_direction(direction) , m_direction(direction)
, m_key(-1) , m_keys(0)
{ {
ignore(); ignore();
if (controller) { if (controller) {
m_key = mInputMapHat(controller->map(), type, hatId, direction); m_keys = mInputMapHat(controller->map(), type, hatId, direction);
} }
} }

View File

@ -25,7 +25,7 @@ public:
int hatId() const { return m_hatId; } int hatId() const { return m_hatId; }
Direction direction() const { return m_direction; } Direction direction() const { return m_direction; }
int platformKey() const { return m_key; } int platformKeys() const { return m_keys; }
static Type Down(); static Type Down();
static Type Up(); static Type Up();
@ -36,7 +36,7 @@ private:
int m_hatId; int m_hatId;
Direction m_direction; Direction m_direction;
int m_key; int m_keys;
}; };
} }