Continue adding opengl font support.
This commit is contained in:
parent
649079a5c7
commit
eef93efc29
37 changed files with 530 additions and 157 deletions
|
@ -34,25 +34,28 @@ void Scene::update(FontsManager* fontsManager, Image<unsigned char>* image)
|
|||
node->update(fontsManager);
|
||||
layer->setIsDirty(false);
|
||||
}
|
||||
|
||||
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
|
||||
mTextures.push_back(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto node = layer->getTextNode();
|
||||
auto node = dynamic_cast<TextNode*>(layer->getTextNode());
|
||||
if (layer->getIsDirty())
|
||||
{
|
||||
node->update(fontsManager);
|
||||
layer->setIsDirty(false);
|
||||
}
|
||||
mWorkingMeshs.push_back(dynamic_cast<TriMesh*>(node->getMesh()));
|
||||
mTextures.push_back(node->getTexture());
|
||||
mTextData.push_back(node->getTextData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<TextData>& Scene::getTextData() const
|
||||
{
|
||||
return mTextData;
|
||||
}
|
||||
|
||||
void Scene::processRectangleNode(RectangleNode* node)
|
||||
{
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "TextData.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
@ -15,6 +17,7 @@ class Image;
|
|||
class Scene
|
||||
{
|
||||
public:
|
||||
|
||||
Scene() = default;
|
||||
|
||||
void syncLayers(const std::vector<VisualLayer*>& layers);
|
||||
|
@ -27,11 +30,14 @@ public:
|
|||
|
||||
Image<unsigned char>* getTexture(std::size_t idx) const;
|
||||
|
||||
private:
|
||||
const std::vector<TextData>& getTextData() const;
|
||||
|
||||
private:
|
||||
void processRectangleNode(RectangleNode* node);
|
||||
|
||||
std::vector<TriMesh*> mWorkingMeshs;
|
||||
std::vector<VisualLayer*> mLayers;
|
||||
std::vector<TriMesh*> mWorkingMeshs;
|
||||
std::vector<Image<unsigned char>* > mTextures;
|
||||
|
||||
std::vector<TextData> mTextData;
|
||||
};
|
||||
|
|
16
src/visual_elements/TextData.h
Normal file
16
src/visual_elements/TextData.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
#include "Color.h"
|
||||
#include "FontItem.h"
|
||||
|
||||
class TextData
|
||||
{
|
||||
public:
|
||||
TextData() = default;
|
||||
DiscretePoint mLocation;
|
||||
std::string mContent;
|
||||
Color mFillColor;
|
||||
Color mStrokeColor;
|
||||
FontItem mFont;
|
||||
};
|
|
@ -4,17 +4,18 @@
|
|||
#include "FontsManager.h"
|
||||
#include "IFontEngine.h"
|
||||
#include "MeshPrimitives.h"
|
||||
#include "FontItem.h"
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
|
||||
: AbstractVisualNode(loc),
|
||||
mContent(content),
|
||||
mFontLabel("fixed"),
|
||||
mFillColor(Color(255, 255, 255)),
|
||||
mStrokeColor(Color(0, 0, 0))
|
||||
: AbstractVisualNode(loc)
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/Fixed_(typeface)#:~:text=misc%2Dfixed%20is%20a%20collection,to%20a%20single%20font%20family.
|
||||
mTextData.mContent = content;
|
||||
mTextData.mFont = FontItem("Arial", 16);
|
||||
mTextData.mLocation = loc;
|
||||
mTextData.mFillColor = Color(255, 255, 255);
|
||||
mTextData.mStrokeColor = Color(0, 0, 0);
|
||||
}
|
||||
|
||||
TextNode::~TextNode()
|
||||
|
@ -29,36 +30,36 @@ std::unique_ptr<TextNode> TextNode::Create(const std::string& content, const Dis
|
|||
|
||||
const Color& TextNode::getFillColor() const
|
||||
{
|
||||
return mFillColor;
|
||||
return mTextData.mFillColor;
|
||||
}
|
||||
const Color& TextNode::getStrokeColor() const
|
||||
{
|
||||
return mStrokeColor;
|
||||
return mTextData.mStrokeColor;
|
||||
}
|
||||
|
||||
std::string TextNode::getFontLabel() const
|
||||
{
|
||||
return mFontLabel;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string TextNode::getContent() const
|
||||
{
|
||||
return mContent;
|
||||
return mTextData.mContent;
|
||||
}
|
||||
|
||||
void TextNode::setContent(const std::string& content)
|
||||
{
|
||||
mContent = content;
|
||||
mTextData.mContent = content;
|
||||
}
|
||||
|
||||
void TextNode::setFillColor(const Color& color)
|
||||
{
|
||||
mFillColor = color;
|
||||
mTextData.mFillColor = color;
|
||||
}
|
||||
|
||||
void TextNode::setStrokeColor(const Color& color)
|
||||
{
|
||||
mStrokeColor = color;
|
||||
mTextData.mStrokeColor = color;
|
||||
}
|
||||
|
||||
void TextNode::update(FontsManager* drawingManager)
|
||||
|
@ -67,32 +68,17 @@ void TextNode::update(FontsManager* drawingManager)
|
|||
updateTexture(drawingManager);
|
||||
}
|
||||
|
||||
const TextData& TextNode::getTextData() const
|
||||
{
|
||||
return mTextData;
|
||||
}
|
||||
|
||||
void TextNode::updateMesh()
|
||||
{
|
||||
double font_height = 16;
|
||||
double font_width = 16;
|
||||
|
||||
double text_width = mContent.size() * font_width;
|
||||
|
||||
const auto rect = Rectangle(mLocation, text_width, font_height);
|
||||
|
||||
auto mesh = MeshPrimitives::build(rect);
|
||||
auto color = Color(0, 0, 0, 1.0);
|
||||
|
||||
mesh->addConstantFaceVectorAttribute("Color", color.getAsVectorDouble());
|
||||
mMesh = std::move(mesh);
|
||||
}
|
||||
|
||||
void TextNode::updateTexture(FontsManager* fontsManager)
|
||||
{
|
||||
fontsManager->getFontEngine()->loadFontFace("truetype/msttcorefonts/arial.ttf");
|
||||
auto glyph = fontsManager->getFontEngine()->loadGlyph('A');
|
||||
|
||||
if (!glyph)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mTexture = std::make_unique<Image<unsigned char> >(glyph->getWidth(), glyph->getHeight());
|
||||
mTexture->setData(glyph->getData());
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#include "AbstractVisualNode.h"
|
||||
#include "Color.h"
|
||||
#include "FontItem.h"
|
||||
#include "TextData.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class Color;
|
||||
|
||||
class TextNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
|
@ -24,6 +24,9 @@ public:
|
|||
|
||||
std::string getContent() const;
|
||||
std::string getFontLabel() const;
|
||||
|
||||
const TextData& getTextData() const;
|
||||
|
||||
void setContent(const std::string& content);
|
||||
void setFillColor(const Color& color);
|
||||
void setStrokeColor(const Color& color);
|
||||
|
@ -34,10 +37,7 @@ private:
|
|||
void updateMesh() override;
|
||||
void updateTexture(FontsManager* fontsManager) override;
|
||||
|
||||
std::string mContent;
|
||||
std::string mFontLabel;
|
||||
Color mFillColor;
|
||||
Color mStrokeColor;
|
||||
TextData mTextData;
|
||||
};
|
||||
|
||||
using TextNodetr = std::unique_ptr<TextNode>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue