Add Keyboard input and enter support for text editor.
This commit is contained in:
parent
cf9bace272
commit
9301769d58
23 changed files with 315 additions and 121 deletions
|
@ -5,17 +5,20 @@
|
|||
#include "IFontEngine.h"
|
||||
#include "MeshPrimitives.h"
|
||||
#include "FontItem.h"
|
||||
#include "FontGlyph.h"
|
||||
|
||||
#include "SceneText.h"
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TextNode::TextNode(const std::string& content, const DiscretePoint& loc)
|
||||
: MaterialNode(loc)
|
||||
{
|
||||
mContent= content;
|
||||
mTextData.mContent= content;
|
||||
}
|
||||
|
||||
TextNode::~TextNode()
|
||||
|
@ -35,18 +38,82 @@ std::string TextNode::getFontLabel() const
|
|||
|
||||
std::string TextNode::getContent() const
|
||||
{
|
||||
return mContent;
|
||||
return mTextData.mContent;
|
||||
}
|
||||
|
||||
unsigned TextNode::getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned TextNode::getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
void TextNode::setWidth(unsigned width)
|
||||
{
|
||||
if (mWidth != width)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mWidth = width;
|
||||
}
|
||||
}
|
||||
|
||||
void TextNode::setHeight(unsigned height)
|
||||
{
|
||||
if (mHeight != height)
|
||||
{
|
||||
mTransformIsDirty = true;
|
||||
mHeight = height;
|
||||
}
|
||||
}
|
||||
|
||||
void TextNode::setContent(const std::string& content)
|
||||
{
|
||||
if (mContent != content)
|
||||
if (mTextData.mContent != content)
|
||||
{
|
||||
mContent = content;
|
||||
mTextData.mContent = content;
|
||||
mContentIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextNode::updateLines(FontsManager* fontsManager)
|
||||
{
|
||||
auto original_count = mTextData.mLines.size();
|
||||
std::vector<std::string> lines = StringUtils::toLines(mTextData.mContent);
|
||||
std::vector<std::string> output_lines;
|
||||
for (auto line : lines)
|
||||
{
|
||||
double running_width{0};
|
||||
std::string working_line;
|
||||
for (auto c : line)
|
||||
{
|
||||
auto glyph_advance = fontsManager->getGlyph(mTextData.mFont.getFaceName(), mTextData.mFont.getSize(), c)->getAdvanceX();
|
||||
if (false)
|
||||
//if (running_width + glyph_advance > mWidth)
|
||||
{
|
||||
output_lines.push_back(working_line);
|
||||
working_line = c;
|
||||
running_width = glyph_advance;
|
||||
}
|
||||
else
|
||||
{
|
||||
working_line += c;
|
||||
running_width += glyph_advance;
|
||||
}
|
||||
}
|
||||
output_lines.push_back(working_line);
|
||||
running_width = 0;
|
||||
}
|
||||
mTextData.mLines = output_lines;
|
||||
|
||||
if (original_count != mTextData.mLines.size())
|
||||
{
|
||||
mLinesAreDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TextNode::update(FontsManager* fontsManager)
|
||||
{
|
||||
if (!mSceneItem)
|
||||
|
@ -55,10 +122,16 @@ void TextNode::update(FontsManager* fontsManager)
|
|||
mSceneItem->setName(mName + "_SceneText");
|
||||
}
|
||||
|
||||
if (mContentIsDirty)
|
||||
if (mTransformIsDirty || mContentIsDirty)
|
||||
{
|
||||
dynamic_cast<SceneText*>(mSceneItem.get())->setContent(mContent);
|
||||
updateLines(fontsManager);
|
||||
}
|
||||
|
||||
if (mContentIsDirty || mLinesAreDirty)
|
||||
{
|
||||
dynamic_cast<SceneText*>(mSceneItem.get())->setTextData(mTextData);
|
||||
mContentIsDirty = false;
|
||||
mLinesAreDirty = false;
|
||||
}
|
||||
|
||||
if (mTransformIsDirty)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue