1+ #include " rive/artboard.hpp"
2+ #include " rive/file.hpp"
3+ #include " rive/scene.hpp"
4+
5+ using namespace rive ;
6+
7+ class SelfContainedScene : public Scene {
8+ std::unique_ptr<File> m_File;
9+ std::unique_ptr<ArtboardInstance> m_ABI;
10+ std::unique_ptr<Scene> m_Scene;
11+
12+ public:
13+ SelfContainedScene (std::unique_ptr<File> file,
14+ std::unique_ptr<ArtboardInstance> abi,
15+ std::unique_ptr<Scene> scene)
16+ : Scene(abi.get())
17+ , m_File(std::move(file))
18+ , m_ABI(std::move(abi))
19+ , m_Scene(std::move(scene)) {}
20+
21+ ~SelfContainedScene () = default ;
22+
23+ // Forward to our m_Scene
24+
25+ std::string name () const { return m_Scene->name (); }
26+ Loop loop () const { return m_Scene->loop (); }
27+ bool isTranslucent () const { return m_Scene->isTranslucent (); }
28+ float durationSeconds () const { return m_Scene->durationSeconds (); }
29+
30+ bool advanceAndApply (float seconds) { return m_Scene->advanceAndApply (seconds); }
31+ void draw (Renderer* renderer) { return m_Scene->draw (renderer); }
32+
33+ void pointerDown (Vec2D pos) { return m_Scene->pointerDown (pos); }
34+ void pointerMove (Vec2D pos) { return m_Scene->pointerMove (pos); }
35+ void pointerUp (Vec2D pos) { return m_Scene->pointerUp (pos); }
36+
37+ size_t inputCount () const { return m_Scene->inputCount (); }
38+ SMIInput* input (size_t index) const { return m_Scene->input (index); }
39+ SMIBool* getBool (const std::string& name) const { return m_Scene->getBool (name); }
40+ SMINumber* getNumber (const std::string& name) const { return m_Scene->getNumber (name); }
41+ SMITrigger* getTrigger (const std::string& name) const { return m_Scene->getTrigger (name); }
42+ };
43+
44+ std::unique_ptr<Scene> Scene::importDefault (Span<uint8_t > span, Factory* factory) {
45+ auto file = File::import (span, factory);
46+ if (file) {
47+ auto abi = file->artboardDefault ();
48+ if (abi) {
49+ auto scene = abi->defaultScene ();
50+ if (scene) {
51+ return std::make_unique<SelfContainedScene>(std::move (file),
52+ std::move (abi),
53+ std::move (scene));
54+ }
55+ }
56+ }
57+ return nullptr ;
58+ }
0 commit comments