diff --git a/Source/ImGui/Private/ImGuiContextProxy.cpp b/Source/ImGui/Private/ImGuiContextProxy.cpp index 18318e4..6a49b60 100644 --- a/Source/ImGui/Private/ImGuiContextProxy.cpp +++ b/Source/ImGui/Private/ImGuiContextProxy.cpp @@ -23,10 +23,10 @@ namespace { FString GetSaveDirectory() { -#if (ENGINE_MAJOR_VERSION > 4 || (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION >= 18)) - const FString SavedDir = FPaths::ProjectSavedDir(); -#else +#if ENGINE_COMPATIBILITY_LEGACY_SAVED_DIR const FString SavedDir = FPaths::GameSavedDir(); +#else + const FString SavedDir = FPaths::ProjectSavedDir(); #endif FString Directory = FPaths::Combine(*SavedDir, TEXT("ImGui")); diff --git a/Source/ImGui/Private/ImGuiDrawData.cpp b/Source/ImGui/Private/ImGuiDrawData.cpp index c2ed960..c524df8 100644 --- a/Source/ImGui/Private/ImGuiDrawData.cpp +++ b/Source/ImGui/Private/ImGuiDrawData.cpp @@ -5,11 +5,11 @@ #include "ImGuiDrawData.h" -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API void FImGuiDrawList::CopyVertexData(TArray& OutVertexBuffer, const FTransform2D& Transform, const FSlateRotatedRect& VertexClippingRect) const #else void FImGuiDrawList::CopyVertexData(TArray& OutVertexBuffer, const FTransform2D& Transform) const -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API { // Reset and reserve space in destination buffer. OutVertexBuffer.SetNumUninitialized(ImGuiVertexBuffer.Size, false); @@ -25,14 +25,14 @@ void FImGuiDrawList::CopyVertexData(TArray& OutVertexBuffer, const SlateVertex.TexCoords[1] = ImGuiVertex.uv.y; SlateVertex.TexCoords[2] = SlateVertex.TexCoords[3] = 1.f; -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API const FVector2D VertexPosition = Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos)); SlateVertex.Position[0] = VertexPosition.X; SlateVertex.Position[1] = VertexPosition.Y; SlateVertex.ClipRect = VertexClippingRect; #else SlateVertex.Position = Transform.TransformPoint(ImGuiInterops::ToVector2D(ImGuiVertex.pos)); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Unpack ImU32 color. SlateVertex.Color = ImGuiInterops::UnpackImU32Color(ImGuiVertex.col); diff --git a/Source/ImGui/Private/ImGuiDrawData.h b/Source/ImGui/Private/ImGuiDrawData.h index c179e95..2f6e404 100644 --- a/Source/ImGui/Private/ImGuiDrawData.h +++ b/Source/ImGui/Private/ImGuiDrawData.h @@ -10,10 +10,6 @@ #include -// Starting from version 4.17 Slate doesn't have per-vertex clipping rectangle and GSlateScissorRect. Use this to -// support older engine versions. -#define WITH_OBSOLETE_CLIPPING_API (ENGINE_MAJOR_VERSION < 4 || (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 17)) - // ImGui draw command data transformed for Slate. struct FImGuiDrawCommand { @@ -41,7 +37,7 @@ public: ImGuiInterops::ToTextureIndex(ImGuiCommand.TextureId) }; } -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Transform and copy vertex data to target buffer (old data in the target buffer are replaced). // @param OutVertexBuffer - Destination buffer // @param Transform - Transform to apply to all vertices @@ -52,7 +48,7 @@ public: // @param OutVertexBuffer - Destination buffer // @param Transform - Transform to apply to all vertices void CopyVertexData(TArray& OutVertexBuffer, const FTransform2D& Transform) const; -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Transform and copy index data to target buffer (old data in the target buffer are replaced). // Internal index buffer contains enough data to match the sum of NumElements from all draw commands. diff --git a/Source/ImGui/Private/ImGuiInputHandler.cpp b/Source/ImGui/Private/ImGuiInputHandler.cpp index de5fd96..fa3c845 100644 --- a/Source/ImGui/Private/ImGuiInputHandler.cpp +++ b/Source/ImGui/Private/ImGuiInputHandler.cpp @@ -15,10 +15,6 @@ #include #include #include - -// Version 4.18 added support for dual key bindings. -#include -#define WITH_SINGLE_KEY_BINDING (ENGINE_MAJOR_VERSION < 4 || (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 18)) #endif // WITH_EDITOR @@ -64,7 +60,7 @@ bool UImGuiInputHandler::IsStopPlaySessionEvent(const FKeyEvent& KeyEvent) const if (StopPlaySessionCommandInfo.IsValid()) { const FInputChord InputChord(KeyEvent.GetKey(), KeyEvent.IsShiftDown(), KeyEvent.IsControlDown(), KeyEvent.IsAltDown(), KeyEvent.IsCommandDown()); -#if WITH_SINGLE_KEY_BINDING +#if ENGINE_COMPATIBILITY_SINGLE_KEY_BINDING const bool bHasActiveChord = (InputChord == StopPlaySessionCommandInfo->GetActiveChord().Get()); #else const bool bHasActiveChord = StopPlaySessionCommandInfo->HasActiveChord(InputChord); diff --git a/Source/ImGui/Private/ImGuiPrivatePCH.h b/Source/ImGui/Private/ImGuiPrivatePCH.h index 8ca3fce..ae53c90 100644 --- a/Source/ImGui/Private/ImGuiPrivatePCH.h +++ b/Source/ImGui/Private/ImGuiPrivatePCH.h @@ -2,6 +2,7 @@ // Module #include "ImGuiModule.h" +#include "VersionCompatibility.h" // Engine #include diff --git a/Source/ImGui/Private/ImGuiSettings.h b/Source/ImGui/Private/ImGuiSettings.h index feb1eab..6310173 100644 --- a/Source/ImGui/Private/ImGuiSettings.h +++ b/Source/ImGui/Private/ImGuiSettings.h @@ -7,10 +7,8 @@ #include #include -// Select right soft class reference header to avoid warning (new header contains FSoftClassPath to FStringClassReference -// typedef, so we will use that as a common denominator). -#include -#if (ENGINE_MAJOR_VERSION < 4 || (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 18)) +// Select right soft class reference header to avoid warning. +#if ENGINE_COMPATIBILITY_LEGACY_STRING_CLASS_REF #include #else #include diff --git a/Source/ImGui/Private/SImGuiWidget.cpp b/Source/ImGui/Private/SImGuiWidget.cpp index e2e2781..631473c 100644 --- a/Source/ImGui/Private/SImGuiWidget.cpp +++ b/Source/ImGui/Private/SImGuiWidget.cpp @@ -836,7 +836,7 @@ namespace }); } -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API void AddQuad(TArray& OutVertexBuffer, TArray& OutIndexBuffer, const FVector2D& Position, const FVector2D& Size, const FVector2D& UVMin, const FVector2D& UVMax, const FColor& Color, const FSlateRotatedClipRectType& InClipRect) { @@ -871,7 +871,7 @@ namespace OutIndexBuffer.Append({ IndexOffset + 0U, IndexOffset + 1U, IndexOffset + 2U, IndexOffset + 0U, IndexOffset + 2U, IndexOffset + 3U }); } -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API } int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, @@ -889,14 +889,14 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo // Calculate transform between ImGui canvas ans screen space (scale and then offset in Screen Space). const FTransform2D Transform{ ImGuiFrameCanvasScale, RoundToFloat(CanvasScreenSpacePosition) }; -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Convert clipping rectangle to format required by Slate vertex. const FSlateRotatedRect VertexClippingRect{ MyClippingRect }; -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API for (const auto& DrawList : ContextProxy->GetDrawData()) { -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API DrawList.CopyVertexData(VertexBuffer, Transform, VertexClippingRect); // Get access to the Slate scissor rectangle defined in Slate Core API, so we can customize elements drawing. @@ -904,7 +904,7 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo auto GSlateScissorRectSaver = ScopeGuards::MakeStateSaver(GSlateScissorRect); #else DrawList.CopyVertexData(VertexBuffer, Transform); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API int IndexBufferOffset = 0; for (int CommandNb = 0; CommandNb < DrawList.NumCommands(); CommandNb++) @@ -922,18 +922,18 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo // Transform clipping rectangle to screen space and apply to elements that we draw. const FSlateRect ClippingRect = DrawCommand.ClippingRect.IntersectionWith(MyClippingRect); -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API GSlateScissorRect = FShortRect{ ClippingRect }; #else OutDrawElements.PushClip(FSlateClippingZone{ ClippingRect }); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Add elements to the list. FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, Handle, VertexBuffer, IndexBuffer, nullptr, 0, 0); -#if !WITH_OBSOLETE_CLIPPING_API +#if !ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API OutDrawElements.PopClip(); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API } } @@ -970,13 +970,13 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo { IndexBuffer.SetNum(0, false); VertexBuffer.SetNum(0, false); -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API AddQuad(VertexBuffer, IndexBuffer, DeadZoneScreenSpaceMin, MyClippingRect.GetBottomRight() - DeadZoneScreenSpaceMin, FVector2D::ZeroVector, FVector2D::ZeroVector, CanvasFrameColor.WithAlpha(128), VertexClippingRect); #else AddQuad(VertexBuffer, IndexBuffer, DeadZoneScreenSpaceMin, MyClippingRect.GetBottomRight() - DeadZoneScreenSpaceMin, FVector2D::ZeroVector, FVector2D::ZeroVector, CanvasFrameColor.WithAlpha(128)); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API const FSlateResourceHandle& Handle = ModuleManager->GetTextureManager().GetTextureHandle(PlainTextureIndex); FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, Handle, VertexBuffer, IndexBuffer, nullptr, 0, 0); @@ -985,13 +985,13 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo // Draw a scaled canvas border. AddLocalRectanglePoints(Points, AllottedGeometry, CanvasScreenSpacePosition, CanvasSizeScaled); -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API FSlateDrawElement::MakeLines(OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), Points, MyClippingRect, ESlateDrawEffect::None, FLinearColor{ CanvasFrameColor }, false); #else FSlateDrawElement::MakeLines(OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), Points, ESlateDrawEffect::None, FLinearColor{ CanvasFrameColor }, false); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API // Draw a movement gizmo (using ImGui move cursor). FVector2D Size, UVMin, UVMax, OutlineUVMin, OutlineUVMax; @@ -1002,13 +1002,13 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo { IndexBuffer.SetNum(0, false); VertexBuffer.SetNum(0, false); -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API AddQuad(VertexBuffer, IndexBuffer, ViewportScreenSpacePosition + ViewportSizeScaled * 0.5f - Size * 0.375f, Size * 0.75f, UVMin, UVMax, FrameColor.WithAlpha(bCanvasDragging ? 32 : 128), VertexClippingRect); #else AddQuad(VertexBuffer, IndexBuffer, ViewportScreenSpacePosition + ViewportSizeScaled * 0.5f - Size * 0.375f, Size * 0.75f, UVMin, UVMax, FrameColor.WithAlpha(bCanvasDragging ? 32 : 128)); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API const FSlateResourceHandle& Handle = ModuleManager->GetTextureManager().GetTextureHandle(FontAtlasIndex); FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, Handle, VertexBuffer, IndexBuffer, nullptr, 0, 0); } @@ -1018,13 +1018,13 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo // Draw frame representing area of the ImGui canvas that is visible when scale is 1. Points.SetNum(0, false); AddLocalRectanglePoints(Points, AllottedGeometry, ViewportScreenSpacePosition, ViewportSizeScaled); -#if WITH_OBSOLETE_CLIPPING_API +#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API FSlateDrawElement::MakeLines(OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), Points, MyClippingRect, ESlateDrawEffect::None, FLinearColor{ FrameColor }, false); #else FSlateDrawElement::MakeLines(OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), Points, ESlateDrawEffect::None, FLinearColor{ FrameColor }, false); -#endif // WITH_OBSOLETE_CLIPPING_API +#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API } } diff --git a/Source/ImGui/Private/VersionCompatibility.h b/Source/ImGui/Private/VersionCompatibility.h new file mode 100644 index 0000000..04e6005 --- /dev/null +++ b/Source/ImGui/Private/VersionCompatibility.h @@ -0,0 +1,25 @@ +// Distributed under the MIT License (MIT) (see accompanying LICENSE file) + +#include + +#define BELOW_ENGINE_VERSION(Major, Minor) (ENGINE_MAJOR_VERSION < (Major) || (ENGINE_MAJOR_VERSION == (Major) && ENGINE_MINOR_VERSION < (Minor))) +#define FROM_ENGINE_VERSION(Major, Minor) !BELOW_ENGINE_VERSION(Major, Minor) + + +// One place to define compatibility with older engine versions. + + +// Starting from version 4.17 Slate has an improved clipping API. Old version required to specify per-vertex clipping +// rectangle and unofficial GSlateScissorRect to correctly clip custom vertices made with FSlateDrawElement. +#define ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API BELOW_ENGINE_VERSION(4, 17) + +// Starting from version 4.18 FPaths::GameSavedDir() has been superseded by FPaths::ProjectSavedDir(). +#define ENGINE_COMPATIBILITY_LEGACY_SAVED_DIR BELOW_ENGINE_VERSION(4, 18) + +// Starting from version 4.18 we have support for dual key bindings. +#define ENGINE_COMPATIBILITY_SINGLE_KEY_BINDING BELOW_ENGINE_VERSION(4, 18) + +// Starting from version 4.18 FStringClassReference is replaced by FSoftClassPath. The new header contains a typedef +// that renames FStringClassReference to FSoftClassPath, so it is still possible tu use the old type name in code. +// The old header forwards to the new one but if used it outputs a warning, so we want to avoid it. +#define ENGINE_COMPATIBILITY_LEGACY_STRING_CLASS_REF BELOW_ENGINE_VERSION(4, 18)