#include "common.hpp" #include "fonts.hpp" #include "logger.hpp" #include "gui.hpp" #include "pointers.hpp" #include "renderer.hpp" #include "imgui/imgui.h" #include "imgui/imgui_impl_dx11.h" #include "imgui/imgui_impl_win32.h" IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); namespace big { renderer::renderer() : m_dxgi_swapchain(*g_pointers->m_swapchain) { void *d3d_device{}; if (SUCCEEDED(m_dxgi_swapchain->GetDevice(__uuidof(ID3D11Device), &d3d_device))) { m_d3d_device.Attach(static_cast(d3d_device)); } else { throw std::runtime_error("Failed to get D3D device."); } m_d3d_device->GetImmediateContext(m_d3d_device_context.GetAddressOf()); ImGui::CreateContext(); ImGui_ImplDX11_Init(m_d3d_device.Get(), m_d3d_device_context.Get()); ImGui_ImplWin32_Init(g_pointers->m_hwnd); ImFontConfig font_cfg{}; font_cfg.FontDataOwnedByAtlas = false; std::strcpy(font_cfg.Name, "Rubik"); m_font = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(const_cast(font_rubik), sizeof(font_rubik), 20.f, &font_cfg); m_monospace_font = ImGui::GetIO().Fonts->AddFontDefault(); g_gui.dx_init(); g_renderer = this; } renderer::~renderer() { ImGui_ImplWin32_Shutdown(); ImGui_ImplDX11_Shutdown(); ImGui::DestroyContext(); g_renderer = nullptr; } void renderer::on_present() { if (g_gui.m_opened) { ImGui::GetIO().MouseDrawCursor = true; ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NoMouse; } else { ImGui::GetIO().MouseDrawCursor = false; ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouse; } ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); if (g_gui.m_opened) { g_gui.dx_on_tick(); } ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); } void renderer::pre_reset() { ImGui_ImplDX11_InvalidateDeviceObjects(); } void renderer::post_reset() { ImGui_ImplDX11_CreateDeviceObjects(); } void renderer::wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (msg == WM_KEYUP && wparam == VK_INSERT) g_gui.m_opened ^= true; if (g_gui.m_opened) { ImGui_ImplWin32_WndProcHandler(hwnd, msg, wparam, lparam); } } }