summaryrefslogtreecommitdiff
path: root/Runtime/GUI/TextMesh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/GUI/TextMesh.cpp')
-rw-r--r--Runtime/GUI/TextMesh.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/Runtime/GUI/TextMesh.cpp b/Runtime/GUI/TextMesh.cpp
index e69de29..6f3b3d6 100644
--- a/Runtime/GUI/TextMesh.cpp
+++ b/Runtime/GUI/TextMesh.cpp
@@ -0,0 +1,90 @@
+#include "../Graphics/CustomVertexLayout.h"
+#include "Runtime/Utilities/StaticInitiator.h"
+#include "../Math/Math.h"
+#include "../Graphics/Color.h"
+#include "TextMesh.h"
+#include <vector>
+#include <unordered_map>
+
+using namespace std;
+
+struct TextMeshVBOLayout
+{
+ Vector2 position;
+ Vector2 uv;
+ Color32 color;
+};
+
+static CustomVertexLayout s_TextMeshVBOLayout;
+
+static unsigned int s_VertexPerText;
+static unsigned int s_SizePerVertex;
+static unsigned int s_SizePerText;
+static unsigned int s_IndicesPerText;
+
+struct TextInfo {
+ const Character* ch;
+ float offset;
+};
+
+static unordered_map<unsigned int, vector<TextInfo>> s_TextInfos;
+
+InitializeStaticVariables([]() {
+ VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(TextMeshVBOLayout));
+ VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Vector2), 2, VertexAttrFormat_Float, sizeof(TextMeshVBOLayout));
+ VertexAttributeDescriptor COLOR = VertexAttributeDescriptor(sizeof(Vector2)*2, 4, VertexAttrFormat_Unsigned_Byte, sizeof(TextMeshVBOLayout), true);
+ s_TextMeshVBOLayout.attributes.push_back(POSITION);
+ s_TextMeshVBOLayout.attributes.push_back(UV);
+ s_TextMeshVBOLayout.attributes.push_back(COLOR);
+
+ s_VertexPerText = 4;
+ s_SizePerVertex = sizeof(TextMeshVBOLayout);
+ s_SizePerText = sizeof(TextMeshVBOLayout) * 4;
+ s_IndicesPerText = 6;
+});
+
+TextMesh::TextMesh(const UnicodeString& str, Font* font,int pixelSize, ETextAnchor anchor, ETextAlignment alignment)
+{
+ m_Font = font;
+ s_TextInfos.clear();
+
+ float offset = 0;
+ for (int i = 0; i < str.length; ++i)
+ {
+ character::Codepoint c = str.str[i];
+ const Character* ch = font->GetCharacter(c, pixelSize);
+ unsigned int index = ch->atlas;
+
+ TextInfo info;
+ info.ch = ch;
+ info.offset = offset;
+
+ auto list = s_TextInfos.find(index);
+ if (list == s_TextInfos.end())
+ {
+ s_TextInfos.insert(std::pair<unsigned int, vector<TextInfo>>(index, vector<TextInfo>()));
+ list = s_TextInfos.find(index);
+ }
+ vector<TextInfo>& v = list->second;
+ v.push_back(info);
+
+ offset += ch->advance;
+ }
+
+ if (s_TextInfos.size() == 0)
+ return;
+
+ for (auto iter : s_TextInfos) {
+ unsigned int index = iter.first;
+ vector<TextInfo>& texts = iter.second;
+ int count = texts.size();
+
+ VertexBuffer* vb = new VertexBuffer(count * s_SizePerText, count * s_IndicesPerText, VertexBuffer::VertexBufferType_Static);
+
+ }
+}
+
+void TextMesh::Draw()
+{
+
+}