summaryrefslogtreecommitdiff
path: root/Runtime/GUI
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/GUI')
-rw-r--r--Runtime/GUI/TextMeshGenerator.h6
-rw-r--r--Runtime/GUI/UITextMesh.cpp28
-rw-r--r--Runtime/GUI/UITextMesh.h4
3 files changed, 18 insertions, 20 deletions
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 <vector>
-// 回收长期没有被使用的text mesh
+// collect unused text mesh gradually
class GraduallyReleaseTextMesh : public IIncrementalTask
{
public:
@@ -20,14 +21,13 @@ public:
};
-
class TextMeshGenerator : public Singleton<TextMeshGenerator>
{
public:
UITextMesh* GetTextMesh(const UnicodeString& str);
private:
-
+ std::vector<UITextMesh*> 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 <unordered_map>
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();