From c34ea0f30d928856da17bfdef62725398787cc54 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 6 Mar 2023 08:44:13 -0600 Subject: [PATCH] feat(gx): handle window messages in d3d backend --- src/gx/CGxDevice.hpp | 1 + src/gx/Types.hpp | 8 +++ src/gx/d3d/CGxDeviceD3d.cpp | 98 +++++++++++++++++++++++++++++++++++++ src/gx/d3d/CGxDeviceD3d.hpp | 1 + src/gx/gll/CGxDeviceGLL.hpp | 1 + 5 files changed, 109 insertions(+) diff --git a/src/gx/CGxDevice.hpp b/src/gx/CGxDevice.hpp index 57d77d4..fa97609 100644 --- a/src/gx/CGxDevice.hpp +++ b/src/gx/CGxDevice.hpp @@ -99,6 +99,7 @@ class CGxDevice { virtual void ICursorCreate(const CGxFormat& format); virtual int32_t DeviceCreate(long (*)(void*, uint32_t, uint32_t, long), const CGxFormat&); virtual int32_t DeviceSetFormat(const CGxFormat&); + virtual void DeviceWM(EGxWM wm, uintptr_t param1, uintptr_t param2) = 0; virtual void CapsWindowSize(CRect&) = 0; virtual void CapsWindowSizeInScreenCoords(CRect& dst) = 0; virtual void ScenePresent(void); diff --git a/src/gx/Types.hpp b/src/gx/Types.hpp index d9d3ed9..f68aaea 100644 --- a/src/gx/Types.hpp +++ b/src/gx/Types.hpp @@ -308,6 +308,14 @@ enum EGxuDrawListCategory { GxuCat_2 = 2 }; +enum EGxWM { + GxWM_Size = 0, + GxWM_DisplayChange = 1, + GxWM_Destroy = 2, + GxWM_SetFocus = 3, + GxWM_KillFocus = 4, +}; + enum COLOR_FILE_FORMAT { COLOR_JPEG = 0, COLOR_PAL = 1, diff --git a/src/gx/d3d/CGxDeviceD3d.cpp b/src/gx/d3d/CGxDeviceD3d.cpp index ab0bfcd..149021d 100644 --- a/src/gx/d3d/CGxDeviceD3d.cpp +++ b/src/gx/d3d/CGxDeviceD3d.cpp @@ -72,6 +72,100 @@ void CGxDeviceD3d::IUnloadD3dLib(HINSTANCE& d3dLib, LPDIRECT3D9& d3d) { } LRESULT CGxDeviceD3d::WindowProcD3d(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + auto device = reinterpret_cast(GetWindowLongPtr(hWnd, GWLP_USERDATA)); + + switch (uMsg) { + case WM_CREATE: { + auto lpcs = reinterpret_cast(lParam); + SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast(lpcs->lpCreateParams)); + + return 0; + } + + case WM_DESTROY: { + device->DeviceWM(GxWM_Destroy, 0, 0); + + return 0; + } + + case WM_SIZE: { + CRect windowRect = { + 0.0f, + 0.0f, + static_cast(HIWORD(lParam)), + static_cast(LOWORD(lParam)) + }; + + int32_t resizeType = 0; + if (wParam == SIZE_MINIMIZED) { + resizeType = 1; + } else if (wParam == SIZE_MAXHIDE) { + resizeType = 2; + } + + device->DeviceWM(GxWM_Size, reinterpret_cast(&windowRect), resizeType); + + break; + } + + case WM_ACTIVATE: { + // TODO + + break; + } + + case WM_SETFOCUS: { + device->DeviceWM(GxWM_SetFocus, 0, 0); + + return 0; + } + + case WM_KILLFOCUS: { + device->DeviceWM(GxWM_KillFocus, 0, 0); + + return 0; + } + + case WM_PAINT: { + PAINTSTRUCT paint; + BeginPaint(hWnd, &paint); + EndPaint(hWnd, &paint); + + return 0; + } + + case WM_ERASEBKGND: { + return 0; + } + + case WM_SETCURSOR: { + // TODO + + return 1; + } + + case WM_DISPLAYCHANGE: { + // TODO + + break; + } + + case WM_SYSCOMMAND: { + // TODO + + break; + } + + case WM_SIZING: { + // TODO + + break; + } + + default: + break; + } + // TODO return DefWindowProc(hWnd, uMsg, wParam, lParam); @@ -143,6 +237,10 @@ int32_t CGxDeviceD3d::DeviceSetFormat(const CGxFormat& format) { } } +void CGxDeviceD3d::DeviceWM(EGxWM wm, uintptr_t param1, uintptr_t param2) { + // TODO +} + int32_t CGxDeviceD3d::ICreateD3d() { if (CGxDeviceD3d::ILoadD3dLib(this->m_d3dLib, this->m_d3d) && this->m_d3d->GetDeviceCaps(0, D3DDEVTYPE_HAL, &this->m_d3dCaps) >= S_OK) { if (this->m_desktopDisplayMode.Format != D3DFMT_UNKNOWN) { diff --git a/src/gx/d3d/CGxDeviceD3d.hpp b/src/gx/d3d/CGxDeviceD3d.hpp index a306b56..1bf587d 100644 --- a/src/gx/d3d/CGxDeviceD3d.hpp +++ b/src/gx/d3d/CGxDeviceD3d.hpp @@ -32,6 +32,7 @@ class CGxDeviceD3d : public CGxDevice { virtual void IRsSendToHw(EGxRenderState rs); virtual int32_t DeviceCreate(long (*windowProc)(void*, uint32_t, uint32_t, long), const CGxFormat& format); virtual int32_t DeviceSetFormat(const CGxFormat& format); + virtual void DeviceWM(EGxWM wm, uintptr_t param1, uintptr_t param2); virtual void CapsWindowSize(CRect& dst); virtual void CapsWindowSizeInScreenCoords(CRect& dst); virtual void PoolSizeSet(CGxPool* pool, uint32_t size); diff --git a/src/gx/gll/CGxDeviceGLL.hpp b/src/gx/gll/CGxDeviceGLL.hpp index 020adbc..8764418 100644 --- a/src/gx/gll/CGxDeviceGLL.hpp +++ b/src/gx/gll/CGxDeviceGLL.hpp @@ -31,6 +31,7 @@ class CGxDeviceGLL : public CGxDevice { virtual void IRsSendToHw(EGxRenderState); virtual int32_t DeviceCreate(long (*)(void*, uint32_t, uint32_t, long), const CGxFormat&); virtual int32_t DeviceSetFormat(const CGxFormat&); + virtual void DeviceWM(EGxWM wm, uintptr_t param1, uintptr_t param2) {}; virtual void CapsWindowSize(CRect&); virtual void CapsWindowSizeInScreenCoords(CRect& dst); virtual void ScenePresent(void);