renderer/picture: added a method to search for a paint object

This utility method allows access to a specific paint instance
by its unique identifier.

Experimental API:
- const Paint* Picture::paint(uint32_t id)
- const Tvg_Paint* tvg_picture_get_paint(Tvg_Paint* paint, uint32_t id)
This commit is contained in:
Hermet Park 2024-07-30 11:30:02 +09:00 committed by Hermet Park
parent ed9eee897a
commit ee3293401b
5 changed files with 62 additions and 1 deletions

View file

@ -1339,6 +1339,21 @@ public:
*/ */
Result load(uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy = false) noexcept; Result load(uint32_t* data, uint32_t w, uint32_t h, bool premultiplied, bool copy = false) noexcept;
/**
* @brief Retrieve a paint object from the Picture scene by its Unique ID.
*
* This function searches for a paint object within the Picture scene that matches the provided @p id.
*
* @param[in] id The Unique ID of the paint object.
*
* @return A pointer to the paint object that matches the given identifier, or @c nullptr if no matching paint object is found.
*
* @see Accessor::id()
*
* @note Experimental API
*/
const Paint* paint(uint32_t id) noexcept;
/** /**
* @brief Sets or removes the triangle mesh to deform the image. * @brief Sets or removes the triangle mesh to deform the image.
* *

View file

@ -2071,6 +2071,22 @@ TVG_API Tvg_Result tvg_picture_set_size(Tvg_Paint* paint, float w, float h);
TVG_API Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h); TVG_API Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h);
/*!
* \brief Retrieve a paint object from the Picture scene by its Unique ID.
*
* This function searches for a paint object within the Picture scene that matches the provided @p id.
*
* \param[in] paint A Tvg_Paint pointer to the picture object.
* \param[in] id The Unique ID of the paint object.
* \return A pointer to the paint object that matches the given identifier, or @c nullptr if no matching paint object is found.
*
* \see tvg_accessor_generate_id()
* \note experimental API
*/
TVG_API const Tvg_Paint* tvg_picture_get_paint(Tvg_Paint* paint, uint32_t id);
/** \} */ // end defgroup ThorVGCapi_Picture /** \} */ // end defgroup ThorVGCapi_Picture

View file

@ -582,6 +582,13 @@ TVG_API Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float*
} }
TVG_API const Tvg_Paint* tvg_picture_get_paint(Tvg_Paint* paint, uint32_t id)
{
if (!paint) return nullptr;
return (Tvg_Paint*) reinterpret_cast<Picture*>(paint)->paint(id);
}
/************************************************************************/ /************************************************************************/
/* Gradient API */ /* Gradient API */
/************************************************************************/ /************************************************************************/

View file

@ -78,7 +78,7 @@ public:
* @note Experimental API * @note Experimental API
*/ */
const char* marker(uint32_t idx) noexcept; const char* marker(uint32_t idx) noexcept;
/** /**
* @brief Creates a new LottieAnimation object. * @brief Creates a new LottieAnimation object.
* *

View file

@ -214,3 +214,26 @@ uint32_t Picture::mesh(const Polygon** triangles) const noexcept
if (triangles) *triangles = pImpl->rm.triangles; if (triangles) *triangles = pImpl->rm.triangles;
return pImpl->rm.triangleCnt; return pImpl->rm.triangleCnt;
} }
const Paint* Picture::paint(uint32_t id) noexcept
{
struct Value
{
uint32_t id;
const Paint* ret;
} value = {id, nullptr};
auto cb = [](const tvg::Paint* paint, void* data) -> bool
{
auto p = static_cast<Value*>(data);
if (p->id == paint->id) {
p->ret = paint;
return false;
}
return true;
};
tvg::Accessor::gen()->set(this, cb, &value);
return value.ret;
}