Skip to content

Commit

Permalink
Install custom AnimationDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Oct 19, 2023
1 parent fd556ce commit e46ecdf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mediafx/animation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <QAnimationDriver>

class AnimationDriver : public QAnimationDriver {
public:
AnimationDriver(qint64 frameDuration, QObject* parent = nullptr)
: QAnimationDriver(parent)
, m_frameDuration(frameDuration)
{
}

void advance() override
{
m_elapsed += m_frameDuration;
advanceAnimation();
}

qint64 elapsed() const override
{
return m_elapsed;
}

private:
qint64 m_frameDuration;
qint64 m_elapsed = 0;
};
5 changes: 5 additions & 0 deletions mediafx/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "session.h"
#include "animation.h"
#include "mediafx.h"
#include <QByteArray>
#include <QCoreApplication>
Expand All @@ -26,9 +27,12 @@ Session::Session(QSize& size, qint64 frameDuration)
, m_frameDuration(frameDuration)
, frameTime(0, frameDuration)
, quickView(QUrl(), &renderControl)
, animationDriver(new AnimationDriver(frameDuration, this))
{
connect(this, &Session::exitApp, qApp, &QCoreApplication::exit, Qt::QueuedConnection);

animationDriver->install();

MediaFXForeign::s_singletonInstance = new MediaFX(this, this);

quickView.setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
Expand Down Expand Up @@ -95,6 +99,7 @@ void Session::render()
}
/**** XXX ****/

animationDriver->advance();
frameTime = frameTime.translated(frameDuration());
}

Expand Down
2 changes: 2 additions & 0 deletions mediafx/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MediaFX;
class QQmlError;
class QSize;
class QUrl;
class AnimationDriver;

class Session : public QObject {
Q_OBJECT
Expand Down Expand Up @@ -43,4 +44,5 @@ private slots:
RenderControl renderControl;
QQuickView quickView;
MediaFX* mediaFX;
AnimationDriver* animationDriver;
};

0 comments on commit e46ecdf

Please sign in to comment.