Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / include / rive / file.hpp
1 #ifndef _RIVE_FILE_HPP_
2 #define _RIVE_FILE_HPP_
3
4 #include "rive/artboard.hpp"
5 #include "rive/backboard.hpp"
6 #include "rive/factory.hpp"
7 #include "rive/file_asset_resolver.hpp"
8 #include <vector>
9
10 ///
11 /// Default namespace for Rive Cpp runtime code.
12 ///
13 namespace rive {
14     class BinaryReader;
15     class RuntimeHeader;
16     class Factory;
17
18     ///
19     /// Tracks the success/failure result when importing a Rive file.
20     ///
21     enum class ImportResult {
22         /// Indicates that a file's been successfully imported.
23         success,
24         /// Indicates that the Rive file is not supported by this runtime.
25         unsupportedVersion,
26         /// Indicates that the there is a formatting problem in the file itself.
27         malformed
28     };
29
30     ///
31     /// A Rive file.
32     ///
33     class File {
34     public:
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;
39
40     private:
41         /// The file's backboard. All Rive files have a single backboard
42         /// where the artboards live.
43         std::unique_ptr<Backboard> m_Backboard;
44
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;
48
49         Factory* m_Factory;
50
51         /// The helper used to resolve assets when they're not provided in-band
52         /// with the file.
53         FileAssetResolver* m_AssetResolver;
54
55         File(Factory*, FileAssetResolver*);
56
57     public:
58         ~File();
59
60         ///
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,
68                                             Factory*,
69                                             ImportResult* result  = nullptr,
70                                             FileAssetResolver* assetResolver = nullptr);
71
72         /// @returns the file's backboard. All files have exactly one backboard.
73         Backboard* backboard() const { return m_Backboard.get(); }
74
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;
78
79         // Instances
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;
83
84         Artboard* artboard() const;
85
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;
89
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;
93
94     private:
95         ImportResult read(BinaryReader&, const RuntimeHeader&);
96     };
97 } // namespace rive
98 #endif