1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "actioninput_p.h"
5
6#include <Qt3DInput/qactioninput.h>
7#include <Qt3DInput/qabstractphysicaldevice.h>
8#include <Qt3DInput/private/qactioninput_p.h>
9#include <Qt3DInput/private/inputhandler_p.h>
10#include <Qt3DInput/private/utils_p.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace Qt3DInput {
15
16namespace Input {
17
18ActionInput::ActionInput()
19 : AbstractActionInput()
20{
21}
22
23void ActionInput::cleanup()
24{
25 setEnabled(false);
26 m_sourceDevice = Qt3DCore::QNodeId();
27 m_buttons.clear();
28}
29
30void ActionInput::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
31{
32 AbstractActionInput::syncFromFrontEnd(frontEnd, firstTime);
33 const QActionInput *node = qobject_cast<const QActionInput *>(object: frontEnd);
34 if (!node)
35 return;
36
37 m_sourceDevice = Qt3DCore::qIdForNode(node: node->sourceDevice());
38 m_buttons = node->buttons();
39}
40
41bool ActionInput::process(InputHandler *inputHandler, qint64 currentTime)
42{
43 Q_UNUSED(currentTime);
44
45 if (!isEnabled())
46 return false;
47
48 QAbstractPhysicalDeviceBackendNode *physicalDeviceBackend = Utils::physicalDeviceForInput(input: this, handler: inputHandler);
49 if (!physicalDeviceBackend)
50 return false;
51
52 for (int button : std::as_const(t&: m_buttons)) {
53 if (physicalDeviceBackend->isButtonPressed(buttonIdentifier: button))
54 return true;
55 }
56
57 return false;
58}
59
60} // namespace Input
61
62} // namespace Qt3DInput
63
64QT_END_NAMESPACE
65
66

source code of qt3d/src/input/backend/actioninput.cpp