summaryrefslogtreecommitdiff
path: root/Runtime/GUI/UITextMesh.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-05 12:14:59 +0800
committerchai <chaifix@163.com>2021-11-05 12:14:59 +0800
commit6d5787d8da9ad1685864668dd4c3d6aa73a563db (patch)
treef4d28a553b13b369a580c482e187bcc4b42f39de /Runtime/GUI/UITextMesh.cpp
parentbe9870f5c1ba4f6ae8cd9764f1a8ed56ee81ddd5 (diff)
TextMeshGenerator
Diffstat (limited to 'Runtime/GUI/UITextMesh.cpp')
-rw-r--r--Runtime/GUI/UITextMesh.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/Runtime/GUI/UITextMesh.cpp b/Runtime/GUI/UITextMesh.cpp
index 24aff47..23c0a9c 100644
--- a/Runtime/GUI/UITextMesh.cpp
+++ b/Runtime/GUI/UITextMesh.cpp
@@ -33,7 +33,6 @@ struct TextInfo {
int line; // 从0开始
};
-static unordered_map<unsigned int, vector<TextInfo>> s_TextInfos;
InitializeStaticVariables([]() {
VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(TextMeshVBOLayout));
@@ -63,6 +62,20 @@ UITextMesh::UITextMesh(
, bool wordwrap // 自动换行
, float preferred // 自动换行区域大小
){
+ m_Font = font;
+ m_PixelSize = pixelSize;
+ m_LineHeight = lineHeight;
+ m_Color = color32;
+ m_Alignment = alignment;
+ m_Anchor = anchor;
+ m_Wordwrap = wordwrap;
+ m_Preferred = preferred;
+ m_Content.length = str.length;
+ m_Content.str = (character::Unicode*)malloc(str.length * sizeof(character::Unicode));
+ memcpy(m_Content.str, str.str, str.length * sizeof(character::Unicode));
+
+ // 记录文本按atlas分类
+ static unordered_map<unsigned int, vector<TextInfo>> s_TextInfos;
s_TextInfos.clear();
// 记录文本每行的长度
@@ -76,9 +89,9 @@ UITextMesh::UITextMesh(
InvokeWhenLeave([]() {
s_LineWidths.clear();
s_LineOffsets.clear();
+ s_TextInfos.clear();
});
- m_Font = font;
const Vector2 atlasSize = font->GetAtlasSize();
//-----------------------------------------------------------------
@@ -149,8 +162,10 @@ UITextMesh::UITextMesh(
textRegion.y = (line + 1) * lineHeight;
- if (s_TextInfos.size() == 0)
- return;
+ if (s_TextInfos.size() == 0)
+ {
+ return;
+ }
Vector2i textOffset;
Vector2 halfRegion = Vector2(textRegion.x/ 2.f, textRegion.y / 2.f);
@@ -240,7 +255,7 @@ UITextMesh::UITextMesh(
WipeGLError();
}
-void UITextMesh::Draw()
+void UITextMesh::Draw() const
{
for (auto subText : m_VBOs)
{