feat(gx): handle window messages in d3d backend

This commit is contained in:
fallenoak 2023-03-06 08:44:13 -06:00 committed by GitHub
parent 49237bf68d
commit c34ea0f30d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 0 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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<CGxDeviceD3d*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
switch (uMsg) {
case WM_CREATE: {
auto lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LPARAM>(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<float>(HIWORD(lParam)),
static_cast<float>(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<uintptr_t>(&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) {

View File

@ -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);

View File

@ -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);