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#ifndef QT3DINPUT_INPUT_MOUSEDEVICE_H
5#define QT3DINPUT_INPUT_MOUSEDEVICE_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 <Qt3DInput/QMouseEvent>
19
20#include <Qt3DInput/private/qabstractphysicaldevicebackendnode_p.h>
21
22QT_BEGIN_NAMESPACE
23
24namespace Qt3DInput {
25
26class QInputAspect;
27
28namespace Input {
29
30class InputHandler;
31
32class Q_AUTOTEST_EXPORT MouseDevice : public Qt3DInput::QAbstractPhysicalDeviceBackendNode
33{
34public:
35 struct MouseState {
36
37 MouseState()
38 : xAxis(0.0f)
39 , yAxis(0.0f)
40 , wXAxis(0.0f)
41 , wYAxis(0.0f)
42 , leftPressed(false)
43 , rightPressed(false)
44 , centerPressed(false)
45 {}
46
47 float xAxis;
48 float yAxis;
49 float wXAxis;
50 float wYAxis;
51 bool leftPressed;
52 bool rightPressed;
53 bool centerPressed;
54 };
55
56 MouseDevice();
57 ~MouseDevice();
58
59 void setInputHandler(InputHandler *handler);
60 InputHandler *inputHandler() const;
61
62 float axisValue(int axisIdentifier) const override;
63 bool isButtonPressed(int buttonIdentifier) const override;
64
65 void updateMouseEvent(QT_PREPEND_NAMESPACE(QMouseEvent) *events);
66#if QT_CONFIG(wheelevent)
67 void updateWheelEvent(QT_PREPEND_NAMESPACE(QWheelEvent) *events);
68#endif
69 void resetMouseAxisState();
70
71 MouseState mouseState() const;
72 QPointF previousPos() const;
73 bool wasPressed() const;
74 float sensitivity() const;
75 bool updateAxesContinuously() const;
76
77 void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override;
78
79private:
80 InputHandler *m_inputHandler;
81
82 MouseState m_mouseState;
83 QPointF m_previousPos;
84 bool m_wasPressed;
85 float m_sensitivity;
86 bool m_updateAxesContinuously;
87};
88
89class MouseDeviceFunctor : public Qt3DCore::QBackendNodeMapper
90{
91public:
92 explicit MouseDeviceFunctor(Qt3DInput::QInputAspect *inputAspect, InputHandler *handler);
93
94 Qt3DCore::QBackendNode *create(Qt3DCore::QNodeId id) const override;
95 Qt3DCore::QBackendNode *get(Qt3DCore::QNodeId id) const override;
96 void destroy(Qt3DCore::QNodeId id) const override;
97
98private:
99 QInputAspect *m_inputAspect;
100 InputHandler *m_handler;
101};
102
103} // namespace Input
104} // namespace Qt3DInput
105
106QT_END_NAMESPACE
107
108#endif // MOUSEDEVICE_H
109

source code of qt3d/src/input/backend/mousedevice_p.h