tsp_cpp/snippets/DrawingElement.cpp

103 lines
2.2 KiB
C++
Raw Normal View History

//
// Created by trotfunky on 15/05/19.
//
#include "DrawingElement.h"
namespace xmlParser
{
DrawingElement::DrawingElement() : x(0), y(1), label("Test DrawingElement"), color(sf::Color::Yellow), shape(nullptr)
{}
DrawingElement::DrawingElement(const pugi::xml_node& node) : x(node.attribute("x").as_int(0)),
y(node.attribute("y").as_int(1)), label(node.attribute("label").as_string("Test DrawingElement")), shape(nullptr)
{
setColor(node.attribute("color").as_string("Yellow"));
}
int xmlParser::DrawingElement::getX() const
{
return x;
}
void xmlParser::DrawingElement::setX(int newX)
{
x = newX;
if(shape)
{
shape->setPosition(x,y);
}
}
int xmlParser::DrawingElement::getY() const
{
return y;
}
void xmlParser::DrawingElement::setY(int newY)
{
y = newY;
if(shape)
{
shape->setPosition(x,y);
}
}
const sf::Color& xmlParser::DrawingElement::getColor() const
{
return color;
}
void xmlParser::DrawingElement::setColor(const sf::Color& newColor)
{
color = newColor;
if(shape)
{
shape->setFillColor(color);
}
}
void DrawingElement::setColor(const std::string& stringColor)
{
if(stringColor == "Black")
{
color = sf::Color::Black;
}
else if(stringColor == "White")
{
color = sf::Color::White;
}
else if(stringColor == "Red")
{
color = sf::Color::Red;
}
else if(stringColor == "Green")
{
color = sf::Color::Green;
}
else if(stringColor == "Blue")
{
color = sf::Color::Blue;
}
else if(stringColor == "Yellow")
{
color = sf::Color::Yellow;
}
else if(stringColor == "Magenta")
{
color = sf::Color::Magenta;
}
else if(stringColor == "Cyan")
{
color = sf::Color::Cyan;
}
else
{
color = sf::Color::Green;
}
}
}