summaryrefslogtreecommitdiff
path: root/Runtime/GUI
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-02 21:52:09 +0800
committerchai <chaifix@163.com>2021-11-02 21:52:09 +0800
commit3898f2c648b1a731dead8337aad8912d2b8b80d7 (patch)
treeda06ea76f91ead6ba13722dd73ebbd8e8fb9b30c /Runtime/GUI
parent72812a7b47f90f9460e54e8149ba9199a7841244 (diff)
*misc
Diffstat (limited to 'Runtime/GUI')
-rw-r--r--Runtime/GUI/TextMesh.cpp2
-rw-r--r--Runtime/GUI/TextMesh.h2
-rw-r--r--Runtime/GUI/UIQuad.cpp63
-rw-r--r--Runtime/GUI/UIQuad.h21
-rw-r--r--Runtime/GUI/utf8.cpp (renamed from Runtime/GUI/utf8_decode.cpp)0
5 files changed, 86 insertions, 2 deletions
diff --git a/Runtime/GUI/TextMesh.cpp b/Runtime/GUI/TextMesh.cpp
index de9a195..2f66170 100644
--- a/Runtime/GUI/TextMesh.cpp
+++ b/Runtime/GUI/TextMesh.cpp
@@ -50,6 +50,8 @@ InitializeStaticVariables([]() {
s_SizePerText = sizeof(TextMeshVBOLayout) * 4;
});
+// 一段文字里面的网格可能会来自不同的atlas,在生成TextMesh时做好合批
+
TextMesh::TextMesh(const UnicodeString& str, Font* font,int pixelSize, ETextAnchor anchor, ETextAlignment alignment)
{
m_Font = font;
diff --git a/Runtime/GUI/TextMesh.h b/Runtime/GUI/TextMesh.h
index c091a78..c5f05a2 100644
--- a/Runtime/GUI/TextMesh.h
+++ b/Runtime/GUI/TextMesh.h
@@ -34,8 +34,6 @@ namespace TextHelper
TextMeshHash GetTextMeshHash();
}
-// 一段文字里面的网格可能会来自不同的atlas,在生成TextMesh时做好合批
-
class TextMesh
{
public:
diff --git a/Runtime/GUI/UIQuad.cpp b/Runtime/GUI/UIQuad.cpp
new file mode 100644
index 0000000..089d0e1
--- /dev/null
+++ b/Runtime/GUI/UIQuad.cpp
@@ -0,0 +1,63 @@
+#include "../Math/Vector2.h"
+#include "../Graphics/GfxDevice.h"
+#include "UIQuad.h"
+
+struct UIQuadLayout
+{
+ Internal::Vector2 position;
+ Internal::Vector2 uv;
+};
+
+static CustomVertexLayout layout;
+
+InitializeStaticVariables([]() {
+ VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UIQuadLayout));
+ VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Internal::Vector2), 2, VertexAttrFormat_Float, sizeof(UIQuadLayout));
+
+ layout.attributes.push_back(POSITION);
+ layout.attributes.push_back(UV);
+});
+
+void UIQuad::Draw()
+{
+ const int nVerts = 4;
+ const int nIndices = 6;
+
+ float pos[] = {
+ m_Left, m_Bottom, // left-bottom
+ m_Right, m_Bottom, // right-bottom
+ m_Right, m_Top, // right-top
+ m_Left, m_Top, // top-left
+ };
+
+ float uv[] = {
+ 0, 0,
+ 1, 0,
+ 1, 1,
+ 0, 1,
+ };
+
+ int indices[] = {
+ 0, 1, 3, // right-top
+ 1, 2, 3, // left-bottom
+ };
+
+ uint8* vb;
+ uint16* ib;
+
+ g_SharedVBO.GetChunk(sizeof(UIQuadLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib);
+
+ UIQuadLayout* dst = (UIQuadLayout*)vb;
+
+ for (int i = 0; i < nVerts; ++i)
+ {
+ dst[i].position.Set(pos[2 * i], pos[2 * i + 1]);
+ dst[i].uv.Set(uv[2 * i], uv[2 * i + 1]);
+ }
+
+ for (int i = 0; i < nIndices; ++i)
+ ib[i] = indices[i];
+
+ g_SharedVBO.ReleaseChunk(4, 6);
+ g_SharedVBO.DrawChunk(layout);
+} \ No newline at end of file
diff --git a/Runtime/GUI/UIQuad.h b/Runtime/GUI/UIQuad.h
new file mode 100644
index 0000000..bcd95a0
--- /dev/null
+++ b/Runtime/GUI/UIQuad.h
@@ -0,0 +1,21 @@
+#pragma once
+#include "../Rendering/DynamicMesh.h"
+#include "../Utilities/StaticInitiator.h"
+
+class UIQuad : public DynamicMesh
+{
+public :
+ UIQuad(float l, float r, float t, float b)
+ {
+ m_Left = l;
+ m_Right = r;
+ m_Top = t;
+ m_Bottom = b;
+ }
+
+ void Draw() override;
+
+private:
+ float m_Left, m_Right, m_Top, m_Bottom;
+
+};
diff --git a/Runtime/GUI/utf8_decode.cpp b/Runtime/GUI/utf8.cpp
index 8a3a086..8a3a086 100644
--- a/Runtime/GUI/utf8_decode.cpp
+++ b/Runtime/GUI/utf8.cpp