8 #include <QElapsedTimer>
10 #include <QQuickPaintedItem>
11 #include <QSGRenderNode>
12 #include <QSGTextureProvider>
16 #include <QtCore/QtGlobal>
18 #include <rive/artboard.hpp>
19 #include <rive/listener_type.hpp>
21 #include "rivestatemachineinput.h"
22 #include "datatypes.h"
23 #include "renderer/riveqtfactory.h"
25 #if defined(RIVEQTQUICKITEM_LIBRARY)
26 # define RIVEQTQUICKITEM_EXPORT Q_DECL_EXPORT
28 # define RIVEQTQUICKITEM_EXPORT Q_DECL_IMPORT
31 class RiveQSGRenderNode;
32 class RiveQSGRHIRenderNode;
34 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
35 class RiveQSGSoftwareRenderNode;
45 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
279 stateMachineInterfaceChanged)
300 Q_PROPERTY(RiveRenderSettings::RenderQuality
renderQuality READ
renderQuality WRITE setRenderQuality NOTIFY renderQualityChanged)
321 postprocessingModeChanged)
342 Q_PROPERTY(RiveRenderSettings::FillMode
fillMode READ
fillMode WRITE setFillMode NOTIFY fillModeChanged)
380 void triggerAnimation(
int id);
382 bool isTextureProvider()
const override;
384 QSGTextureProvider *textureProvider()
const override;
387 void setFileSource(
const QString &source);
393 void setCurrentArtboardIndex(
const int newCurrentArtboardIndex);
395 const QVector<ArtBoardInfo> &
artboards()
const;
397 const QVector<AnimationInfo> &
animations()
const;
400 void setCurrentStateMachineIndex(
const int newCurrentStateMachineIndex);
406 void setInteractive(
bool newInteractive);
409 void setPostprocessingMode(
const RiveRenderSettings::PostprocessingMode mode);
412 void setRenderQuality(
const RiveRenderSettings::RenderQuality quality);
414 RiveRenderSettings::FillMode
fillMode()
const;
415 void setFillMode(
const RiveRenderSettings::FillMode
fillMode);
419 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
420 void paint(QPainter *painter)
override;
424 void animationsChanged();
425 void artboardsChanged();
426 void stateMachinesChanged();
428 void fileSourceChanged();
429 void loadingStatusChanged();
431 void currentArtboardIndexChanged();
432 void currentAnimationIndexChanged();
433 void currentStateMachineIndexChanged();
435 void interactiveChanged();
437 void loadFileAfterUnloading(QString fileName);
438 void internalArtboardChanged();
439 void internalStateMachineChanged();
440 void stateMachineInterfaceChanged();
441 void stateMachineStringInterfaceChanged();
443 void renderQualityChanged();
444 void postprocessingModeChanged();
445 void fillModeChanged();
447 void frameRateChanged();
450 QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
override;
451 void componentComplete()
override;
453 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
454 void geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
override;
456 void geometryChanged(
const QRectF &newGeometry,
const QRectF &oldGeometry)
override;
459 void mousePressEvent(QMouseEvent *event)
override;
460 void mouseReleaseEvent(QMouseEvent *event)
override;
462 void hoverMoveEvent(QHoverEvent *event)
override;
463 void hoverEnterEvent(QHoverEvent *event)
override;
464 void hoverLeaveEvent(QHoverEvent *event)
override;
467 void loadRiveFile(
const QString &source);
469 void updateInternalArtboard();
470 void updateAnimations();
471 void updateStateMachines();
472 void updateCurrentArtboardIndex();
473 void updateCurrentStateMachineIndex();
475 QRectF artboardRect();
477 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
478 void renderOffscreen();
481 bool hitTest(
const QPointF &pos,
const rive::ListenerType &type);
483 QVector<ArtBoardInfo> m_artboardInfoList;
484 QVector<AnimationInfo> m_animationList;
485 QVector<StateMachineInfo> m_stateMachineList;
487 std::unique_ptr<rive::File> m_riveFile;
489 mutable QScopedPointer<QSGTextureProvider> m_textureProvider;
491 QString m_fileSource;
494 std::shared_ptr<rive::ArtboardInstance> m_currentArtboardInstance {
nullptr };
495 std::unique_ptr<rive::LinearAnimationInstance> m_animationInstance {
nullptr };
496 std::shared_ptr<rive::StateMachineInstance> m_currentStateMachineInstance {
nullptr };
498 bool m_scheduleArtboardChange {
false };
499 bool m_scheduleStateMachineChange {
false };
501 int m_currentArtboardIndex { -1 };
502 int m_currentAnimationIndex { -1 };
503 int m_initialArtboardIndex { -1 };
504 int m_currentStateMachineIndex { -1 };
505 int m_initialStateMachineIndex { -1 };
509 RiveRenderSettings m_renderSettings;
511 RiveQtFactory m_riveQtFactory { m_renderSettings };
513 QElapsedTimer m_elapsedTimer;
514 qint64 m_lastUpdateTime;
515 bool m_geometryChanged {
true };
517 bool m_hasValidRenderNode {
false };
518 float m_lastMouseX { 0.f };
519 float m_lastMouseY { 0.f };
521 int m_frameRate { 0 };
523 RiveQSGRenderNode *m_renderNode {
nullptr };
524 void updateStateMachineValues();
526 bool m_loadingGuard {
false };
527 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
528 RiveQSGSoftwareRenderNode *softwareRenderNode;
A quick item for Rive-based animations.
Definition: riveqtquickitem.h:50
int currentArtboardIndex
Represents the currently active artboard index.
Definition: riveqtquickitem.h:186
RiveRenderSettings::RenderQuality renderQuality
Represents the render quality setting.
Definition: riveqtquickitem.h:300
bool interactive
Indicates if the item is interactive.
Definition: riveqtquickitem.h:250
LoadingStatus
Enum representing the possible loading states.
Definition: riveqtquickitem.h:368
QVector< AnimationInfo > animations
Contains a list of available animations.
Definition: riveqtquickitem.h:143
RiveRenderSettings::FillMode fillMode
Represents the fill mode setting.
Definition: riveqtquickitem.h:342
int currentAnimationIndex
Represents the currently active animation index.
Definition: riveqtquickitem.h:214
QString fileSource
Represents the source file for the Rive animation.
Definition: riveqtquickitem.h:73
LoadingStatus loadingStatus
Indicates the loading status of the Rive file.
Definition: riveqtquickitem.h:91
RiveRenderSettings::PostprocessingMode postprocessingMode
Represents the postprocessing.
Definition: riveqtquickitem.h:321
int currentStateMachineIndex
Represents the currently active state machine index.
Definition: riveqtquickitem.h:233
int frameRate
Represents the frame rate of the animation.
Definition: riveqtquickitem.h:361
RiveStateMachineInput * stateMachineInterface
Represents the state machine property interface.
Definition: riveqtquickitem.h:279
QVector< ArtBoardInfo > artboards
Contains a list of available artboards.
Definition: riveqtquickitem.h:116
QVector< StateMachineInfo > stateMachines
Contains a list of available state machines.
Definition: riveqtquickitem.h:168