1 #ifndef _RIVE_FILE_HPP_
2 #define _RIVE_FILE_HPP_
4 #include "rive/artboard.hpp"
5 #include "rive/backboard.hpp"
6 #include "rive/factory.hpp"
7 #include "rive/file_asset_resolver.hpp"
11 /// Default namespace for Rive Cpp runtime code.
19 /// Tracks the success/failure result when importing a Rive file.
21 enum class ImportResult {
22 /// Indicates that a file's been successfully imported.
24 /// Indicates that the Rive file is not supported by this runtime.
26 /// Indicates that the there is a formatting problem in the file itself.
35 /// Major version number supported by the runtime.
36 static const int majorVersion = 7;
37 /// Minor version number supported by the runtime.
38 static const int minorVersion = 0;
41 /// The file's backboard. All Rive files have a single backboard
42 /// where the artboards live.
43 std::unique_ptr<Backboard> m_Backboard;
45 /// List of artboards in the file. Each artboard encapsulates a set of
46 /// Rive components and animations.
47 std::vector<std::unique_ptr<Artboard>> m_Artboards;
51 /// The helper used to resolve assets when they're not provided in-band
53 FileAssetResolver* m_AssetResolver;
55 File(Factory*, FileAssetResolver*);
61 /// Imports a Rive file from a binary buffer.
62 /// @param data the raw date of the file.
63 /// @param result is an optional status result.
64 /// @param assetResolver is an optional helper to resolve assets which
65 /// cannot be found in-band.
66 /// @returns a pointer to the file, or null on failure.
67 static std::unique_ptr<File> import(Span<const uint8_t> data,
69 ImportResult* result = nullptr,
70 FileAssetResolver* assetResolver = nullptr);
72 /// @returns the file's backboard. All files have exactly one backboard.
73 Backboard* backboard() const { return m_Backboard.get(); }
75 /// @returns the number of artboards in the file.
76 size_t artboardCount() const { return m_Artboards.size(); }
77 std::string artboardNameAt(size_t index) const;
80 std::unique_ptr<ArtboardInstance> artboardDefault() const;
81 std::unique_ptr<ArtboardInstance> artboardAt(size_t index) const;
82 std::unique_ptr<ArtboardInstance> artboardNamed(std::string name) const;
84 Artboard* artboard() const;
86 /// @returns the named artboard. If no artboard is found with that name,
87 /// the null pointer is returned.
88 Artboard* artboard(std::string name) const;
90 /// @returns the artboard at the specified index, or the nullptr if the
91 /// index is out of range.
92 Artboard* artboard(size_t index) const;
95 ImportResult read(BinaryReader&, const RuntimeHeader&);