Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to get compiling with Unreal 5.0 Preview 1 #62

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
56987d2
Updated ImGui to 1.87, added ImPlot v0.13 WIP and updated core plugin…
WiggleWizard Feb 19, 2022
ea84ccf
Updated readme with info about NetImGui branch
WiggleWizard Feb 19, 2022
d0034be
Added the ability to latch specific world's debug frame. Also moved I…
WiggleWizard Feb 25, 2022
e96a11a
Updated the way keys are handled to the new way ImGui now deals with …
WiggleWizard Feb 25, 2022
fa7134f
Updated readme with new changes
WiggleWizard Feb 25, 2022
7b055e4
Fixes to get compiling with Unreal 5.0 Preview 1
benui-dev Mar 1, 2022
14749e5
Fixed warnings from Unreal 5.0 Preview 1
benui-dev Mar 1, 2022
2b8f3e5
Support for general UTexture instead of being limited to Texture2D fo…
WiggleWizard Mar 25, 2022
48b1abd
Added some useful info into the readme about render textures. Also up…
WiggleWizard Mar 25, 2022
91825ac
Messing around trying to get input sharing to work
benui-dev Mar 26, 2022
b346fa8
Custom font support
WiggleWizard Apr 1, 2022
cb89223
Merged changes from WiggleWizard
benui-dev Apr 1, 2022
9496087
Cleaned up unused input processor
benui-dev Apr 14, 2022
cff6ff6
Fix compilation error on UE 5.1
sinbad Feb 16, 2023
0977194
UE5.1 Warning fix: C++ class refs must include module
sinbad Feb 20, 2023
8f61809
UE 5.2 fixes
sinbad Jul 11, 2023
5dc3b1f
Remove "Handler Down" debug message
sinbad Jul 11, 2023
2584667
Fix warning about plugin not referencing plugin
sinbad Jul 11, 2023
59645db
Fixing compile error on Unreal 5.3
Edstub207 Sep 21, 2023
f662f8b
Merge pull request #3 from Edstub207/patch-1
benui-dev Nov 1, 2023
487cd08
Merge pull request #1 from sinbad/master
benui-dev Nov 1, 2023
b7f9cb9
Update README.md
benui-dev Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ImGui.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
"Modules": [
{
"Name": "ImGui",
"Type": "Developer",
"Type": "DeveloperTool",
"LoadingPhase": "PreDefault"
}
],
"Plugins": [
{
"Name": "EnhancedInput",
"Enabled": true
}
]
}
371 changes: 133 additions & 238 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Source/ImGui/ImGui.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ImGui(TargetInfo Target)

PublicIncludePaths.AddRange(
new string[] {
Path.Combine(ModuleDirectory, "../ThirdParty/ImGuiLibrary/Include")
Path.Combine(ModuleDirectory, "../ThirdParty/ImGuiLibrary/Include"),
// ... add public include paths required here ...
}
);
Expand All @@ -42,7 +42,7 @@ public ImGui(TargetInfo Target)
PrivateIncludePaths.AddRange(
new string[] {
"ImGui/Private",
"ThirdParty/ImGuiLibrary/Private"
"ThirdParty/ImGuiLibrary/Private",
// ... add other private include paths required here ...
}
);
Expand All @@ -62,6 +62,7 @@ public ImGui(TargetInfo Target)
new string[]
{
"CoreUObject",
"EnhancedInput",
"Engine",
"InputCore",
"Slate",
Expand Down
20 changes: 18 additions & 2 deletions Source/ImGui/Private/ImGuiContextManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ImGuiDelegatesContainer.h"
#include "ImGuiImplementation.h"
#include "ImGuiModuleSettings.h"
#include "ImGuiModule.h"
#include "Utilities/WorldContext.h"
#include "Utilities/WorldContextIndex.h"

Expand Down Expand Up @@ -254,14 +255,29 @@ void FImGuiContextManager::SetDPIScale(const FImGuiDPIScaleInfo& ScaleInfo)
}
}

