Start aligning Dx and OpenGl approaches.

This commit is contained in:
jmsgrogan 2023-01-05 08:46:01 +00:00
parent d1ec8b4f68
commit d99a36f24f
22 changed files with 899 additions and 366 deletions

View file

@ -20,7 +20,7 @@ Win32Window::Win32Window(mt::Window* window, Win32DxInterface* dxInterface)
{
if (dxInterface)
{
mDxInterface = std::make_unique<Win32DxWindowInterface>(dxInterface);
mDxInterface = std::make_unique<Win32DxWindowInterface>(window, dxInterface);
}
}
@ -80,6 +80,13 @@ void Win32Window::createNative(Win32ApplicationContext* context, DesktopManager*
MLOG_INFO("Request window create got handle: " << "0x" << mHandle);
}
void Win32Window::onPaintMessage()
{
mDesktopManager->onUiEvent(PaintEvent::Create());
mWindow->doPaint(nullptr);
}
LRESULT CALLBACK Win32Window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
@ -89,7 +96,6 @@ LRESULT CALLBACK Win32Window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
PostQuitMessage(0);
return 0;
}
case WM_CHAR:
{
auto key_event = std::make_unique<KeyboardEvent>();
@ -99,25 +105,9 @@ LRESULT CALLBACK Win32Window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
key_event->setKeyString(StringUtils::convert(std::wstring(1, keyChar)));
mDesktopManager->onUiEvent(std::move(key_event));
}
case WM_PAINT:
{
if (mDxInterface)
{
mDxInterface->onRender();
}
else
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(mHandle, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
auto text = L"Hello World";
auto val = DrawText(hdc, (LPCSTR)(&text[0]), -1, &ps.rcPaint, 0);
EndPaint(mHandle, &ps);
}
onPaintMessage();
}
}
return DefWindowProc(mHandle, message, wParam, lParam);
@ -136,7 +126,9 @@ static LRESULT CALLBACK FreeWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPAR
if (::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)window) == 0)
{
if (GetLastError() != 0)
{
return FALSE;
}
}
}
else
@ -157,6 +149,26 @@ void Win32Window::beforePaint(mt::Screen* screen)
{
if (mDxInterface)
{
mDxInterface->initialize(mWindow);
mDxInterface->initialize();
}
}
void Win32Window::afterPaint(mt::Screen* screen)
{
if (mDxInterface)
{
mDxInterface->onRender();
}
else
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(mHandle, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
auto text = L"Hello World";
auto val = DrawText(hdc, (LPCSTR)(&text[0]), -1, &ps.rcPaint, 0);
EndPaint(mHandle, &ps);
}
}