stuff-from-scratch/src/visual_elements/TextNode.cpp

76 lines
1.4 KiB
C++
Raw Normal View History

2022-11-13 17:02:09 +00:00
#include "TextNode.h"
2022-11-15 09:32:28 +00:00
#include "Rectangle.h"
#include "FontsManager.h"
#include "IFontEngine.h"
#include "MeshPrimitives.h"
2022-11-15 15:50:36 +00:00
#include "FontItem.h"
2022-11-15 09:32:28 +00:00
2022-11-16 15:06:08 +00:00
#include "SceneText.h"
2022-11-13 17:02:09 +00:00
#include "Color.h"
2022-11-16 17:00:55 +00:00
#include <iostream>
2022-11-13 17:02:09 +00:00
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
2022-11-16 15:06:08 +00:00
: MaterialNode(loc)
2022-11-13 17:02:09 +00:00
{
2022-11-16 15:06:08 +00:00
mContent= content;
2022-11-13 17:02:09 +00:00
}
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
{
2022-11-15 15:50:36 +00:00
return {};
2022-11-13 17:02:09 +00:00
}
std::string TextNode::getContent() const
{
2022-11-16 15:06:08 +00:00
return mContent;
2022-11-13 17:02:09 +00:00
}
void TextNode::setContent(const std::string& content)
{
2022-11-16 15:06:08 +00:00
if (mContent != content)
{
mContent = content;
mContentIsDirty = true;
}
2022-11-13 17:02:09 +00:00
}
2022-11-15 09:32:28 +00:00
2022-11-16 15:06:08 +00:00
void TextNode::update(FontsManager* fontsManager)
2022-11-15 09:32:28 +00:00
{
2022-11-16 15:06:08 +00:00
if (!mSceneItem)
{
mSceneItem = std::make_unique<SceneText>();
2022-11-16 17:00:55 +00:00
mSceneItem->setName(mName + "_SceneText");
2022-11-16 15:06:08 +00:00
}
2022-11-16 17:00:55 +00:00
if (mContentIsDirty)
2022-11-16 15:06:08 +00:00
{
dynamic_cast<SceneText*>(mSceneItem.get())->setContent(mContent);
mContentIsDirty = false;
}
if (mTransformIsDirty)
{
mSceneItem->updateTransform({mLocation});
mTransformIsDirty = false;
}
if (mMaterialIsDirty)
{
mSceneItem->updateUniformColor(mFillColor);
mMaterialIsDirty = false;
}
2022-11-15 09:32:28 +00:00
}