stuff-from-scratch/src/rendering/visual_elements/nodes/LineEndNode.cpp
2023-01-30 14:53:49 +00:00

63 lines
1.2 KiB
C++

#include "LineEndNode.h"
#include "GeometryNode.h"
#include "PolygonNode.h"
LineEndNode::LineEndNode(const Transform& t)
: MaterialNode(t)
{
}
void LineEndNode::setStyle(LineEndNode::Style style)
{
if (mStyle != style)
{
mStyle = style;
mContentDirty = true;
}
}
void LineEndNode::setSize(double size)
{
if (mSize != size)
{
mSize = size;
mContentDirty = true;
}
}
void LineEndNode::createOrUpdateGeometry(SceneInfo*)
{
if (!mContentNode)
{
if (mStyle == Style::CLOSED_ARROW)
{
auto polygon = std::make_unique<PolygonNode>();
auto p0 = Point2(0.0, -mSize / 2.0);
auto p1 = Point2(mSize, 0.0);
auto p2 = Point2(0.0, mSize / 2.0);
polygon->setPoints({ p0, p1, p2 });
polygon->setFillColor({ 0, 0, 0 });
mContentNode = std::move(polygon);
addChild(mContentNode.get());
}
}
}
void LineEndNode::update(SceneInfo* sceneInfo)
{
if (mContentDirty)
{
createOrUpdateGeometry(sceneInfo);
mContentDirty = false;
}
if (mMaterialIsDirty)
{
//updateMaterial();
mMaterialIsDirty = false;
}
}