summaryrefslogtreecommitdiff
path: root/Editor
diff options
context:
space:
mode:
Diffstat (limited to 'Editor')
-rw-r--r--Editor/Scripting/EditorScripting.cpp2
-rw-r--r--Editor/Scripting/GUI/EditorGUI.bind.cpp105
-rw-r--r--Editor/Scripting/Window/Window.bind.cpp69
3 files changed, 107 insertions, 69 deletions
diff --git a/Editor/Scripting/EditorScripting.cpp b/Editor/Scripting/EditorScripting.cpp
index 12f591c..48d7da8 100644
--- a/Editor/Scripting/EditorScripting.cpp
+++ b/Editor/Scripting/EditorScripting.cpp
@@ -18,6 +18,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_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
@@ -49,6 +50,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/GUI/EditorGUI.bind.cpp b/Editor/Scripting/GUI/EditorGUI.bind.cpp
new file mode 100644
index 0000000..b51e019
--- /dev/null
+++ b/Editor/Scripting/GUI/EditorGUI.bind.cpp
@@ -0,0 +1,105 @@
+#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"
+#include "Editor/Win/Win.h"
+
+using namespace LuaBind;
+using namespace Win;
+
+static std::vector<character::Unicode>* s_Codepoints;
+
+InitializeStaticVariables([]() {
+ s_Codepoints = new std::vector<character::Unicode>();
+});
+
+// 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<Font>(1);
+ char* buf = (char*)state.GetValue<const char*>(2, "");
+ int pixelSize = state.GetValue<int>(3, 12);
+ int lineHeight = state.GetValue<int>(4, pixelSize + 3);
+ Color32 color = state.GetValue<Color32>(5, Color32::white);
+ int anchor = state.GetValue<int>(6, TextAnchor_UpperLeft);
+ int alignment = state.GetValue<int>(7, TextAlignment_Left);
+ bool wordwrap = state.GetValue<bool>(8, false);
+ int preferred = state.GetValue<int>(9, 0);
+ int encoding = state.GetValue<int>(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}
+};
+
+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.RegisterMethods(guiFuncs);
+
+ return 1;
+} \ No newline at end of file
diff --git a/Editor/Scripting/Window/Window.bind.cpp b/Editor/Scripting/Window/Window.bind.cpp
index b720c98..a3610fc 100644
--- a/Editor/Scripting/Window/Window.bind.cpp
+++ b/Editor/Scripting/Window/Window.bind.cpp
@@ -15,74 +15,6 @@
using namespace LuaBind;
using namespace Win;
-static std::vector<character::Unicode>* s_Codepoints;
-
-InitializeStaticVariables([]() {
- s_Codepoints = new std::vector<character::Unicode>();
-});
-
-// 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<Font>(1);
- char* buf = (char*)state.GetValue<const char*>(2, "");
- int pixelSize = state.GetValue<int>(3, 12);
- int lineHeight = state.GetValue<int>(4, pixelSize + 3);
- Color32 color = state.GetValue<Color32>(5, Color32::white);
- int anchor = state.GetValue<int>(6, TextAnchor_UpperLeft);
- int alignment = state.GetValue<int>(7, TextAlignment_Left);
- bool wordwrap = state.GetValue<bool>(8, false);
- int preferred = state.GetValue<int>(9, 0);
- int encoding = state.GetValue<int>(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 int SetCursor(lua_State* L)
{
LUA_BIND_STATE(L);
@@ -95,7 +27,6 @@ static int SetCursor(lua_State* L)
}
static luaL_Reg guiFuncs[] = {
- {"Text", Text},
{"SetCursor", SetCursor},
{0, 0}
};