From d35db57d457132dd9d83fa2bd51491b148530655 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 17 Oct 2021 11:14:00 +0800 Subject: *GUI --- .../Libraries/Framework/Animation/Animation.lua | 0 DefaultAssets/Libraries/Framework/Class.lua | 3 - DefaultAssets/Libraries/Framework/Core/Camera.lua | 5 - .../Libraries/Framework/Core/Component.lua | 11 - DefaultAssets/Libraries/Framework/Core/Game.lua | 14 - .../Libraries/Framework/Core/GameObject.lua | 7 - DefaultAssets/Libraries/Framework/Core/Sprite.lua | 21 -- .../Libraries/Framework/Math/Matrix44.lua | 7 - .../Libraries/Framework/Math/Quaternion.lua | 0 DefaultAssets/Libraries/Framework/Math/Vector2.lua | 0 DefaultAssets/Libraries/Framework/Math/Vector3.lua | 0 DefaultAssets/Libraries/Framework/Math/Vector4.lua | 0 .../Libraries/Framework/Utils/EventCenter.lua | 23 -- .../Libraries/Framework/Utils/StateMachine.lua | 0 DefaultAssets/Libraries/Framework/Utils/Util.lua | 0 DefaultAssets/Libraries/Framework/init.lua | 2 - DefaultAssets/Textures/blank.png | Bin 188 -> 0 bytes .../Libraries/Framework/Animation/Animation.lua | 0 DefaultContent/Libraries/Framework/Class.lua | 3 + DefaultContent/Libraries/Framework/Core/Camera.lua | 5 + .../Libraries/Framework/Core/Component.lua | 11 + DefaultContent/Libraries/Framework/Core/Game.lua | 14 + .../Libraries/Framework/Core/GameObject.lua | 7 + DefaultContent/Libraries/Framework/Core/Sprite.lua | 21 ++ .../Libraries/Framework/Math/Matrix44.lua | 7 + .../Libraries/Framework/Math/Quaternion.lua | 0 .../Libraries/Framework/Math/Vector2.lua | 0 .../Libraries/Framework/Math/Vector3.lua | 0 .../Libraries/Framework/Math/Vector4.lua | 0 .../Libraries/Framework/Utils/EventCenter.lua | 23 ++ .../Libraries/Framework/Utils/StateMachine.lua | 0 DefaultContent/Libraries/Framework/Utils/Util.lua | 0 DefaultContent/Libraries/Framework/init.lua | 2 + DefaultContent/Textures/blank.png | Bin 0 -> 188 bytes "Documents/\346\236\266\346\236\204.xlsx" | Bin 0 -> 6625 bytes Editor/EditorMain.cpp | 105 ++++++-- Editor/EditorManager.cpp | 18 ++ Editor/EditorManager.h | 32 +++ Editor/GUI/ContainnerWindow.cpp | 291 +++++++++++++++++++++ Editor/GUI/EditorWindows.cpp | 171 ------------ Editor/GUI/EditorWindows.h | 89 ++++++- Editor/GUI/GUIWindow.cpp | 211 +++++++++++++++ Editor/GUI/MenuController.cpp | 0 Editor/GUI/MenuController.h | 11 - Editor/GUI/MenuManager.cpp | 61 +++++ Editor/GUI/MenuManager.h | 30 +++ Editor/GUI/SplitWindow.cpp | 0 Editor/GUI/WinUtils.cpp | 4 + Editor/GUI/WindowManager.cpp | 17 ++ Editor/GUI/WindowUtil.cpp | 19 ++ Editor/Utils/HelperFuncs.cpp | 136 ++++++++++ Editor/Utils/HelperFuncs.h | 8 + Editor/Utils/Log.cpp | 94 +++++++ Editor/Utils/Log.h | 22 ++ Projects/VisualStudio/Editor/Editor.vcxproj | 24 +- .../VisualStudio/Editor/Editor.vcxproj.filters | 179 ++++++++----- Projects/VisualStudio/Editor/Editor.vcxproj.user | 5 +- Resources/Icon/GameLab.ico | Bin 0 -> 32870 bytes Resources/readme.txt | 1 + Runtime/Utilities/Assert.h | 2 +- 60 files changed, 1335 insertions(+), 381 deletions(-) delete mode 100644 DefaultAssets/Libraries/Framework/Animation/Animation.lua delete mode 100644 DefaultAssets/Libraries/Framework/Class.lua delete mode 100644 DefaultAssets/Libraries/Framework/Core/Camera.lua delete mode 100644 DefaultAssets/Libraries/Framework/Core/Component.lua delete mode 100644 DefaultAssets/Libraries/Framework/Core/Game.lua delete mode 100644 DefaultAssets/Libraries/Framework/Core/GameObject.lua delete mode 100644 DefaultAssets/Libraries/Framework/Core/Sprite.lua delete mode 100644 DefaultAssets/Libraries/Framework/Math/Matrix44.lua delete mode 100644 DefaultAssets/Libraries/Framework/Math/Quaternion.lua delete mode 100644 DefaultAssets/Libraries/Framework/Math/Vector2.lua delete mode 100644 DefaultAssets/Libraries/Framework/Math/Vector3.lua delete mode 100644 DefaultAssets/Libraries/Framework/Math/Vector4.lua delete mode 100644 DefaultAssets/Libraries/Framework/Utils/EventCenter.lua delete mode 100644 DefaultAssets/Libraries/Framework/Utils/StateMachine.lua delete mode 100644 DefaultAssets/Libraries/Framework/Utils/Util.lua delete mode 100644 DefaultAssets/Libraries/Framework/init.lua delete mode 100644 DefaultAssets/Textures/blank.png create mode 100644 DefaultContent/Libraries/Framework/Animation/Animation.lua create mode 100644 DefaultContent/Libraries/Framework/Class.lua create mode 100644 DefaultContent/Libraries/Framework/Core/Camera.lua create mode 100644 DefaultContent/Libraries/Framework/Core/Component.lua create mode 100644 DefaultContent/Libraries/Framework/Core/Game.lua create mode 100644 DefaultContent/Libraries/Framework/Core/GameObject.lua create mode 100644 DefaultContent/Libraries/Framework/Core/Sprite.lua create mode 100644 DefaultContent/Libraries/Framework/Math/Matrix44.lua create mode 100644 DefaultContent/Libraries/Framework/Math/Quaternion.lua create mode 100644 DefaultContent/Libraries/Framework/Math/Vector2.lua create mode 100644 DefaultContent/Libraries/Framework/Math/Vector3.lua create mode 100644 DefaultContent/Libraries/Framework/Math/Vector4.lua create mode 100644 DefaultContent/Libraries/Framework/Utils/EventCenter.lua create mode 100644 DefaultContent/Libraries/Framework/Utils/StateMachine.lua create mode 100644 DefaultContent/Libraries/Framework/Utils/Util.lua create mode 100644 DefaultContent/Libraries/Framework/init.lua create mode 100644 DefaultContent/Textures/blank.png create mode 100644 "Documents/\346\236\266\346\236\204.xlsx" create mode 100644 Editor/EditorManager.cpp create mode 100644 Editor/EditorManager.h create mode 100644 Editor/GUI/ContainnerWindow.cpp delete mode 100644 Editor/GUI/EditorWindows.cpp create mode 100644 Editor/GUI/GUIWindow.cpp delete mode 100644 Editor/GUI/MenuController.cpp delete mode 100644 Editor/GUI/MenuController.h create mode 100644 Editor/GUI/MenuManager.cpp create mode 100644 Editor/GUI/MenuManager.h create mode 100644 Editor/GUI/SplitWindow.cpp create mode 100644 Editor/GUI/WindowManager.cpp create mode 100644 Editor/GUI/WindowUtil.cpp create mode 100644 Editor/Utils/HelperFuncs.cpp create mode 100644 Editor/Utils/HelperFuncs.h create mode 100644 Editor/Utils/Log.cpp create mode 100644 Editor/Utils/Log.h create mode 100644 Resources/Icon/GameLab.ico create mode 100644 Resources/readme.txt diff --git a/DefaultAssets/Libraries/Framework/Animation/Animation.lua b/DefaultAssets/Libraries/Framework/Animation/Animation.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/Class.lua b/DefaultAssets/Libraries/Framework/Class.lua deleted file mode 100644 index 78c577c..0000000 --- a/DefaultAssets/Libraries/Framework/Class.lua +++ /dev/null @@ -1,3 +0,0 @@ -function Class() - -end \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Core/Camera.lua b/DefaultAssets/Libraries/Framework/Core/Camera.lua deleted file mode 100644 index 5fcfbe7..0000000 --- a/DefaultAssets/Libraries/Framework/Core/Camera.lua +++ /dev/null @@ -1,5 +0,0 @@ -local Camera = {} - - - -return Camera \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Core/Component.lua b/DefaultAssets/Libraries/Framework/Core/Component.lua deleted file mode 100644 index 00bf2ca..0000000 --- a/DefaultAssets/Libraries/Framework/Core/Component.lua +++ /dev/null @@ -1,11 +0,0 @@ -local Component = {} - -Component.New = function() - -end - -Component.GetGameObject = function() - -end - -Jin.Component = Component \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Core/Game.lua b/DefaultAssets/Libraries/Framework/Core/Game.lua deleted file mode 100644 index 51ce25f..0000000 --- a/DefaultAssets/Libraries/Framework/Core/Game.lua +++ /dev/null @@ -1,14 +0,0 @@ - --- Game entry - -local Game = {} - -Game.OnEvent = function(e) - -end - -Game.MainLoop = function() - -end - -return Game \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Core/GameObject.lua b/DefaultAssets/Libraries/Framework/Core/GameObject.lua deleted file mode 100644 index ee0d143..0000000 --- a/DefaultAssets/Libraries/Framework/Core/GameObject.lua +++ /dev/null @@ -1,7 +0,0 @@ -local GameObject = {} - -GameObject.AddComponent = function(self, comp) - -end - -Jin.GameObject = GameObject diff --git a/DefaultAssets/Libraries/Framework/Core/Sprite.lua b/DefaultAssets/Libraries/Framework/Core/Sprite.lua deleted file mode 100644 index 47cb50d..0000000 --- a/DefaultAssets/Libraries/Framework/Core/Sprite.lua +++ /dev/null @@ -1,21 +0,0 @@ --- 对Quad的封装,更能适合2D游戏开发 -local Sprite = {} - -Sprite.New = function(quad) - local spr = {} - spr.quad = Jin.Quad.New(quad) - spr.pivot = Jin.Vector2.New(0.5, 0) - spr.transform = Jin.Transform.New() - spr.depth = 0 - return spr -end - -Sprite.SetDepth = function(self, depth) - spr.depth = depth -end - -Sprite.SetTexture = function(self, tex, reset_quad) - -end - -Jin.Sprite = Sprite \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Math/Matrix44.lua b/DefaultAssets/Libraries/Framework/Math/Matrix44.lua deleted file mode 100644 index b572f74..0000000 --- a/DefaultAssets/Libraries/Framework/Math/Matrix44.lua +++ /dev/null @@ -1,7 +0,0 @@ -local Matrix44 = {} - -Matrix44.New = function() - -end - -return Matrix44 \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Math/Quaternion.lua b/DefaultAssets/Libraries/Framework/Math/Quaternion.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/Math/Vector2.lua b/DefaultAssets/Libraries/Framework/Math/Vector2.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/Math/Vector3.lua b/DefaultAssets/Libraries/Framework/Math/Vector3.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/Math/Vector4.lua b/DefaultAssets/Libraries/Framework/Math/Vector4.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/Utils/EventCenter.lua b/DefaultAssets/Libraries/Framework/Utils/EventCenter.lua deleted file mode 100644 index 664ecba..0000000 --- a/DefaultAssets/Libraries/Framework/Utils/EventCenter.lua +++ /dev/null @@ -1,23 +0,0 @@ -local EventCenter = {} - -EventCenter.Subscribe = function(event, callback) - -end - -EventCenter.Unsubscribe = function(event, callback) - -end - -EventCenter.UnsubscribeAll = function(event) - -end - -EventCenter.Publish = function(event, ...) - -end - -EventCenter.Clear = function() - -end - -Jin.EventCenter = EventCenter \ No newline at end of file diff --git a/DefaultAssets/Libraries/Framework/Utils/StateMachine.lua b/DefaultAssets/Libraries/Framework/Utils/StateMachine.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/Utils/Util.lua b/DefaultAssets/Libraries/Framework/Utils/Util.lua deleted file mode 100644 index e69de29..0000000 diff --git a/DefaultAssets/Libraries/Framework/init.lua b/DefaultAssets/Libraries/Framework/init.lua deleted file mode 100644 index 8b96176..0000000 --- a/DefaultAssets/Libraries/Framework/init.lua +++ /dev/null @@ -1,2 +0,0 @@ ---Jin游戏框架 ---可选,用户可以自行决定是否使用此框架 diff --git a/DefaultAssets/Textures/blank.png b/DefaultAssets/Textures/blank.png deleted file mode 100644 index 877e031..0000000 Binary files a/DefaultAssets/Textures/blank.png and /dev/null differ diff --git a/DefaultContent/Libraries/Framework/Animation/Animation.lua b/DefaultContent/Libraries/Framework/Animation/Animation.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/Class.lua b/DefaultContent/Libraries/Framework/Class.lua new file mode 100644 index 0000000..78c577c --- /dev/null +++ b/DefaultContent/Libraries/Framework/Class.lua @@ -0,0 +1,3 @@ +function Class() + +end \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Core/Camera.lua b/DefaultContent/Libraries/Framework/Core/Camera.lua new file mode 100644 index 0000000..5fcfbe7 --- /dev/null +++ b/DefaultContent/Libraries/Framework/Core/Camera.lua @@ -0,0 +1,5 @@ +local Camera = {} + + + +return Camera \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Core/Component.lua b/DefaultContent/Libraries/Framework/Core/Component.lua new file mode 100644 index 0000000..00bf2ca --- /dev/null +++ b/DefaultContent/Libraries/Framework/Core/Component.lua @@ -0,0 +1,11 @@ +local Component = {} + +Component.New = function() + +end + +Component.GetGameObject = function() + +end + +Jin.Component = Component \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Core/Game.lua b/DefaultContent/Libraries/Framework/Core/Game.lua new file mode 100644 index 0000000..51ce25f --- /dev/null +++ b/DefaultContent/Libraries/Framework/Core/Game.lua @@ -0,0 +1,14 @@ + +-- Game entry + +local Game = {} + +Game.OnEvent = function(e) + +end + +Game.MainLoop = function() + +end + +return Game \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Core/GameObject.lua b/DefaultContent/Libraries/Framework/Core/GameObject.lua new file mode 100644 index 0000000..ee0d143 --- /dev/null +++ b/DefaultContent/Libraries/Framework/Core/GameObject.lua @@ -0,0 +1,7 @@ +local GameObject = {} + +GameObject.AddComponent = function(self, comp) + +end + +Jin.GameObject = GameObject diff --git a/DefaultContent/Libraries/Framework/Core/Sprite.lua b/DefaultContent/Libraries/Framework/Core/Sprite.lua new file mode 100644 index 0000000..47cb50d --- /dev/null +++ b/DefaultContent/Libraries/Framework/Core/Sprite.lua @@ -0,0 +1,21 @@ +-- 对Quad的封装,更能适合2D游戏开发 +local Sprite = {} + +Sprite.New = function(quad) + local spr = {} + spr.quad = Jin.Quad.New(quad) + spr.pivot = Jin.Vector2.New(0.5, 0) + spr.transform = Jin.Transform.New() + spr.depth = 0 + return spr +end + +Sprite.SetDepth = function(self, depth) + spr.depth = depth +end + +Sprite.SetTexture = function(self, tex, reset_quad) + +end + +Jin.Sprite = Sprite \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Math/Matrix44.lua b/DefaultContent/Libraries/Framework/Math/Matrix44.lua new file mode 100644 index 0000000..b572f74 --- /dev/null +++ b/DefaultContent/Libraries/Framework/Math/Matrix44.lua @@ -0,0 +1,7 @@ +local Matrix44 = {} + +Matrix44.New = function() + +end + +return Matrix44 \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Math/Quaternion.lua b/DefaultContent/Libraries/Framework/Math/Quaternion.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/Math/Vector2.lua b/DefaultContent/Libraries/Framework/Math/Vector2.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/Math/Vector3.lua b/DefaultContent/Libraries/Framework/Math/Vector3.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/Math/Vector4.lua b/DefaultContent/Libraries/Framework/Math/Vector4.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/Utils/EventCenter.lua b/DefaultContent/Libraries/Framework/Utils/EventCenter.lua new file mode 100644 index 0000000..664ecba --- /dev/null +++ b/DefaultContent/Libraries/Framework/Utils/EventCenter.lua @@ -0,0 +1,23 @@ +local EventCenter = {} + +EventCenter.Subscribe = function(event, callback) + +end + +EventCenter.Unsubscribe = function(event, callback) + +end + +EventCenter.UnsubscribeAll = function(event) + +end + +EventCenter.Publish = function(event, ...) + +end + +EventCenter.Clear = function() + +end + +Jin.EventCenter = EventCenter \ No newline at end of file diff --git a/DefaultContent/Libraries/Framework/Utils/StateMachine.lua b/DefaultContent/Libraries/Framework/Utils/StateMachine.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/Utils/Util.lua b/DefaultContent/Libraries/Framework/Utils/Util.lua new file mode 100644 index 0000000..e69de29 diff --git a/DefaultContent/Libraries/Framework/init.lua b/DefaultContent/Libraries/Framework/init.lua new file mode 100644 index 0000000..8b96176 --- /dev/null +++ b/DefaultContent/Libraries/Framework/init.lua @@ -0,0 +1,2 @@ +--Jin游戏框架 +--可选,用户可以自行决定是否使用此框架 diff --git a/DefaultContent/Textures/blank.png b/DefaultContent/Textures/blank.png new file mode 100644 index 0000000..877e031 Binary files /dev/null and b/DefaultContent/Textures/blank.png differ diff --git "a/Documents/\346\236\266\346\236\204.xlsx" "b/Documents/\346\236\266\346\236\204.xlsx" new file mode 100644 index 0000000..15e2235 Binary files /dev/null and "b/Documents/\346\236\266\346\236\204.xlsx" differ diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index 8868d88..9d77862 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -2,46 +2,95 @@ #include #include "GUI/EditorWindows.h" #include "Runtime/Scripting/LuaBind.h" +#include "EditorManager.h" +#include "Runtime/Graphics/OpenGL.h" + +// Editor入口 + static int MainMessageLoop() { - BOOL returnValue; - MSG msg, lastMsg; - msg.message = WM_NULL; - std::vector messages; - PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); - bool isQuitSignaled = msg.message == WM_QUIT; - - while (!isQuitSignaled) - { - MSG msg; - while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0) - { - TranslateMessage(&msg); - DispatchMessage(&msg); + BOOL returnValue; + MSG msg, lastMsg; + msg.message = WM_NULL; + std::vector messages; + PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); + bool isQuitSignaled = msg.message == WM_QUIT; + + while (!isQuitSignaled) + { + MSG msg; + while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0) + { + TranslateMessage(&msg); + DispatchMessage(&msg); - if (msg.message == WM_QUIT) - isQuitSignaled = true; + if (msg.message == WM_QUIT) + isQuitSignaled = true; - - } + } - } + } - return (INT)msg.wParam; + return (INT)msg.wParam; +} + +void OpenLogTags() +{ + //log_open_tag("WndProc"); + //log_open_tag("Menu"); } +#ifdef GAMELAB_DEBUG +int main() +#else int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) +#endif { - RegisterWindowClasses(); + OpenLogTags(); + 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); + + 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错误"); + } - ContainnerWindow* wnd = new ContainnerWindow(); + // force repaint + wnd->DoPaint(); + guiWnd->DoPaint(); + guiWnd2->DoPaint(); - Vector2f min = Vector2f(100, 100); - Vector2f max = Vector2f(700, 700); - wnd->Init(Rectf(400, 400, 500, 500), ContainnerWindow::kShowMainWindow, min, max); + MainMessageLoop(); - MainMessageLoop(); - - return 0; + return 0; } \ No newline at end of file diff --git a/Editor/EditorManager.cpp b/Editor/EditorManager.cpp new file mode 100644 index 0000000..6f589d9 --- /dev/null +++ b/Editor/EditorManager.cpp @@ -0,0 +1,18 @@ +#include "EditorManager.h" + +#ifdef GAMELAB_DEBUG +const std::string EditorDefine::kResourceRoot = ""; +#else +const std::string EditorDefine::kResourceRoot = "./"; +#endif + + +void EditorManager::SetMainWindow(ContainnerWindow* wnd) +{ + m_MainWindow = wnd; +} + +ContainnerWindow* EditorManager::GetMainWindow() +{ + return m_MainWindow; +} diff --git a/Editor/EditorManager.h b/Editor/EditorManager.h new file mode 100644 index 0000000..6e6da19 --- /dev/null +++ b/Editor/EditorManager.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include "Runtime/Utilities/Singleton.h" + +#include "./GUI/EditorWindows.h" +#include "./GUI/MenuManager.h" + +class EditorDefine +{ +public: + static const std::string kResourceRoot; +}; + +class EditorUtil +{ +public : + +}; + +class EditorManager : public Singleton +{ +public: + void SetMainWindow(ContainnerWindow* wnd); + ContainnerWindow* GetMainWindow(); + +private: + ContainnerWindow* m_MainWindow; + +}; diff --git a/Editor/GUI/ContainnerWindow.cpp b/Editor/GUI/ContainnerWindow.cpp new file mode 100644 index 0000000..5e6c356 --- /dev/null +++ b/Editor/GUI/ContainnerWindow.cpp @@ -0,0 +1,291 @@ +#include + +#include "EditorWindows.h" +#include "WinUtils.h" +#include "Editor/Utils/HelperFuncs.h" +#include "MenuManager.h" +#include "Runtime/Utilities/Assert.h" + +using namespace std; + +static PAINTSTRUCT ps; +LRESULT CALLBACK ContainnerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + log_info("WndProc", "ContainnerWindow::ContainerWndProc()"); + + ContainnerWindow *self = (ContainnerWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (!self) + { + log_warning("Nullptr ContainnerWindow"); + return DefWindowProcW(hWnd, message, wParam, lParam); + } + + 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; + } + } + + 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 + } + +} + +HWND ContainnerWindow::GetWindowHandle() +{ + return m_Window; +} + +// 初始化,创建窗口 +void ContainnerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize) +{ + // Aux windows are mac only. on windows they look just like normal utility windows. + if (showMode == kShowAuxWindow) + showMode = kShowUtility; + + 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())); +} diff --git a/Editor/GUI/EditorWindows.cpp b/Editor/GUI/EditorWindows.cpp deleted file mode 100644 index 6d24dbd..0000000 --- a/Editor/GUI/EditorWindows.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "EditorWindows.h" -#include "WinUtils.h" - -static const wchar_t* kContainerWindowClassName = L"GameLabContainerWndClass"; -static const wchar_t* kPopupWindowClassName = L"GameLabPopupWndClass"; -static const wchar_t* kViewportClassName = L"GameLabViewportWndClass"; -static const char* kIsMainWindowMaximized = "IsMainWindowMaximized"; - -static ATOM s_ContainerWindowClassAtom; -static ATOM s_PopupWindowClassAtom; -static ATOM s_GUIViewClassAtom; - -void RegisterWindowClasses() -{ - s_ContainerWindowClassAtom = winutils::RegisterWindowClass(kContainerWindowClassName, ContainnerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW); - s_PopupWindowClassAtom = winutils::RegisterWindowClass(kPopupWindowClassName, ContainnerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW);//CS_HREDRAW宽度(水平)变化时重绘、CS_VREDRAW高度(垂直)变化时重绘 - s_GUIViewClassAtom = winutils::RegisterWindowClass(kViewportClassName, GUIView::GUIViewWndProc, CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS); -} - -LRESULT CALLBACK ContainnerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - long flag = DefWindowProcW(hWnd, message, wParam, lParam); - return flag; -} - -ContainnerWindow::ContainnerWindow() -{ -} - - -ContainnerWindow::~ContainnerWindow() -{ - -} - -void ContainnerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize) -{ - // Aux windows are mac only. on windows they look just like normal utility windows. - if (showMode == kShowAuxWindow) - showMode = kShowUtility; - - 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 = { 120, 120, 220, 220 }; - m_InternalRect.x = m_InternalRect.y = m_InternalRect.width = m_InternalRect.height = 0.0f; - - DWORD windowStyle = 0; - DWORD extendedStyle = 0; - LPCWSTR windowClass = 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 = 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); - -} - -//------------------------------------------------------------------------------------------------------------------ - -LRESULT CALLBACK GUIView::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - long flag = DefWindowProcW(hWnd, message, wParam, lParam); - return flag; -} - -void GUIView::DoPaint() -{ - - -} \ No newline at end of file diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h index 4bd33ec..33d99c1 100644 --- a/Editor/GUI/EditorWindows.h +++ b/Editor/GUI/EditorWindows.h @@ -2,15 +2,38 @@ #define EDITOR_WINDOW_H #include +#include #include "Runtime/Math/Rect.h" #include "Runtime/Scripting/LuaBind.h" +#include "Runtime/Utilities/Singleton.h" +#include "Editor/Utils/Log.h" +#include "Runtime/Graphics/OpenGL.h" -void RegisterWindowClasses(); +class GUIWindow; + +class WindowUtil +{ +public : + static void Init(); + + static const wchar_t* kContainerWindowClassName; + static const wchar_t* kPopupWindowClassName; + static const wchar_t* kGUIWindowClassName; +}; + +class WindowManager : Singleton +{ +public: + static Vector2f GetMousePosition(); + static GUIWindow* GetMouseOverWindow(); +}; // 一个containner window中有多个viewport class ContainnerWindow { public: + static LRESULT CALLBACK ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + enum ShowMode { kShowNormalWindow = 0, // normal window with max/min/close buttons kShowPopupMenu = 1, // popup menu - no title bar @@ -23,12 +46,22 @@ public: ContainnerWindow(); ~ContainnerWindow(); - static LRESULT CALLBACK ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - void Init(Rectf size, int showMode, const Vector2f& minSize, const Vector2f& maxSize); + void SetTitle(const char* title); + void SetIcon(LPCSTR iconName); + void SetAsRenderContext(); + void DoPaint(); + + HWND GetWindowHandle(); + HDC GetDC() { return m_DC; } + HGLRC GetRC() { return m_RC; } private: + bool SetRenderContext(); + HWND m_Window; + HDC m_DC; + HGLRC m_RC; POINT m_Size; ShowMode m_ShowMode; // 窗口类型 bool m_IsClosing; @@ -40,20 +73,62 @@ private: }; +// 窗口基类 +class WindowBase +{ +}; + +// 抽象窗口,用来做布局 +class SplitWindow : public WindowBase +{ +public: + enum SplitMode + { + Horizontal, + Vertical, + }; + + SplitMode GetSplitMode() { return m_SplitMode; } + +private: + SplitMode m_SplitMode; + + GUIWindow* m_GUIWindow; + std::vector m_GUIWindows; -// 窗口内的单个子窗口,是事件相应、绘制、布局的单元 -class GUIView +}; + +// GUI窗口,事件相应、绘制、布局的单元 +// 和unity不一样的地方在于一个GUIWindow只会有一个EditorWindow,即一个切页,因为在实际开发中我发现很少会频繁的切换切页,UE逻辑更像blender +// 好处也在于比较好组织 +class GUIWindow : public WindowBase { public: static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static void RepaintAll(); + void Init(); void DoPaint(); + void SetContainnerWindow(ContainnerWindow* wnd); + void Focus(); + void SetPosition(Rectf position); + void SetAsRenderContext(); + + void OnFocus(); + void OnLostFocus(); + + HDC GetDC() { return m_DC; } + HGLRC GetRC() { return m_RC; } private: - HWND m_View; + bool SetRenderContext(); - LuaBind::Ref m_Script; + ContainnerWindow* m_ContainnerWindow; + HWND m_Handle; + HDC m_DC; + HGLRC m_RC; + LuaBind::Ref m_Script; }; diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp new file mode 100644 index 0000000..e13770e --- /dev/null +++ b/Editor/GUI/GUIWindow.cpp @@ -0,0 +1,211 @@ +#include "EditorWindows.h" +#include "WinUtils.h" +#include "Runtime/Graphics/OpenGL.h" + +static PAINTSTRUCT ps; +LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + log_info("WndProc", "GUIWindow::GUIViewWndProc(), hWnd=" /*+ (long)hWnd*/); + + GUIWindow* wnd = (GUIWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); + if (!wnd) + { + log_warning("GUIWindow::GUIViewWndProc(), lParam为空"); + return DefWindowProcW(hWnd, message, wParam, lParam); + } + + switch (message) + { + case WM_PAINT: + { + log_info("WM_PAINT"); + wnd->SetAsRenderContext(); + glEnable(GL_BLEND); + glClearColor(1,0,0,1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glFlush(); + BeginPaint(wnd->m_Handle, &ps); + EndPaint(wnd->m_Handle, &ps); + UpdateWindow(wnd->m_Handle); + return 0; + } + } + + long flag = DefWindowProcW(hWnd, message, wParam, lParam); + return flag; +} + +void GUIWindow::RepaintAll() +{ +} + +////////////////////////////////////////////////////////////////////////////////////////// + +void GUIWindow::Init() +{ + log_info("Init GUIWindow " /*+ (long)this*/); + + DWORD windowStyle = WS_CHILD; + //DWORD windowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; + DWORD extendedStyle = WS_EX_TOOLWINDOW; + + Rectf pixelRect; + pixelRect.x = 0; + pixelRect.y = 0; + pixelRect.width = 32; + pixelRect.height = 32; + + RECT rc; + rc.left = pixelRect.x; + rc.top = pixelRect.y; + rc.right = pixelRect.x + pixelRect.width; + rc.bottom = pixelRect.y + pixelRect.height; + AdjustWindowRectEx(&rc, windowStyle, FALSE, extendedStyle); + + m_Handle = CreateWindowExW( + extendedStyle, + WindowUtil::kGUIWindowClassName, + L"", + windowStyle, + rc.left, + rc.top, + rc.right - rc.left, + rc.bottom - rc.top, + HWND_MESSAGE, // message only + NULL, + winutils::GetInstanceHandle(), + NULL + ); + + SetWindowLongPtr(m_Handle, GWLP_USERDATA, (LONG_PTR)this); + + ShowWindow(m_Handle, SW_SHOW); + + if (!SetRenderContext()) + log_error("Failed to setup rendering context"); + + log_info("Created GUIWindow " /*+ (long)this*/); +} + +bool GUIWindow::SetRenderContext() +{ + m_DC = ::GetDC(m_Handle); + 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 + } + + return true; +} + +void GUIWindow::DoPaint() +{ + SetWindowLongPtr(m_Handle, GWLP_USERDATA,(LONG_PTR ) this); + SendMessage(m_Handle, WM_PAINT, 0, 0); +} + +void GUIWindow::OnFocus() +{ +} + +void GUIWindow::OnLostFocus() +{ +} + +void GUIWindow::SetPosition(Rectf position) +{ + log_info("GUIWindow::SetPosition()"); + RECT rc; + rc.left = position.x; + rc.top = position.y; + rc.right = position.x + position.width; + rc.bottom = position.y + position.height; + ::SetWindowPos(m_Handle, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_FRAMECHANGED | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOZORDER); +} + +void GUIWindow::SetAsRenderContext() +{ + Assert(m_DC != NULL); + Assert(m_RC != NULL); + Assert(wglMakeCurrent(m_DC, m_RC)); + RECT rect; + GetWindowRect(m_Handle, &rect); + glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top); +} + +void GUIWindow::Focus() +{ + log_info("Focus GUIWindow " + (long)this); + if (m_Handle) + { + if (::GetForegroundWindow() != m_ContainnerWindow->GetWindowHandle()) + ::SetForegroundWindow(m_ContainnerWindow->GetWindowHandle()); + SetFocus(m_Handle); + } +} + +void GUIWindow::SetContainnerWindow(ContainnerWindow* wnd) +{ + Assert(wnd != NULL); + + m_ContainnerWindow = wnd; + + if (wnd->GetWindowHandle() != m_Handle) + { + HWND parentWindowHandle = wnd->GetWindowHandle(); + if (::GetParent(m_Handle) != parentWindowHandle) + ::SetParent(m_Handle, parentWindowHandle); + ::ShowWindow(m_Handle, SW_SHOWNORMAL); + } +} \ No newline at end of file diff --git a/Editor/GUI/MenuController.cpp b/Editor/GUI/MenuController.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Editor/GUI/MenuController.h b/Editor/GUI/MenuController.h deleted file mode 100644 index 9abe9e5..0000000 --- a/Editor/GUI/MenuController.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef MENU_CONTROLLER_H -#define MENU_CONTROLLER_H - -// 管理menu item - -class MenuController { - -}; - - -#endif \ No newline at end of file diff --git a/Editor/GUI/MenuManager.cpp b/Editor/GUI/MenuManager.cpp new file mode 100644 index 0000000..53dfd5a --- /dev/null +++ b/Editor/GUI/MenuManager.cpp @@ -0,0 +1,61 @@ +//https://stackoverflow.com/questions/30135494/win32-api-c-menu-bar +//https://docs.microsoft.com/en-us/windows/win32/menurc/using-menus + +#include + +#include "MenuManager.h" +#include "../EditorManager.h" + +const int IDM_FILE_NEW = 10; +const int IDM_ASSET = 20; + +using namespace std; + +MenuManager::MenuManager() + : m_Menus() +{ +} + +void MenuManager::Init() +{ + ContainnerWindow* mainWnd = EditorManager::Instance()->GetMainWindow(); + Assert(mainWnd != NULL); + + HMENU hMenubar = CreateMenu(); + + HMENU hMenu = CreateMenu(); + HMENU hSubMenu = CreatePopupMenu(); + HMENU asserMenu = CreateMenu(); + + AppendMenuW(hMenu, MF_STRING, IDM_FILE_NEW, L"&New"); + AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL); + + AppendMenuW(asserMenu, MF_STRING, IDM_ASSET, L"Import &mail &assets"); + AppendMenuW(hSubMenu, MF_STRING | MF_POPUP, (UINT_PTR)asserMenu, L"Import &mail"); + AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"&Import"); + + AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&File"); + + AppendMenuW(hMenu, MF_STRING, IDM_FILE_NEW + 5, L"New 2"); + //InsertMenu(hMenu, 1, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); + + SetMenu(mainWnd->GetWindowHandle(), hMenubar); + +} + +void MenuManager::AddMenuItem(std::string name, int order) +{ + log_info("Menu", " Add menu item \"" + name + "\""); + +} + +void MenuManager::HandleMenuItemEvent(HMENU menu, unsigned int menuId, unsigned int flags) +{ + log_info("Menu", "menuId=" + to_string(menuId) + ", flags=" + to_string(flags)); + + if (flags & MF_CHECKED) // clicked + { + log_info("Menu", "checked"); + + } +} \ No newline at end of file diff --git a/Editor/GUI/MenuManager.h b/Editor/GUI/MenuManager.h new file mode 100644 index 0000000..8d0339d --- /dev/null +++ b/Editor/GUI/MenuManager.h @@ -0,0 +1,30 @@ +#ifndef MENU_CONTROLLER_H +#define MENU_CONTROLLER_H + +#include +#include +#include + +#include "Runtime/Utilities/Singleton.h" + +class MenuItem +{ + +}; + +class MenuManager : public Singleton +{ +public: + MenuManager(); + + void Init(); + void AddMenuItem(std::string name, int order = 0); + void HandleMenuItemEvent(HMENU menu, unsigned int menuId, unsigned int flags); + +private: + std::unordered_map m_Menus; + +}; + + +#endif \ No newline at end of file diff --git a/Editor/GUI/SplitWindow.cpp b/Editor/GUI/SplitWindow.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Editor/GUI/WinUtils.cpp b/Editor/GUI/WinUtils.cpp index e7b2d5b..84d0e37 100644 --- a/Editor/GUI/WinUtils.cpp +++ b/Editor/GUI/WinUtils.cpp @@ -7,6 +7,10 @@ namespace winutils HINSTANCE GetInstanceHandle() { + if (gInstanceHandle == NULL) + { + gInstanceHandle = GetModuleHandle(NULL); + } return gInstanceHandle; } diff --git a/Editor/GUI/WindowManager.cpp b/Editor/GUI/WindowManager.cpp new file mode 100644 index 0000000..add2066 --- /dev/null +++ b/Editor/GUI/WindowManager.cpp @@ -0,0 +1,17 @@ +#include "EditorWindows.h" +#include "WinUtils.h" + +GUIWindow* WindowManager::GetMouseOverWindow() +{ + return NULL; +} + +Vector2f WindowManager::GetMousePosition() +{ + POINT pt; + if (!GetCursorPos(&pt)) + return Vector2f(0, 0); + + return Vector2f(pt.x, pt.y); + +} diff --git a/Editor/GUI/WindowUtil.cpp b/Editor/GUI/WindowUtil.cpp new file mode 100644 index 0000000..fc32719 --- /dev/null +++ b/Editor/GUI/WindowUtil.cpp @@ -0,0 +1,19 @@ +#include "EditorWindows.h" +#include "WinUtils.h" + +const wchar_t* WindowUtil::kContainerWindowClassName = L"GameLabContainerWndClass"; +const wchar_t* WindowUtil::kPopupWindowClassName = L"GameLabPopupWndClass"; +const wchar_t* WindowUtil::kGUIWindowClassName = L"GUIViewWindowClassName"; + +static ATOM ContainerWindowClassAtom; +static ATOM PopupWindowClassAtom; +static ATOM GUIViewClassAtom; + +void WindowUtil::Init() +{ + 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高度(垂直)变化时重绘 + GUIViewClassAtom = winutils::RegisterWindowClass(kGUIWindowClassName, GUIWindow::GUIViewWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW); +} \ No newline at end of file diff --git a/Editor/Utils/HelperFuncs.cpp b/Editor/Utils/HelperFuncs.cpp new file mode 100644 index 0000000..fd91d85 --- /dev/null +++ b/Editor/Utils/HelperFuncs.cpp @@ -0,0 +1,136 @@ +#include "HelperFuncs.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#pragma comment(lib,"Dbghelp.lib") + +std::string to_string(const char* cstr) +{ + string s(cstr); + return s; +} + +void _Exceptor() +{ + throw exception(); +} + +//https://stackoverflow.com/questions/22467604/ +const int MaxNameLen = 256; +void printStack(CONTEXT* ctx) //Prints stack trace based on context record +{ + BOOL result; + HANDLE process; + HANDLE thread; + HMODULE hModule; + + STACKFRAME64 stack; + ULONG frame; + DWORD64 displacement; + + DWORD disp; + IMAGEHLP_LINE64 *line; + + char buffer[sizeof(SYMBOL_INFO) + 2000 * sizeof(TCHAR)]; + char name[MaxNameLen]; + char module[MaxNameLen]; + PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer; + + memset(&stack, 0, sizeof(STACKFRAME64)); + + process = GetCurrentProcess(); + thread = GetCurrentThread(); + displacement = 0; +#if !defined(_M_AMD64) + stack.AddrPC.Offset = (*ctx).Eip; + stack.AddrPC.Mode = AddrModeFlat; + stack.AddrStack.Offset = (*ctx).Esp; + stack.AddrStack.Mode = AddrModeFlat; + stack.AddrFrame.Offset = (*ctx).Ebp; + stack.AddrFrame.Mode = AddrModeFlat; +#endif + + SymInitialize(process, NULL, TRUE); //load symbols + + for (frame = 0; ; frame++) + { + //get next call from stack + result = StackWalk64 + ( +#if defined(_M_AMD64) + IMAGE_FILE_MACHINE_AMD64 +#else + IMAGE_FILE_MACHINE_I386 +#endif + , + process, + thread, + &stack, + ctx, + NULL, + SymFunctionTableAccess64, + SymGetModuleBase64, + NULL + ); + + if (!result) break; + + //get symbol name for address + pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); + pSymbol->MaxNameLen = 2000; + SymFromAddr(process, (ULONG64)stack.AddrPC.Offset, &displacement, pSymbol); + + line = (IMAGEHLP_LINE64 *)malloc(sizeof(IMAGEHLP_LINE64)); + line->SizeOfStruct = sizeof(IMAGEHLP_LINE64); + + //try to get line + if (SymGetLineFromAddr64(process, stack.AddrPC.Offset, &disp, line)) + { + printf("\tat %s in %s: line: %lu: address: 0x%0X\n", pSymbol->Name, line->FileName, line->LineNumber, pSymbol->Address); + } + else + { + //failed to get line + printf("\tat %s, address 0x%0X.\n", pSymbol->Name, pSymbol->Address); + hModule = NULL; + lstrcpyA(module, ""); + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCTSTR)(stack.AddrPC.Offset), &hModule); + + //at least print module name + if (hModule != NULL)GetModuleFileNameA(hModule, module, MaxNameLen); + + printf("in %s\n", module); + } + + free(line); + line = NULL; + } +} + +int seh_filter(_EXCEPTION_POINTERS* ex) +{ + printf("*** Exception 0x%x occured ***\n\n", ex->ExceptionRecord->ExceptionCode); + printStack(ex->ContextRecord); + + return EXCEPTION_EXECUTE_HANDLER; +} + +void PrintCallStack() +{ + __try + { + _Exceptor(); + } + __except (seh_filter(GetExceptionInformation())) + { + printf("Exception \n"); + } +} \ No newline at end of file diff --git a/Editor/Utils/HelperFuncs.h b/Editor/Utils/HelperFuncs.h new file mode 100644 index 0000000..2ee7932 --- /dev/null +++ b/Editor/Utils/HelperFuncs.h @@ -0,0 +1,8 @@ +#pragma once + +#include +#include + +std::string to_string(const char* cstr); + +extern void PrintCallStack(); \ No newline at end of file diff --git a/Editor/Utils/Log.cpp b/Editor/Utils/Log.cpp new file mode 100644 index 0000000..9ec7d42 --- /dev/null +++ b/Editor/Utils/Log.cpp @@ -0,0 +1,94 @@ +#include "log.h" +#include +#include +#include +#include "HelperFuncs.h" + +using namespace std; + +//long g_LogTags = LogTag::All; +unordered_set s_OpenTags; + +#ifdef GAMELAB_DEBUG +// https://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c +// Get current date/time, format is YYYY-MM-DD.HH:mm:ss +const std::string currentDateTime() { + time_t now = time(0); + struct tm tstruct; + char buf[80]; + tstruct = *localtime(&now); + // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime + // for more information about date/time format + strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct); + + return buf; +} + +void log_open_tag(std::string tag) +{ + s_OpenTags.insert(tag); +} + +// https://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c + +void log_info(std::string log) +{ + cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\033[0m" << endl; +} + +void log_warning(std::string log) +{ + cout << "\x1B[93m" << currentDateTime() << " [Wanning] " << log << "\033[0m" << endl; +} + +void log_error(std::string log) +{ + cout << "\x1B[91m" << currentDateTime() << " [Error] " << log << "\033[0m" << endl; +} + +void log_error_null_param(std::string funcName, std::string param) +{ + log_error("Null parameter in " + funcName + " called " + param); +} + +void log_info(string tag, std::string log) +{ + if (s_OpenTags.count(tag) <= 0) + return; + log_info("[" + tag + "] " + log); +} +void log_warning(string tag, std::string log) +{ + if (s_OpenTags.count(tag) <= 0) + return; + log_warning("[" + tag + "] " + log); +} +void log_error(string tag, std::string log) +{ + if (s_OpenTags.count(tag) <= 0) + return; + log_error("[" + tag + "] " + log); +} +#else +void log_open_tag(std::string tag) {} +void log_info(std::string log) +{ +} + +void log_warning(std::string log) +{ +} + +void log_error(std::string log) +{ +} + +void log_error_null_param(std::string funcName, std::string param) +{ +} + +void log_info(string tag, std::string log) {} +void log_warning(string tag, std::string log) {} +void log_error(string tag, std::string log) {} + +#endif \ No newline at end of file diff --git a/Editor/Utils/Log.h b/Editor/Utils/Log.h new file mode 100644 index 0000000..d66f705 --- /dev/null +++ b/Editor/Utils/Log.h @@ -0,0 +1,22 @@ +#pragma once +#include + +//enum LogTag : unsigned long +//{ +// +// All = ~0 +//}; +// +//extern long g_LogTags; + +void log_open_tag(std::string tag); + +void log_info(std::string log); +void log_warning(std::string log); +void log_error(std::string log); + +void log_error_null_param(std::string funcName, std::string param); + +void log_info(std::string tag, std::string log); +void log_warning(std::string tag, std::string log); +void log_error(std::string tag, std::string log); diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index c682fe5..6418165 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -87,11 +87,12 @@ Disabled true true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - $(SolutionDir)..\..\;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;GAMELAB_DEBUG;%(PreprocessorDefinitions) + $(SolutionDir)..\..\;$(SolutionDir)..\..\ThirdParty\;%(AdditionalIncludeDirectories) - Windows + Console + opengl32.lib;%(AdditionalDependencies) @@ -142,10 +143,17 @@ + + - - + + + + + + + @@ -161,10 +169,14 @@ + - + + + + diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index 982bd5b..de41fde 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -1,177 +1,230 @@ 锘 - - {87a57ef1-78d8-42b8-b179-ce1bbb5c4f8b} + + {37e66f64-a2fe-4adf-b435-e2e42ea17414} + + + {376fd2a5-5333-4bcb-9122-a112c40d5287} - + {ed31f129-996f-4a1c-b8d5-5c3d74139940} - + {61174975-2b52-426f-b871-d33e1bf956d4} - + + {e7e5a875-cafb-48df-9659-8f88d0377208} + + + {87a57ef1-78d8-42b8-b179-ce1bbb5c4f8b} + + {f9573ff2-4a53-4953-806e-f0ce0c586910} + + {6c7e1979-1cd3-40c7-98e1-f063c325d642} + + + {47032dd6-dca2-478f-b594-d08c0b22e119} + + + {bfc8b148-db9d-403d-96b9-32c946e15402} + - - GUI - - GUI - - - GUI + Editor\GUI - Math + Runtime\Math - Math + Runtime\Math - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - GUI + Editor\GUI - - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting + + + Editor\GUI + + + Editor\GUI + + + Editor\GUI + + + Editor\Utils + + + Editor\GUI + + + Editor\GUI + + + Editor + + + Editor + + + Editor\GUI + + + Editor\Utils - - GUI - - GUI + Editor\GUI - GUI + Editor\GUI - Math + Runtime\Math - Math + Runtime\Math - Math + Runtime\Math - Math + Runtime\Math - Math + Runtime\Math - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - Utilities + Runtime\Utilities - GUI + Editor\GUI - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting + + + Editor\Utils + + + Editor\GUI + + + Editor + + + Editor\Utils + + + Editor\GUI - Scripting + Runtime\Scripting - Scripting + Runtime\Scripting \ No newline at end of file diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.user b/Projects/VisualStudio/Editor/Editor.vcxproj.user index be25078..db52b6c 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.user +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.user @@ -1,4 +1,7 @@ 锘 - + + $(SolutionDir)..\..\Resources + WindowsLocalDebugger + \ No newline at end of file diff --git a/Resources/Icon/GameLab.ico b/Resources/Icon/GameLab.ico new file mode 100644 index 0000000..ae94a7d Binary files /dev/null and b/Resources/Icon/GameLab.ico differ diff --git a/Resources/readme.txt b/Resources/readme.txt new file mode 100644 index 0000000..e3b0dc5 --- /dev/null +++ b/Resources/readme.txt @@ -0,0 +1 @@ +缂栬緫鍣ㄧ敤鐨勮祫婧 \ No newline at end of file diff --git a/Runtime/Utilities/Assert.h b/Runtime/Utilities/Assert.h index 4eb7b7a..526ca32 100644 --- a/Runtime/Utilities/Assert.h +++ b/Runtime/Utilities/Assert.h @@ -3,7 +3,7 @@ #include -#define Assert(c) assert(c) +#define Assert(c) assert((c)) #define DebugAssertIf(c) assert(c) #define AssertIf(c) assert(c) -- cgit v1.1-26-g67d0