From de923e949c621cb9a665729849dce5bbae70cd1c Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Thu, 23 Nov 2023 09:50:09 -0500 Subject: [PATCH] CogImGui: rework imgui lib integration --- .../Private/CogEngineWindow_Collisions.cpp | 4 +- .../Private/CogEngineWindow_Metrics.cpp | 2 +- .../Private/CogEngineWindow_OutputLog.cpp | 2 - .../Private/CogEngineWindow_Skeleton.cpp | 4 +- Plugins/Cog/Source/CogImgui/CogImgui.Build.cs | 77 +++++++------------ .../CogImgui/Private/CogImguiConfig.cpp | 12 +++ .../CogImgui/Private/CogImguiLinkage.cpp | 19 ----- .../CogImgui/Private/CogImguiModule.cpp | 22 +++++- .../Source/CogImgui/Public/CogImguiConfig.h | 13 ++++ .../CogWindow/Private/CogWindowManager.cpp | 1 - .../CogWindow/Private/CogWindowWidgets.cpp | 2 +- .../Cog/Source/ThirdParty/ImGui/imconfig.h | 2 +- .../Source/ThirdParty/ImGui/imgui.Build.cs | 1 + .../Source/ThirdParty/ImPlot/implot.Build.cs | 1 + .../Private/CogAIWindow_BehaviorTree.cpp | 4 +- .../Private/CogAbilityWindow_Abilities.cpp | 2 +- .../Private/CogAbilityWindow_Effects.cpp | 2 +- .../Private/CogAbilityWindow_Tags.cpp | 2 +- 18 files changed, 85 insertions(+), 87 deletions(-) create mode 100644 Plugins/Cog/Source/CogImgui/Private/CogImguiConfig.cpp delete mode 100644 Plugins/Cog/Source/CogImgui/Private/CogImguiLinkage.cpp create mode 100644 Plugins/Cog/Source/CogImgui/Public/CogImguiConfig.h diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp index 96f1ce9..0037553 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp @@ -155,14 +155,14 @@ void FCogEngineWindow_Collisions::RenderContent() //------------------------------------------------- for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) { - ImGui::PushID(ChannelIndex); - const FChannel& Channel = Channels[ChannelIndex]; if (Channel.IsValid == false) { continue; } + ImGui::PushID(ChannelIndex); + ImColor Color = FCogImguiHelper::ToImColor(Channel.Color); ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); ImGui::SameLine(); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Metrics.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Metrics.cpp index 173d4c8..9726ef4 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Metrics.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Metrics.cpp @@ -164,7 +164,7 @@ void FCogEngineWindow_Metrics::DrawMetricRow(const char* RowTitle, float Mitigat { ImGui::TableNextRow(); ImGui::TableNextColumn(); - ImGui::Selectable(RowTitle, false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap | ImGuiSelectableFlags_AllowDoubleClick); + ImGui::Selectable(RowTitle, false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick); ImGui::TableNextColumn(); ImGui::TextColored(Color, "%.1f", MitigatedValue); ImGui::TableNextColumn(); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp index 5ee702e..cca2271 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_OutputLog.cpp @@ -5,8 +5,6 @@ #include "Engine/Engine.h" #include "Misc/StringBuilder.h" -char ImGuiTextBuffer::EmptyString[1] = { 0 }; - //-------------------------------------------------------------------------------------------------------------------------- // UCogEngineWindow_OutputLog //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp index 7742c00..eceb947 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp @@ -160,11 +160,11 @@ void FCogEngineWindow_Skeleton::RenderBoneEntry(int32 BoneIndex, bool OpenAllChi //------------------------ if (BoneInfo.Children.Num() > 0 && Filter.IsActive() == false) { - OpenChildren = ImGui::TreeNodeEx("##Bone", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanFullWidth); + OpenChildren = ImGui::TreeNodeEx("##Bone", ImGuiSelectableFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth); } else { - ImGui::TreeNodeEx("##Bone", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanFullWidth); + ImGui::TreeNodeEx("##Bone", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiSelectableFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth); } const bool IsControlDown = ImGui::GetCurrentContext()->IO.KeyCtrl; diff --git a/Plugins/Cog/Source/CogImgui/CogImgui.Build.cs b/Plugins/Cog/Source/CogImgui/CogImgui.Build.cs index 90628e7..e1d0f31 100644 --- a/Plugins/Cog/Source/CogImgui/CogImgui.Build.cs +++ b/Plugins/Cog/Source/CogImgui/CogImgui.Build.cs @@ -5,61 +5,38 @@ public class CogImgui : ModuleRules { public CogImgui(ReadOnlyTargetRules Target) : base(Target) { - PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; - bLegacyPublicIncludePaths = false; + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicIncludePaths.AddRange( - new string[] { - Path.Combine(ModuleDirectory, "../ThirdParty/imgui/"), - Path.Combine(ModuleDirectory, "../ThirdParty/implot/"), - } - ); - - - PrivateIncludePaths.AddRange( - new string[] { - "ThirdParty/imgui", - "ThirdParty/implot", - } - ); - - - PublicDependencyModuleNames.AddRange( - new string[] - { - "Core", - "Projects" - } - ); - - - PrivateDependencyModuleNames.AddRange( - new string[] - { - "CoreUObject", - "Engine", - "InputCore", - "Slate", - "SlateCore", - } - ); + PublicDependencyModuleNames.AddRange(new[] + { + "Core", + "ImGui", + "ImPlot", + }); - DynamicallyLoadedModuleNames.AddRange( - new string[] - { - } - ); + PrivateDependencyModuleNames.AddRange(new[] + { + "ApplicationCore", + "CoreUObject", + "Engine", + "InputCore", + "Slate", + "SlateCore" + }); if (Target.bBuildEditor) { - PrivateDependencyModuleNames.AddRange( - new string[] - { - "EditorStyle", - "Settings", - "UnrealEd", - } - ); + PrivateDependencyModuleNames.AddRange(new[] + { + "MainFrame", + "EditorStyle", + "Settings", + "UnrealEd", + }); } + + PublicDefinitions.Add("IMGUI_USER_CONFIG=\"CogImGuiConfig.h\""); + PublicDefinitions.Add("IMGUI_API=COGIMGUI_API"); + PublicDefinitions.Add("IMPLOT_API=COGIMGUI_API"); } } diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiConfig.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiConfig.cpp new file mode 100644 index 0000000..5373087 --- /dev/null +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiConfig.cpp @@ -0,0 +1,12 @@ +#include "CogImGuiConfig.h" + +THIRD_PARTY_INCLUDES_START +#include +#include +#include +#include +#include +#include +#include +#include +THIRD_PARTY_INCLUDES_END \ No newline at end of file diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiLinkage.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiLinkage.cpp deleted file mode 100644 index 38410ac..0000000 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiLinkage.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "CoreMinimal.h" - -#if PLATFORM_WINDOWS -#include -#endif // PLATFORM_WINDOWS - -#include "imgui.cpp" -#include "imgui_demo.cpp" -#include "imgui_draw.cpp" -#include "imgui_tables.cpp" -#include "imgui_widgets.cpp" - -#include "implot.cpp" -#include "implot_demo.cpp" -#include "implot_items.cpp" - -#if PLATFORM_WINDOWS -#include -#endif // PLATFORM_WINDOWS \ No newline at end of file diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiModule.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiModule.cpp index f2069df..4c9a5c6 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiModule.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiModule.cpp @@ -1,8 +1,11 @@ #include "CogImguiModule.h" -#include "Engine/GameViewportClient.h" -#include "Widgets/Layout/SScaleBox.h" #include "CogImguiWidget.h" +#include "Engine/Engine.h" +#include "Engine/GameViewportClient.h" +#include "HAL/LowLevelMemTracker.h" +#include "HAL/UnrealMemory.h" +#include "Widgets/Layout/SScaleBox.h" #define LOCTEXT_NAMESPACE "FCogImguiModule" @@ -10,10 +13,23 @@ constexpr int32 Cog_ZOrder = 10000; +//-------------------------------------------------------------------------------------------------------------------------- +static void* ImGui_MemAlloc(size_t Size, void* UserData) +{ + LLM_SCOPE_BYNAME(TEXT("ImGui")); + return FMemory::Malloc(Size); +} + +//-------------------------------------------------------------------------------------------------------------------------- +static void ImGui_MemFree(void* Ptr, void* UserData) +{ + FMemory::Free(Ptr); +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogImguiModule::StartupModule() { - + ImGui::SetAllocatorFunctions(ImGui_MemAlloc, ImGui_MemFree); } //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiConfig.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiConfig.h new file mode 100644 index 0000000..24c7ce5 --- /dev/null +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiConfig.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Misc/AssertionMacros.h" + +#define IM_ASSERT(Expr) ensure(Expr) + +#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +#define IMGUI_DISABLE_OBSOLETE_KEYIO +#define IMGUI_DISABLE_WIN32_FUNCTIONS +#define IMGUI_DISABLE_DEFAULT_ALLOCATORS +#define IMGUI_DEFINE_MATH_OPERATORS + +#define ImTextureID class UTexture2D* diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp index 87b4794..599ec77 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowManager.cpp @@ -197,7 +197,6 @@ void UCogWindowManager::Render(float DeltaTime) ImGui::SetNextWindowBgAlpha(0.35f); } - ImGui::DockSpaceOverViewport(0, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingInCentralNode | ImGuiDockNodeFlags_AutoHideTabBar); Window->Render(DeltaTime); } } diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp index e171a4f..434f30f 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp @@ -381,7 +381,7 @@ bool FCogWindowWidgets::CheckBoxState(const char* Label, ECheckBoxState& State) const bool IsPressed = ImGui::CheckboxFlags(Label, &Flags, 3); - ImGui::PopStyleColor(6); + ImGui::PopStyleColor(5); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { diff --git a/Plugins/Cog/Source/ThirdParty/ImGui/imconfig.h b/Plugins/Cog/Source/ThirdParty/ImGui/imconfig.h index 7f45c93..291ce19 100644 --- a/Plugins/Cog/Source/ThirdParty/ImGui/imconfig.h +++ b/Plugins/Cog/Source/ThirdParty/ImGui/imconfig.h @@ -23,7 +23,7 @@ // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. -#define IMGUI_API __declspec( dllexport ) +//#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 clean your code of obsolete function/names. diff --git a/Plugins/Cog/Source/ThirdParty/ImGui/imgui.Build.cs b/Plugins/Cog/Source/ThirdParty/ImGui/imgui.Build.cs index d4de8b8..3089f09 100644 --- a/Plugins/Cog/Source/ThirdParty/ImGui/imgui.Build.cs +++ b/Plugins/Cog/Source/ThirdParty/ImGui/imgui.Build.cs @@ -6,5 +6,6 @@ public class ImGui : ModuleRules public ImGui(ReadOnlyTargetRules Target) : base(Target) { Type = ModuleType.External; + PublicSystemIncludePaths.Add(ModuleDirectory); } } diff --git a/Plugins/Cog/Source/ThirdParty/ImPlot/implot.Build.cs b/Plugins/Cog/Source/ThirdParty/ImPlot/implot.Build.cs index 9fdd7c3..ab7f090 100644 --- a/Plugins/Cog/Source/ThirdParty/ImPlot/implot.Build.cs +++ b/Plugins/Cog/Source/ThirdParty/ImPlot/implot.Build.cs @@ -6,5 +6,6 @@ public class ImPlot : ModuleRules public ImPlot(ReadOnlyTargetRules Target) : base(Target) { Type = ModuleType.External; + PublicSystemIncludePaths.Add(ModuleDirectory); } } diff --git a/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_BehaviorTree.cpp b/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_BehaviorTree.cpp index 7f4a648..d6f3ad1 100644 --- a/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_BehaviorTree.cpp +++ b/Plugins/CogAI/Source/CogAI/Private/CogAIWindow_BehaviorTree.cpp @@ -247,11 +247,11 @@ void FCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeC const bool HasChildren = CompositeNode != nullptr && CompositeNode->GetChildrenNum() > 0; if (HasChildren && Filter.IsActive() == false) { - OpenChildren = ImGui::TreeNodeEx("##Node", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanFullWidth); + OpenChildren = ImGui::TreeNodeEx("##Node", ImGuiSelectableFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth); } else { - ImGui::TreeNodeEx("##Node", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanFullWidth); + ImGui::TreeNodeEx("##Node", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiSelectableFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth); } const bool IsControlDown = ImGui::GetCurrentContext()->IO.KeyCtrl; diff --git a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp index bb90bf3..51826a2 100644 --- a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp +++ b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Abilities.cpp @@ -282,7 +282,7 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent& //------------------------ ImGui::TableNextColumn(); - if (ImGui::Selectable(TCHAR_TO_ANSI(*GetAbilityName(Ability)), SelectedIndex == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap | ImGuiSelectableFlags_AllowDoubleClick)) + if (ImGui::Selectable(TCHAR_TO_ANSI(*GetAbilityName(Ability)), SelectedIndex == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick)) { SelectedIndex = Index; diff --git a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Effects.cpp b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Effects.cpp index 80bde1a..72c05d2 100644 --- a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Effects.cpp +++ b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Effects.cpp @@ -203,7 +203,7 @@ void FCogAbilityWindow_Effects::RenderEffectRow(const UAbilitySystemComponent& A ImGui::PushStyleColor(ImGuiCol_Text, FCogImguiHelper::ToImVec4(AlignmentConfig->GetEffectColor(Asset, Effect))); - if (ImGui::Selectable(EffectName, Selected == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap | ImGuiSelectableFlags_AllowDoubleClick)) + if (ImGui::Selectable(EffectName, Selected == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick)) { Selected = Index; } diff --git a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp index 46e7af2..9a71000 100644 --- a/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp +++ b/Plugins/CogAbility/Source/CogAbility/Private/CogAbilityWindow_Tags.cpp @@ -125,7 +125,7 @@ void FCogAbilityWindow_Tags::RenderTagContainer(const UAbilitySystemComponent& A // Name //------------------------ ImGui::TableNextColumn(); - if (ImGui::Selectable(TCHAR_TO_ANSI(*Tag.GetTagName().ToString()), Selected == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap | ImGuiSelectableFlags_AllowDoubleClick)) + if (ImGui::Selectable(TCHAR_TO_ANSI(*Tag.GetTagName().ToString()), Selected == Index, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick)) { Selected = Index; }