From 50dfa4050343a25a5a34816cc276ec6ec9cf33ce Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 4 Nov 2021 19:03:53 +0800 Subject: *MISC --- Runtime/GUI/TextMeshGenerator.h | 6 +++--- Runtime/GUI/UITextMesh.cpp | 28 ++++++++++++---------------- Runtime/GUI/UITextMesh.h | 4 +++- 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'Runtime/GUI') diff --git a/Runtime/GUI/TextMeshGenerator.h b/Runtime/GUI/TextMeshGenerator.h index 94bcaa2..3598cb0 100644 --- a/Runtime/GUI/TextMeshGenerator.h +++ b/Runtime/GUI/TextMeshGenerator.h @@ -3,8 +3,9 @@ #include "UITextMesh.h" #include "Runtime/Utilities/IIncrementalTask.h" #include "Font.h" +#include -// 回收长期没有被使用的text mesh +// collect unused text mesh gradually class GraduallyReleaseTextMesh : public IIncrementalTask { public: @@ -20,14 +21,13 @@ public: }; - class TextMeshGenerator : public Singleton { public: UITextMesh* GetTextMesh(const UnicodeString& str); private: - + std::vector m_TextMeshes; }; diff --git a/Runtime/GUI/UITextMesh.cpp b/Runtime/GUI/UITextMesh.cpp index a800dcd..39bed55 100644 --- a/Runtime/GUI/UITextMesh.cpp +++ b/Runtime/GUI/UITextMesh.cpp @@ -52,20 +52,17 @@ InitializeStaticVariables([]() { s_SizePerText = sizeof(TextMeshVBOLayout) * 4; }); -// 一段文字里面的网格可能会来自不同的atlas,在生成UITextMesh时做好合批 - -// 需要支持 -// * 大小 -// * 锚点 -// * 对齐方式 -// * 换行 -// * 颜色 - -// lineheight 用来处理换行、锚点 -// wordwrap 自动换行 -// preferredSize 自动换行区域大小 -UITextMesh::UITextMesh(const UnicodeString& str, Font* font, int pixelSize, int lineHeight, ETextAnchor anchor, ETextAlignment alignment, bool wordwrap, float preferred) -{ +UITextMesh::UITextMesh( + const UnicodeString& str // 文本 + , Font* font // 字体 + , int pixelSize // 大小 + , int lineHeight // 行高 + , Color32 color32 // 颜色 + , ETextAnchor anchor // 锚点 + , ETextAlignment alignment // 对齐方式 + , bool wordwrap // 自动换行 + , float preferred // 自动换行区域大小 +){ s_TextInfos.clear(); // 记录文本每行的长度 @@ -110,7 +107,6 @@ UITextMesh::UITextMesh(const UnicodeString& str, Font* font, int pixelSize, int unsigned int atlasIndex = ch->atlas; if (atlasIndex != FONT_NOT_IN_ATLAS_PLACEHOLDER) //非空格 { - // 换行符Unix'\n', Windows'\r\n', MacOS '\r' #define CHECK_BREAKS() \ if (c == '\n' || c == '\r') \ @@ -224,7 +220,7 @@ UITextMesh::UITextMesh(const UnicodeString& str, Font* font, int pixelSize, int { dst[vOff + j].position.Set(pos[2 * j], pos[2 * j + 1]); dst[vOff + j].uv.Set(uv[2 * j], uv[2 * j + 1]); - dst[vOff + j].color.Set(255 , 255, 255, 255); + dst[vOff + j].color = color32; } int iOff = i * s_IndicesPerText; diff --git a/Runtime/GUI/UITextMesh.h b/Runtime/GUI/UITextMesh.h index 7778785..f09cce7 100644 --- a/Runtime/GUI/UITextMesh.h +++ b/Runtime/GUI/UITextMesh.h @@ -2,6 +2,8 @@ #include "../Graphics/VertexBuffer.h" #include "Font.h" #include "Runtime/Utilities/Exception.h" +#include "Runtime/Graphics/Color.h" + #include CustomException(TextMeshException); @@ -35,7 +37,7 @@ namespace TextHelper class UITextMesh { public: - UITextMesh(const UnicodeString& str, Font* font, int pixelSize, int lineHeight, ETextAnchor anchor = TextAnchor_UpperLeft, ETextAlignment alignment = TextAlignment_Left, bool wordwrap = false, float preferred = 0)/*throw TextMeshException*/; + UITextMesh(const UnicodeString& str, Font* font, int pixelSize, int lineHeight, Color32 color32 = Color32::white, ETextAnchor anchor = TextAnchor_UpperLeft, ETextAlignment alignment = TextAlignment_Left, bool wordwrap = false, float preferred = 0)/*throw TextMeshException*/; ~UITextMesh(); -- cgit v1.1-26-g67d0