From e05cea27898e3cefb22557d7bb62808340f9665f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 27 Nov 2018 20:54:26 +0000 Subject: [PATCH] Added to ImGui Context Manager an event raised when a new context proxy is created. --- Source/ImGui/Private/ImGuiContextManager.cpp | 4 ++++ Source/ImGui/Private/ImGuiContextManager.h | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Source/ImGui/Private/ImGuiContextManager.cpp b/Source/ImGui/Private/ImGuiContextManager.cpp index 0a13bdb..ad8e769 100644 --- a/Source/ImGui/Private/ImGuiContextManager.cpp +++ b/Source/ImGui/Private/ImGuiContextManager.cpp @@ -122,6 +122,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetEditorContextData() if (UNLIKELY(!Data)) { Data = &Contexts.Emplace(Utilities::EDITOR_CONTEXT_INDEX, FContextData{ GetEditorContextName(), Utilities::EDITOR_CONTEXT_INDEX, DrawMultiContextEvent, FontAtlas, -1 }); + ContextProxyCreatedEvent.Broadcast(Utilities::EDITOR_CONTEXT_INDEX, Data->ContextProxy); } return *Data; @@ -136,6 +137,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetStandaloneWorldCont if (UNLIKELY(!Data)) { Data = &Contexts.Emplace(Utilities::STANDALONE_GAME_CONTEXT_INDEX, FContextData{ GetWorldContextName(), Utilities::STANDALONE_GAME_CONTEXT_INDEX, DrawMultiContextEvent, FontAtlas }); + ContextProxyCreatedEvent.Broadcast(Utilities::STANDALONE_GAME_CONTEXT_INDEX, Data->ContextProxy); } return *Data; @@ -176,6 +178,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetWorldContextData(co if (UNLIKELY(!Data)) { Data = &Contexts.Emplace(Index, FContextData{ GetWorldContextName(World), Index, DrawMultiContextEvent, FontAtlas, WorldContext->PIEInstance }); + ContextProxyCreatedEvent.Broadcast(Index, Data->ContextProxy); } else { @@ -186,6 +189,7 @@ FImGuiContextManager::FContextData& FImGuiContextManager::GetWorldContextData(co if (UNLIKELY(!Data)) { Data = &Contexts.Emplace(Index, FContextData{ GetWorldContextName(World), Index, DrawMultiContextEvent, FontAtlas }); + ContextProxyCreatedEvent.Broadcast(Index, Data->ContextProxy); } #endif diff --git a/Source/ImGui/Private/ImGuiContextManager.h b/Source/ImGui/Private/ImGuiContextManager.h index a66f086..f810f77 100644 --- a/Source/ImGui/Private/ImGuiContextManager.h +++ b/Source/ImGui/Private/ImGuiContextManager.h @@ -5,6 +5,14 @@ #include "ImGuiContextProxy.h" +// TODO: It might be useful to broadcast FContextProxyCreatedDelegate to users, to support similar cases to our ImGui +// demo, but we would need to remove from that interface internal classes. + +// Delegate called when new context proxy is created. +// @param ContextIndex - Index for that world +// @param ContextProxy - Created context proxy +DECLARE_MULTICAST_DELEGATE_TwoParams(FContextProxyCreatedDelegate, int32, FImGuiContextProxy&); + // Manages ImGui context proxies. class FImGuiContextManager { @@ -51,6 +59,9 @@ public: // draw the same content to multiple contexts. FSimpleMulticastDelegate& OnDrawMultiContext() { return DrawMultiContextEvent; } + // Delegate called when new context proxy is created. + FContextProxyCreatedDelegate& OnContextProxyCreated() { return ContextProxyCreatedEvent; } + void Tick(float DeltaSeconds); private: @@ -107,5 +118,7 @@ private: FSimpleMulticastDelegate DrawMultiContextEvent; + FContextProxyCreatedDelegate ContextProxyCreatedEvent; + ImFontAtlas FontAtlas; };