From 59e6235113a4d933811aa2cf6fdc8282ce394b9d Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 10 Nov 2020 18:46:11 +0800 Subject: *window --- Editor/GUI/EditorWindows.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++ Editor/GUI/EditorWindows.h | 28 +++++++- Editor/GUI/WinUtils.cpp | 43 ++++++++++++ Editor/GUI/WinUtils.h | 17 +++++ 4 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 Editor/GUI/WinUtils.cpp create mode 100644 Editor/GUI/WinUtils.h (limited to 'Editor/GUI') diff --git a/Editor/GUI/EditorWindows.cpp b/Editor/GUI/EditorWindows.cpp index e69de29..18f2e3a 100644 --- a/Editor/GUI/EditorWindows.cpp +++ b/Editor/GUI/EditorWindows.cpp @@ -0,0 +1,164 @@ +#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, Viewport::ViewportWndProc, 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 Viewport::ViewportWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + long flag = DefWindowProcW(hWnd, message, wParam, lParam); + return flag; +} + diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h index 90e71a4..ca1c059 100644 --- a/Editor/GUI/EditorWindows.h +++ b/Editor/GUI/EditorWindows.h @@ -2,23 +2,49 @@ #define EDITOR_WINDOW_H #include +#include "../../Runtime/Math/Rect.h" + +void RegisterWindowClasses(); // 一个containner window中有多个viewport class ContainnerWindow { public: + enum ShowMode { + kShowNormalWindow = 0, // normal window with max/min/close buttons + kShowPopupMenu = 1, // popup menu - no title bar + kShowUtility = 2, // tool window - floats in the app, and hides when the app deactivates + kShowNoShadow = 3, // no shadow/decorations + kShowMainWindow = 4, // main Unity window. On Mac does not have close button; on Windows has menu bar etc. + kShowAuxWindow = 5, // Popup windows like the color picker, gradient editor, etc. Drawn with black background on Mac + }; + + 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); private: HWND m_Window; POINT m_Size; + ShowMode m_ShowMode; + bool m_IsClosing; + bool m_InMenuLoop; + bool m_CloseFromScriptDontShutdown; + Rectf m_InternalRect; + POINT m_MinSize; + POINT m_MaxSize; }; -// 窗口内的单个viewport +// 窗口内的单个子窗口,是事件相应、绘制、布局的单元 class Viewport { public: + static LRESULT CALLBACK ViewportWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); private: HWND m_View; diff --git a/Editor/GUI/WinUtils.cpp b/Editor/GUI/WinUtils.cpp new file mode 100644 index 0000000..e7b2d5b --- /dev/null +++ b/Editor/GUI/WinUtils.cpp @@ -0,0 +1,43 @@ +#include "winutils.h" + +namespace winutils +{ + + static HINSTANCE gInstanceHandle = NULL; + + HINSTANCE GetInstanceHandle() + { + return gInstanceHandle; + } + + ATOM RegisterWindowClass(const wchar_t* className, WNDPROC windowProc, unsigned int style) + { +#if DEBUG_WIN_UTILS + printf_console("Debug winutils: register class %s\n", className); +#endif + + WNDCLASSEXW wcex; + memset(&wcex, 0, sizeof(wcex)); + wcex.cbSize = sizeof(wcex); + wcex.style = style; + wcex.lpfnWndProc = windowProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = winutils::GetInstanceHandle(); + //wcex.hIcon = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_APP_ICON); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = NULL; + wcex.lpszMenuName = NULL; + wcex.lpszClassName = className; + ATOM classAtom = RegisterClassExW(&wcex); + //if (!classAtom) + // printf("Failed to register window class %s: %s\n", className, WIN_LAST_ERROR_TEXT); + return classAtom; + } + + void UnregisterWindowClass(const wchar_t* className) + { + + } + +} diff --git a/Editor/GUI/WinUtils.h b/Editor/GUI/WinUtils.h new file mode 100644 index 0000000..9257d77 --- /dev/null +++ b/Editor/GUI/WinUtils.h @@ -0,0 +1,17 @@ +#ifndef WINUTILS_H +#define WINUTILS_H + +#include + +namespace winutils +{ + HINSTANCE GetInstanceHandle(); + + // 注册windows窗口类 + ATOM RegisterWindowClass(const wchar_t* className, WNDPROC windowProc, unsigned int style); + void UnregisterWindowClass(const wchar_t* className); + + +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0