From afdcbfa9c4259fb003fd072ae011836230e7e39b Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 20 Oct 2021 13:50:50 +0800 Subject: +containers --- Editor/EditorApplication.cpp | 2 +- Editor/EditorApplication.h | 6 +- Editor/EditorManager.cpp | 4 +- Editor/EditorManager.h | 6 +- Editor/GUI/ContainerWindow.cpp | 437 +++++++++++++++++++++ Editor/GUI/ContainnerWindow.cpp | 437 --------------------- Editor/GUI/EditorWindows.h | 16 +- Editor/GUI/GUIWindow.cpp | 16 +- Editor/GUI/MenuManager.cpp | 2 +- Editor/GUI/WindowUtil.cpp | 4 +- Editor/Scripting/Editor/EditorApplication.bind.cpp | 8 +- .../Scripting/EditorGUI/ContainerWindow.bind.cpp | 22 +- Editor/Scripting/EditorGUI/EditorGUI.bind.cpp | 2 +- Editor/Scripting/EditorGUI/GUIWindow.bind.cpp | 8 +- Projects/VisualStudio/Editor/Editor.vcxproj | 2 +- .../VisualStudio/Editor/Editor.vcxproj.filters | 9 +- .../DefaultContent/Libraries/Container/README.md | 202 ---------- .../DefaultContent/Libraries/Container/list.lua | 199 ---------- .../DefaultContent/Libraries/Container/queue.lua | 111 ------ .../DefaultContent/Libraries/Container/stack.lua | 67 ---- .../DefaultContent/Libraries/Container/tuple.lua | 60 --- .../DefaultContent/Libraries/Container/vector.lua | 122 ------ .../DefaultContent/Libraries/containers/README.md | 202 ++++++++++ .../DefaultContent/Libraries/containers/list.lua | 199 ++++++++++ .../DefaultContent/Libraries/containers/queue.lua | 111 ++++++ .../DefaultContent/Libraries/containers/stack.lua | 67 ++++ .../DefaultContent/Libraries/containers/tuple.lua | 60 +++ .../DefaultContent/Libraries/containers/vector.lua | 122 ++++++ Resources/Scripts/EditorApplication.lua | 4 +- 29 files changed, 1255 insertions(+), 1252 deletions(-) create mode 100644 Editor/GUI/ContainerWindow.cpp delete mode 100644 Editor/GUI/ContainnerWindow.cpp delete mode 100644 Resources/DefaultContent/Libraries/Container/README.md delete mode 100644 Resources/DefaultContent/Libraries/Container/list.lua delete mode 100644 Resources/DefaultContent/Libraries/Container/queue.lua delete mode 100644 Resources/DefaultContent/Libraries/Container/stack.lua delete mode 100644 Resources/DefaultContent/Libraries/Container/tuple.lua delete mode 100644 Resources/DefaultContent/Libraries/Container/vector.lua create mode 100644 Resources/DefaultContent/Libraries/containers/README.md create mode 100644 Resources/DefaultContent/Libraries/containers/list.lua create mode 100644 Resources/DefaultContent/Libraries/containers/queue.lua create mode 100644 Resources/DefaultContent/Libraries/containers/stack.lua create mode 100644 Resources/DefaultContent/Libraries/containers/tuple.lua create mode 100644 Resources/DefaultContent/Libraries/containers/vector.lua diff --git a/Editor/EditorApplication.cpp b/Editor/EditorApplication.cpp index 0ebff72..2f2d1e3 100644 --- a/Editor/EditorApplication.cpp +++ b/Editor/EditorApplication.cpp @@ -14,7 +14,7 @@ EditorApplication::~EditorApplication() } -void EditorApplication::SetMainWindow(ContainnerWindow* wnd) +void EditorApplication::SetMainWindow(ContainerWindow* wnd) { Assert(wnd); EditorManager::Instance()->SetMainWindow(wnd); diff --git a/Editor/EditorApplication.h b/Editor/EditorApplication.h index 35c427c..9109a1f 100644 --- a/Editor/EditorApplication.h +++ b/Editor/EditorApplication.h @@ -7,20 +7,20 @@ using namespace LuaBind; class EditorApplication - : public LuaBind::NativeClass + : public LuaBind::NativeClass { public: EditorApplication(); ~EditorApplication(); void PullMessage(); - void SetMainWindow(ContainnerWindow* wnd); + void SetMainWindow(ContainerWindow* wnd); void OnQuit(); private : - LUA_BIND_DECL_FACTORY(EditorApplication); + LUA_BIND_DECL_FACTORY(EditorApplication); LUA_BIND_DECL_METHOD(_New); LUA_BIND_DECL_METHOD(_SetMainWindow); diff --git a/Editor/EditorManager.cpp b/Editor/EditorManager.cpp index 6f589d9..a375d81 100644 --- a/Editor/EditorManager.cpp +++ b/Editor/EditorManager.cpp @@ -7,12 +7,12 @@ const std::string EditorDefine::kResourceRoot = "./"; #endif -void EditorManager::SetMainWindow(ContainnerWindow* wnd) +void EditorManager::SetMainWindow(ContainerWindow* wnd) { m_MainWindow = wnd; } -ContainnerWindow* EditorManager::GetMainWindow() +ContainerWindow* EditorManager::GetMainWindow() { return m_MainWindow; } diff --git a/Editor/EditorManager.h b/Editor/EditorManager.h index 6e6da19..774f2de 100644 --- a/Editor/EditorManager.h +++ b/Editor/EditorManager.h @@ -23,10 +23,10 @@ public : class EditorManager : public Singleton { public: - void SetMainWindow(ContainnerWindow* wnd); - ContainnerWindow* GetMainWindow(); + void SetMainWindow(ContainerWindow* wnd); + ContainerWindow* GetMainWindow(); private: - ContainnerWindow* m_MainWindow; + ContainerWindow* m_MainWindow; }; diff --git a/Editor/GUI/ContainerWindow.cpp b/Editor/GUI/ContainerWindow.cpp new file mode 100644 index 0000000..ee42635 --- /dev/null +++ b/Editor/GUI/ContainerWindow.cpp @@ -0,0 +1,437 @@ +#include + +#include "EditorWindows.h" +#include "WinUtils.h" +#include "Editor/Utils/HelperFuncs.h" +#include "MenuManager.h" +#include "Runtime/Utilities/Assert.h" +#include "Editor/Graphics/Graphics.h" + +using namespace std; + +static bool s_IsMainWindowMaximized; + +extern bool ProcessMainWindowMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT& result); + +static PAINTSTRUCT ps; +LRESULT CALLBACK ContainerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + + ContainerWindow *self = (ContainerWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (!self) + { + log_warning("Nullptr ContainerWindow"); + return DefWindowProcW(hWnd, message, wParam, lParam); + } + + //log_info("WndProc", "ContainerWindow::ContainerWndProc(), ContainerWindow name is " + self->GetName()); + + switch (message) + { + case WM_MENUSELECT: + { + if (self->m_ShowMode != ShowMode::kShowMainWindow) + return 0; + uint menuId = LOWORD(wParam); + uint flags = HIWORD(wParam); + HMENU menu = (HMENU)lParam; + MenuManager::Instance()->HandleMenuItemEvent(menu, menuId, flags); + return 0; + } + case WM_SETICON: + return WM_SETICON; + case WM_PAINT: + { + log_info("WM_PAINT"); + self->SetAsRenderContext(); + glEnable(GL_BLEND); + float c = 26 / 255.f; + glClearColor(c, c, c, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glFlush(); + BeginPaint(self->m_Window, &ps); + EndPaint(self->m_Window, &ps); + UpdateWindow(self->m_Window); + return 0; + } + case WM_ENTERMENULOOP: // 点击菜单 + + return 0; + case WM_EXITMENULOOP: // 松开菜单 + return 0; + + case WM_KEYDOWN: // key down + case WM_KEYUP: // key up + case WM_SYSKEYDOWN: // 和 WM_KEYDOWN 的区别是可以捕获快捷键或系统命令按键,比如alt键, Ctrl和shift不属于WM_SYSKEYDOWN + case WM_SYSKEYUP: // 和 WM_KEYUP 的区别是可以捕获快捷键或系统命令按键,比如alt键 + if (message == WM_KEYDOWN && wParam == VK_ESCAPE) { + // Escape should close utility container windows + // 如果本窗口是 utility 窗口,关闭它 + if (self->m_ShowMode == ShowMode::kShowUtility) { + self->Close(); + return 0; + } + } + return 0; + + case WM_ERASEBKGND:// WM_ERASEBKGND是在当窗口*背景*必须被擦除时 (例如,窗口的移动,窗口的大小的改变)发送。 + { + // unity的窗口背景色要么是灰色(免费版) ,要么是深黑色(专业版) + // 对于透明窗口 + if (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_LAYERED) { // WS_EX_LAYERED是extendedStyle透明窗口 + // 填充用户区 + RECT rc; + GetClientRect(hWnd, &rc); + FillRect((HDC)wParam, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); + } + // do not erase background + // 如果不是透明窗口不要清除背景,跳过DefWindowProc函数 + return 1; + } + + case WM_WINDOWPOSCHANGED: // 窗口大小、位置、z层级改变,即窗口区域改变 + { + if (!self->m_IsClosing && !IsIconic(hWnd)) //IsIconic 窗口是否是最小化(图标化) + { + // OnRectChanged()回调 + self->OnRectChanged(); + } + // WM_WINDOWPOSCHANGED 消息触发后且调用了DefWindowProc会接着发送WM_SIZE和WM_MOVE消息。在WM_WINDOWPOSCHANGED + // 中一起处理大小和位置改变更高效 + /* + By default, the DefWindowProc function sends the WM_SIZE and WM_MOVE messages to the window. + The WM_SIZE and WM_MOVE messages are not sent if an application handles the WM_WINDOWPOSCHANGED + message without calling DefWindowProc. It is more efficient to perform any move or size change + processing during the WM_WINDOWPOSCHANGED message without calling DefWindowProc. + */ + break; + } + + case WM_SIZE: // 窗口大小改变 + if (self->m_ShowMode == ShowMode::kShowMainWindow) + { + if (IsWindowVisible(hWnd)) + { + bool nowMaximized = wParam == SIZE_MAXIMIZED; + if (s_IsMainWindowMaximized != nowMaximized)//更新s_IsMainWindowMaximized变量 + s_IsMainWindowMaximized = nowMaximized; + } + } + break; + + case WM_SETFOCUS: // 窗口获得焦点 + return 0; + + case WM_ACTIVATEAPP: // 编辑器的激活状态改变,所有的窗口都会获得这个消息,和WM_ACTIVATE不同,WM_ACTIVATE只是单个窗口被激活 + // 发送一个 OnActivateApplication 消息 + self->OnActivateApplication(wParam != FALSE); + break; // fall through to main window processing + + + case WM_NCACTIVATE: // non-client active 即非用户区被激活,用这个消息来刷新编辑器 + + break; + + case WM_ACTIVATE: // 单个窗口的激活状态改变 + + return 0; + + case WM_CLOSE: // 窗口关闭消息 + { + bool isMainAndShouldExit = (self->m_ShowMode == kShowMainWindow && !self->m_CloseFromScriptDontShutdown); + if (isMainAndShouldExit) + { + //退出编辑器 + } + else + { + // 关闭此窗口 + ::SetMenu(hWnd, NULL); // 给窗口分配一个菜单,如果是NULL,这个窗口的菜单被删除 + ::DestroyWindow(hWnd); + } + return 0; + } + + case WM_DESTROY: // 窗口被销毁 + + return 0; + + case WM_INITMENUPOPUP: //下拉菜单或子菜单将要被激活的时候 + + return 0; + + case WM_ENTERSIZEMOVE: // 在大小、位置改变前,即当用户点击标题栏、边框 + + return 0; + } + + if (self->m_ShowMode == ShowMode::kShowMainWindow) + { + LRESULT result; + if (ProcessMainWindowMessages(hWnd, message, wParam, lParam, result)) { + return result; + } + } + + long flag = DefWindowProcW(hWnd, message, wParam, lParam); + return flag; +} + +ContainerWindow::ContainerWindow() +{ +} + +ContainerWindow::~ContainerWindow() +{ + +} + +void ContainerWindow::DoPaint() +{ + SetWindowLongPtr(m_Window, GWLP_USERDATA, (LONG_PTR)this); + SendMessage(m_Window, WM_PAINT, 0, 0); +} + +void ContainerWindow::SetAsRenderContext() +{ + Assert(m_DC != NULL); + Assert(m_RC != NULL); + Assert(wglMakeCurrent(m_DC, m_RC)); + RECT rect; + GetWindowRect(m_Window, &rect); + glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top); +} + +bool ContainerWindow::SetRenderContext() +{ + m_DC = ::GetDC(m_Window); + if (!m_DC) + log_error("Can't create DC"); + + int bits = 32; + + //static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be + //{ + // sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + // 1, // Version Number + // PFD_DRAW_TO_WINDOW | // Format Must Support Window + // PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + // PFD_DOUBLEBUFFER, // Must Support Double Buffering + // PFD_TYPE_RGBA, // Request An RGBA Format + // bits, // Select Our Color Depth + // 0, 0, 0, 0, 0, 0, // Color Bits Ignored + // 0, // No Alpha Buffer + // 0, // Shift Bit Ignored + // 0, // No Accumulation Buffer + // 0, 0, 0, 0, // Accumulation Bits Ignored + // 16, // 16Bit Z-Buffer (Depth Buffer) + // 0, // No Stencil Buffer + // 0, // No Auxiliary Buffer + // PFD_MAIN_PLANE, // Main Drawing Layer + // 0, // Reserved + // 0, 0, 0 // Layer Masks Ignored + //}; + static PIXELFORMATDESCRIPTOR pfd; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 32; + + GLuint PixelFormat; + + if (!(PixelFormat = ChoosePixelFormat(m_DC, &pfd))) // Did Windows Find A Matching Pixel Format? + { + MessageBox(NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return FALSE; // Return FALSE + } + + if (!SetPixelFormat(m_DC, PixelFormat, &pfd)) // Are We Able To Set The Pixel Format? + { + MessageBox(NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + return FALSE; // Return FALSE + } + + int pf = 0; + DescribePixelFormat(m_DC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + + if (!(m_RC = wglCreateContext(m_DC))) // Are We Able To Get A Rendering Context? + { + MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); + 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; + } +} + +// 初始化,创建窗口 +void ContainerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize, std::string name) +{ + // Aux windows are mac only. on windows they look just like normal utility windows. + if (showMode == kShowAuxWindow) + showMode = kShowUtility; + + m_Name = name; + m_ShowMode = static_cast(showMode); + m_IsClosing = false; + m_InMenuLoop = false; + m_CloseFromScriptDontShutdown = false; + + bool shouldMaximize = false; + if (showMode == kShowMainWindow) + { + //shouldMaximize = s_IsMainWindowMaximized = EditorPrefs::GetBool(kIsMainWindowMaximized, false); + //GetRestoredMainWindowDimensions(); + } + + RECT rect; + rect.left = pixelRect.x; + rect.right = pixelRect.x + pixelRect.width; + rect.top = pixelRect.y; + rect.bottom = pixelRect.y + pixelRect.height; + m_InternalRect.x = m_InternalRect.y = m_InternalRect.width = m_InternalRect.height = 0.0f; + + DWORD windowStyle = 0; + DWORD extendedStyle = 0; + LPCWSTR windowClass = WindowUtil::kContainerWindowClassName; + + switch (showMode) { + // 容纳GUIPanel的非主窗口 + case kShowNormalWindow: + windowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_THICKFRAME; + extendedStyle = WS_EX_TOOLWINDOW; + break; + // 主窗口,含菜单 + case kShowMainWindow: + windowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; + extendedStyle = 0; + break; + case kShowPopupMenu: + windowStyle = WS_POPUP | WS_CLIPCHILDREN; + extendedStyle = WS_EX_TOOLWINDOW; + windowClass = WindowUtil::kPopupWindowClassName; + break; + case kShowNoShadow: + windowStyle = WS_POPUP | WS_CLIPCHILDREN; + extendedStyle = WS_EX_TOOLWINDOW; + break; + case kShowUtility: + windowStyle = WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU; + extendedStyle = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW; + break; + default: + // ErrorString("Unknown container show mode"); + break; + } + + HWND parentWindow = NULL; + if (showMode == kShowMainWindow) + { + parentWindow = NULL; + } + else + { + // parentWindow = GetMainEditorWindow(); + } + + bool notSizeable = (minSize == maxSize) && (minSize != Vector2f::zero); + if (notSizeable) + windowStyle &= ~(WS_THICKFRAME); + + AdjustWindowRectEx(&rect, windowStyle, showMode == kShowMainWindow, extendedStyle); + int extraX = rect.right - rect.left - 200; + int extraY = rect.bottom - rect.top - 200; + + m_MinSize.x = minSize.x + extraX; + m_MinSize.y = minSize.y + extraY; + m_MaxSize.x = maxSize.x + extraX; + m_MaxSize.y = maxSize.y + extraY; + + //if (showMode == kShowUtility) + // s_ZUtilityWindows.push_back(m_ContainerListNode); + // Create window + m_Window = CreateWindowExW( + extendedStyle, + windowClass, + L"", + windowStyle, + rect.left, + rect.top, + rect.right - rect.left, + rect.bottom - rect.top, + parentWindow, + NULL, + winutils::GetInstanceHandle(), + NULL + ); + SetWindowLongPtr(m_Window, GWLP_USERDATA, (LONG_PTR)this); + //UpdateMaxMaximizedRect(); + + if (pixelRect.width > 10 || pixelRect.height > 10) + { + //SetRect(pixelRect); + if (shouldMaximize) + SetWindowLong(m_Window, GWL_STYLE, windowStyle | WS_MAXIMIZE); + } + + if (showMode == kShowMainWindow) + { + //SetMainEditorWindow(m_Window); + //HMENU menu = GetMainMenuHandle(); + //if (menu) + // SetMenu(m_Window, menu); + //GetApplication().UpdateMainWindowTitle(); + //GetApplication().UpdateDocumentEdited(); + } + ShowWindow(m_Window, SW_SHOW); + + //s_ContainerWindows.insert(this); + + //ShowInTaskbarIfNoMainWindow(m_Window); + + SetRenderContext(); + +} + +void ContainerWindow::SetTitle(const char* title) +{ + SetWindowTextA(m_Window, title); +} + +void ContainerWindow::SetIcon(LPCSTR iconName) +{ + Assert(m_ShowMode == ShowMode::kShowMainWindow); + + HICON hWindowIcon = (HICON )LoadImage(winutils::GetInstanceHandle(), iconName, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE); + if (hWindowIcon == NULL) + log_error("icon error: " + to_string(GetLastError())); + if (SendMessage(m_Window, WM_SETICON, ICON_BIG, (LPARAM)hWindowIcon) != WM_SETICON) + log_error("icon error: " + to_string(GetLastError())); + if (SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon) != WM_SETICON) + log_error("icon error: " + to_string(GetLastError())); +} + +void ContainerWindow::Close() +{ + log_info("Close window " + m_Name); + + SendMessage(m_Window, WM_CLOSE, 0, 0); +} + +void ContainerWindow::OnRectChanged() +{ + +} + +void ContainerWindow::OnActivateApplication(bool active) +{ + +} diff --git a/Editor/GUI/ContainnerWindow.cpp b/Editor/GUI/ContainnerWindow.cpp deleted file mode 100644 index d6a67c9..0000000 --- a/Editor/GUI/ContainnerWindow.cpp +++ /dev/null @@ -1,437 +0,0 @@ -#include - -#include "EditorWindows.h" -#include "WinUtils.h" -#include "Editor/Utils/HelperFuncs.h" -#include "MenuManager.h" -#include "Runtime/Utilities/Assert.h" -#include "Editor/Graphics/Graphics.h" - -using namespace std; - -static bool s_IsMainWindowMaximized; - -extern bool ProcessMainWindowMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT& result); - -static PAINTSTRUCT ps; -LRESULT CALLBACK ContainnerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - - ContainnerWindow *self = (ContainnerWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); - if (!self) - { - log_warning("Nullptr ContainnerWindow"); - return DefWindowProcW(hWnd, message, wParam, lParam); - } - - //log_info("WndProc", "ContainnerWindow::ContainerWndProc(), ContainnerWindow name is " + self->GetName()); - - switch (message) - { - case WM_MENUSELECT: - { - if (self->m_ShowMode != ShowMode::kShowMainWindow) - return 0; - uint menuId = LOWORD(wParam); - uint flags = HIWORD(wParam); - HMENU menu = (HMENU)lParam; - MenuManager::Instance()->HandleMenuItemEvent(menu, menuId, flags); - return 0; - } - case WM_SETICON: - return WM_SETICON; - case WM_PAINT: - { - log_info("WM_PAINT"); - self->SetAsRenderContext(); - glEnable(GL_BLEND); - float c = 26 / 255.f; - glClearColor(c, c, c, 1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glFlush(); - BeginPaint(self->m_Window, &ps); - EndPaint(self->m_Window, &ps); - UpdateWindow(self->m_Window); - return 0; - } - case WM_ENTERMENULOOP: // 点击菜单 - - return 0; - case WM_EXITMENULOOP: // 松开菜单 - return 0; - - case WM_KEYDOWN: // key down - case WM_KEYUP: // key up - case WM_SYSKEYDOWN: // 和 WM_KEYDOWN 的区别是可以捕获快捷键或系统命令按键,比如alt键, Ctrl和shift不属于WM_SYSKEYDOWN - case WM_SYSKEYUP: // 和 WM_KEYUP 的区别是可以捕获快捷键或系统命令按键,比如alt键 - if (message == WM_KEYDOWN && wParam == VK_ESCAPE) { - // Escape should close utility container windows - // 如果本窗口是 utility 窗口,关闭它 - if (self->m_ShowMode == ShowMode::kShowUtility) { - self->Close(); - return 0; - } - } - return 0; - - case WM_ERASEBKGND:// WM_ERASEBKGND是在当窗口*背景*必须被擦除时 (例如,窗口的移动,窗口的大小的改变)发送。 - { - // unity的窗口背景色要么是灰色(免费版) ,要么是深黑色(专业版) - // 对于透明窗口 - if (GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_LAYERED) { // WS_EX_LAYERED是extendedStyle透明窗口 - // 填充用户区 - RECT rc; - GetClientRect(hWnd, &rc); - FillRect((HDC)wParam, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH)); - } - // do not erase background - // 如果不是透明窗口不要清除背景,跳过DefWindowProc函数 - return 1; - } - - case WM_WINDOWPOSCHANGED: // 窗口大小、位置、z层级改变,即窗口区域改变 - { - if (!self->m_IsClosing && !IsIconic(hWnd)) //IsIconic 窗口是否是最小化(图标化) - { - // OnRectChanged()回调 - self->OnRectChanged(); - } - // WM_WINDOWPOSCHANGED 消息触发后且调用了DefWindowProc会接着发送WM_SIZE和WM_MOVE消息。在WM_WINDOWPOSCHANGED - // 中一起处理大小和位置改变更高效 - /* - By default, the DefWindowProc function sends the WM_SIZE and WM_MOVE messages to the window. - The WM_SIZE and WM_MOVE messages are not sent if an application handles the WM_WINDOWPOSCHANGED - message without calling DefWindowProc. It is more efficient to perform any move or size change - processing during the WM_WINDOWPOSCHANGED message without calling DefWindowProc. - */ - break; - } - - case WM_SIZE: // 窗口大小改变 - if (self->m_ShowMode == ShowMode::kShowMainWindow) - { - if (IsWindowVisible(hWnd)) - { - bool nowMaximized = wParam == SIZE_MAXIMIZED; - if (s_IsMainWindowMaximized != nowMaximized)//更新s_IsMainWindowMaximized变量 - s_IsMainWindowMaximized = nowMaximized; - } - } - break; - - case WM_SETFOCUS: // 窗口获得焦点 - return 0; - - case WM_ACTIVATEAPP: // 编辑器的激活状态改变,所有的窗口都会获得这个消息,和WM_ACTIVATE不同,WM_ACTIVATE只是单个窗口被激活 - // 发送一个 OnActivateApplication 消息 - self->OnActivateApplication(wParam != FALSE); - break; // fall through to main window processing - - - case WM_NCACTIVATE: // non-client active 即非用户区被激活,用这个消息来刷新编辑器 - - break; - - case WM_ACTIVATE: // 单个窗口的激活状态改变 - - return 0; - - case WM_CLOSE: // 窗口关闭消息 - { - bool isMainAndShouldExit = (self->m_ShowMode == kShowMainWindow && !self->m_CloseFromScriptDontShutdown); - if (isMainAndShouldExit) - { - //退出编辑器 - } - else - { - // 关闭此窗口 - ::SetMenu(hWnd, NULL); // 给窗口分配一个菜单,如果是NULL,这个窗口的菜单被删除 - ::DestroyWindow(hWnd); - } - return 0; - } - - case WM_DESTROY: // 窗口被销毁 - - return 0; - - case WM_INITMENUPOPUP: //下拉菜单或子菜单将要被激活的时候 - - return 0; - - case WM_ENTERSIZEMOVE: // 在大小、位置改变前,即当用户点击标题栏、边框 - - return 0; - } - - if (self->m_ShowMode == ShowMode::kShowMainWindow) - { - LRESULT result; - if (ProcessMainWindowMessages(hWnd, message, wParam, lParam, result)) { - return result; - } - } - - long flag = DefWindowProcW(hWnd, message, wParam, lParam); - return flag; -} - -ContainnerWindow::ContainnerWindow() -{ -} - -ContainnerWindow::~ContainnerWindow() -{ - -} - -void ContainnerWindow::DoPaint() -{ - SetWindowLongPtr(m_Window, GWLP_USERDATA, (LONG_PTR)this); - SendMessage(m_Window, WM_PAINT, 0, 0); -} - -void ContainnerWindow::SetAsRenderContext() -{ - Assert(m_DC != NULL); - Assert(m_RC != NULL); - Assert(wglMakeCurrent(m_DC, m_RC)); - RECT rect; - GetWindowRect(m_Window, &rect); - glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top); -} - -bool ContainnerWindow::SetRenderContext() -{ - m_DC = ::GetDC(m_Window); - if (!m_DC) - log_error("Can't create DC"); - - int bits = 32; - - //static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be - //{ - // sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor - // 1, // Version Number - // PFD_DRAW_TO_WINDOW | // Format Must Support Window - // PFD_SUPPORT_OPENGL | // Format Must Support OpenGL - // PFD_DOUBLEBUFFER, // Must Support Double Buffering - // PFD_TYPE_RGBA, // Request An RGBA Format - // bits, // Select Our Color Depth - // 0, 0, 0, 0, 0, 0, // Color Bits Ignored - // 0, // No Alpha Buffer - // 0, // Shift Bit Ignored - // 0, // No Accumulation Buffer - // 0, 0, 0, 0, // Accumulation Bits Ignored - // 16, // 16Bit Z-Buffer (Depth Buffer) - // 0, // No Stencil Buffer - // 0, // No Auxiliary Buffer - // PFD_MAIN_PLANE, // Main Drawing Layer - // 0, // Reserved - // 0, 0, 0 // Layer Masks Ignored - //}; - static PIXELFORMATDESCRIPTOR pfd; - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 32; - - GLuint PixelFormat; - - if (!(PixelFormat = ChoosePixelFormat(m_DC, &pfd))) // Did Windows Find A Matching Pixel Format? - { - MessageBox(NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION); - return FALSE; // Return FALSE - } - - if (!SetPixelFormat(m_DC, PixelFormat, &pfd)) // Are We Able To Set The Pixel Format? - { - MessageBox(NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION); - return FALSE; // Return FALSE - } - - int pf = 0; - DescribePixelFormat(m_DC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - - if (!(m_RC = wglCreateContext(m_DC))) // Are We Able To Get A Rendering Context? - { - MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION); - 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; - } -} - -// 初始化,创建窗口 -void ContainnerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize, std::string name) -{ - // Aux windows are mac only. on windows they look just like normal utility windows. - if (showMode == kShowAuxWindow) - showMode = kShowUtility; - - m_Name = name; - m_ShowMode = static_cast(showMode); - m_IsClosing = false; - m_InMenuLoop = false; - m_CloseFromScriptDontShutdown = false; - - bool shouldMaximize = false; - if (showMode == kShowMainWindow) - { - //shouldMaximize = s_IsMainWindowMaximized = EditorPrefs::GetBool(kIsMainWindowMaximized, false); - //GetRestoredMainWindowDimensions(); - } - - RECT rect; - rect.left = pixelRect.x; - rect.right = pixelRect.x + pixelRect.width; - rect.top = pixelRect.y; - rect.bottom = pixelRect.y + pixelRect.height; - m_InternalRect.x = m_InternalRect.y = m_InternalRect.width = m_InternalRect.height = 0.0f; - - DWORD windowStyle = 0; - DWORD extendedStyle = 0; - LPCWSTR windowClass = WindowUtil::kContainerWindowClassName; - - switch (showMode) { - // 容纳GUIPanel的非主窗口 - case kShowNormalWindow: - windowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_THICKFRAME; - extendedStyle = WS_EX_TOOLWINDOW; - break; - // 主窗口,含菜单 - case kShowMainWindow: - windowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; - extendedStyle = 0; - break; - case kShowPopupMenu: - windowStyle = WS_POPUP | WS_CLIPCHILDREN; - extendedStyle = WS_EX_TOOLWINDOW; - windowClass = WindowUtil::kPopupWindowClassName; - break; - case kShowNoShadow: - windowStyle = WS_POPUP | WS_CLIPCHILDREN; - extendedStyle = WS_EX_TOOLWINDOW; - break; - case kShowUtility: - windowStyle = WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU; - extendedStyle = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW; - break; - default: - // ErrorString("Unknown container show mode"); - break; - } - - HWND parentWindow = NULL; - if (showMode == kShowMainWindow) - { - parentWindow = NULL; - } - else - { - // parentWindow = GetMainEditorWindow(); - } - - bool notSizeable = (minSize == maxSize) && (minSize != Vector2f::zero); - if (notSizeable) - windowStyle &= ~(WS_THICKFRAME); - - AdjustWindowRectEx(&rect, windowStyle, showMode == kShowMainWindow, extendedStyle); - int extraX = rect.right - rect.left - 200; - int extraY = rect.bottom - rect.top - 200; - - m_MinSize.x = minSize.x + extraX; - m_MinSize.y = minSize.y + extraY; - m_MaxSize.x = maxSize.x + extraX; - m_MaxSize.y = maxSize.y + extraY; - - //if (showMode == kShowUtility) - // s_ZUtilityWindows.push_back(m_ContainerListNode); - // Create window - m_Window = CreateWindowExW( - extendedStyle, - windowClass, - L"", - windowStyle, - rect.left, - rect.top, - rect.right - rect.left, - rect.bottom - rect.top, - parentWindow, - NULL, - winutils::GetInstanceHandle(), - NULL - ); - SetWindowLongPtr(m_Window, GWLP_USERDATA, (LONG_PTR)this); - //UpdateMaxMaximizedRect(); - - if (pixelRect.width > 10 || pixelRect.height > 10) - { - //SetRect(pixelRect); - if (shouldMaximize) - SetWindowLong(m_Window, GWL_STYLE, windowStyle | WS_MAXIMIZE); - } - - if (showMode == kShowMainWindow) - { - //SetMainEditorWindow(m_Window); - //HMENU menu = GetMainMenuHandle(); - //if (menu) - // SetMenu(m_Window, menu); - //GetApplication().UpdateMainWindowTitle(); - //GetApplication().UpdateDocumentEdited(); - } - ShowWindow(m_Window, SW_SHOW); - - //s_ContainerWindows.insert(this); - - //ShowInTaskbarIfNoMainWindow(m_Window); - - SetRenderContext(); - -} - -void ContainnerWindow::SetTitle(const char* title) -{ - SetWindowTextA(m_Window, title); -} - -void ContainnerWindow::SetIcon(LPCSTR iconName) -{ - Assert(m_ShowMode == ShowMode::kShowMainWindow); - - HICON hWindowIcon = (HICON )LoadImage(winutils::GetInstanceHandle(), iconName, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE); - if (hWindowIcon == NULL) - log_error("icon error: " + to_string(GetLastError())); - if (SendMessage(m_Window, WM_SETICON, ICON_BIG, (LPARAM)hWindowIcon) != WM_SETICON) - log_error("icon error: " + to_string(GetLastError())); - if (SendMessage(m_Window, WM_SETICON, ICON_SMALL, (LPARAM)hWindowIcon) != WM_SETICON) - log_error("icon error: " + to_string(GetLastError())); -} - -void ContainnerWindow::Close() -{ - log_info("Close window " + m_Name); - - SendMessage(m_Window, WM_CLOSE, 0, 0); -} - -void ContainnerWindow::OnRectChanged() -{ - -} - -void ContainnerWindow::OnActivateApplication(bool active) -{ - -} diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h index 97175b3..ba71c06 100644 --- a/Editor/GUI/EditorWindows.h +++ b/Editor/GUI/EditorWindows.h @@ -38,8 +38,8 @@ private: }; // 一个containner window中有多个viewport -class ContainnerWindow - : public LuaBind::NativeClass +class ContainerWindow + : public LuaBind::NativeClass { public: static LRESULT CALLBACK ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -53,8 +53,8 @@ public: kShowAuxWindow = 5, // Popup windows like the color picker, gradient editor, etc. Drawn with black background on Mac }; - ContainnerWindow(); - ~ContainnerWindow(); + ContainerWindow(); + ~ContainerWindow(); void Init(Rectf size, int showMode, const Vector2f& minSize, const Vector2f& maxSize, std::string name = ""); void SetTitle(const char* title); @@ -89,7 +89,7 @@ private: POINT m_MinSize; POINT m_MaxSize; - LUA_BIND_DECL_FACTORY(ContainnerWindow); + LUA_BIND_DECL_FACTORY(ContainerWindow); LUA_BIND_DECL_METHOD(_New); LUA_BIND_DECL_METHOD(_SetTitle); @@ -136,7 +136,7 @@ public: void Init(std::string name = ""); void DoPaint(); - void SetContainnerWindow(ContainnerWindow* wnd); + void SetContainerWindow(ContainerWindow* wnd); void Focus(); void SetPosition(Rectf position); void SetAsRenderContext(); @@ -154,7 +154,7 @@ private: std::string m_Name; - ContainnerWindow* m_ContainnerWindow; + ContainerWindow* m_ContainerWindow; HWND m_Handle; HDC m_DC; HGLRC m_RC; @@ -166,7 +166,7 @@ private: LUA_BIND_DECL_METHOD(_New); LUA_BIND_DECL_METHOD(_DoPaint); LUA_BIND_DECL_METHOD(_Focus); - LUA_BIND_DECL_METHOD(_SetContainnerWindow); + LUA_BIND_DECL_METHOD(_SetContainerWindow); LUA_BIND_DECL_METHOD(_SetPosition); }; diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp index 34d7705..107a298 100644 --- a/Editor/GUI/GUIWindow.cpp +++ b/Editor/GUI/GUIWindow.cpp @@ -294,10 +294,10 @@ bool GUIWindow::SetRenderContext() if (m_RC && !g_IsGLInitialized) { log_info("Initialize OpenGL"); - wglMakeCurrent(m_DC, m_RC); - if (!gladLoadGL()) { - log_error("初始化GL错误"); - } + wglMakeCurrent(m_DC, m_RC); + if (!gladLoadGL()) { + log_error("初始化GL错误"); + } g_IsGLInitialized = true; } return true; @@ -343,17 +343,17 @@ void GUIWindow::Focus() log_info("Focus GUIWindow " + (long)this); if (m_Handle) { - if (::GetForegroundWindow() != m_ContainnerWindow->GetWindowHandle()) - ::SetForegroundWindow(m_ContainnerWindow->GetWindowHandle()); + if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) + ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); SetFocus(m_Handle); } } -void GUIWindow::SetContainnerWindow(ContainnerWindow* wnd) +void GUIWindow::SetContainerWindow(ContainerWindow* wnd) { Assert(wnd != NULL); - m_ContainnerWindow = wnd; + m_ContainerWindow = wnd; if (wnd->GetWindowHandle() != m_Handle) { diff --git a/Editor/GUI/MenuManager.cpp b/Editor/GUI/MenuManager.cpp index 53dfd5a..c0fc989 100644 --- a/Editor/GUI/MenuManager.cpp +++ b/Editor/GUI/MenuManager.cpp @@ -18,7 +18,7 @@ MenuManager::MenuManager() void MenuManager::Init() { - ContainnerWindow* mainWnd = EditorManager::Instance()->GetMainWindow(); + ContainerWindow* mainWnd = EditorManager::Instance()->GetMainWindow(); Assert(mainWnd != NULL); HMENU hMenubar = CreateMenu(); diff --git a/Editor/GUI/WindowUtil.cpp b/Editor/GUI/WindowUtil.cpp index b76b6d0..34a7b30 100644 --- a/Editor/GUI/WindowUtil.cpp +++ b/Editor/GUI/WindowUtil.cpp @@ -13,7 +13,7 @@ void WindowUtil::RegisterClasses() { log_info("WindowUtil::Init()"); - ContainerWindowClassAtom = winutils::RegisterWindowClass(kContainerWindowClassName, ContainnerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW); - PopupWindowClassAtom = winutils::RegisterWindowClass(kPopupWindowClassName, ContainnerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW);//CS_HREDRAW宽度(水平)变化时重绘、CS_VREDRAW高度(垂直)变化时重绘 + ContainerWindowClassAtom = winutils::RegisterWindowClass(kContainerWindowClassName, ContainerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW); + PopupWindowClassAtom = winutils::RegisterWindowClass(kPopupWindowClassName, ContainerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW);//CS_HREDRAW宽度(水平)变化时重绘、CS_VREDRAW高度(垂直)变化时重绘 GUIViewClassAtom = winutils::RegisterWindowClass(kGUIWindowClassName, GUIWindow::GUIViewWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW); } \ No newline at end of file diff --git a/Editor/Scripting/Editor/EditorApplication.bind.cpp b/Editor/Scripting/Editor/EditorApplication.bind.cpp index 184870a..672bdcd 100644 --- a/Editor/Scripting/Editor/EditorApplication.bind.cpp +++ b/Editor/Scripting/Editor/EditorApplication.bind.cpp @@ -1,5 +1,5 @@ -#include "Editor/EditorApplication.h" - +#include "Editor/EditorApplication.h" + LUA_BIND_REGISTRY(EditorApplication) { LUA_BIND_REGISTER_METHODS(state, @@ -33,9 +33,9 @@ LUA_BIND_IMPL_METHOD(EditorApplication, _SetMainWindow) LUA_BIND_PREPARE(L, EditorApplication); LUA_BIND_CHECK(L, "UU"); - ContainnerWindow* wnd = state.GetUserdata(2); + ContainerWindow* wnd = state.GetUserdata(2); self->SetMainWindow(wnd); - MenuManager::Instance()->Init(); + MenuManager::Instance()->Init(); return 0; } diff --git a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp index d3d0997..9c75829 100644 --- a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp +++ b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp @@ -1,6 +1,6 @@ #include "Editor/GUI/EditorWindows.h" -LUA_BIND_REGISTRY(ContainnerWindow) +LUA_BIND_REGISTRY(ContainerWindow) { LUA_BIND_REGISTER_METHODS(state, { "SetTitle", _SetTitle }, @@ -10,7 +10,7 @@ LUA_BIND_REGISTRY(ContainnerWindow) ); } -LUA_BIND_POSTPROCESS(ContainnerWindow) +LUA_BIND_POSTPROCESS(ContainerWindow) { LUA_BIND_REGISTER_ENUM(state, "EShowMode", { "NormalWindow", ShowMode::kShowNormalWindow }, @@ -22,9 +22,9 @@ LUA_BIND_POSTPROCESS(ContainnerWindow) ); } -LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetTitle) +LUA_BIND_IMPL_METHOD(ContainerWindow, _SetTitle) { - LUA_BIND_PREPARE(L, ContainnerWindow); + LUA_BIND_PREPARE(L, ContainerWindow); cc8* title = state.GetValue(2, ""); self->SetTitle(title); @@ -32,9 +32,9 @@ LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetTitle) return 0; } -LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetIcon) +LUA_BIND_IMPL_METHOD(ContainerWindow, _SetIcon) { - LUA_BIND_PREPARE(L, ContainnerWindow); + LUA_BIND_PREPARE(L, ContainerWindow); cc8* path = state.GetValue(2, ""); self->SetIcon(path); @@ -42,19 +42,19 @@ LUA_BIND_IMPL_METHOD(ContainnerWindow, _SetIcon) return 0; } -LUA_BIND_IMPL_METHOD(ContainnerWindow, _DoPaint) +LUA_BIND_IMPL_METHOD(ContainerWindow, _DoPaint) { - LUA_BIND_PREPARE(L, ContainnerWindow); + LUA_BIND_PREPARE(L, ContainerWindow); self->DoPaint(); return 0; } -LUA_BIND_IMPL_METHOD(ContainnerWindow, ContainnerWindow::_New) +LUA_BIND_IMPL_METHOD(ContainerWindow, ContainerWindow::_New) { - LUA_BIND_STATE(L, ContainnerWindow); + LUA_BIND_STATE(L, ContainerWindow); LUA_BIND_CHECK(L, "TNTT"); - ContainnerWindow* wnd = new ContainnerWindow(); + ContainerWindow* wnd = new ContainerWindow(); Rectf rect = state.GetValue(state, Rectf()); int showMode = state.GetValue(2, 0); diff --git a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp index 4e908c4..0f30276 100644 --- a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp +++ b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp @@ -12,7 +12,7 @@ int luaopen_GameLab_Editor_GUI(lua_State* L) state.PushNamespace("Editor"); state.PushNamespace("GUI"); - state.RegisterFactory(); + state.RegisterFactory(); state.RegisterFactory(); return 1; diff --git a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp index ec8f830..50acf44 100644 --- a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp +++ b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp @@ -5,7 +5,7 @@ LUA_BIND_REGISTRY(GUIWindow) LUA_BIND_REGISTER_METHODS(state, { "DoPaint", _DoPaint }, { "Focus", _Focus }, - { "SetContainnerWindow", _SetContainnerWindow }, + { "SetContainerWindow", _SetContainerWindow }, { "SetPosition", _SetPosition }, { "New", _New } ); @@ -29,11 +29,11 @@ LUA_BIND_IMPL_METHOD(GUIWindow, _Focus) return 0; } -LUA_BIND_IMPL_METHOD(GUIWindow, _SetContainnerWindow) +LUA_BIND_IMPL_METHOD(GUIWindow, _SetContainerWindow) { LUA_BIND_PREPARE(L, GUIWindow); - ContainnerWindow* wnd = state.GetUserdata(2); - self->SetContainnerWindow(wnd); + ContainerWindow* wnd = state.GetUserdata(2); + self->SetContainerWindow(wnd); return 0; } diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index 8d8afbe..e6ffe4b 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -147,7 +147,7 @@ - + diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index 81d32e6..30d6087 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -64,6 +64,9 @@ {66d581bf-85b1-4108-b1e1-d5e44f391af8} + + {8810f29e-3166-4dd6-af85-8eebab583f0c} + {d076ff69-6f78-4c7d-be95-e59daf26a3e2} @@ -102,9 +105,6 @@ Editor\GUI - - Editor\GUI - Editor\GUI @@ -225,6 +225,9 @@ Runtime\Scripting + + Editor\GUI + diff --git a/Resources/DefaultContent/Libraries/Container/README.md b/Resources/DefaultContent/Libraries/Container/README.md deleted file mode 100644 index cba8776..0000000 --- a/Resources/DefaultContent/Libraries/Container/README.md +++ /dev/null @@ -1,202 +0,0 @@ -# Lua-ADT(5.1鍒嗘敮鍜5.2鍒嗘敮) -灏佽鐨刲ua鏁版嵁缁撴瀯, 鍏冪粍(tuple)銆佸姩鎬佹暟缁(vector)銆佸弻鍚戦摼琛(list)銆侀槦鍒(queue)銆佹爤(stack)銆 -绾痩ua鏂规硶灏佽锛屾病鏈変娇鐢╫op锛屽欢缁璴ua鐨勭畝娲佺殑椋庢牸銆傚皝瑁呯殑鏁版嵁缁撴瀯鑳藉畨鍏ㄤ娇鐢紝鍦ㄨ瑷灞傞潰杩囨护鎺夐潪娉曟搷浣滐紝浣垮叾浣跨敤鏇村姞绠鍗曢珮鏁堛 - -鎵鏈夌殑绫诲瀷閮芥敮鎸#鑾峰彇闀垮害. -> eg. -```lua - local tuple = require("tuple") - local v = tuple.create({2,3,6}) - print(#v) - ---3 -``` - -### 鍏冪粍(tuple) -闇瑕佺敤table鐨勫姩鎬佹暟缁勫垵濮嬪寲(涓嶆敮鎸乭ashtable),鍙澶栧叕寮閬嶅巻锛屼慨鏀瑰叧闂 - -閬嶅巻锛 -```lua - local tuple = require("tuple") - local v = tuple.create({2,3,6}) - - for i,v in ipairs(v) do --鍙敮鎸乮pairs閬嶅巻,鎶涘純浜唒airs(鍥犱负鍘熷垯涓婃垜浠槸鏁扮粍锛屼笉瀛樺湪key) - print(i,v) - end - ---1 2 - ---2 3 - ---3 6 - - print(v) --閲嶅啓浜哶_tostring,鏂逛究蹇熸祻瑙堟暟鎹 - ---2,3,6 - - v[2] = 9 --鍥犱负瀵逛慨鏀瑰叧闂簡鎵浠ヨ繖鍦版柟淇敼浼氭姏鍑洪敊璇 - ---lua: .\tuple.lua:33: >> Dee: Limited access - ---stack traceback: - ---[C]: in function 'error' -``` - -### 鍔ㄦ佹暟缁(vector) -瀹炵幇楂樻晥鐨勯亶鍘嗗拰淇敼锛屼絾鏄柊澧炲拰鍒犻櫎閮戒笉鏄嚎鎬ф椂闂村鏉傚害銆傚熀鏈笂灏辨槸lua table鐨勬暟缁勶紝浣嗘槸lua鐨則able鎴戜滑浼氫竴涓嶅皬蹇冨氨鎼炴垚涓嶈繛缁殑銆傛瘮濡: -```lua - local t = {2,4} - t[4] = 9 - - print(#t) -- 2 -``` -#### 鏂规硶锛 - * add --灏炬坊鍔(楂樻晥鐨勬搷浣) - * insert --鎻掑叆(浼氭湁鍐呭瓨鏁寸悊) - * addRange --灏炬坊鍔犱竴涓〃, - * removeAt - * remove - * contains - * indexOf - * sort - * find - -#### eg. -```lua - local vector = require("vector") - local v = vector.create() - - v:add(4) - v:add(5) - v:add(6) - v:add(7) - - for i,v in ipairs(v) do - print(i,v) - end - ---1 4 - ---2 5 - ---3 6 - ---4 7 - - print(v) - ---4,5,6,7 - - v[4] = 9 --淇敼鍊 - - print(v) - ---4,5,6,9 - - v[7] = 9 - ---lua: .\vector.lua:101: outrange of vector - ---stack traceback: - --- [C]: in function 'assert' -``` - -### 鍙屽悜閾捐〃(list) -寮ヨˉ鍔ㄦ佹暟缁勫鍒犵殑涓嶈冻锛屾彁渚涘鍒犳晥鐜囷紝浣嗘槸閬嶅巻鍜屼慨鏀规晥鐜囨瘮杈冧綆 - -#### 鏂规硶锛 - * addFirst --澶存坊鍔 - * addLast --灏炬坊鍔 - * addBefore --node鍓嶆坊鍔 - * addAfter --node鍚庢坊鍔 - * removeNode --鍒犻櫎node - * remove --鏍规嵁鍊肩Щ闄 - * find --鏌ユ壘node -#### eg. -```lua - local vector = require("list") - local v = list.create() - - v.addFirst(1) - v.addLast(2) - print(v) - ---1,2 - - local node = v.find(1) - node.value = 9 - print(v) - ---9,2 - - v.removeNode(node) - print(v) - ---2 - - v.addLast(10) - v.addLast(20) - v.addLast(30) - print(v) - ---2,10,20,30 - - for _,i,v in ipairs(v) do --绗竴涓弬鏁版槸node, i: index, v: value - print(i,v) - end - ---1 2 - ---2 10 - ---3 20 - ---4 30 -``` -### 鏍(stack) -FILO鍏堣繘鍚庡嚭, 瀵逛慨鏀瑰叧闂紝鍏抽棴閬嶅巻锛屽彧鑳介氳繃鏂规硶淇敼鏁版嵁 -#### 鏂规硶锛 - * push --娣诲姞 - * pop --绉婚櫎 - * peek --杩斿洖鏍堥《鏁版嵁 - * clear --娓呯┖ -#### eg. -```lua - local stack = require("stack") - local v = stack.create() - - v.push(1) - v.push(2) - v.push(5) - - print(v) - ---5,2,1 - print(v.len) - ---3 - v.pop() - print(v) - ---2,1 - v.clear() - print(v.len) - ---0 -``` -### 闃熷垪(queue) -FIFO,鍏堣繘鍏堝嚭锛屽洜涓烘槸闃熼鍒犻櫎鎵浠ヤ笉鑳戒娇鐢╰able.remove -#### 鏂规硶锛 - * enqueue --娣诲姞 - * dequeue --绉婚櫎 - * peek --杩斿洖鏍堥《鏁版嵁 - * clear --娓呯┖ - * #queue --鑾峰彇闀垮害 -#### eg. -```lua -local queue = require("queue") --- lua table -local cnt = 10000 * 1 - -local t = {} -for i=1,cnt do -t[i] = i -end - -local time = os.clock() -while #t > 0 do --- table.remove(t) - table.remove(t, 1) -end -print(os.clock() - time) ----1.037s - -local v = queue.create() - -for i=1,cnt do - v.enqueue(i) -end - - -local time1 = os.clock() -while v.len > 10 do - v.dequeue() -end -print(os.clock() - time1) ----0.005s -``` -1w鏉℃暟鎹紝lua table鐩存帴鍒犻櫎琛ㄥご鐨勮楁椂1.037s锛宷ueue鑰楁椂0.005s,鑰屼笖queue鏁寸悊鍐呭瓨鐨勬闀垮彲浠ヨ皟鏁达紝鑰楁椂鍙互杩涙涓鎻愰珮. - diff --git a/Resources/DefaultContent/Libraries/Container/list.lua b/Resources/DefaultContent/Libraries/Container/list.lua deleted file mode 100644 index 59233b9..0000000 --- a/Resources/DefaultContent/Libraries/Container/list.lua +++ /dev/null @@ -1,199 +0,0 @@ ---- ---- Generated by EmmyLua(https://github.com/EmmyLua) ---- Created by Dee. ---- DateTime: 2019/3/7 14:00 ---- 楂樻晥澧炲垹鏈夊簭琛紝浣庢晥閬嶅巻 ---- - ---[[ -閬嶅巻: - for _,idx, value in ipairs(l) do .. end - for _, value in pairs(l) do ... end -]] - -list = list or {} - -function list.create() - local lenght = 0 - -- 绫讳技stl鐨勬柟寮忥紝澶村熬鍙槸浣滀负鎸囬拡浣跨敤 - local first = {front = nil, next = nil, value = nil} - local last = {front = nil, next = nil, value = nil} - first.next = last - last.front = first - - - ---鏌ユ壘鍊 - ---@param value - ---@return node - local find = function(value) - local ret = nil - local nextNode = first - while nextNode do - nextNode = nextNode.next - if nextNode.value == value then - ret = nextNode - break - end - end - - return ret - end - - ---鏌ユ壘(鏍规嵁涓嬫爣鏌ユ壘) - ---@param idx 涓嬫爣 - ---@return node - local findByIdx = function(idx) - local i = 0 - local ret - local nextNode = first - while nextNode and i < lenght do - i = i+1 - nextNode = nextNode.next - if i == idx then - ret = nextNode - break - end - end - - return ret - end - - ---鍦╪ode鍓嶆坊鍔 - ---@param node - ---@param v - local addBefore = function(node, v) - assert(node) - - local frontNode = node.front - local newNode = {} - newNode.front = frontNode - newNode.next = node - newNode.value = v - node.front = newNode - frontNode.next = newNode - - lenght = lenght+1 - end - - ---鍦╪ode鍚庢坊鍔 - ---@param node - ---@param v - local addAfter = function(node, v) - assert(node) - local nextNode = node.next - local newNode = {} - newNode.front = node - newNode.next = nextNode - newNode.value = v - node.next = newNode - nextNode.front = newNode - - lenght = lenght+1 - end - - ---鍦ㄩ槦棣栨坊鍔 - ---@param v - local addFirst = function(v) - addAfter(first, v) - end - - ---鍦ㄩ槦灏炬坊鍔 - ---@param v - local addLast = function(v) - addBefore(last, v) - end - - ---鍒犻櫎鑺傜偣 - ---@param node - local removeNode = function(node) - assert(node) - - local frontNode = node.front - local nextNode = node.next - - if frontNode == nil then - first = nextNode - else - frontNode.next = nextNode - end - - if nextNode ~= nil then - nextNode.front = frontNode - end - lenght = lenght - 1 - end - - ---鍒犻櫎鑺傜偣 - ---@param v - local remove = function(v) - local node = find(v) - if node then - removeNode(node) - end - end - - local t = { - addFirst = addFirst, - addLast = addLast, - addBefore = addBefore, - addAfter = addAfter, - removeNode = removeNode, - remove = remove, - find = find, - findByIdx = findByIdx - } - - local mt = { - __index = function(i_t, key) - return findByIdx(key) - end, - __newindex = function(i_t,k,v) - local node = findByIdx(k) - if not node then - error("out range: "..k) - else - node.value = v - end - end, - __tostring = function() - local ret = {} - local next = first.next - while next and next ~= last do - ret[#ret+1] = next.value - next = next.next - end - - return table.concat(ret, ',') - end, - __len = function(v) - return lenght - end, - --杩唬鍣ㄨ繑鍥瀗ode-value - __ipairs = function(i_t) - local idx = 0 - local function iter(i_t, node) - idx = idx + 1 - if node and node.next ~= last then - return node.next, idx, node.next.value - end - end - - return iter, t, first - end, - __pairs = function(i_t) - local function iter(i_t, node) - if node and node.next ~= last then - return node.next, node.next.value - end - end - - return iter, t, first - end - } - - setmetatable(t, mt) - - return t -end - -return list \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/Container/queue.lua b/Resources/DefaultContent/Libraries/Container/queue.lua deleted file mode 100644 index 126daa8..0000000 --- a/Resources/DefaultContent/Libraries/Container/queue.lua +++ /dev/null @@ -1,111 +0,0 @@ ---- ---- Generated by EmmyLua(https://github.com/EmmyLua) ---- Created by Dee. ---- DateTime: 2019/3/7 11:27 ---- FIFO ---- - -queue = queue or {} - ----@return Queue -function queue.create() - ---鏁版嵁瀹瑰櫒 - local data = {} - ---鏁版嵁闀垮害 - local lenght = 0 - ---闃熼绱㈠紩 - local first = 1 - - ---鑾峰彇闃熼鍊 - local peek = function() - return data[first] - end - - ---鍘嬪叆鏁版嵁 - local enqueue = function(v) - assert(v ~= nil, "nil value") - first = lenght == 0 and 1 or first - lenght = lenght + 1 - table.insert(data, first+lenght-1, v) - end - - ---寮瑰嚭鏁版嵁 - local dequeue = function() - assert(lenght > 0, "nill queue") - - local ret = peek() - data[first] = nil - first = first+1 - lenght = lenght - 1 - first = lenght == 0 and 1 or first - - if math.fmod(first, 4) == 0 then - local tmp = {} - table.move(data, first, first + lenght, 1, tmp) - - first = 1 - data = nil - data = tmp - end - - return ret - end - - local clear = function() - data = {} - first = 1 - lenght = 0 - end - - local __tostring = function() - local tmp = {} - for i=1,lenght do - tmp[i] = data[i + first - 1] - end - return table.concat(tmp, ",") - end - - local __len = function() - return lenght - end - - local __index = function(i_t, key) - error(">> Dee: Limited access") - end - - local __newindex = function(i_t, key, v) - error(">> Dee: Limited access") - end - - local __ipairs = function(i_t) - local idx = 0 - local function iter(i_t) - idx = idx + 1 - if idx <= lenght then - return idx, data[first + idx - 1] - end - end - - return iter - end - - local __pairs = function(i_t) - error(">> Dee: Limited access") - end - - local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __ipairs = __ipairs, __pairs = __pairs, __len = __len} - - ---@class Queue - local t = { - enqueue = enqueue, - dequeue = dequeue, - peek = peek, - clear = clear - } - - setmetatable(t, mt) - - return t -end - -return queue diff --git a/Resources/DefaultContent/Libraries/Container/stack.lua b/Resources/DefaultContent/Libraries/Container/stack.lua deleted file mode 100644 index d828c81..0000000 --- a/Resources/DefaultContent/Libraries/Container/stack.lua +++ /dev/null @@ -1,67 +0,0 @@ ---鍫嗘爤瀹炵幇 -stack = stack or {} - -function stack.create() - local data = {} - - local function push(v) - assert(v) - table.insert(data, v) - end - - local function pop() - assert(#data > 0) - table.remove(data) - end - - local function peek() - return #data > 0 and data[#data] or nil - end - - local function clear() - for i=1,#data do - data[i] = nil - end - end - - - - local __tostring = function() - local tmp = {} - for i,v in ipairs(data) do - tmp[#data+1 - i] = v - end - return table.concat(tmp, ",") - end - - local __index = function(i_t, key) - error(">> Dee: Limited access") - end - - local __len = function() - return #data - end - - local __newindex = function(i_t, key, v) - error(">> Dee: Limited access") - end - - local __ipairs = function() - error(">> Dee: Limited access") - end - - local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __ipairs = __ipairs, __pairs = __ipairs, __len = __len} - - local t = { - push = push, - pop = pop, - peek = peek, - clear = clear - } - - setmetatable(t, mt) - - return t -end - -return stack \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/Container/tuple.lua b/Resources/DefaultContent/Libraries/Container/tuple.lua deleted file mode 100644 index 0646d5a..0000000 --- a/Resources/DefaultContent/Libraries/Container/tuple.lua +++ /dev/null @@ -1,60 +0,0 @@ ---- ---- Generated by EmmyLua(https://github.com/EmmyLua) ---- Created by Dee. ---- DateTime: 2019/3/7 14:00 ---- 鍏冪祫,灏嶄慨鏀归棞闁 ---- - -tuple = tuple or {} - -function tuple.create(i_data) - assert(type(i_data) == "table", ">> Dee: shoudle create with table") - - local data = {} - for k,v in pairs(i_data) do - data[#data+1] = v - end - - local t = {} - - local __tostring = function() - return table.concat(data, ",") - end - - local __index = function(i_t, key) - return data[key] - end - - local __newindex = function(i_t, key, v) - error(">> Dee: Limited access") - end - - local __pairs = function() - error(">> Dee: Limited access") - end - - local __ipairs = function(i_t) - local idx = 0 - local function iter(i_t) - idx = idx + 1 - if idx <= #data then - return idx, data[idx] - end - end - - return iter - end - - local __len = function(v) - return #data - end - - local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __pairs =__pairs, __ipairs = __ipairs, __len = __len} - - setmetatable(t, mt) - - return t - end - - -return tuple \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/Container/vector.lua b/Resources/DefaultContent/Libraries/Container/vector.lua deleted file mode 100644 index 0b349ce..0000000 --- a/Resources/DefaultContent/Libraries/Container/vector.lua +++ /dev/null @@ -1,122 +0,0 @@ ---- ---- Generated by EmmyLua(https://github.com/EmmyLua) ---- Created by Dee. ---- DateTime: 2019/3/7 14:00 ---- 蹇熼亶鍘嗕慨鏀,浣庢晥鐨勫鍒 ---- - -vector = vector or {} - -function vector.create() - local t = {} - - - ---灏炬坊鍔犲厓绱(楂樻晥) - function t:add(v) - rawset(self, #self + 1, v) - end - - ---鎻掑叆(浣庢晥) - ---@param k 浣嶇疆 - ---@param v 鍊 - function t:insert(k, v) - assert(k > 0 and k <= #self, "outrange of vector") - - local cnt = #self - for i = cnt, k, -1 do - rawset(self, i+1, self[i]) - end - - rawset(self, k, v) - end - - ---鍊肩殑绱㈠紩 - ---@return -1涓嶅瓨鍦 - function t:indexOf(i_v) - assert(type(self) == 'table') - - local ret = -1 - local cnt = #self - for i = 1, #self do - if self[i] == i_v then - ret = i - end - end - - return ret - end - - ---鏄惁瀛樺湪鏌愬厓绱 - function t:contains(v) - assert(type(self) == 'table') - return self:indexOf(v) ~= -1 - end - - ---鏍规嵁涓嬫爣绱㈠紩绉婚櫎鍏冪礌(浣庢晥) - function t:removeAt(idx) - assert(idx <= #self) - table.remove(self, idx) - end - - ---鍒犻櫎鍊(闈炶椽濠) - ---@return 鍒犻櫎浣嶇疆 -1鏈垹闄 - function t:remove(v) - local ret = self:indexOf(v) - if ret ~= -1 then - self:removeAt(ret) - end - - return ret - end - - ---鍒犻櫎鎵鏈夊 - function t:removeAll(v) - assert(type(self) == 'table') - error(">>Dee: wait ...") - end - - ---鎺掑簭 - function t:sort(comparer) - assert(type(self) == 'table') - table.sort(self, comparer) - end - - ---鍖归厤 - ---@param 鍖归厤鍑芥暟 - ---@return idx,value - function t:find(matcher) - assert(type(self) == 'table') - - local _idx, _value = -1, nil - local cnt = #self - for i = 1, cnt do - if matcher(i, self[i]) then - _value = self[i] - _idx = i - break - end - end - - return _idx, _value - end - - --------------------------------metatable--------------------------------------- - t.__newindex = function(i_t,k,v) - error(">> Dee: [], replace with add()") - end - - t.__tostring = function(i_t) - return table.concat(i_t, ',') - end - - t.__pairs = function(...) - error(">> Dee: Limited access") - end - - setmetatable(t, t) - ----------------------------------------------------------------------- - - return t -end - -return vector \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/containers/README.md b/Resources/DefaultContent/Libraries/containers/README.md new file mode 100644 index 0000000..cba8776 --- /dev/null +++ b/Resources/DefaultContent/Libraries/containers/README.md @@ -0,0 +1,202 @@ +# Lua-ADT(5.1鍒嗘敮鍜5.2鍒嗘敮) +灏佽鐨刲ua鏁版嵁缁撴瀯, 鍏冪粍(tuple)銆佸姩鎬佹暟缁(vector)銆佸弻鍚戦摼琛(list)銆侀槦鍒(queue)銆佹爤(stack)銆 +绾痩ua鏂规硶灏佽锛屾病鏈変娇鐢╫op锛屽欢缁璴ua鐨勭畝娲佺殑椋庢牸銆傚皝瑁呯殑鏁版嵁缁撴瀯鑳藉畨鍏ㄤ娇鐢紝鍦ㄨ瑷灞傞潰杩囨护鎺夐潪娉曟搷浣滐紝浣垮叾浣跨敤鏇村姞绠鍗曢珮鏁堛 + +鎵鏈夌殑绫诲瀷閮芥敮鎸#鑾峰彇闀垮害. +> eg. +```lua + local tuple = require("tuple") + local v = tuple.create({2,3,6}) + print(#v) + ---3 +``` + +### 鍏冪粍(tuple) +闇瑕佺敤table鐨勫姩鎬佹暟缁勫垵濮嬪寲(涓嶆敮鎸乭ashtable),鍙澶栧叕寮閬嶅巻锛屼慨鏀瑰叧闂 + +閬嶅巻锛 +```lua + local tuple = require("tuple") + local v = tuple.create({2,3,6}) + + for i,v in ipairs(v) do --鍙敮鎸乮pairs閬嶅巻,鎶涘純浜唒airs(鍥犱负鍘熷垯涓婃垜浠槸鏁扮粍锛屼笉瀛樺湪key) + print(i,v) + end + ---1 2 + ---2 3 + ---3 6 + + print(v) --閲嶅啓浜哶_tostring,鏂逛究蹇熸祻瑙堟暟鎹 + ---2,3,6 + + v[2] = 9 --鍥犱负瀵逛慨鏀瑰叧闂簡鎵浠ヨ繖鍦版柟淇敼浼氭姏鍑洪敊璇 + ---lua: .\tuple.lua:33: >> Dee: Limited access + ---stack traceback: + ---[C]: in function 'error' +``` + +### 鍔ㄦ佹暟缁(vector) +瀹炵幇楂樻晥鐨勯亶鍘嗗拰淇敼锛屼絾鏄柊澧炲拰鍒犻櫎閮戒笉鏄嚎鎬ф椂闂村鏉傚害銆傚熀鏈笂灏辨槸lua table鐨勬暟缁勶紝浣嗘槸lua鐨則able鎴戜滑浼氫竴涓嶅皬蹇冨氨鎼炴垚涓嶈繛缁殑銆傛瘮濡: +```lua + local t = {2,4} + t[4] = 9 + + print(#t) -- 2 +``` +#### 鏂规硶锛 + * add --灏炬坊鍔(楂樻晥鐨勬搷浣) + * insert --鎻掑叆(浼氭湁鍐呭瓨鏁寸悊) + * addRange --灏炬坊鍔犱竴涓〃, + * removeAt + * remove + * contains + * indexOf + * sort + * find + +#### eg. +```lua + local vector = require("vector") + local v = vector.create() + + v:add(4) + v:add(5) + v:add(6) + v:add(7) + + for i,v in ipairs(v) do + print(i,v) + end + ---1 4 + ---2 5 + ---3 6 + ---4 7 + + print(v) + ---4,5,6,7 + + v[4] = 9 --淇敼鍊 + + print(v) + ---4,5,6,9 + + v[7] = 9 + ---lua: .\vector.lua:101: outrange of vector + ---stack traceback: + --- [C]: in function 'assert' +``` + +### 鍙屽悜閾捐〃(list) +寮ヨˉ鍔ㄦ佹暟缁勫鍒犵殑涓嶈冻锛屾彁渚涘鍒犳晥鐜囷紝浣嗘槸閬嶅巻鍜屼慨鏀规晥鐜囨瘮杈冧綆 + +#### 鏂规硶锛 + * addFirst --澶存坊鍔 + * addLast --灏炬坊鍔 + * addBefore --node鍓嶆坊鍔 + * addAfter --node鍚庢坊鍔 + * removeNode --鍒犻櫎node + * remove --鏍规嵁鍊肩Щ闄 + * find --鏌ユ壘node +#### eg. +```lua + local vector = require("list") + local v = list.create() + + v.addFirst(1) + v.addLast(2) + print(v) + ---1,2 + + local node = v.find(1) + node.value = 9 + print(v) + ---9,2 + + v.removeNode(node) + print(v) + ---2 + + v.addLast(10) + v.addLast(20) + v.addLast(30) + print(v) + ---2,10,20,30 + + for _,i,v in ipairs(v) do --绗竴涓弬鏁版槸node, i: index, v: value + print(i,v) + end + ---1 2 + ---2 10 + ---3 20 + ---4 30 +``` +### 鏍(stack) +FILO鍏堣繘鍚庡嚭, 瀵逛慨鏀瑰叧闂紝鍏抽棴閬嶅巻锛屽彧鑳介氳繃鏂规硶淇敼鏁版嵁 +#### 鏂规硶锛 + * push --娣诲姞 + * pop --绉婚櫎 + * peek --杩斿洖鏍堥《鏁版嵁 + * clear --娓呯┖ +#### eg. +```lua + local stack = require("stack") + local v = stack.create() + + v.push(1) + v.push(2) + v.push(5) + + print(v) + ---5,2,1 + print(v.len) + ---3 + v.pop() + print(v) + ---2,1 + v.clear() + print(v.len) + ---0 +``` +### 闃熷垪(queue) +FIFO,鍏堣繘鍏堝嚭锛屽洜涓烘槸闃熼鍒犻櫎鎵浠ヤ笉鑳戒娇鐢╰able.remove +#### 鏂规硶锛 + * enqueue --娣诲姞 + * dequeue --绉婚櫎 + * peek --杩斿洖鏍堥《鏁版嵁 + * clear --娓呯┖ + * #queue --鑾峰彇闀垮害 +#### eg. +```lua +local queue = require("queue") +-- lua table +local cnt = 10000 * 1 + +local t = {} +for i=1,cnt do +t[i] = i +end + +local time = os.clock() +while #t > 0 do +-- table.remove(t) + table.remove(t, 1) +end +print(os.clock() - time) +---1.037s + +local v = queue.create() + +for i=1,cnt do + v.enqueue(i) +end + + +local time1 = os.clock() +while v.len > 10 do + v.dequeue() +end +print(os.clock() - time1) +---0.005s +``` +1w鏉℃暟鎹紝lua table鐩存帴鍒犻櫎琛ㄥご鐨勮楁椂1.037s锛宷ueue鑰楁椂0.005s,鑰屼笖queue鏁寸悊鍐呭瓨鐨勬闀垮彲浠ヨ皟鏁达紝鑰楁椂鍙互杩涙涓鎻愰珮. + diff --git a/Resources/DefaultContent/Libraries/containers/list.lua b/Resources/DefaultContent/Libraries/containers/list.lua new file mode 100644 index 0000000..59233b9 --- /dev/null +++ b/Resources/DefaultContent/Libraries/containers/list.lua @@ -0,0 +1,199 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by Dee. +--- DateTime: 2019/3/7 14:00 +--- 楂樻晥澧炲垹鏈夊簭琛紝浣庢晥閬嶅巻 +--- + +--[[ +閬嶅巻: + for _,idx, value in ipairs(l) do .. end + for _, value in pairs(l) do ... end +]] + +list = list or {} + +function list.create() + local lenght = 0 + -- 绫讳技stl鐨勬柟寮忥紝澶村熬鍙槸浣滀负鎸囬拡浣跨敤 + local first = {front = nil, next = nil, value = nil} + local last = {front = nil, next = nil, value = nil} + first.next = last + last.front = first + + + ---鏌ユ壘鍊 + ---@param value + ---@return node + local find = function(value) + local ret = nil + local nextNode = first + while nextNode do + nextNode = nextNode.next + if nextNode.value == value then + ret = nextNode + break + end + end + + return ret + end + + ---鏌ユ壘(鏍规嵁涓嬫爣鏌ユ壘) + ---@param idx 涓嬫爣 + ---@return node + local findByIdx = function(idx) + local i = 0 + local ret + local nextNode = first + while nextNode and i < lenght do + i = i+1 + nextNode = nextNode.next + if i == idx then + ret = nextNode + break + end + end + + return ret + end + + ---鍦╪ode鍓嶆坊鍔 + ---@param node + ---@param v + local addBefore = function(node, v) + assert(node) + + local frontNode = node.front + local newNode = {} + newNode.front = frontNode + newNode.next = node + newNode.value = v + node.front = newNode + frontNode.next = newNode + + lenght = lenght+1 + end + + ---鍦╪ode鍚庢坊鍔 + ---@param node + ---@param v + local addAfter = function(node, v) + assert(node) + local nextNode = node.next + local newNode = {} + newNode.front = node + newNode.next = nextNode + newNode.value = v + node.next = newNode + nextNode.front = newNode + + lenght = lenght+1 + end + + ---鍦ㄩ槦棣栨坊鍔 + ---@param v + local addFirst = function(v) + addAfter(first, v) + end + + ---鍦ㄩ槦灏炬坊鍔 + ---@param v + local addLast = function(v) + addBefore(last, v) + end + + ---鍒犻櫎鑺傜偣 + ---@param node + local removeNode = function(node) + assert(node) + + local frontNode = node.front + local nextNode = node.next + + if frontNode == nil then + first = nextNode + else + frontNode.next = nextNode + end + + if nextNode ~= nil then + nextNode.front = frontNode + end + lenght = lenght - 1 + end + + ---鍒犻櫎鑺傜偣 + ---@param v + local remove = function(v) + local node = find(v) + if node then + removeNode(node) + end + end + + local t = { + addFirst = addFirst, + addLast = addLast, + addBefore = addBefore, + addAfter = addAfter, + removeNode = removeNode, + remove = remove, + find = find, + findByIdx = findByIdx + } + + local mt = { + __index = function(i_t, key) + return findByIdx(key) + end, + __newindex = function(i_t,k,v) + local node = findByIdx(k) + if not node then + error("out range: "..k) + else + node.value = v + end + end, + __tostring = function() + local ret = {} + local next = first.next + while next and next ~= last do + ret[#ret+1] = next.value + next = next.next + end + + return table.concat(ret, ',') + end, + __len = function(v) + return lenght + end, + --杩唬鍣ㄨ繑鍥瀗ode-value + __ipairs = function(i_t) + local idx = 0 + local function iter(i_t, node) + idx = idx + 1 + if node and node.next ~= last then + return node.next, idx, node.next.value + end + end + + return iter, t, first + end, + __pairs = function(i_t) + local function iter(i_t, node) + if node and node.next ~= last then + return node.next, node.next.value + end + end + + return iter, t, first + end + } + + setmetatable(t, mt) + + return t +end + +return list \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/containers/queue.lua b/Resources/DefaultContent/Libraries/containers/queue.lua new file mode 100644 index 0000000..126daa8 --- /dev/null +++ b/Resources/DefaultContent/Libraries/containers/queue.lua @@ -0,0 +1,111 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by Dee. +--- DateTime: 2019/3/7 11:27 +--- FIFO +--- + +queue = queue or {} + +---@return Queue +function queue.create() + ---鏁版嵁瀹瑰櫒 + local data = {} + ---鏁版嵁闀垮害 + local lenght = 0 + ---闃熼绱㈠紩 + local first = 1 + + ---鑾峰彇闃熼鍊 + local peek = function() + return data[first] + end + + ---鍘嬪叆鏁版嵁 + local enqueue = function(v) + assert(v ~= nil, "nil value") + first = lenght == 0 and 1 or first + lenght = lenght + 1 + table.insert(data, first+lenght-1, v) + end + + ---寮瑰嚭鏁版嵁 + local dequeue = function() + assert(lenght > 0, "nill queue") + + local ret = peek() + data[first] = nil + first = first+1 + lenght = lenght - 1 + first = lenght == 0 and 1 or first + + if math.fmod(first, 4) == 0 then + local tmp = {} + table.move(data, first, first + lenght, 1, tmp) + + first = 1 + data = nil + data = tmp + end + + return ret + end + + local clear = function() + data = {} + first = 1 + lenght = 0 + end + + local __tostring = function() + local tmp = {} + for i=1,lenght do + tmp[i] = data[i + first - 1] + end + return table.concat(tmp, ",") + end + + local __len = function() + return lenght + end + + local __index = function(i_t, key) + error(">> Dee: Limited access") + end + + local __newindex = function(i_t, key, v) + error(">> Dee: Limited access") + end + + local __ipairs = function(i_t) + local idx = 0 + local function iter(i_t) + idx = idx + 1 + if idx <= lenght then + return idx, data[first + idx - 1] + end + end + + return iter + end + + local __pairs = function(i_t) + error(">> Dee: Limited access") + end + + local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __ipairs = __ipairs, __pairs = __pairs, __len = __len} + + ---@class Queue + local t = { + enqueue = enqueue, + dequeue = dequeue, + peek = peek, + clear = clear + } + + setmetatable(t, mt) + + return t +end + +return queue diff --git a/Resources/DefaultContent/Libraries/containers/stack.lua b/Resources/DefaultContent/Libraries/containers/stack.lua new file mode 100644 index 0000000..d828c81 --- /dev/null +++ b/Resources/DefaultContent/Libraries/containers/stack.lua @@ -0,0 +1,67 @@ +--鍫嗘爤瀹炵幇 +stack = stack or {} + +function stack.create() + local data = {} + + local function push(v) + assert(v) + table.insert(data, v) + end + + local function pop() + assert(#data > 0) + table.remove(data) + end + + local function peek() + return #data > 0 and data[#data] or nil + end + + local function clear() + for i=1,#data do + data[i] = nil + end + end + + + + local __tostring = function() + local tmp = {} + for i,v in ipairs(data) do + tmp[#data+1 - i] = v + end + return table.concat(tmp, ",") + end + + local __index = function(i_t, key) + error(">> Dee: Limited access") + end + + local __len = function() + return #data + end + + local __newindex = function(i_t, key, v) + error(">> Dee: Limited access") + end + + local __ipairs = function() + error(">> Dee: Limited access") + end + + local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __ipairs = __ipairs, __pairs = __ipairs, __len = __len} + + local t = { + push = push, + pop = pop, + peek = peek, + clear = clear + } + + setmetatable(t, mt) + + return t +end + +return stack \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/containers/tuple.lua b/Resources/DefaultContent/Libraries/containers/tuple.lua new file mode 100644 index 0000000..0646d5a --- /dev/null +++ b/Resources/DefaultContent/Libraries/containers/tuple.lua @@ -0,0 +1,60 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by Dee. +--- DateTime: 2019/3/7 14:00 +--- 鍏冪祫,灏嶄慨鏀归棞闁 +--- + +tuple = tuple or {} + +function tuple.create(i_data) + assert(type(i_data) == "table", ">> Dee: shoudle create with table") + + local data = {} + for k,v in pairs(i_data) do + data[#data+1] = v + end + + local t = {} + + local __tostring = function() + return table.concat(data, ",") + end + + local __index = function(i_t, key) + return data[key] + end + + local __newindex = function(i_t, key, v) + error(">> Dee: Limited access") + end + + local __pairs = function() + error(">> Dee: Limited access") + end + + local __ipairs = function(i_t) + local idx = 0 + local function iter(i_t) + idx = idx + 1 + if idx <= #data then + return idx, data[idx] + end + end + + return iter + end + + local __len = function(v) + return #data + end + + local mt = {__tostring = __tostring, __index = __index, __newindex = __newindex, __pairs =__pairs, __ipairs = __ipairs, __len = __len} + + setmetatable(t, mt) + + return t + end + + +return tuple \ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/containers/vector.lua b/Resources/DefaultContent/Libraries/containers/vector.lua new file mode 100644 index 0000000..0b349ce --- /dev/null +++ b/Resources/DefaultContent/Libraries/containers/vector.lua @@ -0,0 +1,122 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by Dee. +--- DateTime: 2019/3/7 14:00 +--- 蹇熼亶鍘嗕慨鏀,浣庢晥鐨勫鍒 +--- + +vector = vector or {} + +function vector.create() + local t = {} + + + ---灏炬坊鍔犲厓绱(楂樻晥) + function t:add(v) + rawset(self, #self + 1, v) + end + + ---鎻掑叆(浣庢晥) + ---@param k 浣嶇疆 + ---@param v 鍊 + function t:insert(k, v) + assert(k > 0 and k <= #self, "outrange of vector") + + local cnt = #self + for i = cnt, k, -1 do + rawset(self, i+1, self[i]) + end + + rawset(self, k, v) + end + + ---鍊肩殑绱㈠紩 + ---@return -1涓嶅瓨鍦 + function t:indexOf(i_v) + assert(type(self) == 'table') + + local ret = -1 + local cnt = #self + for i = 1, #self do + if self[i] == i_v then + ret = i + end + end + + return ret + end + + ---鏄惁瀛樺湪鏌愬厓绱 + function t:contains(v) + assert(type(self) == 'table') + return self:indexOf(v) ~= -1 + end + + ---鏍规嵁涓嬫爣绱㈠紩绉婚櫎鍏冪礌(浣庢晥) + function t:removeAt(idx) + assert(idx <= #self) + table.remove(self, idx) + end + + ---鍒犻櫎鍊(闈炶椽濠) + ---@return 鍒犻櫎浣嶇疆 -1鏈垹闄 + function t:remove(v) + local ret = self:indexOf(v) + if ret ~= -1 then + self:removeAt(ret) + end + + return ret + end + + ---鍒犻櫎鎵鏈夊 + function t:removeAll(v) + assert(type(self) == 'table') + error(">>Dee: wait ...") + end + + ---鎺掑簭 + function t:sort(comparer) + assert(type(self) == 'table') + table.sort(self, comparer) + end + + ---鍖归厤 + ---@param 鍖归厤鍑芥暟 + ---@return idx,value + function t:find(matcher) + assert(type(self) == 'table') + + local _idx, _value = -1, nil + local cnt = #self + for i = 1, cnt do + if matcher(i, self[i]) then + _value = self[i] + _idx = i + break + end + end + + return _idx, _value + end + + --------------------------------metatable--------------------------------------- + t.__newindex = function(i_t,k,v) + error(">> Dee: [], replace with add()") + end + + t.__tostring = function(i_t) + return table.concat(i_t, ',') + end + + t.__pairs = function(...) + error(">> Dee: Limited access") + end + + setmetatable(t, t) + ----------------------------------------------------------------------- + + return t +end + +return vector \ No newline at end of file diff --git a/Resources/Scripts/EditorApplication.lua b/Resources/Scripts/EditorApplication.lua index 305ee87..89efb0d 100644 --- a/Resources/Scripts/EditorApplication.lua +++ b/Resources/Scripts/EditorApplication.lua @@ -10,14 +10,14 @@ if app == nil then Debug.LogError("app is nil") end -local mainWindow = GUI.ContainnerWindow.New({400, 400, 800, 500}, GUI.EShowMode.MainWindow, {100, 100}, {700, 700}) +local mainWindow = GUI.ContainerWindow.New({400, 400, 800, 500}, GUI.EShowMode.MainWindow, {100, 100}, {700, 700}) mainWindow:SetTitle("GameLab") mainWindow:SetIcon("./Icon/GameLab.ico") app:SetMainWindow(mainWindow) local guiWindow = GUI.GUIWindow.New() -guiWindow:SetContainnerWindow(mainWindow) +guiWindow:SetContainerWindow(mainWindow) guiWindow:SetPosition({0,0, 500, 400}) -- cgit v1.1-26-g67d0