From b162eea544fe005fb5fcade099e36f49f8e45ff4 Mon Sep 17 00:00:00 2001 From: nkwn Date: Mon, 6 Nov 2023 18:15:27 +0700 Subject: [PATCH] Update folder tree --- .gitignore | 1 + src/Parser.hpp | 11 ++++++----- src/{ => graphics}/Circle.cpp | 0 src/{ => graphics}/Circle.hpp | 9 +++++---- src/{ => graphics}/Ellipse.cpp | 0 src/{ => graphics}/Ellipse.hpp | 3 ++- {graphics => src/graphics}/Shape.cpp | 0 {graphics => src/graphics}/Shape.hpp | 0 src/main.cpp | 9 +++++---- 9 files changed, 19 insertions(+), 14 deletions(-) rename src/{ => graphics}/Circle.cpp (100%) rename src/{ => graphics}/Circle.hpp (70%) rename src/{ => graphics}/Ellipse.cpp (100%) rename src/{ => graphics}/Ellipse.hpp (99%) rename {graphics => src/graphics}/Shape.cpp (100%) rename {graphics => src/graphics}/Shape.hpp (100%) diff --git a/.gitignore b/.gitignore index 3750f63a..3acc3f8c 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ *.bat build svg-reader +*.json diff --git a/src/Parser.hpp b/src/Parser.hpp index 508f7357..51d827cd 100644 --- a/src/Parser.hpp +++ b/src/Parser.hpp @@ -3,8 +3,8 @@ #include #include -#include "Circle.hpp" -#include "Ellipse.hpp" +#include "graphics/Circle.hpp" +#include "graphics/Ellipse.hpp" #include "pugixml.hpp" namespace parser { @@ -72,9 +72,10 @@ namespace parser { } } - std::vector< sf::Shape* > parseSVG(std::string path) { + std::vector< Shape* > parseSVG(std::string path) { pugi::xml_node svg = loadFile(path); - std::vector< sf::Shape* > shapes; + std::vector< Shape* > shapes; + for (pugi::xml_node tool = svg.first_child(); tool; tool = tool.next_sibling()) { sf::Color stroke_color = parseColor(tool, "stroke"); @@ -107,7 +108,7 @@ namespace parser { return shapes; } - void deleteShapes(std::vector< sf::Shape* >& shapes) { + void deleteShapes(std::vector< Shape* >& shapes) { for (auto shape : shapes) { delete shape; } diff --git a/src/Circle.cpp b/src/graphics/Circle.cpp similarity index 100% rename from src/Circle.cpp rename to src/graphics/Circle.cpp diff --git a/src/Circle.hpp b/src/graphics/Circle.hpp similarity index 70% rename from src/Circle.hpp rename to src/graphics/Circle.hpp index d6a2cef2..c5bee670 100644 --- a/src/Circle.hpp +++ b/src/graphics/Circle.hpp @@ -1,9 +1,10 @@ -#include -#ifndef CIRCLE_H_ -#define CIRCLE_H_ +#ifndef CIRCLE_HPP_ +#define CIRCLE_HPP_ + +#include "Shape.hpp" #define SCALE 1000000 -class Circle : public sf::Shape { +class Circle : public Shape { private: float radius; diff --git a/src/Ellipse.cpp b/src/graphics/Ellipse.cpp similarity index 100% rename from src/Ellipse.cpp rename to src/graphics/Ellipse.cpp diff --git a/src/Ellipse.hpp b/src/graphics/Ellipse.hpp similarity index 99% rename from src/Ellipse.hpp rename to src/graphics/Ellipse.hpp index 0ad8d139..4a74f689 100644 --- a/src/Ellipse.hpp +++ b/src/graphics/Ellipse.hpp @@ -1,7 +1,8 @@ -#include "Circle.hpp" #ifndef ELLIPSE_H_ #define ELLIPSE_H_ +#include "Circle.hpp" + class Ellipse : public Circle { private: sf::Vector2f radius; diff --git a/graphics/Shape.cpp b/src/graphics/Shape.cpp similarity index 100% rename from graphics/Shape.cpp rename to src/graphics/Shape.cpp diff --git a/graphics/Shape.hpp b/src/graphics/Shape.hpp similarity index 100% rename from graphics/Shape.hpp rename to src/graphics/Shape.hpp diff --git a/src/main.cpp b/src/main.cpp index 02c3366f..72faf889 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,5 @@ #include -#include "Circle.hpp" -#include "Ellipse.hpp" #include "Parser.hpp" #include "pugixml.hpp" @@ -9,7 +7,8 @@ int main() { constexpr int screen_width = 1600; constexpr int screen_height = 900; - std::vector< sf::Shape* > shapes = parser::parseSVG("../sample/sample.svg"); + std::vector< Shape* > shapes = parser::parseSVG("./sample/sample.svg"); + sf::ContextSettings settings; settings.antialiasingLevel = 16; sf::RenderWindow window(sf::VideoMode(screen_width, screen_height), @@ -24,12 +23,14 @@ int main() { } window.clear(sf::Color::White); + for (auto shape : shapes) { window.draw(*shape); } + window.display(); } - parser::deleteShapes(shapes); + // parser::deleteShapes(shapes); return 0; } \ No newline at end of file