2019-05-14 13:07:25 +02:00
|
|
|
//
|
|
|
|
// Created by trotfunky on 14/05/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Circle.h"
|
|
|
|
|
|
|
|
namespace xmlParser
|
|
|
|
{
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
Circle::Circle(std::string label, float x, float y, float r, const sf::Color& color) : DrawingElement(std::move(label),x,y,color), r(2)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
shape = new sf::CircleShape(r);
|
2019-05-16 13:07:29 +02:00
|
|
|
shape->setPosition(x-r,y-r);
|
2019-05-16 01:16:19 +02:00
|
|
|
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);
|
2019-05-16 13:07:29 +02:00
|
|
|
shape->setPosition(x-r,y-r);
|
2019-05-16 01:16:19 +02:00
|
|
|
shape->setFillColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Circle::draw(sf::RenderWindow& window)
|
|
|
|
{
|
|
|
|
window.draw(*(dynamic_cast<sf::CircleShape*>(shape)));
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
float Circle::getR() const
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
void Circle::setR(float newR)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
r = newR;
|
|
|
|
dynamic_cast<sf::CircleShape*>(shape)->setRadius(r);
|
2019-05-16 13:07:29 +02:00
|
|
|
shape->setPosition(x-r,y-r);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string Circle::toString() const
|
|
|
|
{
|
|
|
|
std::stringstream string;
|
|
|
|
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);
|
2019-05-16 01:16:19 +02:00
|
|
|
}
|
2019-05-14 13:07:25 +02:00
|
|
|
}
|