126 lines
2.6 KiB
C++
126 lines
2.6 KiB
C++
#include "SvgShapeElements.h"
|
|
|
|
#include <sstream>
|
|
|
|
SvgCircle::SvgCircle()
|
|
: SvgShapeElement("circle")
|
|
{
|
|
|
|
}
|
|
|
|
void SvgCircle::setLocation(const Point& loc)
|
|
{
|
|
auto cx = std::make_unique<XmlAttribute>("cx");
|
|
auto cy = std::make_unique<XmlAttribute>("cy");
|
|
|
|
cx->setValue(std::to_string(loc.getX()));
|
|
cy->setValue(std::to_string(loc.getY()));
|
|
|
|
addAttribute(std::move(cx));
|
|
addAttribute(std::move(cy));
|
|
}
|
|
|
|
void SvgCircle::setRadius(double rad)
|
|
{
|
|
auto r = std::make_unique<XmlAttribute>("r");
|
|
r->setValue(std::to_string(rad));
|
|
addAttribute(std::move(r));
|
|
}
|
|
|
|
SvgRectangle::SvgRectangle()
|
|
: SvgShapeElement("rect")
|
|
{
|
|
|
|
}
|
|
|
|
void SvgRectangle::setLocation(const Point& loc)
|
|
{
|
|
auto x = std::make_unique<XmlAttribute>("x");
|
|
auto y = std::make_unique<XmlAttribute>("y");
|
|
|
|
x->setValue(std::to_string(loc.getX()));
|
|
y->setValue(std::to_string(loc.getY()));
|
|
|
|
addAttribute(std::move(x));
|
|
addAttribute(std::move(y));
|
|
}
|
|
|
|
void SvgRectangle::setWidth(double w)
|
|
{
|
|
auto width = std::make_unique<XmlAttribute>("width");
|
|
|
|
width->setValue(std::to_string(w));
|
|
|
|
addAttribute(std::move(width));
|
|
}
|
|
|
|
void SvgRectangle::setHeight(double h)
|
|
{
|
|
auto height = std::make_unique<XmlAttribute>("height");
|
|
|
|
height->setValue(std::to_string(h));
|
|
|
|
addAttribute(std::move(height));
|
|
}
|
|
|
|
|
|
SvgPolygon::SvgPolygon()
|
|
: SvgShapeElement("polygon")
|
|
{
|
|
|
|
}
|
|
|
|
void SvgPolygon::setPoints(const std::vector<Point>& locs)
|
|
{
|
|
auto points = std::make_unique<XmlAttribute>("points");
|
|
|
|
std::stringstream sstr;
|
|
for (const auto& loc : locs)
|
|
{
|
|
sstr << loc.getX() << "," << loc.getY() << " ";
|
|
}
|
|
points->setValue(sstr.str());
|
|
addAttribute(std::move(points));
|
|
}
|
|
|
|
SvgPolyline::SvgPolyline()
|
|
: SvgShapeElement("polyline")
|
|
{
|
|
auto fill = std::make_unique<XmlAttribute>("fill");
|
|
fill->setValue("none");
|
|
addAttribute(std::move(fill));
|
|
}
|
|
|
|
void SvgPolyline::setPoints(const std::vector<Point>& locs)
|
|
{
|
|
auto points = std::make_unique<XmlAttribute>("points");
|
|
|
|
std::stringstream sstr;
|
|
for (const auto& loc : locs)
|
|
{
|
|
sstr << loc.getX() << "," << loc.getY() << " ";
|
|
}
|
|
points->setValue(sstr.str());
|
|
addAttribute(std::move(points));
|
|
}
|
|
|
|
|
|
SvgPath::SvgPath()
|
|
: SvgShapeElement("path")
|
|
{
|
|
|
|
}
|
|
|
|
void SvgPath::setPath(const std::string& mPath)
|
|
{
|
|
auto path = std::make_unique<XmlAttribute>("d");
|
|
path->setValue(mPath);
|
|
addAttribute(std::move(path));
|
|
}
|
|
|
|
void SvgPath::setFillRule(const std::string& fillRule)
|
|
{
|
|
auto rule = std::make_unique<XmlAttribute>("fill-rule");
|
|
rule->setValue(fillRule);
|
|
addAttribute(std::move(rule));
|
|
}
|