Add path rendering.

This commit is contained in:
jmsgrogan 2023-01-19 14:25:58 +00:00
parent f2ab532005
commit 97afa782a0
39 changed files with 1148 additions and 131 deletions

View file

@ -1,7 +1,9 @@
#include "SvgNode.h"
#include "CircleNode.h"
#include "PathNode.h"
#include "SvgElement.h"
#include "SvgShapeElements.h"
SvgNode::SvgNode(const Point& location)
@ -39,26 +41,11 @@ void SvgNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
if (svg_element->getTagName() == "circle")
{
auto svg_circle = dynamic_cast<SvgCircle*>(svg_element.get());
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 (svg_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);
onCircle(svg_element.get(), node);
}
else if (svg_element->getTagName() == "path")
{
onPath(svg_element.get(), node);
}
if (!node)
@ -71,7 +58,6 @@ void SvgNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
addChild(raw_node);
}
}
void SvgNode::update(SceneInfo* sceneInfo)
@ -87,4 +73,38 @@ void SvgNode::update(SceneInfo* sceneInfo)
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);
}