stuff-from-scratch/src/visual_elements/TextNode.cpp
2022-11-16 17:00:55 +00:00

75 lines
1.4 KiB
C++

#include "TextNode.h"
#include "Rectangle.h"
#include "FontsManager.h"
#include "IFontEngine.h"
#include "MeshPrimitives.h"
#include "FontItem.h"
#include "SceneText.h"
#include "Color.h"
#include <iostream>
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
: MaterialNode(loc)
{
mContent= content;
}
TextNode::~TextNode()
{
}
std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const DiscretePoint& loc)
{
return std::make_unique<TextNode>(content, loc);
}
std::string TextNode::getFontLabel() const
{
return {};
}
std::string TextNode::getContent() const
{
return mContent;
}
void TextNode::setContent(const std::string& content)
{
if (mContent != content)
{
mContent = content;
mContentIsDirty = true;
}
}
void TextNode::update(FontsManager* fontsManager)
{
if (!mSceneItem)
{
mSceneItem = std::make_unique<SceneText>();
mSceneItem->setName(mName + "_SceneText");
}
if (mContentIsDirty)
{
dynamic_cast<SceneText*>(mSceneItem.get())->setContent(mContent);
mContentIsDirty = false;
}
if (mTransformIsDirty)
{
mSceneItem->updateTransform({mLocation});
mTransformIsDirty = false;
}
if (mMaterialIsDirty)
{
mSceneItem->updateUniformColor(mFillColor);
mMaterialIsDirty = false;
}
}