From 0e0aa82ab2ebc9f15519cea710a52c5895690152 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 11 Nov 2021 18:27:36 +0800 Subject: * rename Editor.GUI to Editor.Window --- .../Scripting/EditorGUI/ContainerWindow.bind.cpp | 64 ----------- Editor/Scripting/EditorGUI/EditorGUI.bind.cpp | 118 --------------------- Editor/Scripting/EditorGUI/GUIWindow.bind.cpp | 70 ------------ Editor/Scripting/EditorGUI/SplitWindow.bind.cpp | 0 Editor/Scripting/EditorScripting.cpp | 6 +- Editor/Scripting/Window/ContainerWindow.bind.cpp | 64 +++++++++++ Editor/Scripting/Window/EditorGUI.bind.cpp | 118 +++++++++++++++++++++ Editor/Scripting/Window/GUIWindow.bind.cpp | 70 ++++++++++++ Editor/Scripting/Window/SplitWindow.bind.cpp | 0 9 files changed, 254 insertions(+), 256 deletions(-) delete mode 100644 Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp delete mode 100644 Editor/Scripting/EditorGUI/EditorGUI.bind.cpp delete mode 100644 Editor/Scripting/EditorGUI/GUIWindow.bind.cpp delete mode 100644 Editor/Scripting/EditorGUI/SplitWindow.bind.cpp create mode 100644 Editor/Scripting/Window/ContainerWindow.bind.cpp create mode 100644 Editor/Scripting/Window/EditorGUI.bind.cpp create mode 100644 Editor/Scripting/Window/GUIWindow.bind.cpp create mode 100644 Editor/Scripting/Window/SplitWindow.bind.cpp (limited to 'Editor/Scripting') diff --git a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp deleted file mode 100644 index 6c73116..0000000 --- a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "Editor/GUI/EditorWindows.h" -#include "Runtime/Math/Math.h" - -using namespace LuaBind; - -LUA_BIND_REGISTRY(ContainerWindow) -{ - LUA_BIND_REGISTER_METHODS(state, - { "New", _New }, - { "SetTitle", _SetTitle }, - { "SetIcon", _SetIcon }, - { "DoPaint", _DoPaint } - ); -} - -LUA_BIND_POSTPROCESS(ContainerWindow) -{ -} - -LUA_BIND_IMPL_METHOD(ContainerWindow, _SetTitle) -{ - LUA_BIND_PREPARE(L, ContainerWindow); - - cc8* title = state.GetValue(2, ""); - self->SetTitle(title); - - return 0; -} - -LUA_BIND_IMPL_METHOD(ContainerWindow, _SetIcon) -{ - LUA_BIND_PREPARE(L, ContainerWindow); - - cc8* path = state.GetValue(2, ""); - self->SetIcon(path); - - return 0; -} - -LUA_BIND_IMPL_METHOD(ContainerWindow, _DoPaint) -{ - LUA_BIND_PREPARE(L, ContainerWindow); - self->DoPaint(); - return 0; -} - -LUA_BIND_IMPL_METHOD(ContainerWindow, ContainerWindow::_New) -{ - LUA_BIND_STATE(L, ContainerWindow); - LUA_BIND_CHECK(L, "TNTT"); - - ContainerWindow* wnd = new ContainerWindow(state.GetVM()); - - Rect rect = state.GetValue(state, Rect()); - int showMode = state.GetValue(2, 0); - Vector2 min = state.GetValue(state, Vector2()); - Vector2 max = state.GetValue(state, Vector2()); - - wnd->Init(rect, showMode, min, max); - - wnd->PushUserdata(state); - - return 1; -} diff --git a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp deleted file mode 100644 index ed26604..0000000 --- a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "Editor/GUI/EditorWindows.h" -#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" -#include "Runtime/GUI/utf8.h" -#include "Runtime/Utilities/StaticInitiator.h" -#include "Runtime/GUI/UITextMesh.h" -#include "Runtime/Math/Math.h" -#include "Runtime/GUI/TextMeshGenerator.h" -#include "Runtime/Utilities/AutoInvoke.h" - -using namespace LuaBind; - -static std::vector* s_Codepoints; - -InitializeStaticVariables([]() { - s_Codepoints = new std::vector(); -}); - -// Editor.GUI.Text(font, str, pixelSize, lineHeight, color, anchor, alignment, wordwrap, preferred, encoding) -static int Text(lua_State* L) -{ - LUA_BIND_STATE(L); - - Font* font = (Font*)state.GetUserdata(1); - char* buf = (char*)state.GetValue(2, ""); - int pixelSize = state.GetValue(3, 12); - int lineHeight = state.GetValue(4, pixelSize + 3); - Color32 color = state.GetValue(5, Color32::white); - int anchor = state.GetValue(6, TextAnchor_UpperLeft); - int alignment = state.GetValue(7, TextAlignment_Left); - bool wordwrap = state.GetValue(8, false); - int preferred = state.GetValue(9, 0); - int encoding = state.GetValue(10, 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; - } - } - - font->RenderCharacters(*s_Codepoints, pixelSize); - - UnicodeString str; - str.str = s_Codepoints->data(); - str.length = s_Codepoints->size(); - - WipeGLError(); - - const UITextMesh* tm = g_TextMeshGenerator.GetTextMesh(str, font, pixelSize, lineHeight, color, (ETextAnchor)anchor, (ETextAlignment)alignment, wordwrap, preferred); - tm->Draw(); - - return 0; -} - -static luaL_Reg guiFuncs[] = { - {"Text", Text}, - {0, 0} -}; - -// GameLab.Editor.GUI -int luaopen_GameLab_Editor_GUI(lua_State* L) -{ - log_info_tag("Scripting", "luaopen_GameLab_Editor_GUI()"); - - LUA_BIND_STATE(L); - - state.PushGlobalNamespace(); - state.PushNamespace("GameLab"); - state.PushNamespace("Editor"); - state.PushNamespace("GUI"); - - state.PushNamespace("Internal"); - state.RegisterNativeClass(); - state.RegisterNativeClass(); - state.PopNamespace(); - - LUA_BIND_REGISTER_ENUM(state, "EShowMode", - { "NormalWindow", ContainerWindow::kShowNormalWindow }, - { "ShowPopupMenu", ContainerWindow::kShowPopupMenu }, - { "Utility ", ContainerWindow::kShowUtility }, - { "NoShadow", ContainerWindow::kShowNoShadow }, - { "MainWindow", ContainerWindow::kShowMainWindow }, - { "AuxWindow", ContainerWindow::kShowAuxWindow } - ); - - state.RegisterMethods(guiFuncs); - - return 1; -} \ No newline at end of file diff --git a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp deleted file mode 100644 index 212cb50..0000000 --- a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "Editor/GUI/EditorWindows.h" -#include "Runtime/Math/Math.h" - -LUA_BIND_REGISTRY(GUIWindow) -{ - LUA_BIND_REGISTER_METHODS(state, - { "DoPaint", _DoPaint }, - { "Focus", _Focus }, - { "SetContainerWindow", _SetContainerWindow }, - { "SetPosition", _SetPosition }, - { "New", _New } - ); -} - -LUA_BIND_POSTPROCESS(GUIWindow) -{ -} - -// GUIWindow.New([script]) -LUA_BIND_IMPL_METHOD(GUIWindow, _New) -{ - LUA_BIND_STATE(L, GUIWindow); - LUA_BIND_CHECK(L, "T"); - - GUIWindow* wnd = new GUIWindow(state.GetVM()); - - if (LuaHelper::IsType(state, "GameLab.Editor.GUI.GUIWindow", -1)) - wnd->SetMemberRef(state, wnd->m_Script, -1); - - wnd->PushUserdata(state); - return 1; -} - -LUA_BIND_IMPL_METHOD(GUIWindow, _DoPaint) -{ - LUA_BIND_PREPARE(L, GUIWindow); - self->DoPaint(); - return 0; -} - -LUA_BIND_IMPL_METHOD(GUIWindow, _Focus) -{ - LUA_BIND_PREPARE(L, GUIWindow); - self->Focus(); - return 0; -} - -LUA_BIND_IMPL_METHOD(GUIWindow, _SetContainerWindow) -{ - LUA_BIND_PREPARE(L, GUIWindow); - ContainerWindow* wnd = state.GetUserdata(2); - self->SetContainerWindow(wnd); - return 0; -} - -// GUIWindow.SetPosition(self, {x, y, width, height}) -LUA_BIND_IMPL_METHOD(GUIWindow, _SetPosition) -{ - LUA_BIND_PREPARE(L, GUIWindow); - if (!state.CheckParams(1, "UT")) - return 0; - - Rect rect; - rect.x = state.GetField(2, 1, 0); - rect.y = state.GetField(2, 2, 0); - rect.width = state.GetField(2, 3, 0); - rect.height = state.GetField(2, 4, 0); - self->SetPosition(rect); - return 0; -} diff --git a/Editor/Scripting/EditorGUI/SplitWindow.bind.cpp b/Editor/Scripting/EditorGUI/SplitWindow.bind.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Editor/Scripting/EditorScripting.cpp b/Editor/Scripting/EditorScripting.cpp index c8cfbbb..244dd78 100644 --- a/Editor/Scripting/EditorScripting.cpp +++ b/Editor/Scripting/EditorScripting.cpp @@ -17,9 +17,7 @@ extern int luaopen_GameLab_Engine_Resource(lua_State* L); // GameLab.Engine.Reso extern int luaopen_GameLab_Engine_GUI(lua_State* L); extern int luaopen_GameLab_Editor(lua_State* L); // GameLab.Editor -extern int luaopen_GameLab_Editor_GUI(lua_State* L); // GameLab.Editor.GUI -extern int luaopen_GameLab_Editor_GUILayout(lua_State* L); // GameLab.Editor.GUILayout -extern int luaopen_GameLab_Editor_IMGUI(lua_State* L); // GameLab.Editor.IMGUI +extern int luaopen_GameLab_Editor_Window(lua_State* L); // GameLab.Editor.Window extern int luaopen_GameLab_Editor_Resource(lua_State* L); // GameLab.Editor.Resource extern int luaopen_GameLab_Editor_Profiling(lua_State* L); // GameLab.Editor.Profiling extern int luaopen_GameLab_Editor_Animation(lua_State* L); // GameLab.Editor.Animation @@ -49,7 +47,7 @@ bool SetupGameLabEditorScripting(lua_State* L) openlib(luaopen_GameLab_Engine_GUI); openlib(luaopen_GameLab_Editor); - openlib(luaopen_GameLab_Editor_GUI); + openlib(luaopen_GameLab_Editor_Window); return true; } diff --git a/Editor/Scripting/Window/ContainerWindow.bind.cpp b/Editor/Scripting/Window/ContainerWindow.bind.cpp new file mode 100644 index 0000000..6c73116 --- /dev/null +++ b/Editor/Scripting/Window/ContainerWindow.bind.cpp @@ -0,0 +1,64 @@ +#include "Editor/GUI/EditorWindows.h" +#include "Runtime/Math/Math.h" + +using namespace LuaBind; + +LUA_BIND_REGISTRY(ContainerWindow) +{ + LUA_BIND_REGISTER_METHODS(state, + { "New", _New }, + { "SetTitle", _SetTitle }, + { "SetIcon", _SetIcon }, + { "DoPaint", _DoPaint } + ); +} + +LUA_BIND_POSTPROCESS(ContainerWindow) +{ +} + +LUA_BIND_IMPL_METHOD(ContainerWindow, _SetTitle) +{ + LUA_BIND_PREPARE(L, ContainerWindow); + + cc8* title = state.GetValue(2, ""); + self->SetTitle(title); + + return 0; +} + +LUA_BIND_IMPL_METHOD(ContainerWindow, _SetIcon) +{ + LUA_BIND_PREPARE(L, ContainerWindow); + + cc8* path = state.GetValue(2, ""); + self->SetIcon(path); + + return 0; +} + +LUA_BIND_IMPL_METHOD(ContainerWindow, _DoPaint) +{ + LUA_BIND_PREPARE(L, ContainerWindow); + self->DoPaint(); + return 0; +} + +LUA_BIND_IMPL_METHOD(ContainerWindow, ContainerWindow::_New) +{ + LUA_BIND_STATE(L, ContainerWindow); + LUA_BIND_CHECK(L, "TNTT"); + + ContainerWindow* wnd = new ContainerWindow(state.GetVM()); + + Rect rect = state.GetValue(state, Rect()); + int showMode = state.GetValue(2, 0); + Vector2 min = state.GetValue(state, Vector2()); + Vector2 max = state.GetValue(state, Vector2()); + + wnd->Init(rect, showMode, min, max); + + wnd->PushUserdata(state); + + return 1; +} diff --git a/Editor/Scripting/Window/EditorGUI.bind.cpp b/Editor/Scripting/Window/EditorGUI.bind.cpp new file mode 100644 index 0000000..838e752 --- /dev/null +++ b/Editor/Scripting/Window/EditorGUI.bind.cpp @@ -0,0 +1,118 @@ +#include "Editor/GUI/EditorWindows.h" +#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" +#include "Runtime/GUI/utf8.h" +#include "Runtime/Utilities/StaticInitiator.h" +#include "Runtime/GUI/UITextMesh.h" +#include "Runtime/Math/Math.h" +#include "Runtime/GUI/TextMeshGenerator.h" +#include "Runtime/Utilities/AutoInvoke.h" + +using namespace LuaBind; + +static std::vector* s_Codepoints; + +InitializeStaticVariables([]() { + s_Codepoints = new std::vector(); +}); + +// Editor.GUI.Text(font, str, pixelSize, lineHeight, color, anchor, alignment, wordwrap, preferred, encoding) +static int Text(lua_State* L) +{ + LUA_BIND_STATE(L); + + Font* font = (Font*)state.GetUserdata(1); + char* buf = (char*)state.GetValue(2, ""); + int pixelSize = state.GetValue(3, 12); + int lineHeight = state.GetValue(4, pixelSize + 3); + Color32 color = state.GetValue(5, Color32::white); + int anchor = state.GetValue(6, TextAnchor_UpperLeft); + int alignment = state.GetValue(7, TextAlignment_Left); + bool wordwrap = state.GetValue(8, false); + int preferred = state.GetValue(9, 0); + int encoding = state.GetValue(10, 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; + } + } + + font->RenderCharacters(*s_Codepoints, pixelSize); + + UnicodeString str; + str.str = s_Codepoints->data(); + str.length = s_Codepoints->size(); + + WipeGLError(); + + const UITextMesh* tm = g_TextMeshGenerator.GetTextMesh(str, font, pixelSize, lineHeight, color, (ETextAnchor)anchor, (ETextAlignment)alignment, wordwrap, preferred); + tm->Draw(); + + return 0; +} + +static luaL_Reg guiFuncs[] = { + {"Text", Text}, + {0, 0} +}; + +// GameLab.Editor.Window +int luaopen_GameLab_Editor_Window(lua_State* L) +{ + log_info_tag("Scripting", "luaopen_GameLab_Editor_Window()"); + + LUA_BIND_STATE(L); + + state.PushGlobalNamespace(); + state.PushNamespace("GameLab"); + state.PushNamespace("Editor"); + state.PushNamespace("Window"); + + state.PushNamespace("Internal"); + state.RegisterNativeClass(); + state.RegisterNativeClass(); + state.PopNamespace(); + + LUA_BIND_REGISTER_ENUM(state, "EShowMode", + { "NormalWindow", ContainerWindow::kShowNormalWindow }, + { "ShowPopupMenu", ContainerWindow::kShowPopupMenu }, + { "Utility ", ContainerWindow::kShowUtility }, + { "NoShadow", ContainerWindow::kShowNoShadow }, + { "MainWindow", ContainerWindow::kShowMainWindow }, + { "AuxWindow", ContainerWindow::kShowAuxWindow } + ); + + state.RegisterMethods(guiFuncs); + + return 1; +} \ No newline at end of file diff --git a/Editor/Scripting/Window/GUIWindow.bind.cpp b/Editor/Scripting/Window/GUIWindow.bind.cpp new file mode 100644 index 0000000..604c26a --- /dev/null +++ b/Editor/Scripting/Window/GUIWindow.bind.cpp @@ -0,0 +1,70 @@ +#include "Editor/GUI/EditorWindows.h" +#include "Runtime/Math/Math.h" + +LUA_BIND_REGISTRY(GUIWindow) +{ + LUA_BIND_REGISTER_METHODS(state, + { "DoPaint", _DoPaint }, + { "Focus", _Focus }, + { "SetContainerWindow", _SetContainerWindow }, + { "SetPosition", _SetPosition }, + { "New", _New } + ); +} + +LUA_BIND_POSTPROCESS(GUIWindow) +{ +} + +// GUIWindow.New([script]) +LUA_BIND_IMPL_METHOD(GUIWindow, _New) +{ + LUA_BIND_STATE(L, GUIWindow); + LUA_BIND_CHECK(L, "T"); + + GUIWindow* wnd = new GUIWindow(state.GetVM()); + + if (LuaHelper::IsType(state, "GameLab.Editor.Window.GUIWindow", -1)) + wnd->SetMemberRef(state, wnd->m_Script, -1); + + wnd->PushUserdata(state); + return 1; +} + +LUA_BIND_IMPL_METHOD(GUIWindow, _DoPaint) +{ + LUA_BIND_PREPARE(L, GUIWindow); + self->DoPaint(); + return 0; +} + +LUA_BIND_IMPL_METHOD(GUIWindow, _Focus) +{ + LUA_BIND_PREPARE(L, GUIWindow); + self->Focus(); + return 0; +} + +LUA_BIND_IMPL_METHOD(GUIWindow, _SetContainerWindow) +{ + LUA_BIND_PREPARE(L, GUIWindow); + ContainerWindow* wnd = state.GetUserdata(2); + self->SetContainerWindow(wnd); + return 0; +} + +// GUIWindow.SetPosition(self, {x, y, width, height}) +LUA_BIND_IMPL_METHOD(GUIWindow, _SetPosition) +{ + LUA_BIND_PREPARE(L, GUIWindow); + if (!state.CheckParams(1, "UT")) + return 0; + + Rect rect; + rect.x = state.GetField(2, 1, 0); + rect.y = state.GetField(2, 2, 0); + rect.width = state.GetField(2, 3, 0); + rect.height = state.GetField(2, 4, 0); + self->SetPosition(rect); + return 0; +} diff --git a/Editor/Scripting/Window/SplitWindow.bind.cpp b/Editor/Scripting/Window/SplitWindow.bind.cpp new file mode 100644 index 0000000..e69de29 -- cgit v1.1-26-g67d0