summaryrefslogtreecommitdiff
path: root/Editor
diff options
context:
space:
mode:
Diffstat (limited to 'Editor')
-rw-r--r--Editor/EditorApplication.cpp41
-rw-r--r--Editor/EditorApplication.h31
-rw-r--r--Editor/EditorMain.cpp48
-rw-r--r--Editor/GUI/ContainnerWindow.cpp11
-rw-r--r--Editor/GUI/EditorWindows.h24
-rw-r--r--Editor/GUI/GUIWindow.cpp14
-rw-r--r--Editor/GUI/WindowUtil.cpp2
-rw-r--r--Editor/Graphics/Graphics.cpp3
-rw-r--r--Editor/Graphics/Graphics.h3
-rw-r--r--Editor/Scripting/Editor/Editor.bind.cpp17
-rw-r--r--Editor/Scripting/Editor/EditorApplication.bind.cpp47
-rw-r--r--Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp50
-rw-r--r--Editor/Scripting/EditorGUI/EditorGUI.bind.cpp3
-rw-r--r--Editor/Scripting/EditorGUI/GUIWindow.bind.cpp63
-rw-r--r--Editor/Scripting/EditorScripting.cpp4
-rw-r--r--Editor/Scripting/EditorScripting.h2
16 files changed, 299 insertions, 64 deletions
diff --git a/Editor/EditorApplication.cpp b/Editor/EditorApplication.cpp
new file mode 100644
index 0000000..0ebff72
--- /dev/null
+++ b/Editor/EditorApplication.cpp
@@ -0,0 +1,41 @@
+#include "EditorApplication.h"
+#include "Runtime/Utilities/Assert.h"
+#include "Editor/EditorManager.h"
+
+static bool s_Created;
+
+EditorApplication::EditorApplication()
+{
+ Assert(!s_Created);
+}
+
+EditorApplication::~EditorApplication()
+{
+
+}
+
+void EditorApplication::SetMainWindow(ContainnerWindow* wnd)
+{
+ Assert(wnd);
+ EditorManager::Instance()->SetMainWindow(wnd);
+}
+
+void EditorApplication::PullMessage()
+{
+ MSG msg;
+ while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0)
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+
+ if (msg.message == WM_QUIT)
+ {
+ OnQuit();
+ }
+ }
+}
+
+void EditorApplication::OnQuit()
+{
+
+} \ No newline at end of file
diff --git a/Editor/EditorApplication.h b/Editor/EditorApplication.h
new file mode 100644
index 0000000..eb08c46
--- /dev/null
+++ b/Editor/EditorApplication.h
@@ -0,0 +1,31 @@
+#include <string>
+#include <windows.h>
+#include "Runtime/Lua/LuaBind/LuaBind.h"
+#include "Editor/GUI/EditorWindows.h"
+#include "Editor/GUI/MenuManager.h"
+
+using namespace LuaBind;
+
+class EditorApplication
+ : public LuaBind::NativeClass<EditorApplication >
+{
+public:
+ EditorApplication();
+ ~EditorApplication();
+
+ void PullMessage();
+ void SetMainWindow(ContainnerWindow* wnd);
+
+ void OnQuit();
+
+private :
+
+ LUA_BIND_DECL_FACTORY(EditorApplication);
+
+ LUA_BIND_DECL_METHOD(_New);
+ LUA_BIND_DECL_METHOD(_SetMainWindow);
+ LUA_BIND_DECL_METHOD(_SetupMenu);
+ LUA_BIND_DECL_METHOD(_PullMessage);
+
+
+};
diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp
index 1606e94..67ddc38 100644
--- a/Editor/EditorMain.cpp
+++ b/Editor/EditorMain.cpp
@@ -1,7 +1,7 @@
#include <windows.h>
#include <vector>
#include "GUI/EditorWindows.h"
-#include "Runtime/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
#include "EditorManager.h"
#include "Runtime/Graphics/OpenGL.h"
#include "Editor/Scripting/EditorScripting.h"
@@ -54,51 +54,9 @@ int main()
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
#endif
{
- InitLuaState();
-
- WindowUtil::Init();
-
- ContainnerWindow* wnd = new ContainnerWindow();
- Vector2f min = Vector2f(100, 100);
- Vector2f max = Vector2f(700, 700);
- wnd->Init(Rectf(400, 400, 800, 500), ContainnerWindow::kShowMainWindow, min, max);
- wnd->SetTitle("GameLab");
- wnd->SetIcon("./Icon/GameLab.ico");
-
- EditorManager::Instance()->SetMainWindow(wnd);
- MenuManager::Instance()->Init();
-
- GUIWindow* guiWnd = new GUIWindow();
- guiWnd->Init();
- guiWnd->SetContainnerWindow(wnd);
- Rectf position;
- position.x = 0;
- position.y = 0;
- position.width = 200;
- position.height = 200;
- guiWnd->SetPosition(position);
+ WindowUtil::RegisterClasses();
- GUIWindow* guiWnd2 = new GUIWindow();
- guiWnd2->Init();
- guiWnd2->SetContainnerWindow(wnd);
- position.x = 200;
- position.y = 0;
- position.width = 200;
- position.height = 200;
- guiWnd2->SetPosition(position);
-
- // init gl
- wglMakeCurrent(guiWnd2->GetDC(), guiWnd2->GetRC());
- if (!gladLoadGL()) {
- log_error("初始化GL错误");
- }
-
- // force repaint
- wnd->DoPaint();
- guiWnd->DoPaint();
- guiWnd2->DoPaint();
-
- MainLoop();
+ InitLuaState();
return 0;
} \ No newline at end of file
diff --git a/Editor/GUI/ContainnerWindow.cpp b/Editor/GUI/ContainnerWindow.cpp
index 3778485..d6a67c9 100644
--- a/Editor/GUI/ContainnerWindow.cpp
+++ b/Editor/GUI/ContainnerWindow.cpp
@@ -5,6 +5,7 @@
#include "Editor/Utils/HelperFuncs.h"
#include "MenuManager.h"
#include "Runtime/Utilities/Assert.h"
+#include "Editor/Graphics/Graphics.h"
using namespace std;
@@ -260,6 +261,15 @@ bool ContainnerWindow::SetRenderContext()
return FALSE; // Return FALSE
}
+ if (m_RC && !g_IsGLInitialized)
+ {
+ log_info("Initialize OpenGL");
+ wglMakeCurrent(m_DC, m_RC);
+ if (!gladLoadGL()) {
+ log_error("初始化GL错误");
+ }
+ g_IsGLInitialized = true;
+ }
}
// 初始化,创建窗口
@@ -388,6 +398,7 @@ void ContainnerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSi
//ShowInTaskbarIfNoMainWindow(m_Window);
SetRenderContext();
+
}
void ContainnerWindow::SetTitle(const char* title)
diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h
index 307ab86..97175b3 100644
--- a/Editor/GUI/EditorWindows.h
+++ b/Editor/GUI/EditorWindows.h
@@ -4,7 +4,8 @@
#include <windows.h>
#include <vector>
#include "Runtime/Math/Rect.h"
-#include "Runtime/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Utilities/Singleton.h"
#include "Runtime/Debug/Log.h"
#include "Runtime/Graphics/OpenGL.h"
@@ -18,7 +19,7 @@ class GUIWindow;
class WindowUtil
{
public :
- static void Init();
+ static void RegisterClasses();
static const wchar_t* kContainerWindowClassName;
static const wchar_t* kPopupWindowClassName;
@@ -89,8 +90,11 @@ private:
POINT m_MaxSize;
LUA_BIND_DECL_FACTORY(ContainnerWindow);
- LUA_BIND_DECL_METHOD(_SetTitle);
- LUA_BIND_DECL_METHOD(_DoPaint);
+
+ LUA_BIND_DECL_METHOD(_New);
+ LUA_BIND_DECL_METHOD(_SetTitle);
+ LUA_BIND_DECL_METHOD(_SetIcon);
+ LUA_BIND_DECL_METHOD(_DoPaint);
};
@@ -122,7 +126,9 @@ private:
};
// GUI窗口,事件相应、绘制、布局的单元
-class GUIWindow : public WindowBase
+class GUIWindow
+ : public WindowBase
+ , public LuaBind::NativeClass<GUIWindow>
{
public:
static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
@@ -155,6 +161,14 @@ private:
LuaBind::Ref m_Script;
+ LUA_BIND_DECL_FACTORY(GUIWindow);
+
+ LUA_BIND_DECL_METHOD(_New);
+ LUA_BIND_DECL_METHOD(_DoPaint);
+ LUA_BIND_DECL_METHOD(_Focus);
+ LUA_BIND_DECL_METHOD(_SetContainnerWindow);
+ LUA_BIND_DECL_METHOD(_SetPosition);
+
};
#endif \ No newline at end of file
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp
index 3df0370..34d7705 100644
--- a/Editor/GUI/GUIWindow.cpp
+++ b/Editor/GUI/GUIWindow.cpp
@@ -1,6 +1,7 @@
#include "EditorWindows.h"
#include "WinUtils.h"
#include "Runtime/Graphics/OpenGL.h"
+#include "Editor/Graphics/Graphics.h"
static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam)
{
@@ -223,10 +224,12 @@ void GUIWindow::Init(std::string name)
ShowWindow(m_Handle, SW_SHOW);
- if (!SetRenderContext())
+ bool bRC = SetRenderContext();
+ if (!bRC)
log_error("Failed to setup rendering context");
log_info("Created GUIWindow " /*+ (long)this*/);
+
}
bool GUIWindow::SetRenderContext()
@@ -288,6 +291,15 @@ bool GUIWindow::SetRenderContext()
return FALSE; // Return FALSE
}
+ if (m_RC && !g_IsGLInitialized)
+ {
+ log_info("Initialize OpenGL");
+ wglMakeCurrent(m_DC, m_RC);
+ if (!gladLoadGL()) {
+ log_error("初始化GL错误");
+ }
+ g_IsGLInitialized = true;
+ }
return true;
}
diff --git a/Editor/GUI/WindowUtil.cpp b/Editor/GUI/WindowUtil.cpp
index fc32719..b76b6d0 100644
--- a/Editor/GUI/WindowUtil.cpp
+++ b/Editor/GUI/WindowUtil.cpp
@@ -9,7 +9,7 @@ static ATOM ContainerWindowClassAtom;
static ATOM PopupWindowClassAtom;
static ATOM GUIViewClassAtom;
-void WindowUtil::Init()
+void WindowUtil::RegisterClasses()
{
log_info("WindowUtil::Init()");
diff --git a/Editor/Graphics/Graphics.cpp b/Editor/Graphics/Graphics.cpp
new file mode 100644
index 0000000..af48d75
--- /dev/null
+++ b/Editor/Graphics/Graphics.cpp
@@ -0,0 +1,3 @@
+#include "Graphics.h"
+
+bool g_IsGLInitialized = false;
diff --git a/Editor/Graphics/Graphics.h b/Editor/Graphics/Graphics.h
new file mode 100644
index 0000000..ad27ede
--- /dev/null
+++ b/Editor/Graphics/Graphics.h
@@ -0,0 +1,3 @@
+#pragma once
+
+extern bool g_IsGLInitialized;
diff --git a/Editor/Scripting/Editor/Editor.bind.cpp b/Editor/Scripting/Editor/Editor.bind.cpp
index e69de29..2300d2f 100644
--- a/Editor/Scripting/Editor/Editor.bind.cpp
+++ b/Editor/Scripting/Editor/Editor.bind.cpp
@@ -0,0 +1,17 @@
+#include "Editor/EditorApplication.h"
+
+// GameLab.Editor
+int luaopen_GameLab_Editor(lua_State* L)
+{
+ log_info("Scripting", "luaopen_GameLab_Editor()");
+
+ LUA_BIND_STATE(L);
+
+ state.PushGlobalNamespace();
+ state.PushNamespace("GameLab");
+ state.PushNamespace("Editor");
+
+ state.RegisterFactory<EditorApplication>();
+
+ return 1;
+} \ No newline at end of file
diff --git a/Editor/Scripting/Editor/EditorApplication.bind.cpp b/Editor/Scripting/Editor/EditorApplication.bind.cpp
index e69de29..82abdd5 100644
--- a/Editor/Scripting/Editor/EditorApplication.bind.cpp
+++ b/Editor/Scripting/Editor/EditorApplication.bind.cpp
@@ -0,0 +1,47 @@
+#include "Editor/EditorApplication.h"
+
+LUA_BIND_REGISTRY(EditorApplication)
+{
+ LUA_BIND_REGISTER_METHODS(state,
+ {"New", EditorApplication::_New},
+ { "SetMainWindow", _SetMainWindow },
+ { "SetupMenu", _SetupMenu },
+ { "PullMessage", _PullMessage }
+ );
+}
+
+LUA_BIND_POSTPROCESS(EditorApplication)
+{
+}
+
+LUA_BIND_IMPL_METHOD(EditorApplication, EditorApplication::_New)
+{
+ LUA_BIND_PREPARE(L, EditorApplication);
+ EditorApplication* app = new EditorApplication();
+ app->PushUserdata(state);
+ return 1;
+}
+
+LUA_BIND_IMPL_METHOD(EditorApplication, EditorApplication::_PullMessage)
+{
+ LUA_BIND_PREPARE(L, EditorApplication);
+ self->PullMessage();
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(EditorApplication, _SetMainWindow)
+{
+ LUA_BIND_PREPARE(L, EditorApplication);
+ LUA_BIND_CHECK(L, "UU");
+
+ ContainnerWindow* wnd = state.GetUserdata<ContainnerWindow>(2);
+ self->SetMainWindow(wnd);
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(EditorApplication, _SetupMenu)
+{
+ LUA_BIND_PREPARE(L, EditorApplication);
+ MenuManager::Instance()->Init();
+ return 0;
+} \ No newline at end of file
diff --git a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp
index 265ea2e..d3d0997 100644
--- a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp
+++ b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp
@@ -3,9 +3,11 @@
LUA_BIND_REGISTRY(ContainnerWindow)
{
LUA_BIND_REGISTER_METHODS(state,
- { "SetTitle", _SetTitle },
- { "DoPaint", _DoPaint }
- );
+ { "SetTitle", _SetTitle },
+ { "SetIcon", _SetIcon },
+ { "DoPaint", _DoPaint },
+ { "New", _New }
+ );
}
LUA_BIND_POSTPROCESS(ContainnerWindow)
@@ -22,16 +24,46 @@ LUA_BIND_POSTPROCESS(ContainnerWindow)
LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetTitle)
{
- LUA_BIND_PREPARE(L, ContainnerWindow);
+ LUA_BIND_PREPARE(L, ContainnerWindow);
+
+ cc8* title = state.GetValue<cc8*>(2, "");
+ self->SetTitle(title);
+ return 0;
+}
+LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetIcon)
+{
+ LUA_BIND_PREPARE(L, ContainnerWindow);
- return 0;
+ cc8* path = state.GetValue<cc8*>(2, "");
+ self->SetIcon(path);
+
+ return 0;
}
LUA_BIND_IMPL_METHOD(ContainnerWindow, _DoPaint)
{
- LUA_BIND_PREPARE(L, ContainnerWindow);
- self->DoPaint();
- return 0;
-} \ No newline at end of file
+ LUA_BIND_PREPARE(L, ContainnerWindow);
+ self->DoPaint();
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(ContainnerWindow, ContainnerWindow::_New)
+{
+ LUA_BIND_STATE(L, ContainnerWindow);
+ LUA_BIND_CHECK(L, "TNTT");
+
+ ContainnerWindow* wnd = new ContainnerWindow();
+
+ Rectf rect = state.GetValue<Rectf>(state, Rectf());
+ int showMode = state.GetValue<int>(2, 0);
+ Vector2f min = state.GetValue<Vector2f>(state, Vector2f());
+ Vector2f max = state.GetValue<Vector2f>(state, Vector2f());
+
+ 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
index 57c45ca..4e908c4 100644
--- a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp
+++ b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp
@@ -12,7 +12,8 @@ int luaopen_GameLab_Editor_GUI(lua_State* L)
state.PushNamespace("Editor");
state.PushNamespace("GUI");
- state.RegisterFactory<ContainnerWindow>();
+ state.RegisterFactory<ContainnerWindow>();
+ state.RegisterFactory<GUIWindow>();
return 1;
} \ No newline at end of file
diff --git a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp
index e69de29..ec8f830 100644
--- a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp
+++ b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp
@@ -0,0 +1,63 @@
+#include "Editor/GUI/EditorWindows.h"
+
+LUA_BIND_REGISTRY(GUIWindow)
+{
+ LUA_BIND_REGISTER_METHODS(state,
+ { "DoPaint", _DoPaint },
+ { "Focus", _Focus },
+ { "SetContainnerWindow", _SetContainnerWindow },
+ { "SetPosition", _SetPosition },
+ { "New", _New }
+ );
+}
+
+LUA_BIND_POSTPROCESS(GUIWindow)
+{
+}
+
+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, _SetContainnerWindow)
+{
+ LUA_BIND_PREPARE(L, GUIWindow);
+ ContainnerWindow* wnd = state.GetUserdata<ContainnerWindow>(2);
+ self->SetContainnerWindow(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;
+
+ Rectf rect;
+ rect.x = state.GetField<float>(2, 1, 0);
+ rect.y = state.GetField<float>(2, 2, 0);
+ rect.width = state.GetField<float>(2, 3, 0);
+ rect.height = state.GetField<float>(2, 4, 0);
+ self->SetPosition(rect);
+ return 0;
+}
+
+LUA_BIND_IMPL_METHOD(GUIWindow, _New)
+{
+ LUA_BIND_PREPARE(L, GUIWindow);
+ GUIWindow* wnd = new GUIWindow();
+ wnd->PushUserdata(state);
+ wnd->Init();
+ return 1;
+} \ No newline at end of file
diff --git a/Editor/Scripting/EditorScripting.cpp b/Editor/Scripting/EditorScripting.cpp
index 294d6f9..bb53848 100644
--- a/Editor/Scripting/EditorScripting.cpp
+++ b/Editor/Scripting/EditorScripting.cpp
@@ -32,7 +32,9 @@ bool SetupGameLabEditorScripting(lua_State* L)
log_info("Scripting", "SetupGameLabEditorScripting()");
openlib(luaopen_GameLab_Debug);
- openlib(luaopen_GameLab_Editor_GUI);
+
+ openlib(luaopen_GameLab_Editor);
+ openlib(luaopen_GameLab_Editor_GUI);
return true;
}
diff --git a/Editor/Scripting/EditorScripting.h b/Editor/Scripting/EditorScripting.h
index 2ed2233..301ac3f 100644
--- a/Editor/Scripting/EditorScripting.h
+++ b/Editor/Scripting/EditorScripting.h
@@ -1,4 +1,4 @@
#pragma once
-#include "Runtime/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
bool SetupGameLabEditorScripting(lua_State* L);