CogImGui: rework imgui lib integration

This commit is contained in:
Arnaud Jamin
2023-11-23 09:50:09 -05:00
parent 988b048bde
commit de923e949c
18 changed files with 85 additions and 87 deletions
@@ -155,14 +155,14 @@ void FCogEngineWindow_Collisions::RenderContent()
//------------------------------------------------- //-------------------------------------------------
for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex)
{ {
ImGui::PushID(ChannelIndex);
const FChannel& Channel = Channels[ChannelIndex]; const FChannel& Channel = Channels[ChannelIndex];
if (Channel.IsValid == false) if (Channel.IsValid == false)
{ {
continue; continue;
} }
ImGui::PushID(ChannelIndex);
ImColor Color = FCogImguiHelper::ToImColor(Channel.Color); ImColor Color = FCogImguiHelper::ToImColor(Channel.Color);
ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine(); ImGui::SameLine();
@@ -164,7 +164,7 @@ void FCogEngineWindow_Metrics::DrawMetricRow(const char* RowTitle, float Mitigat
{ {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); 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::TableNextColumn();
ImGui::TextColored(Color, "%.1f", MitigatedValue); ImGui::TextColored(Color, "%.1f", MitigatedValue);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@@ -5,8 +5,6 @@
#include "Engine/Engine.h" #include "Engine/Engine.h"
#include "Misc/StringBuilder.h" #include "Misc/StringBuilder.h"
char ImGuiTextBuffer::EmptyString[1] = { 0 };
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
// UCogEngineWindow_OutputLog // UCogEngineWindow_OutputLog
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -160,11 +160,11 @@ void FCogEngineWindow_Skeleton::RenderBoneEntry(int32 BoneIndex, bool OpenAllChi
//------------------------ //------------------------
if (BoneInfo.Children.Num() > 0 && Filter.IsActive() == false) 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 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; const bool IsControlDown = ImGui::GetCurrentContext()->IO.KeyCtrl;
+27 -50
View File
@@ -5,61 +5,38 @@ public class CogImgui : ModuleRules
{ {
public CogImgui(ReadOnlyTargetRules Target) : base(Target) public CogImgui(ReadOnlyTargetRules Target) : base(Target)
{ {
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
bLegacyPublicIncludePaths = false;
PublicIncludePaths.AddRange( PublicDependencyModuleNames.AddRange(new[]
new string[] { {
Path.Combine(ModuleDirectory, "../ThirdParty/imgui/"), "Core",
Path.Combine(ModuleDirectory, "../ThirdParty/implot/"), "ImGui",
} "ImPlot",
); });
PrivateIncludePaths.AddRange(
new string[] {
"ThirdParty/imgui",
"ThirdParty/implot",
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Projects"
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"InputCore",
"Slate",
"SlateCore",
}
);
DynamicallyLoadedModuleNames.AddRange( PrivateDependencyModuleNames.AddRange(new[]
new string[] {
{ "ApplicationCore",
} "CoreUObject",
); "Engine",
"InputCore",
"Slate",
"SlateCore"
});
if (Target.bBuildEditor) if (Target.bBuildEditor)
{ {
PrivateDependencyModuleNames.AddRange( PrivateDependencyModuleNames.AddRange(new[]
new string[] {
{ "MainFrame",
"EditorStyle", "EditorStyle",
"Settings", "Settings",
"UnrealEd", "UnrealEd",
} });
);
} }
PublicDefinitions.Add("IMGUI_USER_CONFIG=\"CogImGuiConfig.h\"");
PublicDefinitions.Add("IMGUI_API=COGIMGUI_API");
PublicDefinitions.Add("IMPLOT_API=COGIMGUI_API");
} }
} }
@@ -0,0 +1,12 @@
#include "CogImGuiConfig.h"
THIRD_PARTY_INCLUDES_START
#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>
THIRD_PARTY_INCLUDES_END
@@ -1,19 +0,0 @@
#include "CoreMinimal.h"
#if PLATFORM_WINDOWS
#include <Windows/AllowWindowsPlatformTypes.h>
#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 <Windows/HideWindowsPlatformTypes.h>
#endif // PLATFORM_WINDOWS
@@ -1,8 +1,11 @@
#include "CogImguiModule.h" #include "CogImguiModule.h"
#include "Engine/GameViewportClient.h"
#include "Widgets/Layout/SScaleBox.h"
#include "CogImguiWidget.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" #define LOCTEXT_NAMESPACE "FCogImguiModule"
@@ -10,10 +13,23 @@
constexpr int32 Cog_ZOrder = 10000; 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() void FCogImguiModule::StartupModule()
{ {
ImGui::SetAllocatorFunctions(ImGui_MemAlloc, ImGui_MemFree);
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -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*
@@ -197,7 +197,6 @@ void UCogWindowManager::Render(float DeltaTime)
ImGui::SetNextWindowBgAlpha(0.35f); ImGui::SetNextWindowBgAlpha(0.35f);
} }
ImGui::DockSpaceOverViewport(0, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoDockingInCentralNode | ImGuiDockNodeFlags_AutoHideTabBar);
Window->Render(DeltaTime); Window->Render(DeltaTime);
} }
} }
@@ -381,7 +381,7 @@ bool FCogWindowWidgets::CheckBoxState(const char* Label, ECheckBoxState& State)
const bool IsPressed = ImGui::CheckboxFlags(Label, &Flags, 3); const bool IsPressed = ImGui::CheckboxFlags(Label, &Flags, 3);
ImGui::PopStyleColor(6); ImGui::PopStyleColor(5);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary))
{ {
+1 -1
View File
@@ -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. // 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() // 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. // 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 ) //#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. //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
+1
View File
@@ -6,5 +6,6 @@ public class ImGui : ModuleRules
public ImGui(ReadOnlyTargetRules Target) : base(Target) public ImGui(ReadOnlyTargetRules Target) : base(Target)
{ {
Type = ModuleType.External; Type = ModuleType.External;
PublicSystemIncludePaths.Add(ModuleDirectory);
} }
} }
+1
View File
@@ -6,5 +6,6 @@ public class ImPlot : ModuleRules
public ImPlot(ReadOnlyTargetRules Target) : base(Target) public ImPlot(ReadOnlyTargetRules Target) : base(Target)
{ {
Type = ModuleType.External; Type = ModuleType.External;
PublicSystemIncludePaths.Add(ModuleDirectory);
} }
} }
@@ -247,11 +247,11 @@ void FCogAIWindow_BehaviorTree::RenderNode(UBehaviorTreeComponent& BehaviorTreeC
const bool HasChildren = CompositeNode != nullptr && CompositeNode->GetChildrenNum() > 0; const bool HasChildren = CompositeNode != nullptr && CompositeNode->GetChildrenNum() > 0;
if (HasChildren && Filter.IsActive() == false) if (HasChildren && Filter.IsActive() == false)
{ {
OpenChildren = ImGui::TreeNodeEx("##Node", ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_SpanFullWidth); OpenChildren = ImGui::TreeNodeEx("##Node", ImGuiSelectableFlags_AllowOverlap | ImGuiTreeNodeFlags_SpanFullWidth);
} }
else 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; const bool IsControlDown = ImGui::GetCurrentContext()->IO.KeyCtrl;
@@ -282,7 +282,7 @@ void FCogAbilityWindow_Abilities::RenderAbilitiesTable(UAbilitySystemComponent&
//------------------------ //------------------------
ImGui::TableNextColumn(); 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; SelectedIndex = Index;
@@ -203,7 +203,7 @@ void FCogAbilityWindow_Effects::RenderEffectRow(const UAbilitySystemComponent& A
ImGui::PushStyleColor(ImGuiCol_Text, FCogImguiHelper::ToImVec4(AlignmentConfig->GetEffectColor(Asset, Effect))); 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; Selected = Index;
} }
@@ -125,7 +125,7 @@ void FCogAbilityWindow_Tags::RenderTagContainer(const UAbilitySystemComponent& A
// Name // Name
//------------------------ //------------------------
ImGui::TableNextColumn(); 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; Selected = Index;
} }