2019-05-16 13:07:29 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2019-05-16 01:16:19 +02:00
|
|
|
//
|
|
|
|
// Created by trotfunky on 15/05/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "DrawingElement.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace xmlParser
|
|
|
|
{
|
2019-05-16 13:07:29 +02:00
|
|
|
DrawingElement::DrawingElement(std::string label, float x, float y, const sf::Color& color) : x(x), y(-y), label(std::move(label)),
|
|
|
|
color(color), shape(nullptr)
|
2019-05-16 01:16:19 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
DrawingElement::DrawingElement(const pugi::xml_node& node) : x(node.attribute("x").as_int(0)),
|
2019-05-16 13:07:29 +02:00
|
|
|
y(-node.attribute("y").as_int(1)), label(node.attribute("label").as_string("Test DrawingElement")), shape(nullptr)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
setColor(node.attribute("color").as_string("Yellow"));
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
void DrawingElement::draw(sf::RenderWindow& window, float referenceX, float referenceY)
|
|
|
|
{
|
|
|
|
setX(x+referenceX);
|
|
|
|
setY(y-referenceY);
|
|
|
|
draw(window);
|
|
|
|
setX(x-referenceX);
|
|
|
|
setY(y+referenceY);
|
|
|
|
}
|
|
|
|
|
|
|
|
float xmlParser::DrawingElement::getX() const
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
void xmlParser::DrawingElement::setX(float newX)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
x = newX;
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
if(shape != nullptr)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
2019-05-16 13:07:29 +02:00
|
|
|
shape->setPosition(x,-y);
|
2019-05-16 01:16:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
float xmlParser::DrawingElement::getY() const
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
2019-05-16 13:07:29 +02:00
|
|
|
return -y;
|
2019-05-16 01:16:19 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
void xmlParser::DrawingElement::setY(float newY)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
y = newY;
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
if(shape != nullptr)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
2019-05-16 13:07:29 +02:00
|
|
|
shape->setPosition(x,-y);
|
2019-05-16 01:16:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const sf::Color& xmlParser::DrawingElement::getColor() const
|
|
|
|
{
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
const std::string DrawingElement::getStringColor() const
|
|
|
|
{
|
|
|
|
return(colorToStr(color));
|
|
|
|
}
|
|
|
|
|
2019-05-16 01:16:19 +02:00
|
|
|
void xmlParser::DrawingElement::setColor(const sf::Color& newColor)
|
|
|
|
{
|
|
|
|
color = newColor;
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
if(shape != nullptr)
|
2019-05-16 01:16:19 +02:00
|
|
|
{
|
|
|
|
shape->setFillColor(color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawingElement::setColor(const std::string& stringColor)
|
|
|
|
{
|
2019-05-16 13:07:29 +02:00
|
|
|
color = strToColor(stringColor);
|
|
|
|
}
|
|
|
|
|
2019-05-21 12:48:08 +02:00
|
|
|
const std::string DrawingElement::toString(int indent) const
|
2019-05-16 13:07:29 +02:00
|
|
|
{
|
|
|
|
std::stringstream string;
|
2019-05-21 12:48:08 +02:00
|
|
|
for(int i = 0;i<indent;i++)
|
|
|
|
{
|
|
|
|
string << "\t";
|
|
|
|
}
|
|
|
|
|
2019-05-16 13:07:29 +02:00
|
|
|
string << label << " at x:" << getX() << " y:" << getY();
|
|
|
|
string << " | color:" << getStringColor();
|
|
|
|
return(string.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& ostream, const DrawingElement& element)
|
|
|
|
{
|
2019-05-21 12:48:08 +02:00
|
|
|
ostream << element.toString(0);
|
2019-05-16 13:07:29 +02:00
|
|
|
return(ostream);
|
2019-05-16 01:16:19 +02:00
|
|
|
}
|
|
|
|
}
|