From 45328cbadd8a946c19a77301f218efbf650e2f28 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 18 Oct 2021 19:56:41 +0800 Subject: *misc --- Editor/EditorApplication.cpp | 41 ++++++++++++++ Editor/EditorApplication.h | 31 +++++++++++ Editor/EditorMain.cpp | 48 ++--------------- Editor/GUI/ContainnerWindow.cpp | 11 ++++ Editor/GUI/EditorWindows.h | 24 +++++++-- Editor/GUI/GUIWindow.cpp | 14 ++++- Editor/GUI/WindowUtil.cpp | 2 +- Editor/Graphics/Graphics.cpp | 3 ++ Editor/Graphics/Graphics.h | 3 ++ Editor/Scripting/Editor/Editor.bind.cpp | 17 ++++++ Editor/Scripting/Editor/EditorApplication.bind.cpp | 47 ++++++++++++++++ .../Scripting/EditorGUI/ContainerWindow.bind.cpp | 50 +++++++++++++---- Editor/Scripting/EditorGUI/EditorGUI.bind.cpp | 3 +- Editor/Scripting/EditorGUI/GUIWindow.bind.cpp | 63 ++++++++++++++++++++++ Editor/Scripting/EditorScripting.cpp | 4 +- Editor/Scripting/EditorScripting.h | 2 +- 16 files changed, 299 insertions(+), 64 deletions(-) create mode 100644 Editor/EditorApplication.cpp create mode 100644 Editor/EditorApplication.h create mode 100644 Editor/Graphics/Graphics.cpp create mode 100644 Editor/Graphics/Graphics.h (limited to 'Editor') 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 +#include +#include "Runtime/Lua/LuaBind/LuaBind.h" +#include "Editor/GUI/EditorWindows.h" +#include "Editor/GUI/MenuManager.h" + +using namespace LuaBind; + +class EditorApplication + : public LuaBind::NativeClass +{ +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 #include #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 #include #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 { 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(); + + 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(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(2, ""); + self->SetTitle(title); + return 0; +} +LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetIcon) +{ + LUA_BIND_PREPARE(L, ContainnerWindow); - return 0; + cc8* path = state.GetValue(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(state, Rectf()); + int showMode = state.GetValue(2, 0); + Vector2f min = state.GetValue(state, Vector2f()); + Vector2f max = state.GetValue(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(); + state.RegisterFactory(); + state.RegisterFactory(); 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(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(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; +} + +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); -- cgit v1.1-26-g67d0