#include #include #include "Lottie/Private/Model/Animation.hpp" #include "Lottie/Private/MainThread/LayerContainers/MainThreadAnimationLayer.hpp" namespace lottie { class Renderer::Impl { public: Impl(std::shared_ptr animation) : _animation(animation) { _layer = std::make_shared( *_animation.get(), std::make_shared(), std::make_shared(), std::make_shared() ); } public: int frameCount() { return (int)(_animation->endFrame - _animation->startFrame); } int framesPerSecond() { return (int)_animation->framerate; } Vector2D size() { return Vector2D(_animation->width, _animation->height); } void setFrame(float index) { _layer->setCurrentFrame(_animation->startFrame + index); } std::shared_ptr renderNode() { return _layer->renderTreeNode(); } private: std::shared_ptr _animation; std::shared_ptr _layer; }; Renderer::Renderer(std::shared_ptr impl) : _impl(impl) { } std::shared_ptr Renderer::make(std::string const &jsonString) { std::string errorText; auto json = lottiejson11::Json::parse(jsonString, errorText); if (!json.is_object()) { return nullptr; } std::shared_ptr animation; try { animation = Animation::fromJson(json.object_items()); } catch(...) { return nullptr; } if (!animation) { return nullptr; } auto impl = std::make_shared(animation); return std::shared_ptr(new Renderer(impl)); } int Renderer::frameCount() { return _impl->frameCount(); } int Renderer::framesPerSecond() { return _impl->framesPerSecond(); } Vector2D Renderer::size() { return _impl->size(); } void Renderer::setFrame(float index) { _impl->setFrame(index); } std::shared_ptr Renderer::renderNode() { return _impl->renderNode(); } }