tsp_cpp/xmlParser/Circle.cpp

70 lines
No EOL
1.6 KiB
C++

//
// 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 = 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 = new sf::CircleShape(r);
shape->setPosition(x-r,y-r);
shape->setFillColor(color);
}
void Circle::draw(sf::RenderWindow& window)
{
window.draw(*(dynamic_cast<sf::CircleShape*>(shape)));
}
float Circle::getR() const
{
return r;
}
void Circle::setR(float newR)
{
r = newR;
dynamic_cast<sf::CircleShape*>(shape)->setRadius(r);
shape->setPosition(x-r,y-r);
}
const std::string Circle::toString(int indent) const
{
std::stringstream string;
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);
}
}