diff options
Diffstat (limited to 'Editor/GUI/GUIWindow.cpp')
-rw-r--r-- | Editor/GUI/GUIWindow.cpp | 112 |
1 files changed, 67 insertions, 45 deletions
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp index 6bf7fd8..16cf768 100644 --- a/Editor/GUI/GUIWindow.cpp +++ b/Editor/GUI/GUIWindow.cpp @@ -5,6 +5,8 @@ #include "Editor/Win/Win.h" #include "Runtime/Math/Math.h" +using namespace LuaBind; + static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam) { /// prevent reentrancy @@ -27,10 +29,10 @@ static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { -#if GAMELAB_DEBUG - static int _event_count = 0; - log_info_tag("WndProc", "GUIWindow Event %d", ++_event_count); -#endif +//#if GAMELAB_DEBUG +// static int _event_count = 0; +// log_info_tag("WndProc", "GUIWindow Event %d", ++_event_count); +//#endif GUIWindow* self = (GUIWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (!self) @@ -82,7 +84,6 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara } case WM_CAPTURECHANGED: - return 0; case WM_LBUTTONDOWN: @@ -103,8 +104,32 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara case WM_SYSKEYDOWN: case WM_CHAR: case WM_MOUSEMOVE: + { + log_info_tag("WndProc", "Mouse Or Key Events"); + switch (message) { + case WM_MOUSEMOVE: + case WM_MOUSEHOVER: + { + if (!self->m_MouseTracking) + { + // Start tracking mouse + TRACKMOUSEEVENT trackMouseEvent; + trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT); + trackMouseEvent.dwFlags = TME_HOVER | TME_LEAVE; + trackMouseEvent.hwndTrack = self->m_Handle; + trackMouseEvent.dwHoverTime = self->m_MouseHoverTime; + self->m_MouseTracking = TrackMouseEvent(&trackMouseEvent); + } + } + break; + case WM_MOUSELEAVE: + { + // Cancel tracking + self->m_MouseTracking = FALSE; + } + break; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: @@ -113,23 +138,13 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara SetFocus(hWnd); self->DoPaint(); - - 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. @@ -138,6 +153,8 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara case WM_WINDOWPOSCHANGED: { + log_info_tag("WndProc", "WM_WINDOWPOSCHANGED"); + // 切换opengl渲染目标,重绘用户区 //if (self->m_GfxWindow) //{ @@ -160,19 +177,25 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara } case WM_SETFOCUS: //获得焦点 + log_info_tag("WndProc", "WM_SETFOCUS"); + self->OnFocus(); return 0; case WM_KILLFOCUS: //失去焦点 + log_info_tag("WndProc", "WM_KILLFOCUS"); + return 0; case WM_ACTIVATE: break; case WM_CLOSE: + log_info_tag("WndProc", "WM_CLOSE"); delete self; return 0; case WM_INITMENUPOPUP: //下拉菜单或子菜单将要被激活的时候 + log_info_tag("WndProc", "WM_INITMENUPOPUP"); return 0; } @@ -185,28 +208,20 @@ void GUIWindow::RepaintAll() //////////////////////////////////////////////////////////// -GUIWindow::GUIWindow(LuaBind::VM* vm) +GUIWindow::GUIWindow(LuaBind::VM* vm, std::string name) : LuaBind::NativeClass<GUIWindow>(vm) , m_Script() { -} - -void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam) -{ - -} - -void GUIWindow::Init(std::string name) -{ log_info("Init GUIWindow"); - + m_Name = name; + m_MouseHoverTime = 1; 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; - Rect pixelRect; + Rect pixelRect; pixelRect.x = 0; pixelRect.y = 0; pixelRect.width = 32; @@ -220,17 +235,17 @@ void GUIWindow::Init(std::string name) AdjustWindowRectEx(&rc, windowStyle, FALSE, extendedStyle); m_Handle = CreateWindowExW( - extendedStyle, - WindowUtil::kGUIWindowClassName, + extendedStyle, + WindowUtil::kGUIWindowClassName, L"", windowStyle, - rc.left, - rc.top, - rc.right - rc.left, + rc.left, + rc.top, + rc.right - rc.left, rc.bottom - rc.top, HWND_MESSAGE, // message only - NULL, - winutils::GetInstanceHandle(), + NULL, + winutils::GetInstanceHandle(), NULL ); @@ -238,13 +253,18 @@ void GUIWindow::Init(std::string name) ShowWindow(m_Handle, SW_SHOW); - bool bRC = SetRenderContext(); + bool bRC = SetRenderContext(); if (!bRC) log_error("Failed to setup rendering context"); log_info("Created GUIWindow "); } +void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam) +{ + +} + bool GUIWindow::SetRenderContext() { m_DC = ::GetDC(m_Handle); @@ -318,7 +338,11 @@ void GUIWindow::OnLostFocus() void GUIWindow::OnPaint() { - InvokeLuaCallback(m_Script, "OnGUI"); + LuaBind::MemberInvoker invoker = MemberInvoker(GetVM()->GetCurThread(), this); + invoker.member = m_Script; + invoker.method = "OnGUI"; + invoker.AddMember(m_Script); + invoker.Invoke(0); } void GUIWindow::SetPosition(Rect position) @@ -344,20 +368,18 @@ void GUIWindow::SetAsRenderContext() void GUIWindow::Focus() { log_info("Focus GUIWindow "); - if (m_Handle) - { - if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) - ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); - SetFocus(m_Handle); - } + //if (m_Handle) + //{ + // if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) + // ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); + // SetFocus(m_Handle); + //} } void GUIWindow::SetContainerWindow(ContainerWindow* wnd) { Assert(wnd != NULL); - m_ContainerWindow = wnd; - if (wnd->GetWindowHandle() != m_Handle) { HWND parentWindowHandle = wnd->GetWindowHandle(); |