diff options
author | chai <chaifix@163.com> | 2021-11-01 16:53:51 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-01 16:53:51 +0800 |
commit | b7310c9cce95bfc9bfe135063ee0e97fbc654928 (patch) | |
tree | 459d37f0acd9b9dd6719b71d1ecc8620dc1f5fef /Runtime/Scripting/GUI | |
parent | 4dead522e513ffd326101b790b2129595f72ff42 (diff) |
*misc
Diffstat (limited to 'Runtime/Scripting/GUI')
-rw-r--r-- | Runtime/Scripting/GUI/Font.bind.cpp | 103 | ||||
-rw-r--r-- | Runtime/Scripting/GUI/GUI.bind.cpp | 24 |
2 files changed, 127 insertions, 0 deletions
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<const char*>(1, "");
+ TextGeneratingSettings setting;
+ setting.atlasSize = state.GetValue<Internal::Vector2>(2, Internal::Vector2(128, 128));
+ setting.margin = state.GetValue<int>(3, 0);
+ setting.padding = state.GetValue<int>(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<DataBuffer>(1);
+ if (buffer == NULL)
+ {
+ log_error("Create font failed, DataBuffer is invalid.");
+ state.PushNil();
+ return 1;
+ }
+ TextGeneratingSettings setting;
+ setting.atlasSize = state.GetValue<Internal::Vector2>(2, Internal::Vector2(128, 128));
+ setting.margin = state.GetValue<int>(3, 0);
+ setting.padding = state.GetValue<int>(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<int>(2, 0);
+ //GlyphAtals atlas = self->m_Atlases[i];
+
+ //state.Push((const void*)atlas.altas);
+
+ return 1;
+}
\ No newline at end of file diff --git a/Runtime/Scripting/GUI/GUI.bind.cpp b/Runtime/Scripting/GUI/GUI.bind.cpp new file mode 100644 index 0000000..4f6ed7a --- /dev/null +++ b/Runtime/Scripting/GUI/GUI.bind.cpp @@ -0,0 +1,24 @@ +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/Common/DataBuffer.h" +#include "Runtime/FileSystem/FileJobs.h" +#include "Runtime/GUI/Font.h"
+
+using namespace std; +using namespace LuaBind; +
+int luaopen_GameLab_Engine_GUI(lua_State* L) +{ + log_info_tag("Scripting", "luaopen_GameLab_Engine_GUI()"); + + LUA_BIND_STATE(L); + + state.PushGlobalNamespace(); + state.PushNamespace("GameLab"); + state.PushNamespace("Engine"); + state.PushNamespace("GUI"); + + state.RegisterNativeClass<Font>(); + + return 1; +}
\ No newline at end of file |