mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
lottie: Introduce the LottieAnimation class
This class extends the Animation and serves advanced Lottie features. It's designed to separately have Lottie Animation's unique specs. For now, this will have Slot overriding feature, you can include <thorvg_lottie.h> for its extensive features. @APIs: - Result LottieAnimation::override(const char* slotJson) noexcept; - static std::unique_ptr<LottieAnimation> LottieAnimation::gen() noexcept; @Issue: https://github.com/thorvg/thorvg/issues/1808
This commit is contained in:
parent
362e6faacb
commit
53878919b5
6 changed files with 160 additions and 22 deletions
|
@ -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('.')
|
49
src/loaders/lottie/thorvg_lottie.h
Normal file
49
src/loaders/lottie/thorvg_lottie.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef _THORVG_LOTTIE_H_
|
||||
#define _THORVG_LOTTIE_H_
|
||||
|
||||
#include <thorvg.h>
|
||||
|
||||
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<LottieAnimation> gen() noexcept;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif //_THORVG_LOTTIE_H_
|
56
src/loaders/lottie/tvgLottieAnimation.cpp
Normal file
56
src/loaders/lottie/tvgLottieAnimation.cpp
Normal file
|
@ -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<LottieLoader*>(pImpl->picture->pImpl->loader)->override(slot)) {
|
||||
return Result::Success;
|
||||
}
|
||||
|
||||
return Result::InsufficientCondition;
|
||||
}
|
||||
|
||||
|
||||
unique_ptr<LottieAnimation> LottieAnimation::gen() noexcept
|
||||
{
|
||||
return unique_ptr<LottieAnimation>(new LottieAnimation);
|
||||
}
|
|
@ -13,6 +13,7 @@ if get_option('engines').contains('wg_beta') == true
|
|||
endif
|
||||
|
||||
source_file = [
|
||||
'tvgAnimation.h',
|
||||
'tvgCanvas.h',
|
||||
'tvgCommon.h',
|
||||
'tvgFill.h',
|
||||
|
|
|
@ -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> Animation::gen() noexcept
|
||||
{
|
||||
return unique_ptr<Animation>(new Animation);
|
||||
}
|
||||
}
|
||||
|
|
48
src/renderer/tvgAnimation.h
Normal file
48
src/renderer/tvgAnimation.h
Normal file
|
@ -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_
|
Loading…
Add table
Reference in a new issue