From b7310c9cce95bfc9bfe135063ee0e97fbc654928 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 1 Nov 2021 16:53:51 +0800 Subject: *misc --- Runtime/Scripting/GUI/Font.bind.cpp | 103 ++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Runtime/Scripting/GUI/Font.bind.cpp (limited to 'Runtime/Scripting/GUI/Font.bind.cpp') diff --git a/Runtime/Scripting/GUI/Font.bind.cpp b/Runtime/Scripting/GUI/Font.bind.cpp new file mode 100644 index 0000000..73fb7e6 --- /dev/null +++ b/Runtime/Scripting/GUI/Font.bind.cpp @@ -0,0 +1,103 @@ +#include "Runtime/GUI/Font.h" +#include "Runtime/Graphics/Shader.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/Graphics/GfxDevice.h" +#include "Runtime/Common/DataBuffer.h" + +LUA_BIND_REGISTRY(Font) +{ + LUA_BIND_REGISTER_METHODS(state, + { "New", _New }, + { "GetCharacter", _GetCharacter }, + { "GetGlyphAtlas", _GetGlyphAtlas } + ); +} + +LUA_BIND_POSTPROCESS(Font) +{ +} + +// Font.New(ttfPath, atlasSize, margin, padding) +// Font.New(ttfData, atlasSize, margin, padding) +LUA_BIND_IMPL_METHOD(Font, _New) +{ + LUA_BIND_STATE(L); + LUA_BIND_CHECK(L, "STNN!|UTNN!"); + + Font* font = NULL; + if (state.CheckParams(1, "STNN!")) + { + const char* path = state.GetValue(1, ""); + TextGeneratingSettings setting; + setting.atlasSize = state.GetValue(2, Internal::Vector2(128, 128)); + setting.margin = state.GetValue(3, 0); + setting.padding = state.GetValue(4, 0); + try { + font = new Font(path, setting); + } + catch (FontException& e) + { + log_error(e.what()); + state.PushNil(); + return 1; + } + } + else if (state.CheckParams(1, "UTNN!")) + { + DataBuffer* buffer = state.GetUserdata(1); + if (buffer == NULL) + { + log_error("Create font failed, DataBuffer is invalid."); + state.PushNil(); + return 1; + } + TextGeneratingSettings setting; + setting.atlasSize = state.GetValue(2, Internal::Vector2(128, 128)); + setting.margin = state.GetValue(3, 0); + setting.padding = state.GetValue(4, 0); + try { + font = new Font(buffer, setting); + } + catch (FontException& e) + { + log_error(e.what()); + state.PushNil(); + return 1; + } + } + + font->PushUserdata(state); + + return 1; +} + +// font:GetCharacter(char, size, encoding) +LUA_BIND_IMPL_METHOD(Font, _GetCharacter) +{ + LUA_BIND_PREPARE(L, Font); +// Character character = self->GetCharacter(character); + return 1; +} + +// font:GetCharacter(str, size, encoding) +LUA_BIND_IMPL_METHOD(Font, _GetCharacters) +{ + LUA_BIND_PREPARE(L, Font); +// Character character = self->GetCharacter(character); + return 1; +} + +// 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