Browse Source

Add Svg::getNumShapes/Paths/Points().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
ced42c0db4
3 changed files with 42 additions and 2 deletions
  1. +3
    -0
      include/svg.hpp
  2. +3
    -2
      src/app/RackRail.cpp
  3. +36
    -0
      src/svg.cpp

+ 3
- 0
include/svg.hpp View File

@@ -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<Svg> load(const std::string& filename);


+ 3
- 2
src/app/RackRail.cpp View File

@@ -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);
}
}


+ 36
- 0
src/svg.cpp View File

@@ -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<std::string, std::shared_ptr<Svg>> svgCache;



Loading…
Cancel
Save