void FImGuiContextManager::BuildFontAtlas()
void FImGuiContextManager::BuildFontAtlas(const TMap<FName, TSharedPtr<ImFontConfig>>& CustomFontConfigs)
{
if (!FontAtlas.IsBuilt())
{
ImFontConfig FontConfig = {};
FontConfig.SizePixels = FMath::RoundFromZero(13.f * DPIScale);
FontAtlas.AddFontDefault(&FontConfig);

// Build custom fonts
for (const TPair<FName, TSharedPtr<ImFontConfig>>& CustomFontPair : CustomFontConfigs)
{
FName CustomFontName = CustomFontPair.Key;
TSharedPtr<ImFontConfig> CustomFontConfig = CustomFontPair.Value;

// Set font name for debugging
if (CustomFontConfig.IsValid())
{
strcpy_s(CustomFontConfig->Name, 40, TCHAR_TO_ANSI(*CustomFontName.ToString()));
}

FontAtlas.AddFont(CustomFontConfig.Get());
}

unsigned char* Pixels;
int Width, Height, Bpp;
FontAtlas.GetTexDataAsRGBA32(&Pixels, &Width, &Height, &Bpp);
Expand All @@ -283,5 +299,5 @@ void FImGuiContextManager::RebuildFontAtlas()
FontResourcesReleaseCountdown = 3;
}

BuildFontAtlas();
BuildFontAtlas(FImGuiModule::Get().GetProperties().GetCustomFonts());
}
5 changes: 3 additions & 2 deletions Source/ImGui/Private/ImGuiContextManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class FImGuiContextManager

void Tick(float DeltaSeconds);

void RebuildFontAtlas();

private:

struct FContextData
Expand Down Expand Up @@ -102,8 +104,7 @@ class FImGuiContextManager
FContextData& GetWorldContextData(const UWorld& World, int32* OutContextIndex = nullptr);

void SetDPIScale(const FImGuiDPIScaleInfo& ScaleInfo);
void BuildFontAtlas();
void RebuildFontAtlas();
void BuildFontAtlas(const TMap<FName, TSharedPtr<ImFontConfig>>& CustomFontConfigs = {});

TMap<int32, FContextData> Contexts;

Expand Down
4 changes: 2 additions & 2 deletions Source/ImGui/Private/ImGuiContextProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ FImGuiContextProxy::FImGuiContextProxy(const FString& InName, int32 InContextInd

// Start with the default canvas size.
ResetDisplaySize();
IO.DisplaySize = { DisplaySize.X, DisplaySize.Y };
IO.DisplaySize = {(float)DisplaySize.X, (float)DisplaySize.Y};

// Set the initial DPI scale.
SetDPIScale(InDPIScale);
Expand Down Expand Up @@ -211,7 +211,7 @@ void FImGuiContextProxy::BeginFrame(float DeltaTime)
ImGuiInterops::CopyInput(IO, InputState);
InputState.ClearUpdateState();

IO.DisplaySize = { DisplaySize.X, DisplaySize.Y };
IO.DisplaySize = { (float)DisplaySize.X, (float)DisplaySize.Y };

ImGui::NewFrame();

Expand Down
8 changes: 4 additions & 4 deletions Source/ImGui/Private/ImGuiDrawData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ void FImGuiDrawList::CopyVertexData(TArray<FSlateVertex>& OutVertexBuffer, const
SlateVertex.Position[1] = VertexPosition.Y;
SlateVertex.ClipRect = VertexClippingRect;
#else
#if ENGINE_COMPATIBILITY_LEGACY_VECTOR2F
SlateVertex.Position = Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos));
#else
SlateVertex.Position = (FVector2f)Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos));
#endif // ENGINE_COMPATIBILITY_LEGACY_VECTOR2F
#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API

// Unpack ImU32 color.
Expand All @@ -56,8 +60,4 @@ void FImGuiDrawList::TransferDrawData(ImDrawList& Src)
Src.CmdBuffer.swap(ImGuiCommandBuffer);
Src.IdxBuffer.swap(ImGuiIndexBuffer);
Src.VtxBuffer.swap(ImGuiVertexBuffer);

