96 lines
No EOL
2.1 KiB
C++
96 lines
No EOL
2.1 KiB
C++
#include <utility>
|
|
|
|
//
|
|
// Created by trotfunky on 15/05/19.
|
|
//
|
|
|
|
#include "DrawingElement.h"
|
|
|
|
|
|
namespace xmlParser
|
|
{
|
|
DrawingElement::DrawingElement(std::string label, float x, float y, const sf::Color& color) : label(std::move(label)), x(x), y(-y),
|
|
color(color), shape(nullptr)
|
|
{}
|
|
|
|
DrawingElement::DrawingElement(const pugi::xml_node& node) : label(node.attribute("label").as_string("Test DrawingElement")),
|
|
x(node.attribute("x").as_int(0)), y(-node.attribute("y").as_int(1)), shape(nullptr)
|
|
{
|
|
setColor(node.attribute("color").as_string("Yellow"));
|
|
}
|
|
|
|
void DrawingElement::draw(sf::RenderWindow& window)
|
|
{
|
|
window.draw(*shape);
|
|
}
|
|
|
|
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
|
|
{
|
|
return x;
|
|
}
|
|
|
|
void xmlParser::DrawingElement::setX(float newX)
|
|
{
|
|
x = newX;
|
|
|
|
if(shape)
|
|
{
|
|
shape->setPosition(x,-y);
|
|
}
|
|
}
|
|
|
|
float xmlParser::DrawingElement::getY() const
|
|
{
|
|
return -y;
|
|
}
|
|
|
|
void xmlParser::DrawingElement::setY(float newY)
|
|
{
|
|
y = newY;
|
|
|
|
if(shape)
|
|
{
|
|
shape->setPosition(x,-y);
|
|
}
|
|
}
|
|
|
|
const sf::Color& xmlParser::DrawingElement::getColor() const
|
|
{
|
|
return color;
|
|
}
|
|
|
|
const std::string DrawingElement::getStringColor() const
|
|
{
|
|
return(colorToStr(color));
|
|
}
|
|
|
|
void xmlParser::DrawingElement::setColor(const sf::Color& newColor)
|
|
{
|
|
color = newColor;
|
|
|
|
if(shape != nullptr)
|
|
{
|
|
shape->setFillColor(color);
|
|
}
|
|
}
|
|
|
|
void DrawingElement::setColor(const std::string& stringColor)
|
|
{
|
|
color = strToColor(stringColor);
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& ostream, const DrawingElement& element)
|
|
{
|
|
ostream << element.toString(0);
|
|
return(ostream);
|
|
}
|
|
} |