diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2016-08-23 16:26:10 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-08-24 19:33:24 +0000 |
commit | 335052336eb0e1816f24a4f120551ee2b23ac1aa (patch) | |
tree | 1be1483acc4071a44f665686eeb45e7991a38b65 /src/input | |
parent | 81ecbf04bf7c8a091916f0fa4c8840d499099453 (diff) |
Move input, chord and sequence logic out of job
The bookkeeping and activation logic of ActionInput, InputChord and
InputSequence now move outside of the job, which make them testable
properly. The tests already show bugs which will be fixed in following
commits.
Change-Id: I4e434118a6ba285d08632c43d487b17ee5b4cb66
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/backend/actioninput.cpp | 21 | ||||
-rw-r--r-- | src/input/backend/inputchord.cpp | 20 | ||||
-rw-r--r-- | src/input/backend/inputsequence.cpp | 20 | ||||
-rw-r--r-- | src/input/backend/updateaxisactionjob.cpp | 62 |
4 files changed, 62 insertions, 61 deletions
diff --git a/src/input/backend/actioninput.cpp b/src/input/backend/actioninput.cpp index 7b620611e..c22d20730 100644 --- a/src/input/backend/actioninput.cpp +++ b/src/input/backend/actioninput.cpp @@ -41,6 +41,8 @@ #include <Qt3DInput/qactioninput.h> #include <Qt3DInput/qabstractphysicaldevice.h> #include <Qt3DInput/private/qactioninput_p.h> +#include <Qt3DInput/private/qinputdeviceintegration_p.h> +#include <Qt3DInput/private/inputhandler_p.h> #include <Qt3DCore/qpropertyupdatedchange.h> QT_BEGIN_NAMESPACE @@ -85,6 +87,25 @@ void ActionInput::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) bool ActionInput::process(InputHandler *inputHandler, qint64 currentTime) { + Q_UNUSED(currentTime); + + QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = nullptr; + + const auto integrations = inputHandler->inputDeviceIntegrations(); + for (QInputDeviceIntegration *integration : integrations) { + physicalDeviceBackend = integration->physicalDevice(sourceDevice()); + if (physicalDeviceBackend) + break; + } + + if (!physicalDeviceBackend) + return false; + + for (int button : qAsConst(m_buttons)) { + if (physicalDeviceBackend->isButtonPressed(button)) + return true; + } + return false; } diff --git a/src/input/backend/inputchord.cpp b/src/input/backend/inputchord.cpp index 81394c935..e9ce8315f 100644 --- a/src/input/backend/inputchord.cpp +++ b/src/input/backend/inputchord.cpp @@ -40,6 +40,7 @@ #include "inputchord_p.h" #include <Qt3DInput/qinputchord.h> #include <Qt3DInput/private/qinputchord_p.h> +#include <Qt3DInput/private/inputhandler_p.h> #include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DCore/qpropertynodeaddedchange.h> #include <Qt3DCore/qpropertynoderemovedchange.h> @@ -134,7 +135,24 @@ void InputChord::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) bool InputChord::process(InputHandler *inputHandler, qint64 currentTime) { - return false; + if (m_startTime != 0) { + // Check if we are still inside the time limit for the chord + if ((currentTime - m_startTime) > m_timeout) { + reset(); + return false; + } + } + + bool triggered = false; + for (const Qt3DCore::QNodeId &actionInputId : qAsConst(m_chords)) { + AbstractActionInput *actionInput = inputHandler->lookupActionInput(actionInputId); + if (actionInput && actionInput->process(inputHandler, currentTime)) { + triggered |= actionTriggered(actionInputId); + if (m_startTime == 0) + m_startTime = currentTime; + } + } + return triggered; } } // namespace Input diff --git a/src/input/backend/inputsequence.cpp b/src/input/backend/inputsequence.cpp index 94616fdac..f9771d066 100644 --- a/src/input/backend/inputsequence.cpp +++ b/src/input/backend/inputsequence.cpp @@ -41,6 +41,7 @@ #include <Qt3DInput/qinputsequence.h> #include <Qt3DInput/qabstractphysicaldevice.h> #include <Qt3DInput/private/qinputsequence_p.h> +#include <Qt3DInput/private/inputhandler_p.h> #include <Qt3DCore/qpropertyupdatedchange.h> #include <Qt3DCore/qpropertynodeaddedchange.h> #include <Qt3DCore/qpropertynoderemovedchange.h> @@ -159,7 +160,24 @@ void InputSequence::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) bool InputSequence::process(InputHandler *inputHandler, qint64 currentTime) { - return false; + if (m_startTime != 0) { + // Check if we are still inside the time limit for the sequence + if ((currentTime - m_startTime) > m_timeout) { + reset(); + return false; + } + } + + bool triggered = false; + for (const Qt3DCore::QNodeId &actionInputId : qAsConst(m_sequences)) { + AbstractActionInput *actionInput = inputHandler->lookupActionInput(actionInputId); + if (actionInput && actionInput->process(inputHandler, currentTime)) { + triggered |= actionTriggered(actionInputId, currentTime); + if (m_startTime == 0) + m_startTime = currentTime; + } + } + return triggered; } } // namespace Input diff --git a/src/input/backend/updateaxisactionjob.cpp b/src/input/backend/updateaxisactionjob.cpp index 3a1bfb465..0cbd325c9 100644 --- a/src/input/backend/updateaxisactionjob.cpp +++ b/src/input/backend/updateaxisactionjob.cpp @@ -101,65 +101,9 @@ void UpdateAxisActionJob::updateAction(LogicalDevice *device) bool UpdateAxisActionJob::processActionInput(const Qt3DCore::QNodeId actionInputId) { - - if (m_handler->actionInputManager()->lookupResource(actionInputId)) { - ActionInput *actionInput = m_handler->actionInputManager()->lookupResource(actionInputId); - QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = nullptr; - - const auto integrations = m_handler->inputDeviceIntegrations(); - for (QInputDeviceIntegration *integration : integrations) { - if ((physicalDeviceBackend = integration->physicalDevice(actionInput->sourceDevice())) != nullptr) - break; - } - - if (physicalDeviceBackend != nullptr) { - // Update the value - return anyOfRequiredButtonsPressed(actionInput->buttons(), physicalDeviceBackend); - } - } else if (m_handler->inputSequenceManager()->lookupResource(actionInputId)) { - InputSequence *inputSequence = m_handler->inputSequenceManager()->lookupResource(actionInputId); - const qint64 startTime = inputSequence->startTime(); - if (startTime != 0) { - // Check if we are still inside the time limit for the chord - if ((m_currentTime - startTime) > inputSequence->timeout()) { - inputSequence->reset(); - return false; - } - } - bool actionTriggered = false; - const auto actionInputIds = inputSequence->sequences(); - for (const Qt3DCore::QNodeId actionInputId : actionInputIds) { - if (processActionInput(actionInputId)){ - actionTriggered |= inputSequence->actionTriggered(actionInputId, m_currentTime); - // Set the start time if it wasn't set before - if (startTime == 0) - inputSequence->setStartTime(m_currentTime); - } - } - return actionTriggered; - } else if (m_handler->inputChordManager()->lookupResource(actionInputId)) { - InputChord *inputChord = m_handler->inputChordManager()->lookupResource(actionInputId); - const qint64 startTime = inputChord->startTime(); - if (startTime != 0) { - // Check if we are still inside the time limit for the chord - if ((m_currentTime - startTime) > inputChord->timeout()) { - inputChord->reset(); - return false; - } - } - bool actionTriggered = false; - const auto actionInputIds = inputChord->chords(); - for (const Qt3DCore::QNodeId actionInputId : actionInputIds) { - if (processActionInput(actionInputId)){ - actionTriggered |= inputChord->actionTriggered(actionInputId); - if (startTime == 0) - inputChord->setStartTime(m_currentTime); - } - } - return actionTriggered; - } - //Should Never reach this point - return false; + AbstractActionInput *actionInput = m_handler->lookupActionInput(actionInputId); + Q_ASSERT(actionInput); + return actionInput->process(m_handler, m_currentTime); } void UpdateAxisActionJob::updateAxis(LogicalDevice *device) |