Skip to content

Commit

Permalink
Hack in a test window for ImGui
Browse files Browse the repository at this point in the history
  • Loading branch information
chreden committed Jan 23, 2022
1 parent 33dc3a8 commit b514ec1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
8 changes: 8 additions & 0 deletions trview.app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
#include <trview.app/Settings/IStartupOptions.h>
#include <trview.ui.render/DefaultFonts.h>

#include <external/imgui/backends/imgui_impl_win32.h>

using namespace DirectX::SimpleMath;

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

namespace trview
{
namespace
Expand Down Expand Up @@ -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);
}

Expand Down
43 changes: 41 additions & 2 deletions trview.app/Windows/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include <trview.common/Strings.h>

#include <external/imgui/imgui.h>
#include <external/imgui/backends/imgui_impl_win32.h>
#include <external/imgui/backends/imgui_impl_dx11.h>

namespace trview
{
namespace
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -565,6 +587,8 @@ namespace trview
_mouse_changed = false;
}

_ui_changed = true;

if (_scene_changed || _ui_changed)
{
_device->begin();
Expand All @@ -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);
}

Expand All @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion trview.app/Windows/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace trview
const graphics::IRenderTarget::SizeSource& render_target_source,
const graphics::IDeviceWindow::Source& device_window_source,
std::unique_ptr<ISectorHighlight> sector_highlight);
virtual ~Viewer() = default;
virtual ~Viewer();
virtual CameraMode camera_mode() const override;
virtual void render() override;
virtual void open(ILevel* level) override;
Expand Down
11 changes: 7 additions & 4 deletions trview.app/trview.app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated""</Command>
<None Include="Resources\Generated\ui_vertex_shader.cso" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\external\imgui\imgui.vcxproj">
<Project>{6aabd08e-3361-4d84-88f0-851ee588162a}</Project>
</ProjectReference>
<ProjectReference Include="..\external\lua\lua.vcxproj">
<Project>{2a4f1e89-71ac-46c3-a711-1a4d67accdf5}</Project>
</ProjectReference>
Expand Down Expand Up @@ -472,7 +475,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated""</Command>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
Expand All @@ -497,7 +500,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated""</Command>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
Expand All @@ -520,7 +523,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated""</Command>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
Expand All @@ -545,7 +548,7 @@ copy ""$(OutDir)*.cso"" ""$(ProjectDir)Resources\Generated""</Command>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir);$(SolutionDir)external\DirectXTK\Inc;$(ProjectDir);$(SolutionDir)external\imgui</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
Expand Down

0 comments on commit b514ec1

Please sign in to comment.