mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
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:
parent
32c4e1d815
commit
d1664a162e
5 changed files with 62 additions and 1 deletions
15
inc/thorvg.h
15
inc/thorvg.h
|
@ -1343,6 +1343,21 @@ public:
|
|||
*/
|
||||
Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) 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.
|
||||
*
|
||||
|
|
|
@ -2065,6 +2065,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);
|
||||
|
||||
|
||||
/*!
|
||||
* \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
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
/************************************************************************/
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
* @note Experimental API
|
||||
*/
|
||||
const char* marker(uint32_t idx) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a new LottieAnimation object.
|
||||
*
|
||||
|
|
|
@ -220,3 +220,26 @@ uint32_t Picture::mesh(const Polygon** triangles) const noexcept
|
|||
if (triangles) *triangles = pImpl->rm.triangles;
|
||||
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;
|
||||
}
|
Loading…
Add table
Reference in a new issue