From b514ec16264794c897d040593e1ac9bc8a94b847 Mon Sep 17 00:00:00 2001 From: chreden <4263940+chreden@users.noreply.github.com> Date: Tue, 18 Jan 2022 14:14:19 +0000 Subject: [PATCH] Hack in a test window for ImGui #402 --- trview.app/Application.cpp | 8 +++++++ trview.app/Windows/Viewer.cpp | 43 +++++++++++++++++++++++++++++++++-- trview.app/Windows/Viewer.h | 2 +- trview.app/trview.app.vcxproj | 11 +++++---- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/trview.app/Application.cpp b/trview.app/Application.cpp index de5bb2296..f28ad4557 100644 --- a/trview.app/Application.cpp +++ b/trview.app/Application.cpp @@ -27,8 +27,12 @@ #include #include +#include + using namespace DirectX::SimpleMath; +extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + namespace trview { namespace @@ -56,6 +60,10 @@ namespace trview LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + if (ImGui_ImplWin32_WndProcHandler(hWnd, message, wParam, lParam)) + { + return true; + } return DefWindowProc(hWnd, message, wParam, lParam); } diff --git a/trview.app/Windows/Viewer.cpp b/trview.app/Windows/Viewer.cpp index feba552e8..219494d72 100644 --- a/trview.app/Windows/Viewer.cpp +++ b/trview.app/Windows/Viewer.cpp @@ -7,6 +7,10 @@ #include +#include +#include +#include + namespace trview { namespace @@ -322,6 +326,24 @@ namespace trview }; register_lua(); + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + // Setup Platform/Renderer backends + ImGui_ImplWin32_Init(window); + ImGui_ImplDX11_Init(device->device().Get(), device->context().Get()); + } + + Viewer::~Viewer() + { + ImGui_ImplDX11_Shutdown(); + ImGui_ImplWin32_Shutdown(); + ImGui::DestroyContext(); } void Viewer::initialise_input() @@ -565,6 +587,8 @@ namespace trview _mouse_changed = false; } + _ui_changed = true; + if (_scene_changed || _ui_changed) { _device->begin(); @@ -590,6 +614,19 @@ namespace trview _ui->render(); _ui_changed = false; + ImGui_ImplDX11_NewFrame(); + ImGui_ImplWin32_NewFrame(); + ImGui::NewFrame(); + + { + ImGui::Begin("Tomb Raider Legend Glitche"); + ImGui::Text("Nice Glitch bug vid"); + ImGui::End(); + } + + ImGui::Render(); + ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + _main_window->present(_settings.vsync); } @@ -598,7 +635,8 @@ namespace trview bool Viewer::should_pick() const { - return !(!_level || window_under_cursor() != _window || window_is_minimised(_window) || _ui->is_cursor_over() || cursor_outside_window(_window)); + auto& io = ImGui::GetIO(); + return !(!_level || window_under_cursor() != _window || window_is_minimised(_window) || _ui->is_cursor_over() || cursor_outside_window(_window) || io.WantCaptureMouse || io.WantCaptureKeyboard); } void Viewer::render_scene() @@ -911,7 +949,8 @@ namespace trview _token_store += _camera_input.on_pan += [&](bool vertical, float x, float y) { - if (_ui->is_cursor_over() || _camera_mode != CameraMode::Orbit) + auto& io = ImGui::GetIO(); + if (_ui->is_cursor_over() || io.WantCaptureKeyboard || io.WantCaptureMouse || _camera_mode != CameraMode::Orbit) { return; } diff --git a/trview.app/Windows/Viewer.h b/trview.app/Windows/Viewer.h index d8e2a7458..6eb235c3d 100644 --- a/trview.app/Windows/Viewer.h +++ b/trview.app/Windows/Viewer.h @@ -65,7 +65,7 @@ namespace trview const graphics::IRenderTarget::SizeSource& render_target_source, const graphics::IDeviceWindow::Source& device_window_source, std::unique_ptr sector_highlight); - virtual ~Viewer() = default; + virtual ~Viewer(); virtual CameraMode camera_mode() const override; virtual void render() override; virtual void open(ILevel* level) override; diff --git a/trview.app/trview.app.vcxproj b/trview.app/trview.app.vcxproj index 58cc916cd..48b977e71 100644 --- a/trview.app/trview.app.vcxproj +++ b/trview.app/trview.app.vcxproj @@ -376,6 +376,9 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated"" + + {6aabd08e-3361-4d84-88f0-851ee588162a} + {2a4f1e89-71ac-46c3-a711-1a4d67accdf5} @@ -472,7 +475,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated"" true NDEBUG;_LIB;%(PreprocessorDefinitions) true - $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir) + $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui stdafx.h stdcpp17 stdafx.h @@ -497,7 +500,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated"" true WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true - $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir) + $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui stdafx.h stdcpp17 stdafx.h @@ -520,7 +523,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated"" true _DEBUG;_LIB;%(PreprocessorDefinitions) true - $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir) + $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui stdafx.h stdcpp17 stdafx.h @@ -545,7 +548,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated"" true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true - $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir) + $(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui stdafx.h stdcpp17 stdafx.h