From 2b9621a46288532b352b7838f96aca80f971e3d1 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 5 Nov 2021 14:25:39 +0800 Subject: *misc --- Runtime/GUI/Font.h | 2 +- Runtime/GUI/UITextMesh.cpp | 1 - Runtime/GUI/UITextMesh.h | 12 ++--- Runtime/Graphics/VertexBuffer.cpp | 1 - Runtime/Lua/LuaHelper.cpp | 41 +++++++++++++++-- Runtime/Scripting/GUI/Font.bind.cpp | 91 +------------------------------------ 6 files changed, 44 insertions(+), 104 deletions(-) (limited to 'Runtime') diff --git a/Runtime/GUI/Font.h b/Runtime/GUI/Font.h index 565fafc..df0bc7b 100644 --- a/Runtime/GUI/Font.h +++ b/Runtime/GUI/Font.h @@ -36,7 +36,7 @@ namespace character Unicode codepoint; unsigned short size;//字体大小 }; -#pragma pack() +#pragma pack(pop) bool operator==(const Hash &other) const { diff --git a/Runtime/GUI/UITextMesh.cpp b/Runtime/GUI/UITextMesh.cpp index 23c0a9c..aeaee38 100644 --- a/Runtime/GUI/UITextMesh.cpp +++ b/Runtime/GUI/UITextMesh.cpp @@ -33,7 +33,6 @@ struct TextInfo { int line; // 从0开始 }; - InitializeStaticVariables([]() { VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(TextMeshVBOLayout)); VertexAttributeDescriptor UV = VertexAttributeDescriptor(sizeof(Vector2), 2, VertexAttrFormat_Float, sizeof(TextMeshVBOLayout)); diff --git a/Runtime/GUI/UITextMesh.h b/Runtime/GUI/UITextMesh.h index 505b390..ea543f3 100644 --- a/Runtime/GUI/UITextMesh.h +++ b/Runtime/GUI/UITextMesh.h @@ -36,6 +36,12 @@ class UITextMesh public: void Draw() const; +private: + friend class TextMeshGenerator; + + 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(); + GET(const Font*, Font, m_Font); GET(int, PixelSize, m_PixelSize); GET(int, LineHeight, m_LineHeight); @@ -46,12 +52,6 @@ public: GET(float, Preferred, m_Preferred); GET(const UnicodeString&, Content, m_Content); -private: - friend class TextMeshGenerator; - - 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(); - std::unordered_map m_VBOs; Font* m_Font; diff --git a/Runtime/Graphics/VertexBuffer.cpp b/Runtime/Graphics/VertexBuffer.cpp index 8973275..29ecc57 100644 --- a/Runtime/Graphics/VertexBuffer.cpp +++ b/Runtime/Graphics/VertexBuffer.cpp @@ -47,7 +47,6 @@ void VertexBuffer::FlushChunk(int actualVerts, int actualIndices) m_VB->FlushMapedRange(0, actualVBufferSize); m_IB->FlushMapedRange(0, actualIBufferSize); - // 一定要unmap m_VB->UnMap(); m_IB->UnMap(); diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp index 951f2fe..f1dc349 100644 --- a/Runtime/Lua/LuaHelper.cpp +++ b/Runtime/Lua/LuaHelper.cpp @@ -2,6 +2,7 @@ #include "Runtime/Math/Math.h" #include "Runtime/GUI/Font.h" +#include "Runtime/Graphics/Color.h" using namespace LuaBind; @@ -16,7 +17,7 @@ Rect State::GetValue < Rect >(int idx, const Rect value) rect.width = GetField(idx, "z", 0); rect.height = GetField(idx, "w", 0); } - else + else if (LuaHelper::IsType(*this, "table", idx)) { rect.x = GetField(idx, 1, 0); rect.y = GetField(idx, 2, 0); @@ -35,7 +36,7 @@ Vector2 State::GetValue < Vector2 >(int idx, const Vector2 value) v2.x = GetField(idx, "x", 0); v2.y = GetField(idx, "y", 0); } - else + else if (LuaHelper::IsType(*this, "table", idx)) { v2.x = GetField(idx, 1, 0); v2.y = GetField(idx, 2, 0); @@ -53,7 +54,7 @@ Vector3 State::GetValue < Vector3 >(int idx, const Vector3 value) v3.y = GetField(idx, "y", 0); v3.z = GetField(idx, "z", 0); } - else + else if (LuaHelper::IsType(*this, "table", idx)) { v3.x = GetField(idx, 1, 0); v3.y = GetField(idx, 2, 0); @@ -73,7 +74,7 @@ Vector4 State::GetValue < Vector4 >(int idx, const Vector4 value) v4.z = GetField(idx, "z", 0); v4.w = GetField(idx, "w", 0); } - else + else if (LuaHelper::IsType(*this, "table", idx)) { v4.x = GetField(idx, 1, 0); v4.y = GetField(idx, 2, 0); @@ -83,6 +84,34 @@ Vector4 State::GetValue < Vector4 >(int idx, const Vector4 value) return v4; } +template <> +Color32 State::GetValue < Color32 >(int idx, const Color32 value) +{ + Color32 col = value; + if (LuaHelper::IsType(*this, "GameLab.Engine.Rendering.Color", idx)) + { + col.r = GetField(idx, "r", 0) * 255.f; + col.g = GetField(idx, "g", 0) * 255.f; + col.b = GetField(idx, "b", 0) * 255.f; + col.a = GetField(idx, "a", 0) * 255.f; + } + else if (LuaHelper::IsType(*this, "GameLab.Engine.Rendering.Color32", idx)) + { + col.r = GetField(idx, "r", 0); + col.g = GetField(idx, "g", 0); + col.b = GetField(idx, "b", 0); + col.a = GetField(idx, "a", 0); + } + else if(LuaHelper::IsType(*this, "table", idx)) + { + col.r = GetField(idx, 1, 0); + col.g = GetField(idx, 2, 0); + col.b = GetField(idx, 3, 0); + col.a = GetField(idx, 4, 0); + } + return col; +} + template <> Matrix44 State::GetValue < Matrix44 >(int idx, const Matrix44 value) { @@ -109,7 +138,7 @@ Matrix44 State::GetValue < Matrix44 >(int idx, const Matrix44 value) m4.m[3][2] = GetField(idx, "m32", 0); m4.m[3][3] = GetField(idx, "m33", 0); } - else + else if (LuaHelper::IsType(*this, "table", idx)) { m4.m[0][0] = GetField(idx, 1, 0); m4.m[0][1] = GetField(idx, 2, 0); @@ -159,6 +188,8 @@ bool LuaHelper::IsType(LuaBind::State& state, const char* typeName, int idx) { int top = state.GetTop(); cc8* type = luaL_typename(state, idx); + if (strcmp(type, "nil") == 0 || strcmp(type, "no value") == 0) + return false; if (strcmp(type, typeName) == 0) return true; state.GetField(idx, "_type"); diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp index 0570df0..8759fe1 100644 --- a/Runtime/Scripting/GUI/Font.bind.cpp +++ b/Runtime/Scripting/GUI/Font.bind.cpp @@ -10,19 +10,10 @@ #include "Runtime/GUI/TextMeshGenerator.h" #include "Runtime/Utilities/AutoInvoke.h" -static std::vector* s_Codepoints; - -InitializeStaticVariables([](){ - s_Codepoints = new std::vector(); -}); - LUA_BIND_REGISTRY(Font) { LUA_BIND_REGISTER_METHODS(state, - { "New", _New }, - { "GetCharacter", _GetCharacter }, - { "GetCharacters", _GetCharacters }, - { "GetGlyphAtlas", _GetGlyphAtlas } + { "New", _New } ); } @@ -83,83 +74,3 @@ LUA_BIND_IMPL_METHOD(Font, _New) return 1; } - -// font:GetCharacter(char, size, encoding) -LUA_BIND_IMPL_METHOD(Font, _GetCharacter) -{ - LUA_BIND_PREPARE(L, Font); - return 1; -} - -// font:GetCharacter(str, size, wordwrap, preferredWidth, encoding) -LUA_BIND_IMPL_METHOD(Font, _GetCharacters) -{ - LUA_BIND_PREPARE(L, Font); - //LUA_BIND_CHECK(L, "US"); - - char* buf = (char*)state.GetValue(2, ""); - int size = state.GetValue(3, 12); - bool wordwrap = state.GetValue(4, false); - float preferred = state.GetValue(5, 0); - int encoding = state.GetValue(6, EEncoding::Encoding_UTF8); - - s_Codepoints->clear(); - InvokeWhenLeave([]() { - s_Codepoints->clear(); - }); - - if (encoding == EEncoding::Encoding_UTF8) - { - while (*buf != 0) { - int err; - s_Codepoints->push_back(utf8::getu8c(&buf, &err)); - if (err != 0) - { - log_warning("Illegal utf8 bytes %d", err); - } - } - } - else if (encoding == EEncoding::Encoding_UTF16) - { - while (*buf != 0) { - unsigned short* s = (unsigned short*)(buf); - s_Codepoints->push_back(*s); - buf += 2; - } - } - else if (encoding == EEncoding::Encoding_ASCII) - { - while (*buf != 0) { - s_Codepoints->push_back(*buf); - buf += 1; - } - } - - self->RenderCharacters(*s_Codepoints, size); - - UnicodeString str; - str.str = s_Codepoints->data(); - str.length = s_Codepoints->size(); - - WipeGLError(); - - const UITextMesh* tm = g_TextMeshGenerator.GetTextMesh(str, self, size, size + 3, Color32::white, TextAnchor_UpperLeft, TextAlignment_Left, wordwrap, preferred); - tm->Draw(); - - return 0; -} - -// font:GetAtlas(i) -// return lightuserdata -LUA_BIND_IMPL_METHOD(Font, _GetGlyphAtlas) -{ - LUA_BIND_PREPARE(L, Font); - //LUA_BIND_CHECK(L, "UN"); - - //int i = state.GetValue(2, 0); - //GlyphAtals atlas = self->m_Atlases[i]; - - //state.Push((const void*)atlas.altas); - - return 1; -} \ No newline at end of file -- cgit v1.1-26-g67d0