1 | // Copyright (C) 2016 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 | #ifndef GENERICDEVICEBACKENDNODE_H |
5 | #define GENERICDEVICEBACKENDNODE_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of other Qt classes. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/QHash> |
19 | #include <QtCore/QMutex> |
20 | |
21 | #include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | namespace Qt3DInput { |
26 | |
27 | class QAbstractPhysicalDevice; |
28 | |
29 | namespace Input { |
30 | class InputHandler; |
31 | class GenericDeviceBackendNodeData; |
32 | class GenericDeviceBackendNode : public QAbstractPhysicalDeviceBackendNode |
33 | { |
34 | public: |
35 | explicit GenericDeviceBackendNode(QBackendNode::Mode mode = QBackendNode::ReadWrite); |
36 | ~GenericDeviceBackendNode(); |
37 | void updateEvents(); |
38 | |
39 | // QAbstractPhysicalDeviceBackendNode interface |
40 | void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; |
41 | void cleanup() override; |
42 | float axisValue(int axisIdentifier) const override; |
43 | bool isButtonPressed(int buttonIdentifier) const override; |
44 | |
45 | private: |
46 | QHash<int, qreal> m_axesValues; |
47 | QHash<int, qreal> m_buttonsValues; |
48 | mutable QMutex m_mutex; |
49 | }; |
50 | |
51 | class GenericDeviceBackendFunctor : public Qt3DCore::QBackendNodeMapper |
52 | { |
53 | public: |
54 | explicit GenericDeviceBackendFunctor(QInputAspect *inputaspect, InputHandler *handler); |
55 | |
56 | Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const override; |
57 | Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override; |
58 | void destroy(Qt3DCore::QNodeId id) const override; |
59 | |
60 | private: |
61 | QInputAspect *m_inputAspect; |
62 | InputHandler *m_handler; |
63 | }; |
64 | |
65 | } // namespace Input |
66 | } // namespace Qt3DInput |
67 | |
68 | QT_END_NAMESPACE |
69 | |
70 | #endif // GENERICDEVICEBACKENDNODE_H |
71 | |