From 6cfc22d123ab810ff4e5831b9f6215a6891a1a99 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Mon, 7 Oct 2024 15:33:38 +0900 Subject: [PATCH] svg_loader: Support id attribute for tvg::Accessor Supports access with tvg::Accessor using the value set in the id attribute of SVG Please refer to examples/Accessor.cpp --- examples/Accessor.cpp | 9 ++++++++- examples/resources/svg/favorite_on.svg | 2 +- src/loaders/svg/tvgSvgSceneBuilder.cpp | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/Accessor.cpp b/examples/Accessor.cpp index 30b91f74..d28095e5 100644 --- a/examples/Accessor.cpp +++ b/examples/Accessor.cpp @@ -60,6 +60,13 @@ struct UserExample : tvgexam::Example if (!tvgexam::verify(accessor->set(picture.get(), f, nullptr))) return false; + // Try to retrieve the shape that corresponds to the SVG node with the unique ID "star". + if (auto paint = picture->paint(tvg::Accessor::id("star"))) { + auto shape = static_cast(const_cast(paint)); + shape->strokeFill(255, 255, 0); + shape->strokeWidth(5); + } + canvas->push(std::move(picture)); return true; @@ -74,4 +81,4 @@ struct UserExample : tvgexam::Example int main(int argc, char **argv) { return tvgexam::main(new UserExample, argc, argv); -} \ No newline at end of file +} diff --git a/examples/resources/svg/favorite_on.svg b/examples/resources/svg/favorite_on.svg index c34b3209..bcfec2a5 100644 --- a/examples/resources/svg/favorite_on.svg +++ b/examples/resources/svg/favorite_on.svg @@ -3,7 +3,7 @@ -