summaryrefslogtreecommitdiffstats
path: root/src/animation
diff options
context:
space:
mode:
authorChip Collier <gregory.collier@kdab.com>2017-07-20 10:38:49 +0200
committerSean Harmer <sean.harmer@kdab.com>2017-07-24 09:02:34 +0000
commite256972b2f1be3a0ccf2a0fa31424171ba856e01 (patch)
treeff716b4b07fdade83e917b25020332650168fba4 /src/animation
parentbb0e4bb405f6a6fdde6ff96fa48cac1dc0dc1504 (diff)
Add QClock to Qt3DAnimation
Clocks are to be used the animation aspect to allow an application to vary animation clip playback rates. [ChangeLog][Qt3DAnimation][General] Introduce the QClock frontend and backend nodes. Change-Id: Ib73e76800deda07c2fd793d2e3eb3f8a6ee5becb Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r--src/animation/backend/backend.pri6
-rw-r--r--src/animation/backend/clock.cpp71
-rw-r--r--src/animation/backend/clock_p.h86
-rw-r--r--src/animation/frontend/frontend.pri7
-rw-r--r--src/animation/frontend/qclock.cpp109
-rw-r--r--src/animation/frontend/qclock.h77
-rw-r--r--src/animation/frontend/qclock_p.h80
7 files changed, 432 insertions, 4 deletions
diff --git a/src/animation/backend/backend.pri b/src/animation/backend/backend.pri
index 2bc72e1d3..5e4fa925f 100644
--- a/src/animation/backend/backend.pri
+++ b/src/animation/backend/backend.pri
@@ -26,7 +26,8 @@ HEADERS += \
$$PWD/lerpclipblend_p.h \
$$PWD/additiveclipblend_p.h \
$$PWD/clipblendvalue_p.h \
- $$PWD/animationclip_p.h
+ $$PWD/animationclip_p.h \
+ $$PWD/clock_p.h
SOURCES += \
$$PWD/handler.cpp \
@@ -50,4 +51,5 @@ SOURCES += \
$$PWD/lerpclipblend.cpp \
$$PWD/additiveclipblend.cpp \
$$PWD/clipblendvalue.cpp \
- $$PWD/animationclip.cpp
+ $$PWD/animationclip.cpp \
+ $$PWD/clock.cpp
diff --git a/src/animation/backend/clock.cpp b/src/animation/backend/clock.cpp
new file mode 100644
index 000000000..870c79078
--- /dev/null
+++ b/src/animation/backend/clock.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 "clock_p.h"
+#include <Qt3DAnimation/qclock.h>
+#include <Qt3DAnimation/private/qclock_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+#include <Qt3DCore/private/qpropertyupdatedchangebase_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DAnimation {
+namespace Animation {
+
+Clock::Clock()
+ : BackendNode(ReadOnly)
+ , m_startGlobalTime(0)
+ , m_playbackRate(1.f)
+{
+}
+
+void Clock::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+{
+ const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClockData>>(change);
+ const auto &data = typedChange->data;
+ m_playbackRate = data.playbackRate;
+}
+
+void Clock::cleanup()
+{
+ m_startGlobalTime = 0;
+ m_playbackRate = 1.f;
+}
+
+} // namespace Animation
+} // namespace Qt3DAnimation
+
+QT_END_NAMESPACE
diff --git a/src/animation/backend/clock_p.h b/src/animation/backend/clock_p.h
new file mode 100644
index 000000000..a8dd86890
--- /dev/null
+++ b/src/animation/backend/clock_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 QT3DANIMATION_ANIMATION_CLOCK_P_H
+#define QT3DANIMATION_ANIMATION_CLOCK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DAnimation/private/backendnode_p.h>
+#include <Qt3DAnimation/private/animationutils_p.h>
+#include <Qt3DCore/qnodeid.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DAnimation {
+namespace Animation {
+
+class Q_AUTOTEST_EXPORT Clock : public BackendNode
+{
+public:
+ Clock();
+
+ void cleanup();
+
+ void setPlaybackRate(float playbackRate) { m_playbackRate = playbackRate; }
+ int playbackRate() const { return m_playbackRate; }
+
+ void setStartTime(qint64 globalTime) { m_startGlobalTime = globalTime; }
+ qint64 startTime() const { return m_startGlobalTime; }
+
+private:
+ void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL;
+
+ qint64 m_startGlobalTime;
+ float m_playbackRate;
+};
+
+} // namespace Animation
+} // namespace Qt3DAnimation
+
+
+QT_END_NAMESPACE
+
+#endif // QT3DANIMATION_ANIMATION_CLOCK_P_H
diff --git a/src/animation/frontend/frontend.pri b/src/animation/frontend/frontend.pri
index 7f397462b..35835416b 100644
--- a/src/animation/frontend/frontend.pri
+++ b/src/animation/frontend/frontend.pri
@@ -46,7 +46,9 @@ HEADERS += \
$$PWD/qanimationclip.h \
$$PWD/qanimationclip_p.h \
$$PWD/qanimationcallback.h \
- $$PWD/qanimationcallbacktrigger_p.h
+ $$PWD/qanimationcallbacktrigger_p.h \
+ $$PWD/qclock.h \
+ $$PWD/qclock_p.h
SOURCES += \
$$PWD/qanimationaspect.cpp \
@@ -74,6 +76,7 @@ SOURCES += \
$$PWD/qchannelcomponent.cpp \
$$PWD/qkeyframe.cpp \
$$PWD/qanimationclip.cpp \
- $$PWD/qanimationcallbacktrigger.cpp
+ $$PWD/qanimationcallbacktrigger.cpp \
+ $$PWD/qclock.cpp
INCLUDEPATH += $$PWD
diff --git a/src/animation/frontend/qclock.cpp b/src/animation/frontend/qclock.cpp
new file mode 100644
index 000000000..1a3649900
--- /dev/null
+++ b/src/animation/frontend/qclock.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 "qclock.h"
+#include "qclock_p.h"
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DAnimation {
+
+QClockPrivate::QClockPrivate()
+ : Qt3DCore::QNodePrivate()
+ , m_playbackRate(1.0f)
+{
+}
+
+void QClockPrivate::setPlaybackRate(float playbackRate)
+{
+ if (qFuzzyCompare(playbackRate, m_playbackRate))
+ return;
+
+ Q_Q(QClock);
+ m_playbackRate = playbackRate;
+ emit q->playbackRateChanged(playbackRate);
+}
+
+QClock::QClock(Qt3DCore::QNode* parent)
+ : Qt3DCore::QNode(*new QClockPrivate, parent)
+{
+}
+
+QClock::QClock(QClockPrivate &dd, Qt3DCore::QNode *parent)
+ : Qt3DCore::QNode(dd, parent)
+{
+}
+
+QClock::~QClock()
+{
+}
+
+float QClock::playbackRate() const
+{
+ Q_D(const QClock);
+ return d->m_playbackRate;
+}
+
+void QClock::setPlaybackRate(float playbackRate)
+{
+ Q_D(QClock);
+ d->setPlaybackRate(playbackRate);
+}
+
+void QClock::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change)
+{
+ if (change->type() == Qt3DCore::PropertyUpdated) {
+ Qt3DCore::QPropertyUpdatedChangePtr e = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(change);
+ if (e->propertyName() == QByteArrayLiteral("playbackRate")) {
+ Q_D(QClock);
+ d->setPlaybackRate(e->value().toFloat());
+ }
+ }
+}
+
+Qt3DCore::QNodeCreatedChangeBasePtr QClock::createNodeCreationChange() const
+{
+ auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QClockData>::create(this);
+ auto &data = creationChange->data;
+ Q_D(const QClock);
+ data.playbackRate = d->m_playbackRate;
+ return creationChange;
+}
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/animation/frontend/qclock.h b/src/animation/frontend/qclock.h
new file mode 100644
index 000000000..5b6790362
--- /dev/null
+++ b/src/animation/frontend/qclock.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2017 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 QT3DANIMATION_QCLOCK_H
+#define QT3DANIMATION_QCLOCK_H
+
+#include <Qt3DAnimation/qt3danimation_global.h>
+#include <Qt3DCore/qnode.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DAnimation {
+
+class QClockPrivate;
+
+class QT3DANIMATIONSHARED_EXPORT QClock : public Qt3DCore::QNode
+{
+ Q_OBJECT
+ Q_PROPERTY(float playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged)
+
+public:
+ explicit QClock(Qt3DCore::QNode *parent = nullptr);
+ ~QClock();
+
+ float playbackRate() const;
+ void setPlaybackRate(float playbackRate);
+
+Q_SIGNALS:
+ void playbackRateChanged(float playbackRate);
+
+protected:
+ QClock(QClockPrivate &dd, Qt3DCore::QNode *parent = nullptr);
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE;
+
+private:
+ Q_DECLARE_PRIVATE(QClock)
+ Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE;
+};
+
+} // namespace Qt3DAnimation
+
+QT_END_NAMESPACE
+
+#endif // QT3DANIMATION_QCLOCK_H
diff --git a/src/animation/frontend/qclock_p.h b/src/animation/frontend/qclock_p.h
new file mode 100644
index 000000000..d633d071e
--- /dev/null
+++ b/src/animation/frontend/qclock_p.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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 QT3DANIMATION_QCLOCK_P_H
+#define QT3DANIMATION_QCLOCK_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DCore/private/qnode_p.h>
+#include "qclock.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DAnimation {
+
+class QClockPrivate : public Qt3DCore::QNodePrivate
+{
+public:
+ QClockPrivate();
+
+ Q_DECLARE_PUBLIC(QClock)
+
+ void setPlaybackRate(float playbackRate);
+
+ float m_playbackRate;
+};
+
+struct QClockData
+{
+ float playbackRate;
+};
+
+} // namespace Qt3DAnimation
+
+
+QT_END_NAMESPACE
+
+#endif // QT3DANIMATION_QCLOCK_P_H