From e13f699ee5f575198552d94ada1167305c82bb2f Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 17 Oct 2021 16:01:09 +0800 Subject: *misc --- Editor/GUI/GUIWindow.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 152 insertions(+), 12 deletions(-) (limited to 'Editor/GUI/GUIWindow.cpp') 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; -- cgit v1.1-26-g67d0