diff --git a/src/loaders/lottie/meson.build b/src/loaders/lottie/meson.build index 3732cd59..bd952a91 100644 --- a/src/loaders/lottie/meson.build +++ b/src/loaders/lottie/meson.build @@ -1,4 +1,5 @@ source_file = [ + 'tvgLottieAnimation.cpp', 'tvgLottieBuilder.h', 'tvgLottieInterpolator.h', 'tvgLottieLoader.h', @@ -18,3 +19,6 @@ subloader_dep += [declare_dependency( include_directories : include_directories('.'), sources : source_file )] + +install_headers('thorvg_lottie.h') +headers += include_directories('.') \ No newline at end of file diff --git a/src/loaders/lottie/thorvg_lottie.h b/src/loaders/lottie/thorvg_lottie.h new file mode 100644 index 00000000..ff26d2e9 --- /dev/null +++ b/src/loaders/lottie/thorvg_lottie.h @@ -0,0 +1,49 @@ +#ifndef _THORVG_LOTTIE_H_ +#define _THORVG_LOTTIE_H_ + +#include + +namespace tvg +{ + +/** + * @class LottieAnimation + * + * @brief The LottieAnimation class enables control of advanced Lottie features. + * + * This class extends the Animation and has additional interfaces. + * + * @see Animation + * + * @note Experimental API + */ +class TVG_API LottieAnimation final : public Animation +{ +public: + ~LottieAnimation(); + + /** + * @brief Rewrite lottie properties through the slot data + * + * @param[in] slot The lottie slot data + * + * @retval Result::Success When succeed. + * @retval Result::InsufficientCondition When the given parameter is invalid. + * + * @note Experimental API + */ + Result override(const char* slot) noexcept; + + /** + * @brief Creates a new LottieAnimation object. + * + * @return A new LottieAnimation object. + * + * @note Experimental API + */ + static std::unique_ptr gen() noexcept; +}; + +} //namespace + +#endif //_THORVG_LOTTIE_H_ diff --git a/src/loaders/lottie/tvgLottieAnimation.cpp b/src/loaders/lottie/tvgLottieAnimation.cpp new file mode 100644 index 00000000..c81a8d93 --- /dev/null +++ b/src/loaders/lottie/tvgLottieAnimation.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "tvgCommon.h" +#include "thorvg_lottie.h" +#include "tvgLottieLoader.h" +#include "tvgAnimation.h" + + +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + +LottieAnimation::~LottieAnimation() +{ +} + +Result LottieAnimation::override(const char* slot) noexcept +{ + if (!pImpl->picture->pImpl->loader) return Result::InsufficientCondition; + + if (static_cast(pImpl->picture->pImpl->loader)->override(slot)) { + return Result::Success; + } + + return Result::InsufficientCondition; +} + + +unique_ptr LottieAnimation::gen() noexcept +{ + return unique_ptr(new LottieAnimation); +} diff --git a/src/renderer/meson.build b/src/renderer/meson.build index efbfb10f..39a64910 100644 --- a/src/renderer/meson.build +++ b/src/renderer/meson.build @@ -13,6 +13,7 @@ if get_option('engines').contains('wg_beta') == true endif source_file = [ + 'tvgAnimation.h', 'tvgCanvas.h', 'tvgCommon.h', 'tvgFill.h', diff --git a/src/renderer/tvgAnimation.cpp b/src/renderer/tvgAnimation.cpp index eceb557b..809c4e98 100644 --- a/src/renderer/tvgAnimation.cpp +++ b/src/renderer/tvgAnimation.cpp @@ -20,33 +20,13 @@ * SOFTWARE. */ -#include "tvgCommon.h" #include "tvgFrameModule.h" -#include "tvgPaint.h" -#include "tvgPicture.h" +#include "tvgAnimation.h" /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ -struct Animation::Impl -{ - Picture* picture = nullptr; - - Impl() - { - picture = Picture::gen().release(); - PP(picture)->ref(); - } - - ~Impl() - { - if (PP(picture)->unref() == 0) { - delete(picture); - } - } -}; - /************************************************************************/ /* External Class Implementation */ /************************************************************************/ @@ -116,4 +96,4 @@ float Animation::duration() const noexcept unique_ptr Animation::gen() noexcept { return unique_ptr(new Animation); -} \ No newline at end of file +} diff --git a/src/renderer/tvgAnimation.h b/src/renderer/tvgAnimation.h new file mode 100644 index 00000000..14212eb6 --- /dev/null +++ b/src/renderer/tvgAnimation.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _TVG_ANIMATION_H_ +#define _TVG_ANIMATION_H_ + +#include "tvgCommon.h" +#include "tvgPaint.h" +#include "tvgPicture.h" + +struct Animation::Impl +{ + Picture* picture = nullptr; + + Impl() + { + picture = Picture::gen().release(); + PP(picture)->ref(); + } + + ~Impl() + { + if (PP(picture)->unref() == 0) { + delete(picture); + } + } +}; + +#endif //_TVG_ANIMATION_H_