Skip to content

Commit

Permalink
Add pugixml
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAugust12 committed Oct 31, 2023
1 parent 329d181 commit 716d91c
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
#include <SFML/Graphics.hpp>
#include <iostream>

#include "raylib.h"
#include "Polygon.h"
#include "Polyline.h"
#include "SF_Line.h"
#include "pugixml.hpp"

int main() {
constexpr int screen_width = 1600;
constexpr int screen_height = 900;

pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("sample/pic.svg");
if (!result) return -1;
sf::RenderWindow window(sf::VideoMode(screen_width, screen_height),
"svg-reader-version-0.1");

auto get_attribute = [&](std::string name) {
auto node = doc.child("svg").child("circle");
auto attr = node.attribute(name.c_str());
return attr.value();
};
sf::View view;
window.setView(view);
sf::Vector2i lastMousePosition;
bool isMouseDragging = false;

int pos_x = std::stoi(get_attribute("cx"));
int pos_y = std::stoi(get_attribute("cy"));
float radius = std::stof(get_attribute("r"));
Polygon polygon;
polygon.setFillColor(sf::Color::White);
polygon.setStrokeColor(sf::Color::Red);
polygon.setThickNess(8);
polygon.addPoint(sf::Vector2f(200, 40));
polygon.addPoint(sf::Vector2f(250, 220));
polygon.addPoint(sf::Vector2f(160, 240));

sf::RenderWindow window(sf::VideoMode(screen_width, screen_height),
"svg-reader-version-0.1");
sfLine l(sf::Vector2f(100, 200), sf::Vector2f(600, 500), 1.f,
sf::Color::Red);

constexpr int pos_x = 700;
constexpr int pos_y = 300;
constexpr float radius = 100.f;
sf::CircleShape shape(radius, 1000);
shape.setPosition(pos_x, pos_y);
shape.setFillColor(sf::Color::Green);
PolyLine p(3, sf::Color::Black);
p.setColor(sf::Color::Black);
p.addPoint(sf::Vector2f(20, 20));
p.addPoint(sf::Vector2f(40, 25));
p.addPoint(sf::Vector2f(60, 40));
p.addPoint(sf::Vector2f(80, 120));
p.addPoint(sf::Vector2f(120, 140));
p.addPoint(sf::Vector2f(200, 180));
p.addPoint(sf::Vector2f(300, 400));
p.addPoint(sf::Vector2f(460, 570));
p.addPoint(sf::Vector2f(600, 400));
p.addPoint(sf::Vector2f(650, 700));
p.addPoint(sf::Vector2f(400, 450));
p.addPoint(sf::Vector2f(300, 275));
p.addPoint(sf::Vector2f(10, 800));
p.addPoint(sf::Vector2f(50, 820));
p.addPoint(sf::Vector2f(100, 840));
p.addPoint(sf::Vector2f(310, 800));
p.addPoint(sf::Vector2f(330, 812));
p.addPoint(sf::Vector2f(340, 820));

while (window.isOpen()) {
sf::Event event;
Expand Down Expand Up @@ -77,5 +95,6 @@ int main() {
p.draw(window);
window.display();
}

return 0;
}

0 comments on commit 716d91c

Please sign in to comment.