summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-03-16 14:20:19 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-08-03 14:44:04 +0000
commit6a5f72d17fd198ac29fa09dbdd54138faeccef8d (patch)
tree31c8f8b36d1e98a96529aa1a78b92819b512ac67 /src/input
parent2d8e5a80262e23b01ea911f619b344f94185ed5a (diff)
MouseInput backend class for QMouseInput
Change-Id: I24f302c28d944e18a1c19f7344f80abc5c86d309 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/handle_types_p.h2
-rw-r--r--src/input/input.pri6
-rw-r--r--src/input/inputhandler.cpp1
-rw-r--r--src/input/inputhandler_p.h3
-rw-r--r--src/input/inputmanagers_p.h11
-rw-r--r--src/input/mouseinput.cpp156
-rw-r--r--src/input/mouseinput_p.h94
7 files changed, 271 insertions, 2 deletions
diff --git a/src/input/handle_types_p.h b/src/input/handle_types_p.h
index b954e18ed..ba158eb75 100644
--- a/src/input/handle_types_p.h
+++ b/src/input/handle_types_p.h
@@ -48,10 +48,12 @@ namespace Input {
class KeyboardController;
class KeyboardInput;
class MouseController;
+class MouseInput;
typedef QHandle<KeyboardController, 8> HKeyboardController;
typedef QHandle<KeyboardInput, 16> HKeyboardInput;
typedef QHandle<MouseController, 8> HMouseController;
+typedef QHandle<MouseInput, 16> HMouseInput;
} // Input
diff --git a/src/input/input.pri b/src/input/input.pri
index 4c4a8bd62..a16677905 100644
--- a/src/input/input.pri
+++ b/src/input/input.pri
@@ -20,7 +20,8 @@ HEADERS += \
$$PWD/qmouseinput_p.h \
$$PWD/qmousecontroller_p.h \
$$PWD/q3dmouseevent.h \
- $$PWD/mousecontroller_p.h
+ $$PWD/mousecontroller_p.h \
+ $$PWD/mouseinput_p.h
SOURCES += \
$$PWD/cameracontroller.cpp \
@@ -37,6 +38,7 @@ SOURCES += \
$$PWD/qmouseinput.cpp \
$$PWD/qmousecontroller.cpp \
$$PWD/q3dmouseevent.cpp \
- $$PWD/mousecontroller.cpp
+ $$PWD/mousecontroller.cpp \
+ $$PWD/mouseinput.cpp
INCLUDEPATH += $$PWD
diff --git a/src/input/inputhandler.cpp b/src/input/inputhandler.cpp
index 6cfe8f248..56daf8ed6 100644
--- a/src/input/inputhandler.cpp
+++ b/src/input/inputhandler.cpp
@@ -50,6 +50,7 @@ InputHandler::InputHandler()
: m_keyboardControllerManager(new KeyboardControllerManager())
, m_keyboardInputManager(new KeyboardInputManager())
, m_mouseControllerManager(new MouseControllerManager())
+ , m_mouseInputManager(new MouseInputManager())
, m_eventSource(Q_NULLPTR)
, m_keyboardEventFilter(new KeyboardEventFilter())
{
diff --git a/src/input/inputhandler_p.h b/src/input/inputhandler_p.h
index c909d6bf1..84bad456c 100644
--- a/src/input/inputhandler_p.h
+++ b/src/input/inputhandler_p.h
@@ -53,6 +53,7 @@ class KeyboardInputManager;
class KeyboardControllerManager;
class KeyboardEventFilter;
class MouseControllerManager;
+class MouseInputManager;
class InputHandler
{
@@ -65,6 +66,7 @@ public:
inline KeyboardControllerManager *keyboardControllerManager() const { return m_keyboardControllerManager; }
inline KeyboardInputManager *keyboardInputManager() const { return m_keyboardInputManager; }
inline MouseControllerManager *mouseControllerManager() const { return m_mouseControllerManager; }
+ inline MouseInputManager *mouseInputManager() const { return m_mouseInputManager; }
void appendKeyEvent(const QKeyEvent &event);
QList<QKeyEvent> pendingKeyEvents();
@@ -82,6 +84,7 @@ private:
KeyboardControllerManager *m_keyboardControllerManager;
KeyboardInputManager *m_keyboardInputManager;
MouseControllerManager *m_mouseControllerManager;
+ MouseInputManager *m_mouseInputManager;
QVector<HKeyboardController> m_activeKeyboardControllers;
QVector<HMouseController> m_activeMouseControllers;
QObject *m_eventSource;
diff --git a/src/input/inputmanagers_p.h b/src/input/inputmanagers_p.h
index 994519da4..928786c16 100644
--- a/src/input/inputmanagers_p.h
+++ b/src/input/inputmanagers_p.h
@@ -42,6 +42,7 @@
#include <Qt3DInput/private/keyboardcontroller_p.h>
#include <Qt3DInput/private/keyboardinput_p.h>
#include <Qt3DInput/private/mousecontroller_p.h>
+#include <Qt3DInput/private/mouseinput_p.h>
#include <Qt3DCore/private/qresourcemanager_p.h>
QT_BEGIN_NAMESPACE
@@ -80,6 +81,16 @@ public:
MouseControllerManager() {}
};
+class MouseInputManager : public QResourceManager<
+ MouseInput,
+ QNodeId,
+ 16,
+ Qt3D::ArrayAllocatingPolicy>
+{
+public:
+ MouseInputManager() {}
+};
+
} // Input
} // Qt3D
diff --git a/src/input/mouseinput.cpp b/src/input/mouseinput.cpp
new file mode 100644
index 000000000..e58c28192
--- /dev/null
+++ b/src/input/mouseinput.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mouseinput_p.h"
+#include "mousecontroller_p.h"
+#include "inputmanagers_p.h"
+#include "inputhandler_p.h"
+
+#include <Qt3DInput/qmouseinput.h>
+#include <Qt3DInput/qmousecontroller.h>
+#include <Qt3DCore/qscenepropertychange.h>
+#include <Qt3DCore/qbackendscenepropertychange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Input {
+
+MouseInput::MouseInput()
+ : QBackendNode(ReadWrite)
+ , m_enabled(false)
+ , m_inputHandler(Q_NULLPTR)
+{
+}
+
+MouseInput::~MouseInput()
+{
+}
+
+void MouseInput::updateFromPeer(QNode *peer)
+{
+ QMouseInput *input = static_cast<QMouseInput *>(peer);
+ if (input->controller() != Q_NULLPTR)
+ setController(input->controller()->id());
+ m_enabled = input->isEnabled();
+}
+
+QNodeId MouseInput::mouseController() const
+{
+ return m_mouseController;
+}
+
+void MouseInput::setInputHandler(InputHandler *handler)
+{
+ m_inputHandler = handler;
+}
+
+void MouseInput::mouseEvent(const Q3DMouseEventPtr &event)
+{
+ QBackendScenePropertyChangePtr e(new QBackendScenePropertyChange(NodeUpdated, peerUuid()));
+ e->setTargetNode(peerUuid());
+ e->setPropertyName("mouse");
+ e->setValue(QVariant::fromValue(event));
+ notifyObservers(e);
+}
+
+void MouseInput::wheelEvent(const Q3DWheelEventPtr &event)
+{
+ QBackendScenePropertyChangePtr e(new QBackendScenePropertyChange(NodeUpdated, peerUuid()));
+ e->setTargetNode(peerUuid());
+ e->setPropertyName("wheel");
+ e->setValue(QVariant::fromValue(event));
+ notifyObservers(e);
+}
+
+void MouseInput::sceneChangeEvent(const QSceneChangePtr &e)
+{
+ if (e->type() == NodeUpdated) {
+ QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e);
+ if (propertyChange->propertyName() == QByteArrayLiteral("controller")) {
+ const QNodeId newId = propertyChange->value().value<QNodeId>();
+ if (m_mouseController != newId) {
+ setController(newId);
+ }
+ }
+ }
+}
+
+void MouseInput::setController(const QNodeId &controller)
+{
+ if (!m_mouseController.isNull()) {
+ MouseController *controller = m_inputHandler->mouseControllerManager()->lookupResource(m_mouseController);
+ if (controller)
+ controller->removeMouseInput(peerUuid());
+ }
+ m_mouseController = controller;
+ if (!m_mouseController.isNull()) {
+ MouseController *controller = m_inputHandler->mouseControllerManager()->lookupResource(m_mouseController);
+ if (controller)
+ controller->addMouseInput(peerUuid());
+ }
+}
+
+MouseInputFunctor::MouseInputFunctor(InputHandler *handler)
+ : m_handler(handler)
+{
+}
+
+QBackendNode *MouseInputFunctor::create(QNode *frontend, const QBackendNodeFactory *factory) const
+{
+ MouseInput *input = m_handler->mouseInputManager()->getOrCreateResource(frontend->id());
+ input->setFactory(factory);
+ input->setInputHandler(m_handler);
+ input->setPeer(frontend);
+ return input;
+}
+
+QBackendNode *MouseInputFunctor::get(const QNodeId &id) const
+{
+ return m_handler->mouseInputManager()->lookupResource(id);
+}
+
+void MouseInputFunctor::destroy(const QNodeId &id) const
+{
+ m_handler->mouseInputManager()->releaseResource(id);
+}
+
+} // Input
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/input/mouseinput_p.h b/src/input/mouseinput_p.h
new file mode 100644
index 000000000..f0804788e
--- /dev/null
+++ b/src/input/mouseinput_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3D_INPUT_MOUSEINPUT_H
+#define QT3D_INPUT_MOUSEINPUT_H
+
+#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DInput/q3dmouseevent.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Input {
+
+class InputHandler;
+
+class MouseInput : public QBackendNode
+{
+public:
+ MouseInput();
+ ~MouseInput();
+
+ void updateFromPeer(QNode *peer) Q_DECL_OVERRIDE;
+ QNodeId mouseController() const;
+ void setInputHandler(InputHandler *handler);
+ void mouseEvent(const Q3DMouseEventPtr &event);
+ void wheelEvent(const Q3DWheelEventPtr &event);
+
+ inline bool isEnabled() const { return m_enabled; }
+
+protected:
+ void sceneChangeEvent(const QSceneChangePtr &e) Q_DECL_OVERRIDE;
+ void setController(const QNodeId &controller);
+
+private:
+ bool m_enabled;
+ QNodeId m_mouseController;
+ InputHandler *m_inputHandler;
+};
+
+class MouseInputFunctor : public QBackendNodeFunctor
+{
+public:
+ explicit MouseInputFunctor(InputHandler *handler);
+
+ QBackendNode *create(QNode *frontend, const QBackendNodeFactory *factory) const Q_DECL_OVERRIDE;
+ QBackendNode *get(const QNodeId &id) const Q_DECL_OVERRIDE;
+ void destroy(const QNodeId &id) const Q_DECL_OVERRIDE;
+
+private:
+ InputHandler *m_handler;
+};
+
+} // Input
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // MOUSEINPUT_H