2017-03-26 20:32:57 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ImGuiInteroperability.h"
|
2020-06-25 09:52:46 +00:00
|
|
|
#include "VersionCompatibility.h"
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2020-06-14 19:21:49 +00:00
|
|
|
#include <Rendering/RenderingCommon.h>
|
2017-03-26 20:32:57 +00:00
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
|
|
|
// ImGui draw command data transformed for Slate.
|
|
|
|
struct FImGuiDrawCommand
|
|
|
|
{
|
|
|
|
uint32 NumElements;
|
|
|
|
FSlateRect ClippingRect;
|
|
|
|
TextureIndex TextureId;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Wraps raw ImGui draw list data in utilities that transform them for Slate.
|
|
|
|
class FImGuiDrawList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Get the number of draw commands in this list.
|
|
|
|
FORCEINLINE int NumCommands() const { return ImGuiCommandBuffer.Size; }
|
|
|
|
|
|
|
|
// Get the draw command by number.
|
|
|
|
// @param CommandNb - Number of draw command
|
2018-04-17 19:28:29 +00:00
|
|
|
// @param Transform - Transform to apply to clipping rectangle
|
2017-03-26 20:32:57 +00:00
|
|
|
// @returns Draw command data
|
2018-04-17 19:28:29 +00:00
|
|
|
FImGuiDrawCommand GetCommand(int CommandNb, const FTransform2D& Transform) const
|
2017-03-26 20:32:57 +00:00
|
|
|
{
|
|
|
|
const ImDrawCmd& ImGuiCommand = ImGuiCommandBuffer[CommandNb];
|
2018-04-17 19:28:29 +00:00
|
|
|
return { ImGuiCommand.ElemCount, TransformRect(Transform, ImGuiInterops::ToSlateRect(ImGuiCommand.ClipRect)),
|
|
|
|
ImGuiInterops::ToTextureIndex(ImGuiCommand.TextureId) };
|
2017-03-26 20:32:57 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 21:20:33 +00:00
|
|
|
#if ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API
|
2017-03-26 20:32:57 +00:00
|
|
|
// Transform and copy vertex data to target buffer (old data in the target buffer are replaced).
|
|
|
|
// @param OutVertexBuffer - Destination buffer
|
2018-04-17 19:28:29 +00:00
|
|
|
// @param Transform - Transform to apply to all vertices
|
|
|
|
// @param VertexClippingRect - Clipping rectangle for transformed Slate vertices
|
|
|
|
void CopyVertexData(TArray<FSlateVertex>& OutVertexBuffer, const FTransform2D& Transform, const FSlateRotatedRect& VertexClippingRect) const;
|
2017-11-05 19:41:34 +00:00
|
|
|
#else
|
|
|
|
// Transform and copy vertex data to target buffer (old data in the target buffer are replaced).
|
|
|
|
// @param OutVertexBuffer - Destination buffer
|
2018-04-17 19:28:29 +00:00
|
|
|
// @param Transform - Transform to apply to all vertices
|
|
|
|
void CopyVertexData(TArray<FSlateVertex>& OutVertexBuffer, const FTransform2D& Transform) const;
|
2018-08-10 21:20:33 +00:00
|
|
|
#endif // ENGINE_COMPATIBILITY_LEGACY_CLIPPING_API
|
2017-03-26 20:32:57 +00:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
// @param OutIndexBuffer - Destination buffer
|
2017-11-05 19:41:34 +00:00
|
|
|
// @param StartIndex - Start copying source data starting from this index
|
2017-03-26 20:32:57 +00:00
|
|
|
// @param NumElements - How many elements we want to copy
|
|
|
|
void CopyIndexData(TArray<SlateIndex>& OutIndexBuffer, const int32 StartIndex, const int32 NumElements) const;
|
|
|
|
|
|
|
|
// Transfers data from ImGui source list to this object. Leaves source cleared.
|
|
|
|
void TransferDrawData(ImDrawList& Src);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ImVector<ImDrawCmd> ImGuiCommandBuffer;
|
|
|
|
ImVector<ImDrawIdx> ImGuiIndexBuffer;
|
|
|
|
ImVector<ImDrawVert> ImGuiVertexBuffer;
|
|
|
|
};
|