110 lines
No EOL
2.2 KiB
C++
110 lines
No EOL
2.2 KiB
C++
#include "SvgNode.h"
|
|
|
|
#include "CircleNode.h"
|
|
#include "PathNode.h"
|
|
|
|
#include "SvgElement.h"
|
|
#include "SvgShapeElements.h"
|
|
|
|
SvgNode::SvgNode(const Point& location)
|
|
: AbstractVisualNode(location)
|
|
{
|
|
|
|
}
|
|
|
|
void SvgNode::setContent(std::unique_ptr<SvgDocument> doc)
|
|
{
|
|
mContent = std::move(doc);
|
|
mContentDirty = true;
|
|
|
|
mChildren.clear();
|
|
mManagedChildren.clear();
|
|
}
|
|
|
|
void SvgNode::updateTransform()
|
|
{
|
|
|
|
}
|
|
|
|
void SvgNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|
{
|
|
if (!mContent->getRoot())
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto viewbox = mContent->getViewBox();
|
|
|
|
for (const auto& svg_element : mContent->getRoot()->getChildren())
|
|
{
|
|
std::unique_ptr<AbstractVisualNode> node;
|
|
|
|
if (svg_element->getTagName() == "circle")
|
|
{
|
|
onCircle(svg_element.get(), node);
|
|
}
|
|
else if (svg_element->getTagName() == "path")
|
|
{
|
|
onPath(svg_element.get(), node);
|
|
}
|
|
|
|
if (!node)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
auto raw_node = node.get();
|
|
mManagedChildren.push_back(std::move(node));
|
|
|
|
addChild(raw_node);
|
|
}
|
|
}
|
|
|
|
void SvgNode::update(SceneInfo* sceneInfo)
|
|
{
|
|
if (mContent && mContentDirty)
|
|
{
|
|
createOrUpdateGeometry(sceneInfo);
|
|
mContentDirty = false;
|
|
}
|
|
|
|
if (mTransformIsDirty)
|
|
{
|
|
updateTransform();
|
|
mTransformIsDirty = false;
|
|
}
|
|
}
|
|
|
|
void SvgNode::onCircle(XmlElement* element, std::unique_ptr<AbstractVisualNode>& node)
|
|
{
|
|
auto svg_circle = dynamic_cast<SvgCircle*>(element);
|
|
auto loc = svg_circle->getLocation();
|
|
auto radius = svg_circle->getRadius();
|
|
auto minor_radius = radius;
|
|
|
|
if (svg_circle->getType() == SvgCircle::Type::ELLIPSE)
|
|
{
|
|
minor_radius = svg_circle->getMinorRadius();
|
|
}
|
|
|
|
if (element->hasAttribute("transform"))
|
|
{
|
|
const auto transform = svg_circle->getTransform();
|
|
loc.move(transform.getLocation().getX(), transform.getLocation().getY());
|
|
radius *= transform.getScaleX();
|
|
minor_radius *= transform.getScaleY();
|
|
}
|
|
|
|
auto circle_node = std::make_unique<CircleNode>(loc, radius);
|
|
circle_node->setMinorRadius(minor_radius);
|
|
node = std::move(circle_node);
|
|
}
|
|
|
|
void SvgNode::onPath(XmlElement* element, std::unique_ptr<AbstractVisualNode>& node)
|
|
{
|
|
auto svg_path = dynamic_cast<SvgPath*>(element);
|
|
|
|
Point loc;
|
|
auto path_node = std::make_unique<PathNode>(loc, svg_path->getPath());
|
|
node = std::move(path_node);
|
|
} |