Removed custom scope guard and replaced it with TGuardValue defined in the engine.

This commit is contained in:
Sebastian 2020-06-28 18:59:01 +01:00
parent c7d36a802b
commit 5b737e111e
3 changed files with 3 additions and 65 deletions

View File

@ -5,7 +5,6 @@
#include "ImGuiDelegatesContainer.h" #include "ImGuiDelegatesContainer.h"
#include "ImGuiImplementation.h" #include "ImGuiImplementation.h"
#include "ImGuiModuleSettings.h" #include "ImGuiModuleSettings.h"
#include "Utilities/ScopeGuards.h"
#include "Utilities/WorldContext.h" #include "Utilities/WorldContext.h"
#include "Utilities/WorldContextIndex.h" #include "Utilities/WorldContextIndex.h"

View File

@ -1,58 +0,0 @@
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#pragma once
namespace ScopeGuards
{
// Saves snapshot of the object state and restores it during destruction.
template<typename T>
class TStateSaver
{
public:
// Constructor taking target object in state that we want to save.
TStateSaver(T& Target)
: Ptr(&Target)
, Value(Target)
{
}
// Move constructor allowing to transfer state out of scope.
TStateSaver(TStateSaver&& Other)
: Ptr(Other.Ptr)
, Value(MoveTemp(Other.Value))
{
// Release responsibility from the other object (std::exchange currently not supported by all platforms).
Other.Ptr = nullptr;
}
// Non-assignable to enforce acquisition on construction.
TStateSaver& operator=(TStateSaver&&) = delete;
// Non-copyable.
TStateSaver(const TStateSaver&) = delete;
TStateSaver& operator=(const TStateSaver&) = delete;
~TStateSaver()
{
if (Ptr)
{
*Ptr = Value;
}
}
private:
T* Ptr;
T Value;
};
// Create a state saver for target object. Unless saver is moved, state will be restored at the end of scope.
// @param Target - Target object in state that we want to save
// @returns State saver that unless moved, will restore target's state during scope exit
template<typename T>
TStateSaver<T> MakeStateSaver(T& Target)
{
return TStateSaver<T>{ Target };
}
}

View File

@ -12,7 +12,6 @@
#include "ImGuiModuleSettings.h" #include "ImGuiModuleSettings.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "Utilities/Arrays.h" #include "Utilities/Arrays.h"
#include "Utilities/ScopeGuards.h"
#include "VersionCompatibility.h" #include "VersionCompatibility.h"
#include <Engine/Console.h> #include <Engine/Console.h>
@ -647,10 +646,6 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo
{ {
#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API #if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API
DrawList.CopyVertexData(VertexBuffer, ImGuiToScreen, VertexClippingRect); DrawList.CopyVertexData(VertexBuffer, ImGuiToScreen, VertexClippingRect);
// Get access to the Slate scissor rectangle defined in Slate Core API, so we can customize elements drawing.
extern SLATECORE_API TOptional<FShortRect> GSlateScissorRect;
auto GSlateScissorRectSaver = ScopeGuards::MakeStateSaver(GSlateScissorRect);
#else #else
DrawList.CopyVertexData(VertexBuffer, ImGuiToScreen); DrawList.CopyVertexData(VertexBuffer, ImGuiToScreen);
#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API #endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API
@ -672,7 +667,9 @@ int32 SImGuiWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo
const FSlateRect ClippingRect = DrawCommand.ClippingRect.IntersectionWith(MyClippingRect); const FSlateRect ClippingRect = DrawCommand.ClippingRect.IntersectionWith(MyClippingRect);
#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API #if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API
GSlateScissorRect = FShortRect{ ClippingRect }; // Get access to the Slate scissor rectangle defined in Slate Core API, so we can customize elements drawing.
extern SLATECORE_API TOptional<FShortRect> GSlateScissorRect;
TGuardValue<TOptional<FShortRect>> GSlateScissorRecGuard(GSlateScissorRect, FShortRect{ ClippingRect });
#else #else
OutDrawElements.PushClip(FSlateClippingZone{ ClippingRect }); OutDrawElements.PushClip(FSlateClippingZone{ ClippingRect });
#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API #endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API