summaryrefslogtreecommitdiff
path: root/Editor/GUI
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-17 16:01:09 +0800
committerchai <chaifix@163.com>2021-10-17 16:01:09 +0800
commite13f699ee5f575198552d94ada1167305c82bb2f (patch)
treed67ff5ec85959f38a62babf856d4fa9f2f0b4147 /Editor/GUI
parentd35db57d457132dd9d83fa2bd51491b148530655 (diff)
*misc
Diffstat (limited to 'Editor/GUI')
-rw-r--r--Editor/GUI/ContainnerWindow.cpp151
-rw-r--r--Editor/GUI/EditorWindows.h38
-rw-r--r--Editor/GUI/GUIWindow.cpp164
-rw-r--r--Editor/GUI/MainWindow.cpp54
-rw-r--r--Editor/GUI/WindowManager.cpp2
5 files changed, 379 insertions, 30 deletions
diff --git a/Editor/GUI/ContainnerWindow.cpp b/Editor/GUI/ContainnerWindow.cpp
index 5e6c356..3778485 100644
--- a/Editor/GUI/ContainnerWindow.cpp
+++ b/Editor/GUI/ContainnerWindow.cpp
@@ -8,11 +8,14 @@
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)
{
- log_info("WndProc", "ContainnerWindow::ContainerWndProc()");
-
+
ContainnerWindow *self = (ContainnerWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (!self)
{
@@ -20,6 +23,8 @@ LRESULT CALLBACK ContainnerWindow::ContainerWndProc(HWND hWnd, UINT message, WPA
return DefWindowProcW(hWnd, message, wParam, lParam);
}
+ //log_info("WndProc", "ContainnerWindow::ContainerWndProc(), ContainnerWindow name is " + self->GetName());
+
switch (message)
{
case WM_MENUSELECT:
@@ -48,6 +53,123 @@ LRESULT CALLBACK ContainnerWindow::ContainerWndProc(HWND hWnd, UINT message, WPA
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);
@@ -140,18 +262,14 @@ bool ContainnerWindow::SetRenderContext()
}
-HWND ContainnerWindow::GetWindowHandle()
-{
- return m_Window;
-}
-
// 初始化,创建窗口
-void ContainnerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize)
+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>(showMode);
m_IsClosing = false;
m_InMenuLoop = false;
@@ -289,3 +407,20 @@ void ContainnerWindow::SetIcon(LPCSTR iconName)
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 33d99c1..8a146e2 100644
--- a/Editor/GUI/EditorWindows.h
+++ b/Editor/GUI/EditorWindows.h
@@ -8,6 +8,8 @@
#include "Runtime/Utilities/Singleton.h"
#include "Editor/Utils/Log.h"
#include "Runtime/Graphics/OpenGL.h"
+#include "Runtime/Utilities/UtilMacros.h"
+#include "Editor/Utils/HelperFuncs.h"
class GUIWindow;
@@ -26,6 +28,10 @@ class WindowManager : Singleton<WindowManager>
public:
static Vector2f GetMousePosition();
static GUIWindow* GetMouseOverWindow();
+
+private:
+ static std::vector<GUIWindow*> s_GUIWindows;
+
};
// 一个containner window中有多个viewport
@@ -46,19 +52,27 @@ public:
ContainnerWindow();
~ContainnerWindow();
- void Init(Rectf size, int showMode, const Vector2f& minSize, const Vector2f& maxSize);
+ void Init(Rectf size, int showMode, const Vector2f& minSize, const Vector2f& maxSize, std::string name = "");
void SetTitle(const char* title);
void SetIcon(LPCSTR iconName);
void SetAsRenderContext();
void DoPaint();
+ void Close();
+
+ GET_SET(std::string, Name, m_Name);
- HWND GetWindowHandle();
- HDC GetDC() { return m_DC; }
- HGLRC GetRC() { return m_RC; }
+ GET(HWND, WindowHandle, m_Window);
+ GET(HDC, DC, m_DC);
+ GET(HGLRC, RC, m_RC);
+
+ void OnRectChanged();
+ void OnActivateApplication(bool active);
private:
bool SetRenderContext();
+ std::string m_Name;
+
HWND m_Window;
HDC m_DC;
HGLRC m_RC;
@@ -90,24 +104,24 @@ public:
SplitMode GetSplitMode() { return m_SplitMode; }
+ GET(SplitMode, SplitMode, m_SplitMode);
+
private:
SplitMode m_SplitMode;
GUIWindow* m_GUIWindow;
- std::vector<GUIWindow*> m_GUIWindows;
+ std::vector<GUIWindow*>* m_GUIWindows;
};
// 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 Init(std::string name = "");
void DoPaint();
void SetContainnerWindow(ContainnerWindow* wnd);
void Focus();
@@ -117,12 +131,16 @@ public:
void OnFocus();
void OnLostFocus();
- HDC GetDC() { return m_DC; }
- HGLRC GetRC() { return m_RC; }
+ GET_SET(std::string, Name, m_Name);
+ GET(HDC, DC, m_DC);
+ GET(HGLRC, RC, m_RC);
private:
+ void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam);
bool SetRenderContext();
+ std::string m_Name;
+
ContainnerWindow* m_ContainnerWindow;
HWND m_Handle;
HDC m_DC;
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp
index e13770e..1fe88ca 100644
--- a/Editor/GUI/GUIWindow.cpp
+++ b/Editor/GUI/GUIWindow.cpp
@@ -2,37 +2,170 @@
#include "WinUtils.h"
#include "Runtime/Graphics/OpenGL.h"
+static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam)
+{
+ //// prevent reentrancy
+ //static bool s_ReentrancyCheck = false;
+ //if (s_ReentrancyCheck)
+ // return false;
+
+ //// 找到对应的子窗口
+ //GUIWindow* view = GetMouseOverWindow();
+ //if (!view)
+ // return false;
+
+ //// 将鼠标滚轮事件派发到子窗口上去
+ //// send mouse wheel to view under mouse
+ //s_ReentrancyCheck = true;
+ //::SendMessage(view->GetWindowHandle(), WM_MOUSEWHEEL, wParam, lParam);
+ //s_ReentrancyCheck = false;
+ return true;
+}
+
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)
+ GUIWindow* self = (GUIWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ if (!self)
{
log_warning("GUIWindow::GUIViewWndProc(), lParam为空");
return DefWindowProcW(hWnd, message, wParam, lParam);
}
+ //log_info("WndProc", "GUIWindow::GUIViewWndProc(), GUIWindow name is " + wnd->GetName());
+
switch (message)
{
+ case WM_ERASEBKGND:
+
+ return 1;
+
case WM_PAINT:
{
- log_info("WM_PAINT");
- wnd->SetAsRenderContext();
+ log_info("WndProc", "WM_PAINT");
+ self->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);
+ BeginPaint(self->m_Handle, &ps);
+ EndPaint(self->m_Handle, &ps);
+ UpdateWindow(self->m_Handle);
+ return 0;
+ }
+
+ case WM_MOUSEWHEEL: // 在这个子窗口滚动
+ {
+ // quick check if mouse is in our window
+ RECT rc;
+ POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+ ::GetWindowRect(hWnd, &rc);
+ if (!::PtInRect(&rc, pt)) //如果不在这个子窗口范围内
+ {
+ // 重新派发到鼠标所在的那个窗口上去,这里其实就是之前很多windows用户反映的,明明是在某个窗口上滚动,但由于这个窗口没
+ // 被选中,导致滚动事件被触发在选中的那个窗口上
+ if (RedirectMouseWheel(hWnd, wParam, lParam))
+ return 0;
+ }
+
+ Assert(self->m_Handle != hWnd);
+ //self->ProcessEventMessages(message, wParam, lParam);
+ return 0;
+ }
+
+ case WM_CAPTURECHANGED:
+
+ return 0;
+
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_XBUTTONDOWN:
+ case WM_LBUTTONUP:
+ case WM_RBUTTONUP:
+ case WM_MBUTTONUP:
+ case WM_XBUTTONUP:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDBLCLK:
+ case WM_MBUTTONDBLCLK:
+ case WM_XBUTTONDBLCLK:
+ case WM_KEYUP:
+ case WM_KEYDOWN:
+ case WM_SYSKEYUP:
+ case WM_SYSKEYDOWN:
+ case WM_CHAR:
+ case WM_MOUSEMOVE:
+ switch (message)
+ {
+ case WM_LBUTTONDOWN:
+ case WM_RBUTTONDOWN:
+ case WM_MBUTTONDOWN:
+ case WM_XBUTTONDOWN:
+ {
+ SetFocus(hWnd);
+
+ if (/*processInput && !focused*/ true)
+ {
+ //focused = (GetFocus() == hWnd);
+
+ //if (focused)
+ //{
+ // BOOL handled = FALSE;
+ // ProcessInputMessage(hWnd, message, wParam, lParam, handled);
+ //}
+ }
+ }
+ break;
+ }
+
+ // 处理键盘输入,比如输入内容
+ self->ProcessEventMessages(message, wParam, lParam);
+
+ case WM_SETCURSOR:
+ // We're setting the cursor on every WM_MOUSEMOVE.
+ //We eat the WM_SETCURSOR event here so the OS doesn't conflict with us causing cursor garbage flicker.
+ return 1;
+
+ case WM_WINDOWPOSCHANGED:
+ {
+ // 切换opengl渲染目标,重绘用户区
+ //if (self->m_GfxWindow)
+ //{
+ // RECT rect;
+ // GetClientRect(hWnd, &rect);
+ // // 大小变动了
+ // if (self->m_GfxWindow->GetWidth() != rect.right || self->m_GfxWindow->GetHeight() != rect.bottom)
+ // {
+ // // 调用wglMakeCurrent()绑定用户区
+ // // GLWindow.cpp > Reshape
+ // self->m_GfxWindow->Reshape(rect.right, rect.bottom, self->m_DepthFormat, self->m_AntiAlias);
+ // // 请求重绘
+ // self->RequestRepaint();
+ // }
+
+ // // Update the scene so that scripts marked with [ExecuteInEditMode] are able to react to screen size changes
+ // GetApplication().SetSceneRepaintDirty();
+ //}
return 0;
}
+
+ case WM_SETFOCUS: //获得焦点
+ return 0;
+ case WM_KILLFOCUS: //失去焦点
+ return 0;
+
+ case WM_ACTIVATE:
+ break;
+
+ case WM_CLOSE:
+ delete self;
+ return 0;
+
+ case WM_INITMENUPOPUP: //下拉菜单或子菜单将要被激活的时候
+ return 0;
}
- long flag = DefWindowProcW(hWnd, message, wParam, lParam);
- return flag;
+ return DefWindowProcW(hWnd, message, wParam, lParam);
}
void GUIWindow::RepaintAll()
@@ -41,10 +174,17 @@ void GUIWindow::RepaintAll()
//////////////////////////////////////////////////////////////////////////////////////////
-void GUIWindow::Init()
+void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam)
+{
+
+}
+
+void GUIWindow::Init(std::string name)
{
log_info("Init GUIWindow " /*+ (long)this*/);
+ m_Name = name;
+
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;
diff --git a/Editor/GUI/MainWindow.cpp b/Editor/GUI/MainWindow.cpp
new file mode 100644
index 0000000..fe4e499
--- /dev/null
+++ b/Editor/GUI/MainWindow.cpp
@@ -0,0 +1,54 @@
+#include <string>
+
+#include "EditorWindows.h"
+#include "WinUtils.h"
+#include "Editor/Utils/HelperFuncs.h"
+#include "MenuManager.h"
+#include "Runtime/Utilities/Assert.h"
+
+bool ProcessMainWindowMessages(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT& result)
+{
+
+ //if(message!=WM_TIMER && message!=WM_SETCURSOR)
+ // printf_console("msg: %s\n", winutils::GetWindowsMessageInfo(message,wParam,lParam).c_str());
+
+ switch (message)
+ {
+
+ // Ok, this is fun: when we're using swap chains and no "regular window", often we don't get device loss events, even though it
+ // looks like the device is put into "lost" state. So whenever anything important changes (resolution, user logs in, etc.),
+ // try to manually reset the device and repaint everything. Yay!
+ case WM_SETTINGCHANGE:
+ // when switching to screen saver, it seems that the only way to detect that is by handling working area change message.
+ if (wParam == SPI_SETWORKAREA) {
+ }
+ break;
+ case WM_DISPLAYCHANGE:
+ case WM_DEVMODECHANGE:
+ case WM_USERCHANGED:
+ break;
+
+ case WM_COPYDATA:
+ {
+
+ }
+ break;
+ case WM_INITMENU: // 主窗口菜单栏初始化
+
+ return true;
+ case WM_COMMAND: // 点击菜单,点击加速键,点击子窗口按钮,点击工具栏按钮。这些时候都有command消息产生。
+
+ break;
+
+ case WM_ACTIVATEAPP:
+
+ break;
+
+ case WM_DESTROY:
+ ::PostQuitMessage(0);
+ break;
+ }
+
+ return false;
+}
+
diff --git a/Editor/GUI/WindowManager.cpp b/Editor/GUI/WindowManager.cpp
index add2066..533435f 100644
--- a/Editor/GUI/WindowManager.cpp
+++ b/Editor/GUI/WindowManager.cpp
@@ -1,6 +1,8 @@
#include "EditorWindows.h"
#include "WinUtils.h"
+std::vector<GUIWindow*> WindowManager::s_GUIWindows;
+
GUIWindow* WindowManager::GetMouseOverWindow()
{
return NULL;