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+ bool advanceAndApply (float seconds) { return m_Scene->advanceAndApply (seconds); }
30+
31+ void draw (Renderer* renderer) { return m_Scene->draw (renderer); }
32+ void pointerDown (Vec2D pos) { return m_Scene->pointerDown (pos); }
33+ void pointerMove (Vec2D pos) { return m_Scene->pointerMove (pos); }
34+ void pointerUp (Vec2D pos) { return m_Scene->pointerUp (pos); }
35+
36+ size_t inputCount () const { return m_Scene->inputCount (); }
37+ SMIInput* input (size_t index) const { return m_Scene->input (index); }
38+ SMIBool* getBool (const std::string& name) const { return m_Scene->getBool (name); }
39+ SMINumber* getNumber (const std::string& name) const { return m_Scene->getNumber (name); }
40+ SMITrigger* getTrigger (const std::string& name) const { return m_Scene->getTrigger (name); }
41+ };
42+
43+ std::unique_ptr<Scene> Scene::importDefault (Span<uint8_t > span, Factory* factory) {
44+ auto file = File::import (span, factory);
45+ if (file) {
46+ auto abi = file->artboardDefault ();
47+ if (abi) {
48+ auto scene = abi->defaultScene ();
49+ if (scene) {
50+ return std::make_unique<SelfContainedScene>(std::move (file),
51+ std::move (abi),
52+ std::move (scene));
53+ }
54+ }
55+ }
56+ return nullptr ;
57+ }
0 commit comments