capi: exposed Accessor apis

This patch adds basic Accessor API to the C bindings
This commit is contained in:
Dragoș Tiselice 2025-03-25 15:18:02 +02:00 committed by Hermet Park
parent 6ee410e042
commit bc5d90c157
2 changed files with 73 additions and 4 deletions

View file

@ -101,6 +101,11 @@ typedef struct _Tvg_Saver Tvg_Saver;
*/ */
typedef struct _Tvg_Animation Tvg_Animation; typedef struct _Tvg_Animation Tvg_Animation;
/**
* @brief A structure representing an object that enables iterating through a scene's descendents.
*/
typedef struct _Tvg_Accessor Tvg_Accessor;
/** /**
* @brief Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed. * @brief Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed.
@ -2448,6 +2453,48 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation);
/************************************************************************/ /************************************************************************/
/* Accessor API */ /* Accessor API */
/************************************************************************/ /************************************************************************/
/*!
* @brief Creates a new accessor object.
*
* @return A new accessor object.
*
* @note Experimental API
*/
TVG_API Tvg_Accessor* tvg_accessor_new();
/*!
* @brief Deletes the given accessor object.
*
* @param[in] accessor The accessor object to be deleted.
*
* @return Tvg_Result enumeration.
* @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Accessor pointer.
*
* @note Experimental API
*/
TVG_API Tvg_Result tvg_accessor_del(Tvg_Accessor* accessor);
/*!
* @brief Sets the paint of the accessor then iterates through its descendents.
*
* Iterates through all descendents of the scene passed through the paint argument
* while calling func on each and passing the data pointer to this function. When
* func returns false iteration stops and the function returns.
*
* @param[in] accessor A Tvg_Accessor pointer to the accessor object.
* @param[in] paint A Tvg_Paint pointer to the scene object.
* @param[in] func A function pointer to the function that will be execute for each child.
* @param[in] data A void pointer to data that will be passed to the func.
*
* @return Tvg_Result enumeration.
* @retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Accessor, Tvg_Paint, or function pointer.
*
* @note Experimental API
*/
TVG_API Tvg_Result tvg_accessor_set_paint(Tvg_Accessor* accessor, Tvg_Paint* paint, bool (*func)(Tvg_Paint* paint, void* data), void* data);
/*! /*!
* @brief Generate a unique ID (hash key) from a given name. * @brief Generate a unique ID (hash key) from a given name.

View file

@ -903,6 +903,28 @@ TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation)
/* Accessor API */ /* Accessor API */
/************************************************************************/ /************************************************************************/
TVG_API Tvg_Accessor* tvg_accessor_new()
{
return (Tvg_Accessor*) Accessor::gen();
}
TVG_API Tvg_Result tvg_accessor_del(Tvg_Accessor* accessor)
{
if (!accessor) return TVG_RESULT_INVALID_ARGUMENT;
delete(reinterpret_cast<Accessor*>(accessor));
return TVG_RESULT_SUCCESS;
}
TVG_API Tvg_Result tvg_accessor_set(Tvg_Accessor* accessor, Tvg_Paint* paint, bool (*func)(Tvg_Paint* paint, void* data), void* data)
{
if (!accessor) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Accessor*>(accessor)->set(static_cast<Picture*>(reinterpret_cast<Paint*>(paint)),
[func](const Paint* paint, void* data) { return func((Tvg_Paint*) paint, data); }, data);
}
TVG_API uint32_t tvg_accessor_generate_id(const char* name) TVG_API uint32_t tvg_accessor_generate_id(const char* name)
{ {
return Accessor::id(name); return Accessor::id(name);