From ced42c0db4aa578688a97c710f022e11044dd480 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 10 Jul 2021 12:05:52 -0400 Subject: [PATCH] Add Svg::getNumShapes/Paths/Points(). --- include/svg.hpp | 3 +++ src/app/RackRail.cpp | 5 +++-- src/svg.cpp | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/svg.hpp b/include/svg.hpp index 615e18fe..8ef12ed6 100644 --- a/include/svg.hpp +++ b/include/svg.hpp @@ -44,6 +44,9 @@ struct Svg { /** Loads SVG data from a string. */ void loadString(const std::string& str); void draw(NVGcontext* vg); + int getNumShapes(); + int getNumPaths(); + int getNumPoints(); /** Loads Svg from a cache. */ static std::shared_ptr load(const std::string& filename); diff --git a/src/app/RackRail.cpp b/src/app/RackRail.cpp index 74b7d6f8..37640ed6 100644 --- a/src/app/RackRail.cpp +++ b/src/app/RackRail.cpp @@ -11,6 +11,7 @@ namespace app { RackRail::RackRail() { busBoardSvg = Svg::load(asset::system("res/ComponentLibrary/RackBusboard.svg")); railsSvg = Svg::load(asset::system("res/ComponentLibrary/RackRails.svg")); + // DEBUG("%d %d %d", railsSvg->getNumShapes(), railsSvg->getNumPaths(), railsSvg->getNumPoints()); } @@ -40,7 +41,7 @@ void RackRail::draw(const DrawArgs& args) { for (float x = 0; x < box.size.x; x += busBoardWidth) { nvgSave(args.vg); nvgTranslate(args.vg, x, busBoardY); - svgDraw(args.vg, busBoardSvg->handle); + busBoardSvg->draw(args.vg); nvgRestore(args.vg); } @@ -56,7 +57,7 @@ void RackRail::draw(const DrawArgs& args) { for (float x = 0; x < box.size.x; x += RACK_GRID_WIDTH) { nvgSave(args.vg); nvgTranslate(args.vg, x, y ); - svgDraw(args.vg, railsSvg->handle); + railsSvg->draw(args.vg); nvgRestore(args.vg); } } diff --git a/src/svg.cpp b/src/svg.cpp index f09372b4..b102b684 100644 --- a/src/svg.cpp +++ b/src/svg.cpp @@ -41,6 +41,42 @@ void Svg::draw(NVGcontext* vg) { } +int Svg::getNumShapes() { + if (!handle) + return 0; + int count = 0; + for (NSVGshape* shape = handle->shapes; shape; shape = shape->next) { + count++; + } + return count; +} + + +int Svg::getNumPaths() { + if (!handle) + return 0; + int count = 0; + for (NSVGshape* shape = handle->shapes; shape; shape = shape->next) { + for (NSVGpath* path = shape->paths; path; path = path->next) { + count++; + } + } + return count; +} + + +int Svg::getNumPoints() { + if (!handle) + return 0; + int count = 0; + for (NSVGshape* shape = handle->shapes; shape; shape = shape->next) { + for (NSVGpath* path = shape->paths; path; path = path->next) { + count += (path->npts / 3); + } + } + return count; +} + static std::map> svgCache;