tsp_cpp/xmlParser/Circle.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

//
// Created by trotfunky on 14/05/19.
//
#include "Circle.h"
namespace xmlParser
{
Circle::Circle(std::string label, float x, float y, float r, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), r(2)
{
shape = std::unique_ptr<sf::Shape>(new sf::CircleShape(r));
shape->setPosition(x-r,y-r);
shape->setFillColor(color);
}
Circle::Circle(const pugi::xml_node& node) : DrawingElement(node), r(node.attribute("r").as_int(2))
{
if(label == "Test DrawingElement")
{
label = "Test Circle";
}
shape = std::unique_ptr<sf::Shape>(new sf::CircleShape(r));
shape->setPosition(x-r,y-r);
shape->setFillColor(color);
}
float Circle::getR() const
{
return r;
}
void Circle::setR(float newR)
{
r = newR;
dynamic_cast<sf::CircleShape*>(shape.get())->setRadius(r);
shape->setPosition(x-r,y-r);
}
2019-05-21 12:48:08 +02:00
const std::string Circle::toString(int indent) const
{
std::stringstream string;
2019-05-21 12:48:08 +02:00
for(int i = 0;i<indent;i++)
{
string << "\t";
}
string << label << " at x:" << getX() << " y:" << getY() << " | r:" << getR();
string << " color:" << getStringColor();
return(string.str());
}
void Circle::setX(float newX)
{
DrawingElement::setX(newX);
shape->setPosition(x-r,y-r);
}
void Circle::setY(float newY)
{
DrawingElement::setY(newY);
shape->setPosition(x-r,y-r);
}
}