summaryrefslogtreecommitdiff
path: root/Editor/GUI/GUIWindow.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-17 11:14:00 +0800
committerchai <chaifix@163.com>2021-10-17 11:14:00 +0800
commitd35db57d457132dd9d83fa2bd51491b148530655 (patch)
treeb5a29675f091f268577b5991988c723f273b0bd1 /Editor/GUI/GUIWindow.cpp
parent7b0a6d1fe0117cf42a5776aaabda2db78599e5b8 (diff)
*GUI
Diffstat (limited to 'Editor/GUI/GUIWindow.cpp')
-rw-r--r--Editor/GUI/GUIWindow.cpp211
1 files changed, 211 insertions, 0 deletions
diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp
new file mode 100644
index 0000000..e13770e
--- /dev/null
+++ b/Editor/GUI/GUIWindow.cpp
@@ -0,0 +1,211 @@
+#include "EditorWindows.h"
+#include "WinUtils.h"
+#include "Runtime/Graphics/OpenGL.h"
+
+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)
+ {
+ log_warning("GUIWindow::GUIViewWndProc(), lParamΪ¿Õ");
+ return DefWindowProcW(hWnd, message, wParam, lParam);
+ }
+
+ switch (message)
+ {
+ case WM_PAINT:
+ {
+ log_info("WM_PAINT");
+ wnd->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);
+ return 0;
+ }
+ }
+
+ long flag = DefWindowProcW(hWnd, message, wParam, lParam);
+ return flag;
+}
+
+void GUIWindow::RepaintAll()
+{
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+void GUIWindow::Init()
+{
+ log_info("Init GUIWindow " /*+ (long)this*/);
+
+ 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;
+
+ Rectf pixelRect;
+ pixelRect.x = 0;
+ pixelRect.y = 0;
+ pixelRect.width = 32;
+ pixelRect.height = 32;
+
+ RECT rc;
+ rc.left = pixelRect.x;
+ rc.top = pixelRect.y;
+ rc.right = pixelRect.x + pixelRect.width;
+ rc.bottom = pixelRect.y + pixelRect.height;
+ AdjustWindowRectEx(&rc, windowStyle, FALSE, extendedStyle);
+
+ m_Handle = CreateWindowExW(
+ extendedStyle,
+ WindowUtil::kGUIWindowClassName,
+ L"",
+ windowStyle,
+ rc.left,
+ rc.top,
+ rc.right - rc.left,
+ rc.bottom - rc.top,
+ HWND_MESSAGE, // message only
+ NULL,
+ winutils::GetInstanceHandle(),
+ NULL
+ );
+
+ SetWindowLongPtr(m_Handle, GWLP_USERDATA, (LONG_PTR)this);
+
+ ShowWindow(m_Handle, SW_SHOW);
+
+ if (!SetRenderContext())
+ log_error("Failed to setup rendering context");
+
+ log_info("Created GUIWindow " /*+ (long)this*/);
+}
+
+bool GUIWindow::SetRenderContext()
+{
+ m_DC = ::GetDC(m_Handle);
+ if (!m_DC)
+ log_error("Can't create DC");
+
+ int bits = 32;
+
+ //static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
+ //{
+ // sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
+ // 1, // Version Number
+ // PFD_DRAW_TO_WINDOW | // Format Must Support Window
+ // PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
+ // PFD_DOUBLEBUFFER, // Must Support Double Buffering
+ // PFD_TYPE_RGBA, // Request An RGBA Format
+ // bits, // Select Our Color Depth
+ // 0, 0, 0, 0, 0, 0, // Color Bits Ignored
+ // 0, // No Alpha Buffer
+ // 0, // Shift Bit Ignored
+ // 0, // No Accumulation Buffer
+ // 0, 0, 0, 0, // Accumulation Bits Ignored
+ // 16, // 16Bit Z-Buffer (Depth Buffer)
+ // 0, // No Stencil Buffer
+ // 0, // No Auxiliary Buffer
+ // PFD_MAIN_PLANE, // Main Drawing Layer
+ // 0, // Reserved
+ // 0, 0, 0 // Layer Masks Ignored
+ //};
+ static PIXELFORMATDESCRIPTOR pfd;
+ pfd.nSize = sizeof(pfd);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 32;
+
+ GLuint PixelFormat;
+
+ if (!(PixelFormat = ChoosePixelFormat(m_DC, &pfd))) // Did Windows Find A Matching Pixel Format?
+ {
+ MessageBox(NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
+ return FALSE; // Return FALSE
+ }
+
+ if (!SetPixelFormat(m_DC, PixelFormat, &pfd)) // Are We Able To Set The Pixel Format?
+ {
+ MessageBox(NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
+ return FALSE; // Return FALSE
+ }
+
+ int pf = 0;
+ DescribePixelFormat(m_DC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+
+ if (!(m_RC = wglCreateContext(m_DC))) // Are We Able To Get A Rendering Context?
+ {
+ MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
+ return FALSE; // Return FALSE
+ }
+
+ return true;
+}
+
+void GUIWindow::DoPaint()
+{
+ SetWindowLongPtr(m_Handle, GWLP_USERDATA,(LONG_PTR ) this);
+ SendMessage(m_Handle, WM_PAINT, 0, 0);
+}
+
+void GUIWindow::OnFocus()
+{
+}
+
+void GUIWindow::OnLostFocus()
+{
+}
+
+void GUIWindow::SetPosition(Rectf position)
+{
+ log_info("GUIWindow::SetPosition()");
+ RECT rc;
+ rc.left = position.x;
+ rc.top = position.y;
+ rc.right = position.x + position.width;
+ rc.bottom = position.y + position.height;
+ ::SetWindowPos(m_Handle, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_FRAMECHANGED | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOZORDER);
+}
+
+void GUIWindow::SetAsRenderContext()
+{
+ Assert(m_DC != NULL);
+ Assert(m_RC != NULL);
+ Assert(wglMakeCurrent(m_DC, m_RC));
+ RECT rect;
+ GetWindowRect(m_Handle, &rect);
+ glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top);
+}
+
+void GUIWindow::Focus()
+{
+ log_info("Focus GUIWindow " + (long)this);
+ if (m_Handle)
+ {
+ if (::GetForegroundWindow() != m_ContainnerWindow->GetWindowHandle())
+ ::SetForegroundWindow(m_ContainnerWindow->GetWindowHandle());
+ SetFocus(m_Handle);
+ }
+}
+
+void GUIWindow::SetContainnerWindow(ContainnerWindow* wnd)
+{
+ Assert(wnd != NULL);
+
+ m_ContainnerWindow = wnd;
+
+ if (wnd->GetWindowHandle() != m_Handle)
+ {
+ HWND parentWindowHandle = wnd->GetWindowHandle();
+ if (::GetParent(m_Handle) != parentWindowHandle)
+ ::SetParent(m_Handle, parentWindowHandle);
+ ::ShowWindow(m_Handle, SW_SHOWNORMAL);
+ }
+} \ No newline at end of file