mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +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
ed9eee897a
commit
ee3293401b
5 changed files with 62 additions and 1 deletions
15
inc/thorvg.h
15
inc/thorvg.h
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue