diff options
Diffstat (limited to 'Runtime/GUI/UITextMesh.cpp')
-rw-r--r-- | Runtime/GUI/UITextMesh.cpp | 25 |
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) { |