Skip to content

Commit

Permalink
Setup ImGui during CMake build
Browse files Browse the repository at this point in the history
  • Loading branch information
alipbcs committed Sep 5, 2023
1 parent 3153050 commit 3c57d81
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 60,731 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ External/*
!External/concurrentqueue
!External/FastDelegate
!External/FSR2
!External/ImGui
!External/ImGui/imconfig.h
!External/stb
!External/json

Expand Down
54 changes: 54 additions & 0 deletions CMake/SetupImGui.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function(SetupImGui)
set(IMGUI_VER "1.89.8")
set(IMPLOT_VER "0.15")
set(IMNODES_COMMIT "d88f99125bb72cdb71b4c27ff6eb7f318d89a4c5")
set(IMGUI_DIR "${EXTERNAL_DIR}/ImGui")
file(GLOB_RECURSE HEADER_PATH "${IMGUI_DIR}/*imgui.h")

if(HEADER_PATH STREQUAL "")
# download ImGui source code
set(URL "https://github.com/ocornut/imgui/archive/refs/tags/v${IMGUI_VER}.zip")
message(STATUS "Downloading ImGui ${IMGUI_VER} from ${URL}...")
set(ARCHIVE_PATH "${IMGUI_DIR}/temp/imgui.zip")
file(DOWNLOAD "${URL}" "${ARCHIVE_PATH}" TIMEOUT 120)
file(ARCHIVE_EXTRACT INPUT "${ARCHIVE_PATH}" DESTINATION "${IMGUI_DIR}/temp")

# download ImPlot source code
set(URL "https://github.com/epezent/implot/archive/refs/tags/v${IMPLOT_VER}.zip")
message(STATUS "Downloading ImPlot ${IMPLOT_VER} from ${URL}...")
set(ARCHIVE_PATH "${IMGUI_DIR}/temp/implot.zip")
file(DOWNLOAD "${URL}" "${ARCHIVE_PATH}" TIMEOUT 120)
file(ARCHIVE_EXTRACT INPUT "${ARCHIVE_PATH}" DESTINATION "${IMGUI_DIR}/temp")

# download imnodes source code
set(URL "https://github.com/Nelarius/imnodes/archive/${IMNODES_COMMIT}.zip")
message(STATUS "Downloading imnodes from ${URL}...")
set(ARCHIVE_PATH "${IMGUI_DIR}/temp/imnodes.zip")
file(DOWNLOAD "${URL}" "${ARCHIVE_PATH}" TIMEOUT 120)
file(ARCHIVE_EXTRACT INPUT "${ARCHIVE_PATH}" DESTINATION "${IMGUI_DIR}/temp")

# copy headers & source files
set(FILES
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imgui_draw.cpp"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imgui_internal.h"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imgui_tables.cpp"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imgui_widgets.cpp"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imgui.cpp"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imgui.h"
"${IMGUI_DIR}/temp/imnodes-${IMNODES_COMMIT}/imnodes_internal.h"
"${IMGUI_DIR}/temp/imnodes-${IMNODES_COMMIT}/imnodes.cpp"
"${IMGUI_DIR}/temp/imnodes-${IMNODES_COMMIT}/imnodes.h"
"${IMGUI_DIR}/temp/implot-${IMPLOT_VER}/implot_internal.h"
"${IMGUI_DIR}/temp/implot-${IMPLOT_VER}/implot_items.cpp"
"${IMGUI_DIR}/temp/implot-${IMPLOT_VER}/implot.cpp"
"${IMGUI_DIR}/temp/implot-${IMPLOT_VER}/implot.h"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imstb_rectpack.h"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imstb_textedit.h"
"${IMGUI_DIR}/temp/imgui-${IMGUI_VER}/imstb_truetype.h")

file(COPY ${FILES} DESTINATION ${IMGUI_DIR})

# cleanup
file(REMOVE_RECURSE "${IMGUI_DIR}/temp")
endif()
endfunction()
50 changes: 28 additions & 22 deletions External/ImGui/imconfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
// DEAR IMGUI COMPILE-TIME OPTIONS
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
Expand All @@ -9,7 +9,7 @@
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------

#pragma once
Expand All @@ -26,20 +26,21 @@
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )

//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.

//---- Disable all of Dear ImGui or don't implement standard windows.
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger and other debug tools: ShowMetricsWindow() and ShowStackToolWindow() will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).

//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
Expand All @@ -61,33 +62,43 @@
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
#define IMGUI_STB_SPRINTF_FILENAME "../stb/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.

//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
#define IMGUI_USE_STB_SPRINTF

//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
//#define IMGUI_ENABLE_FREETYPE

//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
// Only works in combination with IMGUI_ENABLE_FREETYPE.
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
//#define IMGUI_ENABLE_FREETYPE_LUNASVG

//---- Use stb_truetype to build and rasterize the font atlas (default)
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
//#define IMGUI_ENABLE_STB_TRUETYPE

//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
#define IM_VEC2_CLASS_EXTRA \
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
#define IM_VEC4_CLASS_EXTRA \
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
//---- ...Or use Dear ImGui's own very basic math operators.
#define IMGUI_DEFINE_MATH_OPERATORS

//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
Expand All @@ -101,23 +112,18 @@
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
//#define ImDrawCallback MyImDrawCallback

//---- Debug Tools: Macro to break in Debugger
//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase)
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
//#define IM_DEBUG_BREAK IM_ASSERT(0)
//#define IM_DEBUG_BREAK __debugbreak()

//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
// This adds a small runtime cost which is why it is not enabled by default.
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX

//---- Debug Tools: Enable slower asserts
//#define IMGUI_DEBUG_PARANOID

//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
/*
namespace ImGui
{
void MyFunction(const char* name, const MyMatrix44& v);
void MyFunction(const char* name, MyMatrix44* mtx);
}
*/

0 comments on commit 3c57d81

Please sign in to comment.