UnrealImGui/Source/ImGui/Private/ImGuiImplementation.cpp
Sebastian a76f4bc451 Improved hot-reload stability and support for reloading after recompiling outside of the editor:
- Hot-reloading from inside of the editor and after recompiling from the outside should be equally supported and work together.
- Improved robustness of the delegates redirections. There should be no lost delegates when reloading (either after in-editor or outside recompilation).
- Refactored code to use the same redirection template for context and delegates container.
2020-07-31 10:24:53 +01:00

71 lines
1.9 KiB
C++

// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#include "ImGuiImplementation.h"
#include <CoreMinimal.h>
// For convenience and easy access to the ImGui source code, we build it as part of this module.
// We don't need to define IMGUI_API manually because it is already done for this module.
#if PLATFORM_XBOXONE
// Disable Win32 functions used in ImGui and not supported on XBox.
#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
#endif // PLATFORM_XBOXONE
#if PLATFORM_WINDOWS
#include <Windows/AllowWindowsPlatformTypes.h>
#endif // PLATFORM_WINDOWS
#if WITH_EDITOR
#include "ImGuiModule.h"
#include "Utilities/RedirectingHandle.h"
// Redirecting handle which will automatically bind to another one, if a different instance of the module is loaded.
struct FImGuiContextHandle : public Utilities::TRedirectingHandle<ImGuiContext*>
{
FImGuiContextHandle(ImGuiContext*& InDefaultContext)
: Utilities::TRedirectingHandle<ImGuiContext*>(InDefaultContext)
{
if (FImGuiModule* Module = FModuleManager::GetModulePtr<FImGuiModule>("ImGui"))
{
SetParent(&Module->GetImGuiContextHandle());
}
}
};
static ImGuiContext* ImGuiContextPtr = nullptr;
static FImGuiContextHandle ImGuiContextPtrHandle(ImGuiContextPtr);
// Get the global ImGui context pointer (GImGui) indirectly to allow redirections in obsolete modules.
#define GImGui (ImGuiContextPtrHandle.Get())
#endif // WITH_EDITOR
#include "imgui.cpp"
#include "imgui_demo.cpp"
#include "imgui_draw.cpp"
#include "imgui_widgets.cpp"
#if PLATFORM_WINDOWS
#include <Windows/HideWindowsPlatformTypes.h>
#endif // PLATFORM_WINDOWS
#include "ImGuiInteroperability.h"
namespace ImGuiImplementation
{
#if WITH_EDITOR
FImGuiContextHandle& GetContextHandle()
{
return ImGuiContextPtrHandle;
}
void SetParentContextHandle(FImGuiContextHandle& Parent)
{
ImGuiContextPtrHandle.SetParent(&Parent);
}
#endif // WITH_EDITOR
}