summaryrefslogtreecommitdiff
path: root/Editor/GUI
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-08 09:23:38 +0800
committerchai <chaifix@163.com>2021-11-08 09:23:38 +0800
commit138d3f4d3d6e2aaf5ba34f89af15ef85ea074357 (patch)
tree31ca6e8ea6d2e960e8d35f801bd92555942822e2 /Editor/GUI
parentefce5b6bd5c9d4f8214a71e0f7a7c35751710a4c (diff)
*misc
Diffstat (limited to 'Editor/GUI')
-rw-r--r--Editor/GUI/ContainerWindow.cpp12
-rw-r--r--Editor/GUI/ContainerWindow.h82
-rw-r--r--Editor/GUI/EditorWindows.h186
-rw-r--r--Editor/GUI/GUIWindow.cpp112
-rw-r--r--Editor/GUI/GUIWindow.h69
-rw-r--r--Editor/GUI/WindowBase.h43
6 files changed, 272 insertions, 232 deletions
diff --git a/Editor/GUI/ContainerWindow.cpp b/Editor/GUI/ContainerWindow.cpp
index 57b1b48..99fa6cb 100644
--- a/Editor/GUI/ContainerWindow.cpp
+++ b/Editor/GUI/ContainerWindow.cpp
@@ -9,6 +9,7 @@
#include "Runtime/Math/Math.h"
using namespace std;
+using namespace LuaBind;
static bool s_IsMainWindowMaximized;
@@ -16,10 +17,10 @@ extern bool ProcessMainWindowMessages(HWND hWnd, UINT message, WPARAM wParam, LP
LRESULT CALLBACK ContainerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
-#if GAMELAB_DEBUG
- static int _event_count = 0;
- log_info_tag("WndProc", "ContrainerWindow Event %d", ++_event_count);
-#endif
+//#if GAMELAB_DEBUG
+// static int _event_count = 0;
+// log_info_tag("WndProc", "ContrainerWindow Event %d", ++_event_count);
+//#endif
ContainerWindow *self = (ContainerWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (!self)
@@ -45,13 +46,14 @@ LRESULT CALLBACK ContainerWindow::ContainerWndProc(HWND hWnd, UINT message, WPAR
case WM_PAINT:
{
static PAINTSTRUCT ps;
- 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);
diff --git a/Editor/GUI/ContainerWindow.h b/Editor/GUI/ContainerWindow.h
new file mode 100644
index 0000000..140748d
--- /dev/null
+++ b/Editor/GUI/ContainerWindow.h
@@ -0,0 +1,82 @@
+#pragma once
+
+#include <windows.h>
+#include <vector>
+
+#include "Runtime/Math/Rect.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaHelper.h"
+#include "Runtime/Utilities/Singleton.h"
+#include "Runtime/Debug/Log.h"
+#include "Runtime/Graphics/OpenGL.h"
+#include "Runtime/Utilities/UtilMacros.h"
+#include "Editor/Utils/HelperFuncs.h"
+#include "Runtime/Math/Math.h"
+#include "Runtime/Utilities/Exception.h"
+
+// 一个containner window中有多个viewport
+class ContainerWindow
+ : public LuaBind::NativeClass<ContainerWindow>
+{
+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
+ 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
+ };
+
+ ContainerWindow(LuaBind::VM* vm);
+ ~ContainerWindow();
+
+ void Init(Rect size, int showMode, const Vector2& minSize, const Vector2& 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);
+
+ GET(HWND, WindowHandle, m_Window);
+ GET(HDC, DC, m_DC);
+
+ void OnRectChanged();
+ void OnActivateApplication(bool active);
+
+private:
+ bool SetRenderContext();
+
+ //--------------------------------------------------------
+
+ std::string m_Name;
+
+ POINT m_Size;
+ ShowMode m_ShowMode; // 窗口类型
+ bool m_IsClosing;
+ bool m_InMenuLoop;
+ bool m_CloseFromScriptDontShutdown;
+ Rect m_InternalRect;
+ POINT m_MinSize;
+ POINT m_MaxSize;
+
+#ifdef GAMELAB_WIN
+ HWND m_Window;
+ HDC m_DC;
+#endif
+
+ //--------------------------------------------------------
+
+ LUA_BIND_DECL_CLASS(ContainerWindow);
+
+ LUA_BIND_DECL_METHOD(_New);
+ LUA_BIND_DECL_METHOD(_SetTitle);
+ LUA_BIND_DECL_METHOD(_SetIcon);
+ LUA_BIND_DECL_METHOD(_DoPaint);
+
+};
+
diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h
index d8a3f66..d31627c 100644
--- a/Editor/GUI/EditorWindows.h
+++ b/Editor/GUI/EditorWindows.h
@@ -1,5 +1,4 @@
-#ifndef EDITOR_WINDOW_H
-#define EDITOR_WINDOW_H
+#pragma once
#include <windows.h>
#include <vector>
@@ -12,184 +11,7 @@
#include "Runtime/Utilities/UtilMacros.h"
#include "Editor/Utils/HelperFuncs.h"
#include "Runtime/Math/Math.h"
+#include "Runtime/Utilities/Exception.h"
-using namespace LuaBind;
-
-class GUIWindow;
-
-class WindowUtil
-{
-public :
- static void RegisterClasses();
-
- static const wchar_t* kContainerWindowClassName;
- static const wchar_t* kPopupWindowClassName;
- static const wchar_t* kGUIWindowClassName;
-};
-
-class WindowManager : Singleton<WindowManager>
-{
-public:
- static Vector2 GetMousePosition();
- static GUIWindow* GetMouseOverWindow();
-
-private:
- static std::vector<GUIWindow*> s_GUIWindows;
-
-};
-
-// 一个containner window中有多个viewport
-class ContainerWindow
- : public LuaBind::NativeClass<ContainerWindow>
-{
-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
- 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
- };
-
- ContainerWindow(LuaBind::VM* vm);
- ~ContainerWindow();
-
- void Init(Rect size, int showMode, const Vector2& minSize, const Vector2& 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);
-
- GET(HWND, WindowHandle, m_Window);
- GET(HDC, DC, m_DC);
-
- void OnRectChanged();
- void OnActivateApplication(bool active);
-
-private:
- bool SetRenderContext();
-
- //--------------------------------------------------------
-
- std::string m_Name;
-
- POINT m_Size;
- ShowMode m_ShowMode; // 窗口类型
- bool m_IsClosing;
- bool m_InMenuLoop;
- bool m_CloseFromScriptDontShutdown;
- Rect m_InternalRect;
- POINT m_MinSize;
- POINT m_MaxSize;
-
-#ifdef GAMELAB_WIN
- HWND m_Window;
- HDC m_DC;
-#endif
-
- //--------------------------------------------------------
-
- LUA_BIND_DECL_CLASS(ContainerWindow);
-
- LUA_BIND_DECL_METHOD(_New);
- LUA_BIND_DECL_METHOD(_SetTitle);
- LUA_BIND_DECL_METHOD(_SetIcon);
- LUA_BIND_DECL_METHOD(_DoPaint);
-
-};
-
-class WindowBase
-{
-};
-
-// 抽象窗口,用来做布局,SplitWindow是嵌套的
-class SplitWindow : public WindowBase
-{
-public:
- enum SplitMode
- {
- Horizontal,
- Vertical,
- };
-
- SplitMode GetSplitMode() { return m_SplitMode; }
-
- GET(SplitMode, SplitMode, m_SplitMode);
-
-private:
- SplitMode m_SplitMode;
-
- // 嵌套split
- std::vector< SplitWindow*> m_ChildSplitWindows;
-
- // 最顶层的split window包含的是GUIWindows
- std::vector<GUIWindow*>* m_GUIWindows;
-
-};
-
-// GUI窗口,事件相应、绘制、布局的单元
-class GUIWindow
- : public WindowBase
- , public LuaBind::NativeClass<GUIWindow>
-{
-public:
- static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- static void RepaintAll();
-
- GUIWindow(LuaBind::VM* vm);
-
- void Init(std::string name = "");
- void DoPaint();
- void SetContainerWindow(ContainerWindow* wnd);
- void Focus();
- void SetPosition(Rect position);
- void SetAsRenderContext();
-
- void OnFocus();
- void OnLostFocus();
- void OnPaint();
-
- GET_SET(std::string, Name, m_Name);
- GET(HDC, DC, m_DC);
-
-private:
- void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam);
- bool SetRenderContext();
-
- //-----------------------------------------------------------------
-
- std::string m_Name;
-
- ContainerWindow* m_ContainerWindow;
-
- std::vector<LuaBind::MemberRef> m_EditorWindows;
- LuaBind::MemberRef m_EditorWindow; // EditorWindow脚本
- LuaBind::MemberRef m_ActiveEditorWindow; // 当前激活的EditorWindow
-
- LuaBind::MemberRef m_Script; // EditorWindow脚本
-
-#if GAMELAB_WIN
- HWND m_Handle;
- HDC m_DC;
-#endif
-
- //-----------------------------------------------------------------
-
- LUA_BIND_DECL_CLASS(GUIWindow);
-
- LUA_BIND_DECL_METHOD(_New);
- LUA_BIND_DECL_METHOD(_DoPaint);
- LUA_BIND_DECL_METHOD(_Focus);
- LUA_BIND_DECL_METHOD(_SetContainerWindow);
- LUA_BIND_DECL_METHOD(_SetPosition);
- LUA_BIND_DECL_METHOD(_SetInstance);
-
-};
-
-#endif \ No newline at end of file
+#include "ContainerWindow.h"
+#include "GUIWindow.h"
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();
diff --git a/Editor/GUI/GUIWindow.h b/Editor/GUI/GUIWindow.h
new file mode 100644
index 0000000..aa81b38
--- /dev/null
+++ b/Editor/GUI/GUIWindow.h
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <windows.h>
+#include <vector>
+#include "Runtime/Math/Rect.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaHelper.h"
+#include "Runtime/Utilities/Singleton.h"
+#include "Runtime/Debug/Log.h"
+#include "Runtime/Graphics/OpenGL.h"
+#include "Runtime/Utilities/UtilMacros.h"
+#include "Editor/Utils/HelperFuncs.h"
+#include "Runtime/Math/Math.h"
+#include "Runtime/Utilities/Exception.h"
+
+#include "WindowBase.h"
+
+// GUI窗口,事件相应、绘制、布局的单元
+class GUIWindow
+ : public WindowBase
+ , public LuaBind::NativeClass<GUIWindow>
+{
+public:
+ static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+ static void RepaintAll();
+
+ GUIWindow(LuaBind::VM* vm, std::string name = ""); //throw WindowException
+
+ void DoPaint();
+ void SetContainerWindow(ContainerWindow* wnd);
+ void Focus();
+ void SetPosition(Rect position);
+ void SetAsRenderContext();
+
+ void OnFocus();
+ void OnLostFocus();
+ void OnPaint();
+
+ GET_SET(std::string, Name, m_Name);
+ GET(HDC, DC, m_DC);
+
+private:
+ void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam);
+ bool SetRenderContext();
+
+ //-----------------------------------------------------------------
+
+ std::string m_Name;
+
+ LuaBind::MemberRef m_Script;
+
+ BOOL m_MouseTracking;
+ DWORD m_MouseHoverTime;
+
+ HWND m_Handle;
+ HDC m_DC;
+
+ //-----------------------------------------------------------------
+
+ LUA_BIND_DECL_CLASS(GUIWindow);
+
+ LUA_BIND_DECL_METHOD(_New);
+ LUA_BIND_DECL_METHOD(_DoPaint);
+ LUA_BIND_DECL_METHOD(_Focus);
+ LUA_BIND_DECL_METHOD(_SetContainerWindow);
+ LUA_BIND_DECL_METHOD(_SetPosition);
+
+};
+
diff --git a/Editor/GUI/WindowBase.h b/Editor/GUI/WindowBase.h
new file mode 100644
index 0000000..cf3cae6
--- /dev/null
+++ b/Editor/GUI/WindowBase.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <windows.h>
+#include <vector>
+#include "Runtime/Math/Rect.h"
+#include "Runtime/Lua/LuaBind/LuaBind.h"
+#include "Runtime/Lua/LuaHelper.h"
+#include "Runtime/Utilities/Singleton.h"
+#include "Runtime/Debug/Log.h"
+#include "Runtime/Graphics/OpenGL.h"
+#include "Runtime/Utilities/UtilMacros.h"
+#include "Editor/Utils/HelperFuncs.h"
+#include "Runtime/Math/Math.h"
+#include "Runtime/Utilities/Exception.h"
+
+class WindowBase
+{
+};
+
+CustomException(WindowException);
+
+class GUIWindow;
+
+class WindowUtil
+{
+public:
+ static void RegisterClasses();
+
+ static const wchar_t* kContainerWindowClassName;
+ static const wchar_t* kPopupWindowClassName;
+ static const wchar_t* kGUIWindowClassName;
+};
+
+class WindowManager : Singleton<WindowManager>
+{
+public:
+ static Vector2 GetMousePosition();
+ static GUIWindow* GetMouseOverWindow();
+
+private:
+ static std::vector<GUIWindow*> s_GUIWindows;
+
+};