diff options
Diffstat (limited to 'Runtime')
-rw-r--r-- | Runtime/GUI/TextMeshGenerator.h | 6 | ||||
-rw-r--r-- | Runtime/GUI/UITextMesh.cpp | 28 | ||||
-rw-r--r-- | Runtime/GUI/UITextMesh.h | 4 | ||||
-rw-r--r-- | Runtime/Scripting/GUI/Font.bind.cpp | 2 | ||||
-rw-r--r-- | Runtime/Scripting/GUI/GUI.bind.cpp | 25 |
5 files changed, 41 insertions, 24 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(); diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp index 699b97f..7d7e3f2 100644 --- a/Runtime/Scripting/GUI/Font.bind.cpp +++ b/Runtime/Scripting/GUI/Font.bind.cpp @@ -137,7 +137,7 @@ LUA_BIND_IMPL_METHOD(Font, _GetCharacters) WipeGLError();
- UITextMesh* tm = new UITextMesh(str, self, size, size + 3, TextAnchor_UpperLeft, TextAlignment_Left, wordwrap, preferred);
+ UITextMesh* tm = new UITextMesh(str, self, size, size + 3, Color32::white, TextAnchor_UpperLeft, TextAlignment_Left, wordwrap, preferred);
tm->Draw();
return 0;
diff --git a/Runtime/Scripting/GUI/GUI.bind.cpp b/Runtime/Scripting/GUI/GUI.bind.cpp index fcc2848..a4ee772 100644 --- a/Runtime/Scripting/GUI/GUI.bind.cpp +++ b/Runtime/Scripting/GUI/GUI.bind.cpp @@ -3,6 +3,7 @@ #include "Runtime/Common/DataBuffer.h" #include "Runtime/FileSystem/FileJobs.h" #include "Runtime/GUI/Font.h"
+#include "Runtime/GUI/UITextMesh.h"
using namespace std; using namespace LuaBind; @@ -21,9 +22,27 @@ int luaopen_GameLab_Engine_GUI(lua_State* L) state.RegisterNativeClass<Font>(); LUA_BIND_REGISTER_ENUM(state, "EEncoding", - { "ASCII", EEncoding::Encoding_ASCII }, - { "UTF8", EEncoding::Encoding_UTF8 }, - { "UTF16", EEncoding::Encoding_UTF16 } + { "ASCII", Encoding_ASCII }, + { "UTF8", Encoding_UTF8 }, + { "UTF16", Encoding_UTF16 } + ); + + LUA_BIND_REGISTER_ENUM(state, "ETextAnchor", + { "UpperLeft", TextAnchor_UpperLeft }, + { "UpperCenter", TextAnchor_UpperCenter }, + { "UpperRight", TextAnchor_UpperRight }, + { "MiddleLeft", TextAnchor_MiddleLeft }, + { "MiddleCenter", TextAnchor_MiddleCenter }, + { "MiddleRight", TextAnchor_MiddleRight }, + { "LowerLeft", TextAnchor_LowerLeft }, + { "LowerCenter", TextAnchor_LowerCenter }, + { "LowerRight", TextAnchor_LowerRight } + ); + + LUA_BIND_REGISTER_ENUM(state, "ETextAlignment", + { "Left", TextAlignment_Left }, + { "Center", TextAlignment_Center }, + { "Right", TextAlignment_Right } ); return 1; |