bindings/capi: Support lottie segment and marker

new experimental apis for animation segment and lottie marker.

APIs:
- TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation* animation, float begin, float end)
- TVG_API Tvg_Result tvg_animation_get_segment(Tvg_Animation* animation, float* begin, float* end = nullptr)
- TVG_API Tvg_Result tvg_lottie_animation_set_marker(Tvg_Animation* animation, const char* marker)
- TVG_API Tvg_Result tvg_lottie_animation_get_marker_cnt(Tvg_Animation* animation, uint32_t* cnt)
- TVG_API Tvg_Result tvg_lottie_animation_get_marker(Tvg_Animation* animation, uint32_t idx, const char** name)
This commit is contained in:
Jinny You 2024-04-13 23:30:48 +09:00 committed by Hermet Park
parent 5992a28e47
commit 34105bd85a
2 changed files with 119 additions and 0 deletions

View file

@ -2323,6 +2323,36 @@ TVG_API Tvg_Result tvg_animation_get_total_frame(Tvg_Animation* animation, float
TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation* animation, float* duration);
/*!
* \brief Specifies the playback segment of the animation. (Experimental API)
*
* \param[in] animation The Tvg_Animation pointer to the animation object.
* \param[in] begin segment begin.
* \param[in] end segment end.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_SUCCESS Succeed.
* \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded.
* \retval TVG_RESULT_INVALID_ARGUMENT When the given parameters are out of range.
*/
TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation* animation, float begin, float end);
/*!
* \brief Gets the current segment. (Experimental API)
*
* \param[in] animation The Tvg_Animation pointer to the animation object.
* \param[out] begin segment begin.
* \param[out] end segment end.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_SUCCESS Succeed.
* \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded.
* \retval TVG_RESULT_INVALID_ARGUMENT When the given parameters are @c nullptr.
*/
TVG_API Tvg_Result tvg_animation_get_segment(Tvg_Animation* animation, float* begin, float* end = nullptr);
/*!
* \brief Deletes the given Tvg_Animation object.
*
@ -2373,6 +2403,48 @@ TVG_API Tvg_Animation* tvg_lottie_animation_new();
TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot);
/*!
* \brief Specifies a segment by marker. (Experimental API)
*
* \param[in] animation The Tvg_Animation pointer to the Lottie animation object.
* \param[in] marker The name of the segment marker.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_SUCCESS Succeed.
* \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded.
* \retval TVG_RESULT_INVALID_ARGUMENT When the given @p marker is invalid.
* \retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported.
*/
TVG_API Tvg_Result tvg_lottie_animation_set_marker(Tvg_Animation* animation, const char* marker);
/*!
* \brief Gets the marker count of the animation. (Experimental API)
*
* \param[in] animation The Tvg_Animation pointer to the Lottie animation object.
* \param[out] cnt The count value of the merkers.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_SUCCESS Succeed.
* \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument.
*/
TVG_API Tvg_Result tvg_lottie_animation_get_markers_cnt(Tvg_Animation* animation, uint32_t* cnt);
/*!
* \brief Gets the marker name by a given index. (Experimental API)
*
* \param[in] animation The Tvg_Animation pointer to the Lottie animation object.
* \param[in] idx The index of the animation marker, starts from 0.
* \param[out] name The name of marker when succeed.
*
* \return Tvg_Result enumeration.
* \retval TVG_RESULT_SUCCESS Succeed.
* \retval TVG_RESULT_INVALID_ARGUMENT In case @c nullptr is passed as the argument or @c idx is out of range.
*/
TVG_API Tvg_Result tvg_lottie_animation_get_marker(Tvg_Animation* animation, uint32_t idx, const char** name);
/** \} */ // end addtogroup ThorVGCapi_LottieAnimation

View file

@ -768,6 +768,20 @@ TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation* animation, float* d
}
TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation* animation, float start, float end)
{
if (!animation) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Animation*>(animation)->segment(start, end);
}
TVG_API Tvg_Result tvg_animation_get_segment(Tvg_Animation* animation, float* start, float* end)
{
if (!animation) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Animation*>(animation)->segment(start, end);
}
TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation)
{
if (!animation) return TVG_RESULT_INVALID_ARGUMENT;
@ -798,6 +812,39 @@ TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const
return TVG_RESULT_NOT_SUPPORTED;
}
TVG_API Tvg_Result tvg_lottie_animation_set_marker(Tvg_Animation* animation, const char* marker)
{
#ifdef THORVG_LOTTIE_LOADER_SUPPORT
if (!animation) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<LottieAnimation*>(animation)->segment(marker);
#endif
return TVG_RESULT_NOT_SUPPORTED;
}
TVG_API Tvg_Result tvg_lottie_animation_get_markers_cnt(Tvg_Animation* animation, uint32_t* cnt)
{
#ifdef THORVG_LOTTIE_LOADER_SUPPORT
if (!animation || !cnt) return TVG_RESULT_INVALID_ARGUMENT;
*cnt = reinterpret_cast<LottieAnimation*>(animation)->markersCnt();
return TVG_RESULT_SUCCESS;
#endif
return TVG_RESULT_NOT_SUPPORTED;
}
TVG_API Tvg_Result tvg_lottie_animation_get_marker(Tvg_Animation* animation, uint32_t idx, const char** name)
{
#ifdef THORVG_LOTTIE_LOADER_SUPPORT
if (!animation || !name) return TVG_RESULT_INVALID_ARGUMENT;
*name = reinterpret_cast<LottieAnimation*>(animation)->marker(idx);
if (!(*name)) return TVG_RESULT_INVALID_ARGUMENT;
return TVG_RESULT_SUCCESS;
#endif
return TVG_RESULT_NOT_SUPPORTED;
}
#ifdef __cplusplus
}
#endif