From 7301cdaa6cdd4b9276a167db4a01c8bed7a08ce9 Mon Sep 17 00:00:00 2001 From: bicarus-dev <202771338+bicarus-dev@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:56:52 -0700 Subject: [PATCH] imgui: reorganize imgui library files to mirror what's in the imgui releases (#285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Link to GitHub Issue, if one exists n/a ## Description of change Functionally, no change. Move ImGui library files around so that they mirror how they are structured in imgui releases. This will make it easier to migrate to a future version of ImGui. Add a handful of static asserts to check that we have the necessary features enabled / disabled in imgui header. ## Compiling 👍 ## Testing Tested 32-bit overlay, 64-bit overlay, TDJ, and UFC overlays, and spicecfg. Interesting finds during ImGui testing (not part of this PR, but for future reference when upgrading imgui version): * Updating dx9 backend to the newest causes TDJ to stop rendering the overlay completely (fine in UFC or any other game) * Omitting `IMGUI_USE_BGRA_PACKED_COLOR` causes spicecfg software renderer to use the wrong color (RGB format parsing error probably) * At some point - v1.90? the `About` and `Licenses` buttons in spicecfg stop responding after an upgrade, maybe our improper usage of MenuItem? * Using the docking branch of ImGui is not required but we should just stick to it for multi-viewport functionality which we may want to use later. --- src/spice2x/CMakeLists.txt | 3 +-- src/spice2x/external/imgui/CMakeLists.txt | 8 +++++--- .../imgui/backends/imgui_impl_dx9.cpp} | 4 ++-- .../imgui/backends/imgui_impl_dx9.h} | 2 +- .../external/imgui/{ => misc/cpp}/imgui_stdlib.cpp | 0 src/spice2x/external/imgui/{ => misc/cpp}/imgui_stdlib.h | 0 src/spice2x/overlay/imgui/impl_spice.cpp | 8 ++++++++ src/spice2x/overlay/overlay.cpp | 5 +---- src/spice2x/overlay/window.h | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-) rename src/spice2x/{overlay/imgui/impl_dx9.cpp => external/imgui/backends/imgui_impl_dx9.cpp} (99%) rename src/spice2x/{overlay/imgui/impl_dx9.h => external/imgui/backends/imgui_impl_dx9.h} (96%) rename src/spice2x/external/imgui/{ => misc/cpp}/imgui_stdlib.cpp (100%) rename src/spice2x/external/imgui/{ => misc/cpp}/imgui_stdlib.h (100%) diff --git a/src/spice2x/CMakeLists.txt b/src/spice2x/CMakeLists.txt index 9b395c5..de4af6c 100644 --- a/src/spice2x/CMakeLists.txt +++ b/src/spice2x/CMakeLists.txt @@ -211,7 +211,7 @@ add_compile_definitions( #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DACIOEMU_LOG") # add project directory to include path so we can comfortably import -include_directories(${spicetools_SOURCE_DIR}) +include_directories(${spicetools_SOURCE_DIR} ${spicetools_SOURCE_DIR}/external/imgui) # add external libraries add_subdirectory(external/fmt EXCLUDE_FROM_ALL) @@ -516,7 +516,6 @@ set(SOURCE_FILES ${SOURCE_FILES} overlay/overlay.cpp overlay/window.cpp overlay/imgui/extensions.cpp - overlay/imgui/impl_dx9.cpp overlay/imgui/impl_spice.cpp overlay/imgui/impl_sw.cpp overlay/windows/acio_status_buffers.cpp diff --git a/src/spice2x/external/imgui/CMakeLists.txt b/src/spice2x/external/imgui/CMakeLists.txt index 66dae4c..a66e9b7 100644 --- a/src/spice2x/external/imgui/CMakeLists.txt +++ b/src/spice2x/external/imgui/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.12) project(imgui CXX) # dear imgui uses the C++ virtual interfaces for DirectX @@ -8,7 +8,8 @@ set(IMGUI_HEADERS imconfig.h imgui.h imgui_internal.h - imgui_stdlib.h + backends/imgui_impl_dx9.h + misc/cpp/imgui_stdlib.h ) set(IMGUI_SOURCES imgui.cpp @@ -16,7 +17,8 @@ set(IMGUI_SOURCES imgui_tables.cpp imgui_widgets.cpp imgui_demo.cpp - imgui_stdlib.cpp + backends/imgui_impl_dx9.cpp + misc/cpp/imgui_stdlib.cpp ) add_library(imgui STATIC ${IMGUI_HEADERS} ${IMGUI_SOURCES}) diff --git a/src/spice2x/overlay/imgui/impl_dx9.cpp b/src/spice2x/external/imgui/backends/imgui_impl_dx9.cpp similarity index 99% rename from src/spice2x/overlay/imgui/impl_dx9.cpp rename to src/spice2x/external/imgui/backends/imgui_impl_dx9.cpp index 8d04e04..d193a92 100644 --- a/src/spice2x/overlay/imgui/impl_dx9.cpp +++ b/src/spice2x/external/imgui/backends/imgui_impl_dx9.cpp @@ -22,14 +22,14 @@ // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX9_RenderDrawData() in the .h file so you can call it yourself. // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. -#include "impl_dx9.h" +#include "imgui_impl_dx9.h" #include // DirectX #include -#include "external/imgui/imgui.h" +#include "imgui.h" // allow std::min use #ifdef min diff --git a/src/spice2x/overlay/imgui/impl_dx9.h b/src/spice2x/external/imgui/backends/imgui_impl_dx9.h similarity index 96% rename from src/spice2x/overlay/imgui/impl_dx9.h rename to src/spice2x/external/imgui/backends/imgui_impl_dx9.h index dff6431..90f60c2 100644 --- a/src/spice2x/overlay/imgui/impl_dx9.h +++ b/src/spice2x/external/imgui/backends/imgui_impl_dx9.h @@ -11,7 +11,7 @@ #pragma once -#include "external/imgui/imgui.h" +#include "imgui.h" struct IDirect3DDevice9; diff --git a/src/spice2x/external/imgui/imgui_stdlib.cpp b/src/spice2x/external/imgui/misc/cpp/imgui_stdlib.cpp similarity index 100% rename from src/spice2x/external/imgui/imgui_stdlib.cpp rename to src/spice2x/external/imgui/misc/cpp/imgui_stdlib.cpp diff --git a/src/spice2x/external/imgui/imgui_stdlib.h b/src/spice2x/external/imgui/misc/cpp/imgui_stdlib.h similarity index 100% rename from src/spice2x/external/imgui/imgui_stdlib.h rename to src/spice2x/external/imgui/misc/cpp/imgui_stdlib.h diff --git a/src/spice2x/overlay/imgui/impl_spice.cpp b/src/spice2x/overlay/imgui/impl_spice.cpp index 2d2dd18..74134a2 100644 --- a/src/spice2x/overlay/imgui/impl_spice.cpp +++ b/src/spice2x/overlay/imgui/impl_spice.cpp @@ -13,6 +13,14 @@ #include "util/logging.h" #include "util/utils.h" +#if !defined(IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS) || \ + !defined(IMGUI_DISABLE_DEFAULT_ALLOCATORS) || \ + !defined(IMGUI_USE_BGRA_PACKED_COLOR) || \ + !defined(IMGUI_HAS_VIEWPORT) || \ + !defined(IMGUI_HAS_DOCK) +#error "fix imconfig.h after updating imgui version" +#endif + // state static HWND g_hWnd = nullptr; static INT64 g_Time = 0; diff --git a/src/spice2x/overlay/overlay.cpp b/src/spice2x/overlay/overlay.cpp index 5718b1c..7597684 100644 --- a/src/spice2x/overlay/overlay.cpp +++ b/src/spice2x/overlay/overlay.cpp @@ -11,10 +11,7 @@ #include "util/resutils.h" #include "build/resource.h" -#include "imgui/impl_dx9.h" -#include "imgui/impl_spice.h" -#include "imgui/impl_sw.h" -#include "overlay/imgui/impl_dx9.h" +#include "external/imgui/backends/imgui_impl_dx9.h" #include "overlay/imgui/impl_spice.h" #include "overlay/imgui/impl_sw.h" diff --git a/src/spice2x/overlay/window.h b/src/spice2x/overlay/window.h index 07ae0ef..b7124ec 100644 --- a/src/spice2x/overlay/window.h +++ b/src/spice2x/overlay/window.h @@ -3,7 +3,7 @@ #include #include "external/imgui/imgui.h" -#include "external/imgui/imgui_stdlib.h" +#include "external/imgui/misc/cpp/imgui_stdlib.h" #include "overlay.h" namespace overlay {