// ImGui seems to clear draw lists in every frame, but since source list can contain pointers to buffers that
// we just swapped, it is better to clear explicitly here.
Src.Clear();
}
7 changes: 6 additions & 1 deletion Source/ImGui/Private/ImGuiImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

// 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.

// UE 5.1 stopped defining PLATFORM_XBOXONE, so be safe if not defined
#if !defined(PLATFORM_XBOXONE)
#define PLATFORM_XBOXONE 0
#endif
#if PLATFORM_XBOXONE
// Disable Win32 functions used in ImGui and not supported on XBox.
#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
Expand Down Expand Up @@ -47,6 +50,8 @@ static FImGuiContextHandle ImGuiContextPtrHandle(ImGuiContextPtr);
#include "imgui_draw.cpp"
#include "imgui_widgets.cpp"

#include "imgui_tables.cpp"

#if PLATFORM_WINDOWS
#include <Windows/HideWindowsPlatformTypes.h>
#endif // PLATFORM_WINDOWS
Expand Down
13 changes: 13 additions & 0 deletions Source/ImGui/Private/ImGuiInputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ FReply UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent)
InputState->SetKeyDown(KeyEvent, true);
CopyModifierKeys(KeyEvent);

InputState->KeyDownEvents.Add(KeyEvent.GetKeyCode(), KeyEvent);

return ToReply(bConsume);
}
}

FReply UImGuiInputHandler::OnKeyUp(const FKeyEvent& KeyEvent)
{
InputState->KeyUpEvents.Add(KeyEvent.GetKeyCode(), KeyEvent);

if (KeyEvent.GetKey().IsGamepadKey())
{
bool bConsume = false;
Expand Down Expand Up @@ -126,6 +130,15 @@ FReply UImGuiInputHandler::OnMouseButtonDown(const FPointerEvent& MouseEvent)
}

InputState->SetMouseDown(MouseEvent, true);
if (ModuleManager)
{
FImGuiContextProxy* Proxy = ModuleManager->GetContextManager().GetContextProxy(0);
if (Proxy)
{
//GEngine->AddOnScreenDebugMessage(15, 10, Proxy->WantsMouseCapture() ? FColor::Green : FColor::Red, TEXT("Handler Down"));
return ToReply(Proxy->WantsMouseCapture());
}
}
return ToReply(true);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/ImGui/Private/ImGuiInputHandlerFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <InputCoreTypes.h>


UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(const FStringClassReference& HandlerClassReference, FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex)
UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(const FSoftClassPath& HandlerClassReference, FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex)
{
UClass* HandlerClass = nullptr;
if (HandlerClassReference.IsValid())
Expand Down
2 changes: 1 addition & 1 deletion Source/ImGui/Private/ImGuiInputHandlerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FImGuiInputHandlerFactory
{
public:

static UImGuiInputHandler* NewHandler(const FStringClassReference& HandlerClassReference, FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex);
static UImGuiInputHandler* NewHandler(const FSoftClassPath& HandlerClassReference, FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex);

static void ReleaseHandler(UImGuiInputHandler* Handler);
};
3 changes: 3 additions & 0 deletions Source/ImGui/Private/ImGuiInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void FImGuiInputState::ClearUpdateState()
{
ClearCharacters();

KeyDownEvents.Reset();
KeyUpEvents.Reset();

KeysUpdateRange.SetEmpty();
MouseButtonsUpdateRange.SetEmpty();

Expand Down
3 changes: 3 additions & 0 deletions Source/ImGui/Private/ImGuiInputState.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ class FImGuiInputState
// and information about dirty parts of keys or mouse buttons arrays.
void ClearUpdateState();

TMap<uint32, FKeyEvent> KeyDownEvents;
TMap<uint32, FKeyEvent> KeyUpEvents;

private:

void SetKeyDown(uint32 KeyIndex, bool bIsDown);
Expand Down
Loading