From 73ff6907d723003d30e400f661876e7960de574f Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 6 Aug 2018 15:52:38 -0700 Subject: Add basic support for "Dear IMGUI" (#625) This isn't being made visible just yet, but it will allow us to have a simple UI for loading models into the model-viewer example. In order to support rendering with IMGUI I had to add the following to the `Renderer` layer: * viewports * scissor rects * blend support These are really only fully implemented for D3D11, but adding them to the other back-ends should be a reasonably small task. --- tools/gfx/window.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tools/gfx/window.cpp') diff --git a/tools/gfx/window.cpp b/tools/gfx/window.cpp index ee9f50813..9bc63b896 100644 --- a/tools/gfx/window.cpp +++ b/tools/gfx/window.cpp @@ -111,22 +111,53 @@ int runWindowsApplication( struct Window { HWND handle; + WNDPROC nativeHook; }; +void setNativeWindowHook(Window* window, WNDPROC proc) +{ + window->nativeHook = proc; +} + static LRESULT CALLBACK windowProc( HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam) { + Window* window = (Window*) GetWindowLongPtrW(windowHandle, GWLP_USERDATA); + + // Give the installed filter a chance to intercept messages. + // (This is used for ImGui) + if( window ) + { + if(auto nativeHook = window->nativeHook) + { + auto result = nativeHook(windowHandle, message, wParam, lParam); + if(result) + return result; + } + } + // TODO: Actually implement some reasonable logic here. switch (message) { + case WM_CREATE: + { + auto createInfo = (CREATESTRUCTW*) lParam; + window = (Window*) createInfo->lpCreateParams; + window->handle = windowHandle; + + SetWindowLongPtrW(windowHandle, GWLP_USERDATA, (LONG)window); + } + break; + case WM_CLOSE: PostQuitMessage(0); return 0; } + return DefWindowProcW(windowHandle, message, wParam, lParam); } @@ -159,6 +190,8 @@ static ATOM getWindowClassAtom() Window* createWindow(WindowDesc const& desc) { Window* window = new Window(); + window->handle = nullptr; + window->nativeHook = nullptr; OSString windowTitle(desc.title); -- cgit v1.2.3