From c48a73c6f2f25fc8773be304269dc635557338d8 Mon Sep 17 00:00:00 2001 From: Jinny You Date: Mon, 17 Mar 2025 18:05:38 +0900 Subject: [PATCH] capi: update with Slot API --- src/bindings/capi/thorvg_capi.h | 42 ++++++++++++++++++++++++++++----- src/bindings/capi/tvgCapi.cpp | 23 ++++++++++++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index 57b4b4fd..bf02d3f5 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -2623,19 +2623,49 @@ TVG_API Tvg_Animation* tvg_lottie_animation_new(void); /*! -* @brief Override the lottie properties through the slot data. +* @brief Generates a new slot from the given slot data. * -* @param[in] animation The Tvg_Animation object to override the property with the slot. -* @param[in] slot The Lottie slot data in json, or @c nullptr to reset. +* @param[in] animation The Tvg_Animation pointer to the Lottie animation object. +* @param[in] slot The Lottie slot data in JSON format. +* +* @return The generated slot ID when successful, 0 otherwise. +* +* @since 1.0 +*/ +TVG_API uint32_t tvg_lottie_animation_gen_slot(Tvg_Animation* animation, const char* slot); + + +/*! +* @brief Applies a previously generated slot to the animation. +* +* @param[in] animation The Tvg_Animation pointer to the Lottie animation object. +* @param[in] id The ID of the slot to apply, or 0 to reset all slots. * * @return Tvg_Result enumeration. -* @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. -* @retval TVG_RESULT_INVALID_ARGUMENT When the given @p slot is invalid +* @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded or the slot ID is invalid. * @retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. * * @since 1.0 */ -TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot); +TVG_API Tvg_Result tvg_lottie_animation_apply_slot(Tvg_Animation* animation, uint32_t id); + + +/*! +* @brief Deletes a previously generated slot. +* +* @param[in] animation The Tvg_Animation pointer to the Lottie animation object. +* @param[in] id The ID of the slot to delete. +* +* @return Tvg_Result enumeration. +* @retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded or the slot ID is invalid. +* @retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. +* +* @note This function should be paired with gen. +* @see tvg_lottie_animation_gen_slot() +* @since 1.0 +*/ +TVG_API Tvg_Result tvg_lottie_animation_del_slot(Tvg_Animation* animation, uint32_t id); + /*! diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 552534b8..34955345 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -1035,10 +1035,29 @@ TVG_API Tvg_Animation* tvg_lottie_animation_new() } -TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot) +TVG_API uint32_t tvg_lottie_animation_gen_slot(Tvg_Animation* animation, const char* slot) { #ifdef THORVG_LOTTIE_LOADER_SUPPORT - if (animation) return (Tvg_Result) reinterpret_cast(animation)->override(slot); + if (animation) return reinterpret_cast(animation)->gen(slot); +#endif + return 0; +} + + +TVG_API Tvg_Result tvg_lottie_animation_apply_slot(Tvg_Animation* animation, uint32_t id) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->apply(id); + return TVG_RESULT_INVALID_ARGUMENT; +#endif + return TVG_RESULT_NOT_SUPPORTED; +} + + +TVG_API Tvg_Result tvg_lottie_animation_del_slot(Tvg_Animation* animation, uint32_t id) +{ +#ifdef THORVG_LOTTIE_LOADER_SUPPORT + if (animation) return (Tvg_Result) reinterpret_cast(animation)->del(id); return TVG_RESULT_INVALID_ARGUMENT; #endif return TVG_RESULT_NOT_SUPPORTED;