mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-01 04:10:06 +00:00
First Submit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using UnrealBuildTool;
|
||||
using System.IO;
|
||||
|
||||
public class CogImgui : ModuleRules
|
||||
{
|
||||
public CogImgui(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
bLegacyPublicIncludePaths = false;
|
||||
|
||||
PublicIncludePaths.AddRange(
|
||||
new string[] {
|
||||
Path.Combine(ModuleDirectory, "../ThirdParty/imgui/"),
|
||||
Path.Combine(ModuleDirectory, "../ThirdParty/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(
|
||||
new string[]
|
||||
{
|
||||
}
|
||||
);
|
||||
|
||||
if (Target.bBuildEditor)
|
||||
{
|
||||
PrivateDependencyModuleNames.AddRange(
|
||||
new string[]
|
||||
{
|
||||
"EditorStyle",
|
||||
"Settings",
|
||||
"UnrealEd",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "CogImguiDrawList.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiDrawList::CopyVertexData(TArray<FSlateVertex>& OutVertexBuffer, const FTransform2D& Transform) const
|
||||
{
|
||||
// Reset and reserve space in destination buffer.
|
||||
OutVertexBuffer.SetNumUninitialized(ImGuiVertexBuffer.Size, false);
|
||||
|
||||
// Transform and copy vertex data.
|
||||
for (int Idx = 0; Idx < ImGuiVertexBuffer.Size; Idx++)
|
||||
{
|
||||
const ImDrawVert& ImGuiVertex = ImGuiVertexBuffer[Idx];
|
||||
FSlateVertex& SlateVertex = OutVertexBuffer[Idx];
|
||||
|
||||
// Final UV is calculated in shader as XY * ZW, so we need set all components.
|
||||
SlateVertex.TexCoords[0] = ImGuiVertex.uv.x;
|
||||
SlateVertex.TexCoords[1] = ImGuiVertex.uv.y;
|
||||
SlateVertex.TexCoords[2] = SlateVertex.TexCoords[3] = 1.f;
|
||||
|
||||
const FVector2D VertexPosition = Transform.TransformPoint(FCogImguiHelper::ToVector2D(ImGuiVertex.pos));
|
||||
SlateVertex.Position[0] = VertexPosition.X;
|
||||
SlateVertex.Position[1] = VertexPosition.Y;
|
||||
|
||||
// Unpack ImU32 color.
|
||||
SlateVertex.Color = FCogImguiHelper::UnpackImU32Color(ImGuiVertex.col);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FCogImguiDrawList::DrawCommand FCogImguiDrawList::GetCommand(int CommandCount, const FTransform2D& Transform) const
|
||||
{
|
||||
const ImDrawCmd& ImGuiCommand = ImGuiCommandBuffer[CommandCount];
|
||||
return
|
||||
{
|
||||
ImGuiCommand.ElemCount,
|
||||
TransformRect(Transform, FCogImguiHelper::ToSlateRect(ImGuiCommand.ClipRect)),
|
||||
FCogImguiHelper::ToTextureIndex(ImGuiCommand.TextureId)
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiDrawList::CopyIndexData(TArray<SlateIndex>& OutIndexBuffer, const int32 StartIndex, const int32 NumElements) const
|
||||
{
|
||||
// Reset buffer.
|
||||
OutIndexBuffer.SetNumUninitialized(NumElements, false);
|
||||
|
||||
// Copy elements (slow copy because of different sizes of ImDrawIdx and SlateIndex and because SlateIndex can
|
||||
// have different size on different platforms).
|
||||
for (int i = 0; i < NumElements; i++)
|
||||
{
|
||||
OutIndexBuffer[i] = ImGuiIndexBuffer[StartIndex + i];
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiDrawList::TransferDrawData(ImDrawList& Src)
|
||||
{
|
||||
// Move data from source to this list.
|
||||
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._ResetForNewFrame();
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
#include "CogImguiHelper.h"
|
||||
|
||||
#include "InputCoreTypes.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
FString FCogImguiHelper::GetIniSaveDirectory()
|
||||
{
|
||||
const FString SavedDir = FPaths::ProjectSavedDir();
|
||||
const FString Directory = FPaths::Combine(*SavedDir, TEXT("ImGui"));
|
||||
IPlatformFile::GetPlatformPhysical().CreateDirectory(*Directory);
|
||||
return Directory;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
FString FCogImguiHelper::GetIniFilePath(const FString& Filename)
|
||||
{
|
||||
FString SaveDirectory = GetIniSaveDirectory();
|
||||
FString FilePath = FPaths::Combine(SaveDirectory, Filename + TEXT(".ini"));
|
||||
return FilePath;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImGuiWindow* FCogImguiHelper::GetCurrentWindow()
|
||||
{
|
||||
ImGuiContext& Context = *ImGui::GetCurrentContext();
|
||||
Context.CurrentWindow->WriteAccessed = true;
|
||||
return Context.CurrentWindow;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FColor FCogImguiHelper::UnpackImU32Color(ImU32 Color)
|
||||
{
|
||||
return FColor
|
||||
{
|
||||
(uint8)((Color >> IM_COL32_R_SHIFT) & 0xFF),
|
||||
(uint8)((Color >> IM_COL32_G_SHIFT) & 0xFF),
|
||||
(uint8)((Color >> IM_COL32_B_SHIFT) & 0xFF),
|
||||
(uint8)((Color >> IM_COL32_A_SHIFT) & 0xFF)
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FSlateRect FCogImguiHelper::ToSlateRect(const ImVec4& Value)
|
||||
{
|
||||
return FSlateRect{ Value.x, Value.y, Value.z, Value.w };
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FVector2D FCogImguiHelper::ToVector2D(const ImVec2& Value)
|
||||
{
|
||||
return FVector2D(Value.x, Value.y);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImVec2 FCogImguiHelper::ToImVec2(const FVector2D& Value)
|
||||
{
|
||||
return ImVec2(Value.X, Value.Y);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImColor FCogImguiHelper::ToImColor(const FColor& Value)
|
||||
{
|
||||
return ImColor(Value.R, Value.G, Value.B, Value.A);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImColor FCogImguiHelper::ToImColor(const FLinearColor& Value)
|
||||
{
|
||||
return ImColor(Value.R, Value.G, Value.B, Value.A);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImVec4 FCogImguiHelper::ToImVec4(const FColor& Value)
|
||||
{
|
||||
return ToImColor(Value).Value;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImVec4 FCogImguiHelper::ToImVec4(const FLinearColor& Value)
|
||||
{
|
||||
return ImVec4(Value.R, Value.G, Value.B, Value.A);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImVec4 FCogImguiHelper::ToImVec4(const FVector4f& Value)
|
||||
{
|
||||
return ImVec4(Value.X, Value.Y, Value.Z, Value.W);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImU32 FCogImguiHelper::ToImU32(const FColor& Value)
|
||||
{
|
||||
return (ImU32)ToImColor(Value);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImU32 FCogImguiHelper::ToImU32(const FVector4f& Value)
|
||||
{
|
||||
return ImGui::GetColorU32(ToImVec4(Value));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiHelper::ToTextureIndex(ImTextureID Index)
|
||||
{
|
||||
return static_cast<CogTextureIndex>(reinterpret_cast<intptr_t>(Index));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImTextureID FCogImguiHelper::ToImTextureID(CogTextureIndex Index)
|
||||
{
|
||||
return reinterpret_cast<ImTextureID>(static_cast<intptr_t>(Index));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FVector2D FCogImguiHelper::RoundVector(const FVector2D& Vector)
|
||||
{
|
||||
return FVector2D(FMath::RoundToFloat(Vector.X), FMath::RoundToFloat(Vector.Y));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FSlateRenderTransform FCogImguiHelper::RoundTranslation(const FSlateRenderTransform& Transform)
|
||||
{
|
||||
return FSlateRenderTransform(Transform.GetMatrix(), RoundVector(Transform.GetTranslation()));
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
#include "CogImguiInputHelper.h"
|
||||
|
||||
#include "CogImguiModule.h"
|
||||
#include "Framework/Commands/UICommandInfo.h"
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
#include "GameFramework/InputSettings.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "InputCoreTypes.h"
|
||||
|
||||
#if WITH_EDITOR
|
||||
#include "Kismet2/DebuggerCommands.h"
|
||||
#endif //WITH_EDITOR
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TMap<FKey, ImGuiKey> FCogImguiInputHelper::KeyMap;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
APlayerController* FCogImguiInputHelper::GetFirstLocalPlayerController(UWorld& World)
|
||||
{
|
||||
for (FConstPlayerControllerIterator Iterator = World.GetPlayerControllerIterator(); Iterator; ++Iterator)
|
||||
{
|
||||
APlayerController* PlayerController = Iterator->Get();
|
||||
if (PlayerController->IsLocalController())
|
||||
{
|
||||
return PlayerController;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::IsKeyEventHandled(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
if (FCogImguiModule::Get().GetEnableInput() == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (KeyEvent.GetKey().IsGamepadKey())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsConsoleEvent(KeyEvent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsStopPlaySessionEvent(KeyEvent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsImGuiToggleInputEvent(KeyEvent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::IsCheckBoxStateMatchingValue(ECheckBoxState CheckBoxState, bool bValue)
|
||||
{
|
||||
const bool Result = (CheckBoxState == ECheckBoxState::Undetermined) || ((CheckBoxState == ECheckBoxState::Checked) == bValue);
|
||||
return Result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::IsKeyEventMatchingKeyInfo(const FKeyEvent& KeyEvent, const FCogImGuiKeyInfo& KeyInfo)
|
||||
{
|
||||
const bool Result = (KeyInfo.Key == KeyEvent.GetKey())
|
||||
&& IsCheckBoxStateMatchingValue(KeyInfo.Shift, KeyEvent.IsShiftDown())
|
||||
&& IsCheckBoxStateMatchingValue(KeyInfo.Ctrl, KeyEvent.IsControlDown())
|
||||
&& IsCheckBoxStateMatchingValue(KeyInfo.Alt, KeyEvent.IsAltDown())
|
||||
&& IsCheckBoxStateMatchingValue(KeyInfo.Cmd, KeyEvent.IsCommandDown());
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::WasKeyInfoJustPressed(APlayerController& PlayerController, const FCogImGuiKeyInfo& KeyInfo)
|
||||
{
|
||||
if (PlayerController.WasInputKeyJustPressed(KeyInfo.Key))
|
||||
{
|
||||
if (UPlayerInput* PlayerInput = PlayerController.PlayerInput.Get())
|
||||
{
|
||||
const bool MatchCtrl = IsCheckBoxStateMatchingValue(KeyInfo.Ctrl, PlayerInput->IsCtrlPressed());
|
||||
const bool MatchAlt = IsCheckBoxStateMatchingValue(KeyInfo.Alt, PlayerInput->IsAltPressed());
|
||||
const bool MatchShift = IsCheckBoxStateMatchingValue(KeyInfo.Shift, PlayerInput->IsShiftPressed());
|
||||
const bool MatchCmd = IsCheckBoxStateMatchingValue(KeyInfo.Cmd, PlayerInput->IsCmdPressed());
|
||||
|
||||
const bool Result = MatchCtrl && MatchAlt && MatchShift && MatchCmd;
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::IsConsoleEvent(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
const bool bModifierDown = KeyEvent.IsControlDown() || KeyEvent.IsShiftDown() || KeyEvent.IsAltDown() || KeyEvent.IsCommandDown();
|
||||
const bool Result = !bModifierDown && GetDefault<UInputSettings>()->ConsoleKeys.Contains(KeyEvent.GetKey());
|
||||
return Result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::IsStopPlaySessionEvent(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
#if WITH_EDITOR
|
||||
static TSharedPtr<FUICommandInfo> StopPlaySessionCommandInfo = FInputBindingManager::Get().FindCommandInContext("PlayWorld", "StopPlaySession");
|
||||
|
||||
if (StopPlaySessionCommandInfo.IsValid())
|
||||
{
|
||||
const FInputChord InputChord(KeyEvent.GetKey(), KeyEvent.IsShiftDown(), KeyEvent.IsControlDown(), KeyEvent.IsAltDown(), KeyEvent.IsCommandDown());
|
||||
const bool bHasActiveChord = StopPlaySessionCommandInfo->HasActiveChord(InputChord);
|
||||
return bHasActiveChord && FPlayWorldCommands::GlobalPlayWorldActions->CanExecuteAction(StopPlaySessionCommandInfo.ToSharedRef());
|
||||
}
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool FCogImguiInputHelper::IsImGuiToggleInputEvent(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
const bool Result = IsKeyEventMatchingKeyInfo(KeyEvent, FCogImguiModule::Get().GetToggleInputKey());
|
||||
return Result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ImGuiKey FCogImguiInputHelper::KeyEventToImGuiKey(const FKeyEvent& KeyEvent)
|
||||
{
|
||||
if (KeyMap.IsEmpty())
|
||||
{
|
||||
InitializeKeyMap();
|
||||
}
|
||||
|
||||
if (const ImGuiKey* Key = KeyMap.Find(KeyEvent.GetKey()))
|
||||
{
|
||||
return *Key;
|
||||
}
|
||||
|
||||
return ImGuiKey_None;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
uint32 FCogImguiInputHelper::MouseButtonToImGuiMouseButton(const FKey& MouseButton)
|
||||
{
|
||||
if (MouseButton == EKeys::LeftMouseButton) { return 0; }
|
||||
if (MouseButton == EKeys::RightMouseButton) { return 1; }
|
||||
if (MouseButton == EKeys::MiddleMouseButton) { return 2; }
|
||||
if (MouseButton == EKeys::ThumbMouseButton) { return 3; }
|
||||
if (MouseButton == EKeys::ThumbMouseButton2) { return 4; }
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
EMouseCursor::Type FCogImguiInputHelper::ToSlateMouseCursor(ImGuiMouseCursor MouseCursor)
|
||||
{
|
||||
switch (MouseCursor)
|
||||
{
|
||||
case ImGuiMouseCursor_Arrow: return EMouseCursor::Default;
|
||||
case ImGuiMouseCursor_TextInput: return EMouseCursor::TextEditBeam;
|
||||
case ImGuiMouseCursor_ResizeAll: return EMouseCursor::CardinalCross;
|
||||
case ImGuiMouseCursor_ResizeNS: return EMouseCursor::ResizeUpDown;
|
||||
case ImGuiMouseCursor_ResizeEW: return EMouseCursor::ResizeLeftRight;
|
||||
case ImGuiMouseCursor_ResizeNESW: return EMouseCursor::ResizeSouthWest;
|
||||
case ImGuiMouseCursor_ResizeNWSE: return EMouseCursor::ResizeSouthEast;
|
||||
|
||||
case ImGuiMouseCursor_None:
|
||||
default:
|
||||
return EMouseCursor::None;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiInputHelper::InitializeKeyMap()
|
||||
{
|
||||
KeyMap.Add(EKeys::LeftMouseButton, ImGuiKey_MouseLeft);
|
||||
KeyMap.Add(EKeys::RightMouseButton, ImGuiKey_MouseRight);
|
||||
KeyMap.Add(EKeys::MiddleMouseButton, ImGuiKey_MouseMiddle);
|
||||
KeyMap.Add(EKeys::ThumbMouseButton, ImGuiKey_MouseX1);
|
||||
KeyMap.Add(EKeys::ThumbMouseButton2, ImGuiKey_MouseX2);
|
||||
|
||||
KeyMap.Add(EKeys::BackSpace, ImGuiKey_Backspace);
|
||||
KeyMap.Add(EKeys::Tab, ImGuiKey_Tab);
|
||||
KeyMap.Add(EKeys::Enter, ImGuiKey_Enter);
|
||||
KeyMap.Add(EKeys::Pause, ImGuiKey_Pause);
|
||||
|
||||
KeyMap.Add(EKeys::CapsLock, ImGuiKey_CapsLock);
|
||||
KeyMap.Add(EKeys::Escape, ImGuiKey_Escape);
|
||||
KeyMap.Add(EKeys::SpaceBar, ImGuiKey_Space);
|
||||
KeyMap.Add(EKeys::PageUp, ImGuiKey_PageUp);
|
||||
KeyMap.Add(EKeys::PageDown, ImGuiKey_PageDown);
|
||||
KeyMap.Add(EKeys::End, ImGuiKey_End);
|
||||
KeyMap.Add(EKeys::Home, ImGuiKey_Home);
|
||||
|
||||
KeyMap.Add(EKeys::Left, ImGuiKey_LeftArrow);
|
||||
KeyMap.Add(EKeys::Up, ImGuiKey_UpArrow);
|
||||
KeyMap.Add(EKeys::Right, ImGuiKey_RightArrow);
|
||||
KeyMap.Add(EKeys::Down, ImGuiKey_DownArrow);
|
||||
|
||||
KeyMap.Add(EKeys::Insert, ImGuiKey_Insert);
|
||||
KeyMap.Add(EKeys::Delete, ImGuiKey_Delete);
|
||||
|
||||
KeyMap.Add(EKeys::Zero, ImGuiKey_0);
|
||||
KeyMap.Add(EKeys::One, ImGuiKey_1);
|
||||
KeyMap.Add(EKeys::Two, ImGuiKey_2);
|
||||
KeyMap.Add(EKeys::Three, ImGuiKey_3);
|
||||
KeyMap.Add(EKeys::Four, ImGuiKey_4);
|
||||
KeyMap.Add(EKeys::Five, ImGuiKey_5);
|
||||
KeyMap.Add(EKeys::Six, ImGuiKey_6);
|
||||
KeyMap.Add(EKeys::Seven, ImGuiKey_7);
|
||||
KeyMap.Add(EKeys::Eight, ImGuiKey_8);
|
||||
KeyMap.Add(EKeys::Nine, ImGuiKey_9);
|
||||
|
||||
KeyMap.Add(EKeys::A, ImGuiKey_A);
|
||||
KeyMap.Add(EKeys::B, ImGuiKey_B);
|
||||
KeyMap.Add(EKeys::C, ImGuiKey_C);
|
||||
KeyMap.Add(EKeys::D, ImGuiKey_D);
|
||||
KeyMap.Add(EKeys::E, ImGuiKey_E);
|
||||
KeyMap.Add(EKeys::F, ImGuiKey_F);
|
||||
KeyMap.Add(EKeys::G, ImGuiKey_G);
|
||||
KeyMap.Add(EKeys::H, ImGuiKey_H);
|
||||
KeyMap.Add(EKeys::I, ImGuiKey_I);
|
||||
KeyMap.Add(EKeys::J, ImGuiKey_J);
|
||||
KeyMap.Add(EKeys::K, ImGuiKey_K);
|
||||
KeyMap.Add(EKeys::L, ImGuiKey_L);
|
||||
KeyMap.Add(EKeys::M, ImGuiKey_M);
|
||||
KeyMap.Add(EKeys::N, ImGuiKey_N);
|
||||
KeyMap.Add(EKeys::O, ImGuiKey_O);
|
||||
KeyMap.Add(EKeys::P, ImGuiKey_P);
|
||||
KeyMap.Add(EKeys::Q, ImGuiKey_Q);
|
||||
KeyMap.Add(EKeys::R, ImGuiKey_R);
|
||||
KeyMap.Add(EKeys::S, ImGuiKey_S);
|
||||
KeyMap.Add(EKeys::T, ImGuiKey_T);
|
||||
KeyMap.Add(EKeys::U, ImGuiKey_U);
|
||||
KeyMap.Add(EKeys::V, ImGuiKey_V);
|
||||
KeyMap.Add(EKeys::W, ImGuiKey_W);
|
||||
KeyMap.Add(EKeys::X, ImGuiKey_X);
|
||||
KeyMap.Add(EKeys::Y, ImGuiKey_Y);
|
||||
KeyMap.Add(EKeys::Z, ImGuiKey_Z);
|
||||
|
||||
KeyMap.Add(EKeys::NumPadZero, ImGuiKey_Keypad0);
|
||||
KeyMap.Add(EKeys::NumPadOne, ImGuiKey_Keypad1);
|
||||
KeyMap.Add(EKeys::NumPadTwo, ImGuiKey_Keypad2);
|
||||
KeyMap.Add(EKeys::NumPadThree, ImGuiKey_Keypad3);
|
||||
KeyMap.Add(EKeys::NumPadFour, ImGuiKey_Keypad4);
|
||||
KeyMap.Add(EKeys::NumPadFive, ImGuiKey_Keypad5);
|
||||
KeyMap.Add(EKeys::NumPadSix, ImGuiKey_Keypad6);
|
||||
KeyMap.Add(EKeys::NumPadSeven, ImGuiKey_Keypad7);
|
||||
KeyMap.Add(EKeys::NumPadEight, ImGuiKey_Keypad8);
|
||||
KeyMap.Add(EKeys::NumPadNine, ImGuiKey_Keypad9);
|
||||
|
||||
KeyMap.Add(EKeys::Multiply, ImGuiKey_KeypadMultiply);
|
||||
KeyMap.Add(EKeys::Add, ImGuiKey_KeypadAdd);
|
||||
KeyMap.Add(EKeys::Subtract, ImGuiKey_KeypadSubtract);
|
||||
KeyMap.Add(EKeys::Decimal, ImGuiKey_KeypadDecimal);
|
||||
KeyMap.Add(EKeys::Divide, ImGuiKey_KeypadDivide);
|
||||
|
||||
KeyMap.Add(EKeys::F1, ImGuiKey_F1);
|
||||
KeyMap.Add(EKeys::F2, ImGuiKey_F2);
|
||||
KeyMap.Add(EKeys::F3, ImGuiKey_F3);
|
||||
KeyMap.Add(EKeys::F4, ImGuiKey_F4);
|
||||
KeyMap.Add(EKeys::F5, ImGuiKey_F5);
|
||||
KeyMap.Add(EKeys::F6, ImGuiKey_F6);
|
||||
KeyMap.Add(EKeys::F7, ImGuiKey_F7);
|
||||
KeyMap.Add(EKeys::F8, ImGuiKey_F8);
|
||||
KeyMap.Add(EKeys::F9, ImGuiKey_F9);
|
||||
KeyMap.Add(EKeys::F10, ImGuiKey_F10);
|
||||
KeyMap.Add(EKeys::F11, ImGuiKey_F11);
|
||||
KeyMap.Add(EKeys::F12, ImGuiKey_F12);
|
||||
|
||||
KeyMap.Add(EKeys::NumLock, ImGuiKey_NumLock);
|
||||
|
||||
KeyMap.Add(EKeys::ScrollLock, ImGuiKey_ScrollLock);
|
||||
|
||||
KeyMap.Add(EKeys::LeftShift, ImGuiKey_LeftShift);
|
||||
KeyMap.Add(EKeys::RightShift, ImGuiKey_RightShift);
|
||||
KeyMap.Add(EKeys::LeftControl, ImGuiKey_LeftCtrl);
|
||||
KeyMap.Add(EKeys::RightControl, ImGuiKey_RightCtrl);
|
||||
KeyMap.Add(EKeys::LeftAlt, ImGuiKey_LeftAlt);
|
||||
KeyMap.Add(EKeys::RightAlt, ImGuiKey_RightAlt);
|
||||
KeyMap.Add(EKeys::LeftCommand, ImGuiKey_LeftSuper);
|
||||
KeyMap.Add(EKeys::RightCommand, ImGuiKey_RightSuper);
|
||||
|
||||
KeyMap.Add(EKeys::Semicolon, ImGuiKey_Semicolon);
|
||||
KeyMap.Add(EKeys::Equals, ImGuiKey_Equal);
|
||||
KeyMap.Add(EKeys::Comma, ImGuiKey_Comma);
|
||||
KeyMap.Add(EKeys::Hyphen, ImGuiKey_Minus);
|
||||
KeyMap.Add(EKeys::Period, ImGuiKey_Period);
|
||||
KeyMap.Add(EKeys::Slash, ImGuiKey_Slash);
|
||||
|
||||
KeyMap.Add(EKeys::LeftBracket, ImGuiKey_LeftBracket);
|
||||
KeyMap.Add(EKeys::Backslash, ImGuiKey_Backslash);
|
||||
KeyMap.Add(EKeys::RightBracket, ImGuiKey_RightBracket);
|
||||
KeyMap.Add(EKeys::Apostrophe, ImGuiKey_Apostrophe);
|
||||
|
||||
//KeyMap.Add(EKeys::MouseX, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::MouseY, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Mouse2D, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::MouseScrollUp, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::MouseScrollDown, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::MouseWheelAxis, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Underscore, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Tilde, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Ampersand, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Asterix, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Caret, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Colon, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Dollar, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Exclamation, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::LeftParantheses, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::RightParantheses, ImGuiKey_None;
|
||||
//KeyMap.Add(EKeys::Quote, ImGuiKey_None;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#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
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "CogImguiModule.h"
|
||||
|
||||
#include "Engine/GameViewportClient.h"
|
||||
#include "Widgets/Layout/SScaleBox.h"
|
||||
#include "CogImguiWidget.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "FCogImguiModule"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
constexpr int32 Cog_ZOrder = 10000;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiModule::StartupModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiModule::ShutdownModule()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiModule::Initialize()
|
||||
{
|
||||
TextureManager.InitializeErrorTexture();
|
||||
TextureManager.CreatePlainTexture("ImGuiModule_Plain", 2, 2, FColor::White);
|
||||
|
||||
unsigned char* Pixels;
|
||||
int Width, Height, Bpp;
|
||||
|
||||
DefaultFontAtlas.Clear();
|
||||
DefaultFontAtlas.GetTexDataAsRGBA32(&Pixels, &Width, &Height, &Bpp);
|
||||
const CogTextureIndex FontsTexureIndex = TextureManager.CreateTexture("ImGuiModule_FontAtlas", Width, Height, Bpp, Pixels);
|
||||
DefaultFontAtlas.TexID = FCogImguiHelper::ToImTextureID(FontsTexureIndex);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
TSharedPtr<SCogImguiWidget> FCogImguiModule::CreateImGuiViewport(UGameViewportClient* GameViewport, FCogImguiRender Render, ImFontAtlas* FontAtlas /*= nullptr*/)
|
||||
{
|
||||
if (bIsInitialized == false)
|
||||
{
|
||||
Initialize();
|
||||
bIsInitialized = true;
|
||||
}
|
||||
|
||||
if (FontAtlas == nullptr)
|
||||
{
|
||||
FontAtlas = &DefaultFontAtlas;
|
||||
}
|
||||
|
||||
TSharedPtr<SCogImguiWidget> ImguiWidget;
|
||||
SAssignNew(ImguiWidget, SCogImguiWidget)
|
||||
.GameViewport(GameViewport)
|
||||
.FontAtlas(FontAtlas)
|
||||
.Render(Render)
|
||||
.Clipping(EWidgetClipping::ClipToBounds);
|
||||
|
||||
TSharedPtr<SScaleBox> ScaleWidget;
|
||||
SAssignNew(ScaleWidget, SScaleBox)
|
||||
.IgnoreInheritedScale(true)
|
||||
.HAlign(HAlign_Fill)
|
||||
.VAlign(VAlign_Fill)
|
||||
.Visibility(EVisibility::SelfHitTestInvisible)
|
||||
[
|
||||
ImguiWidget.ToSharedRef()
|
||||
];
|
||||
|
||||
GameViewport->AddViewportWidgetContent(ScaleWidget.ToSharedRef(), Cog_ZOrder);
|
||||
|
||||
return ImguiWidget;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
IMPLEMENT_MODULE(FCogImguiModule, CogImGui)
|
||||
@@ -0,0 +1,195 @@
|
||||
#include "CogImguiTextureManager.h"
|
||||
|
||||
#include "Framework/Application/SlateApplication.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiTextureManager::InitializeErrorTexture()
|
||||
{
|
||||
CreatePlainTextureInternal(NAME_ErrorTexture, 2, 2, FColor::Magenta);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiTextureManager::CreateTexture(const FName& Name, int32 Width, int32 Height, uint32 SrcBpp, uint8* SrcData, TFunction<void(uint8*)> SrcDataCleanup)
|
||||
{
|
||||
checkf(Name != NAME_None, TEXT("Trying to create a texture with a name 'NAME_None' is not allowed."));
|
||||
|
||||
return CreateTextureInternal(Name, Width, Height, SrcBpp, SrcData, SrcDataCleanup);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiTextureManager::CreatePlainTexture(const FName& Name, int32 Width, int32 Height, FColor Color)
|
||||
{
|
||||
checkf(Name != NAME_None, TEXT("Trying to create a texture with a name 'NAME_None' is not allowed."));
|
||||
|
||||
return CreatePlainTextureInternal(Name, Width, Height, Color);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiTextureManager::CreateTextureResources(const FName& Name, UTexture2D* Texture)
|
||||
{
|
||||
checkf(Name != NAME_None, TEXT("Trying to create texture resources with a name 'NAME_None' is not allowed."));
|
||||
checkf(Texture, TEXT("Null Texture."));
|
||||
|
||||
// Create an entry for the texture.
|
||||
return AddTextureEntry(Name, Texture, false);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiTextureManager::ReleaseTextureResources(CogTextureIndex Index)
|
||||
{
|
||||
checkf(IsInRange(Index), TEXT("Invalid texture index %d. Texture resources array has %d entries total."), Index, TextureResources.Num());
|
||||
|
||||
TextureResources[Index] = {};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiTextureManager::CreateTextureInternal(const FName& Name, int32 Width, int32 Height, uint32 SrcBpp, uint8* SrcData, TFunction<void(uint8*)> SrcDataCleanup)
|
||||
{
|
||||
// Create a texture.
|
||||
UTexture2D* Texture = UTexture2D::CreateTransient(Width, Height);
|
||||
|
||||
// Create a new resource for that texture.
|
||||
Texture->UpdateResource();
|
||||
|
||||
// Update texture data.
|
||||
FUpdateTextureRegion2D* TextureRegion = new FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);
|
||||
auto DataCleanup = [SrcDataCleanup](uint8* Data, const FUpdateTextureRegion2D* UpdateRegion)
|
||||
{
|
||||
SrcDataCleanup(Data);
|
||||
delete UpdateRegion;
|
||||
};
|
||||
Texture->UpdateTextureRegions(0, 1u, TextureRegion, SrcBpp * Width, SrcBpp, SrcData, DataCleanup);
|
||||
|
||||
// Create an entry for the texture.
|
||||
if (Name == NAME_ErrorTexture)
|
||||
{
|
||||
ErrorTexture = { Name, Texture, true };
|
||||
return INDEX_ErrorTexture;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AddTextureEntry(Name, Texture, true);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiTextureManager::CreatePlainTextureInternal(const FName& Name, int32 Width, int32 Height, const FColor& Color)
|
||||
{
|
||||
// Create buffer with raw data.
|
||||
const uint32 ColorPacked = Color.ToPackedARGB();
|
||||
const uint32 Bpp = sizeof(ColorPacked);
|
||||
const uint32 SizeInPixels = Width * Height;
|
||||
const uint32 SizeInBytes = SizeInPixels * Bpp;
|
||||
uint8* SrcData = new uint8[SizeInBytes];
|
||||
std::fill(reinterpret_cast<uint32*>(SrcData), reinterpret_cast<uint32*>(SrcData) + SizeInPixels, ColorPacked);
|
||||
auto SrcDataCleanup = [](uint8* Data) { delete[] Data; };
|
||||
|
||||
// Create new texture from raw data.
|
||||
return CreateTextureInternal(Name, Width, Height, Bpp, SrcData, SrcDataCleanup);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
CogTextureIndex FCogImguiTextureManager::AddTextureEntry(const FName& Name, UTexture2D* Texture, bool bAddToRoot)
|
||||
{
|
||||
// Try to find an entry with that name.
|
||||
CogTextureIndex Index = FindTextureIndex(Name);
|
||||
|
||||
// If this is a new name, try to find an entry to reuse.
|
||||
if (Index == INDEX_NONE)
|
||||
{
|
||||
Index = FindTextureIndex(NAME_None);
|
||||
}
|
||||
|
||||
// Either update/reuse an entry or add a new one.
|
||||
if (Index != INDEX_NONE)
|
||||
{
|
||||
TextureResources[Index] = { Name, Texture, bAddToRoot };
|
||||
return Index;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TextureResources.Emplace(Name, Texture, bAddToRoot);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FCogImguiTextureManager::FTextureEntry::FTextureEntry(const FName& InName, UTexture2D* InTexture, bool bAddToRoot)
|
||||
: Name(InName)
|
||||
{
|
||||
checkf(InTexture, TEXT("Null texture."));
|
||||
|
||||
if (bAddToRoot)
|
||||
{
|
||||
// Get pointer only for textures that we added to root, so we can later release them.
|
||||
Texture = InTexture;
|
||||
// Add texture to the root to prevent garbage collection.
|
||||
InTexture->AddToRoot();
|
||||
}
|
||||
|
||||
// Create brush and resource handle for input texture.
|
||||
Brush.SetResourceObject(InTexture);
|
||||
CachedResourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(Brush);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FCogImguiTextureManager::FTextureEntry::~FTextureEntry()
|
||||
{
|
||||
Reset(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FCogImguiTextureManager::FTextureEntry& FCogImguiTextureManager::FTextureEntry::operator=(FTextureEntry&& Other)
|
||||
{
|
||||
// Release old resources if allocated.
|
||||
Reset(true);
|
||||
|
||||
// Move data and ownership to this instance.
|
||||
Name = MoveTemp(Other.Name);
|
||||
Texture = MoveTemp(Other.Texture);
|
||||
Brush = MoveTemp(Other.Brush);
|
||||
CachedResourceHandle = MoveTemp(Other.CachedResourceHandle);
|
||||
|
||||
// Reset the other entry (without releasing resources which are already moved to this instance) to remove tracks
|
||||
// of ownership and mark it as empty/reusable.
|
||||
Other.Reset(false);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
const FSlateResourceHandle& FCogImguiTextureManager::FTextureEntry::GetResourceHandle() const
|
||||
{
|
||||
if (!CachedResourceHandle.IsValid() && Brush.HasUObject())
|
||||
{
|
||||
CachedResourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(Brush);
|
||||
}
|
||||
return CachedResourceHandle;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogImguiTextureManager::FTextureEntry::Reset(bool bReleaseResources)
|
||||
{
|
||||
if (bReleaseResources)
|
||||
{
|
||||
// Release brush.
|
||||
if (Brush.HasUObject() && FSlateApplication::IsInitialized())
|
||||
{
|
||||
FSlateApplication::Get().GetRenderer()->ReleaseDynamicResource(Brush);
|
||||
}
|
||||
|
||||
// Remove texture from root to allow for garbage collection (it might be invalid, if we never set it
|
||||
// or this is an application shutdown).
|
||||
if (Texture.IsValid())
|
||||
{
|
||||
Texture->RemoveFromRoot();
|
||||
}
|
||||
}
|
||||
|
||||
// We use empty name to mark unused entries.
|
||||
Name = NAME_None;
|
||||
|
||||
// Clean fields to make sure that we don't reference released or moved resources.
|
||||
Texture.Reset();
|
||||
Brush = FSlateNoResource();
|
||||
CachedResourceHandle = FSlateResourceHandle();
|
||||
}
|
||||
@@ -0,0 +1,494 @@
|
||||
#include "CogImguiWidget.h"
|
||||
|
||||
#include "CogImguiInputHelper.h"
|
||||
#include "CogImguiInputHelper.h"
|
||||
#include "CogImguiModule.h"
|
||||
#include "CogImguiModule.h"
|
||||
#include "CogImguiTextureManager.h"
|
||||
#include "CogImguiWidget.h"
|
||||
#include "Engine/Console.h"
|
||||
#include "Engine/GameViewportClient.h"
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "Framework/Application/SlateApplication.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "implot.h"
|
||||
#include "SlateOptMacros.h"
|
||||
#include "UnrealClient.h"
|
||||
#include "Widgets/Layout/SBorder.h"
|
||||
#include "Widgets/Layout/SBox.h"
|
||||
#include "Widgets/SViewport.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
||||
void SCogImguiWidget::Construct(const FArguments& InArgs)
|
||||
{
|
||||
checkf(InArgs._GameViewport, TEXT("Null Game Viewport argument"));
|
||||
|
||||
GameViewport = InArgs._GameViewport;
|
||||
FontAtlas = InArgs._FontAtlas;
|
||||
Render = InArgs._Render;
|
||||
|
||||
ImGuiContext = ImGui::CreateContext(FontAtlas);
|
||||
ImPlotContext = ImPlot::CreateContext();
|
||||
ImPlot::SetImGuiContext(ImGuiContext);
|
||||
|
||||
const char* InitFilenameTemp = TCHAR_TO_ANSI(*FCogImguiHelper::GetIniFilePath("imgui"));
|
||||
ImStrncpy(IniFilename, InitFilenameTemp, IM_ARRAYSIZE(IniFilename));
|
||||
|
||||
ImGuiIO& IO = ImGui::GetIO();
|
||||
IO.IniFilename = IniFilename;
|
||||
IO.DisplaySize = ImVec2(100, 100);
|
||||
IO.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
SCogImguiWidget::~SCogImguiWidget()
|
||||
{
|
||||
ImPlot::DestroyContext(ImPlotContext);
|
||||
ImGui::DestroyContext(ImGuiContext);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
|
||||
{
|
||||
Super::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
|
||||
|
||||
TickKeyModifiers();
|
||||
TickFocus();
|
||||
TickImGui(InDeltaTime);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::TickKeyModifiers()
|
||||
{
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
// Refresh modifiers otherwise, when pressing ALT-TAB, the Alt modifier is always true
|
||||
//-------------------------------------------------------------------------------------------------------
|
||||
FModifierKeysState ModifierKeys = FSlateApplication::Get().GetModifierKeys();
|
||||
|
||||
ImGuiIO& IO = ImGui::GetIO();
|
||||
if (ModifierKeys.IsControlDown() != IO.KeyCtrl) { IO.AddKeyEvent(ImGuiMod_Ctrl, ModifierKeys.IsControlDown()); }
|
||||
if (ModifierKeys.IsShiftDown() != IO.KeyShift) { IO.AddKeyEvent(ImGuiMod_Shift, ModifierKeys.IsShiftDown()); }
|
||||
if (ModifierKeys.IsAltDown() != IO.KeyAlt) { IO.AddKeyEvent(ImGuiMod_Alt, ModifierKeys.IsAltDown()); }
|
||||
if (ModifierKeys.IsCommandDown() != IO.KeySuper) { IO.AddKeyEvent(ImGuiMod_Super, ModifierKeys.IsCommandDown()); }
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::TickImGui(float InDeltaTime)
|
||||
{
|
||||
if (ImGuiContext == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(ImGuiContext);
|
||||
ImGuiIO& IO = ImGui::GetIO();
|
||||
IO.DeltaTime = InDeltaTime;
|
||||
|
||||
ImPlot::SetImGuiContext(ImGuiContext);
|
||||
ImPlot::SetCurrentContext(ImPlotContext);
|
||||
|
||||
FVector2D DisplaySize;
|
||||
GameViewport->GetViewportSize(DisplaySize);
|
||||
IO.DisplaySize = FCogImguiHelper::ToImVec2(DisplaySize);
|
||||
|
||||
ImGui::NewFrame();
|
||||
Render(InDeltaTime);
|
||||
ImGui::Render();
|
||||
|
||||
SetCursor(FCogImguiInputHelper::ToSlateMouseCursor(ImGui::GetMouseCursor()));
|
||||
|
||||
ImDrawData* DrawData = ImGui::GetDrawData();
|
||||
if (DrawData && DrawData->CmdListsCount > 0)
|
||||
{
|
||||
DrawLists.SetNum(DrawData->CmdListsCount, false);
|
||||
for (int i = 0; i < DrawData->CmdListsCount; i++)
|
||||
{
|
||||
DrawLists[i].TransferDrawData(*DrawData->CmdLists[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawLists.Empty();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::TickFocus()
|
||||
{
|
||||
FCogImguiModule& Module = FCogImguiModule::Get();
|
||||
|
||||
if (UWorld* World = GameViewport->GetWorld())
|
||||
{
|
||||
if (APlayerController* Controller = FCogImguiInputHelper::GetFirstLocalPlayerController(*World))
|
||||
{
|
||||
if (FCogImguiInputHelper::WasKeyInfoJustPressed(*Controller, Module.GetToggleInputKey()))
|
||||
{
|
||||
Module.ToggleEnableInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bool bShouldEnableInput = Module.GetEnableInput();
|
||||
if (bEnableInput != bShouldEnableInput)
|
||||
{
|
||||
bEnableInput = bShouldEnableInput;
|
||||
|
||||
if (bEnableInput)
|
||||
{
|
||||
TakeFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnFocus();
|
||||
}
|
||||
}
|
||||
else if (bEnableInput)
|
||||
{
|
||||
const auto& ViewportWidget = GameViewport->GetGameViewportWidget();
|
||||
if (!HasKeyboardFocus() && !IsConsoleOpened() && (ViewportWidget->HasKeyboardFocus() || ViewportWidget->HasFocusedDescendants()))
|
||||
{
|
||||
TakeFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::TakeFocus()
|
||||
{
|
||||
FSlateApplication& SlateApplication = FSlateApplication::Get();
|
||||
|
||||
PreviousUserFocusedWidget = SlateApplication.GetUserFocusedWidget(SlateApplication.GetUserIndexForKeyboard());
|
||||
|
||||
if (ULocalPlayer* LocalPlayer = GetLocalPlayer())
|
||||
{
|
||||
TSharedRef<SWidget> FocusWidget = SharedThis(this);
|
||||
LocalPlayer->GetSlateOperations().CaptureMouse(FocusWidget);
|
||||
LocalPlayer->GetSlateOperations().SetUserFocus(FocusWidget);
|
||||
}
|
||||
else
|
||||
{
|
||||
SlateApplication.SetKeyboardFocus(SharedThis(this));
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::ReturnFocus()
|
||||
{
|
||||
if (HasKeyboardFocus())
|
||||
{
|
||||
auto FocusWidgetPtr = PreviousUserFocusedWidget.IsValid()
|
||||
? PreviousUserFocusedWidget.Pin()
|
||||
: GameViewport->GetGameViewportWidget();
|
||||
|
||||
if (ULocalPlayer* LocalPlayer = GetLocalPlayer())
|
||||
{
|
||||
auto FocusWidgetRef = FocusWidgetPtr.ToSharedRef();
|
||||
|
||||
if (FocusWidgetPtr == GameViewport->GetGameViewportWidget())
|
||||
{
|
||||
LocalPlayer->GetSlateOperations().CaptureMouse(FocusWidgetRef);
|
||||
}
|
||||
|
||||
LocalPlayer->GetSlateOperations().SetUserFocus(FocusWidgetRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
FSlateApplication& SlateApplication = FSlateApplication::Get();
|
||||
SlateApplication.ResetToDefaultPointerInputSettings();
|
||||
SlateApplication.SetUserFocus(SlateApplication.GetUserIndexForKeyboard(), FocusWidgetPtr);
|
||||
}
|
||||
}
|
||||
|
||||
PreviousUserFocusedWidget.Reset();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
int32 SCogImguiWidget::OnPaint(
|
||||
const FPaintArgs& Args,
|
||||
const FGeometry& AllottedGeometry,
|
||||
const FSlateRect& MyClippingRect,
|
||||
FSlateWindowElementList& OutDrawElements,
|
||||
int32 LayerId,
|
||||
const FWidgetStyle& WidgetStyle,
|
||||
bool bParentEnabled) const
|
||||
{
|
||||
|
||||
const FSlateRenderTransform& WidgetToScreen = AllottedGeometry.GetAccumulatedRenderTransform();
|
||||
const FSlateRenderTransform ImGuiToScreen = FCogImguiHelper::RoundTranslation(ImGuiRenderTransform.Concatenate(WidgetToScreen));
|
||||
|
||||
FCogImguiTextureManager& TextureManager = FCogImguiModule::Get().GetTextureManager();
|
||||
|
||||
for (const auto& DrawList : DrawLists)
|
||||
{
|
||||
DrawList.CopyVertexData(VertexBuffer, ImGuiToScreen);
|
||||
|
||||
int IndexBufferOffset = 0;
|
||||
for (int i = 0; i < DrawList.NumCommands(); i++)
|
||||
{
|
||||
const auto& DrawCommand = DrawList.GetCommand(i, ImGuiToScreen);
|
||||
|
||||
DrawList.CopyIndexData(IndexBuffer, IndexBufferOffset, DrawCommand.NumElements);
|
||||
|
||||
// Advance offset by number of copied elements to position it for the next command.
|
||||
IndexBufferOffset += DrawCommand.NumElements;
|
||||
|
||||
// Get texture resource handle for this draw command (null index will be also mapped to a valid texture).
|
||||
const FSlateResourceHandle& Handle = TextureManager.GetTextureHandle(DrawCommand.TextureId);
|
||||
|
||||
// Transform clipping rectangle to screen space and apply to elements that we draw.
|
||||
const FSlateRect ClippingRect = DrawCommand.ClippingRect.IntersectionWith(MyClippingRect);
|
||||
|
||||
OutDrawElements.PushClip(FSlateClippingZone{ ClippingRect });
|
||||
|
||||
// Add elements to the list.
|
||||
FSlateDrawElement::MakeCustomVerts(OutDrawElements, LayerId, Handle, VertexBuffer, IndexBuffer, nullptr, 0, 0);
|
||||
|
||||
OutDrawElements.PopClip();
|
||||
}
|
||||
}
|
||||
|
||||
return Super::OnPaint(Args, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, WidgetStyle, bParentEnabled);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FVector2D SCogImguiWidget::ComputeDesiredSize(float Scale) const
|
||||
{
|
||||
return Super::ComputeDesiredSize(Scale);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
ULocalPlayer* SCogImguiWidget::GetLocalPlayer() const
|
||||
{
|
||||
if (GameViewport.IsValid())
|
||||
{
|
||||
if (UWorld* World = GameViewport->GetWorld())
|
||||
{
|
||||
if (ULocalPlayer* LocalPlayer = World->GetFirstLocalPlayerFromController())
|
||||
{
|
||||
return World->GetFirstLocalPlayerFromController();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FVector2D SCogImguiWidget::TransformScreenPointToImGui(const FGeometry& MyGeometry, const FVector2D& Point) const
|
||||
{
|
||||
const FSlateRenderTransform ImGuiToScreen = MyGeometry.GetAccumulatedRenderTransform();
|
||||
return ImGuiToScreen.Inverse().TransformPoint(Point);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool SCogImguiWidget::IsConsoleOpened() const
|
||||
{
|
||||
return GameViewport->ViewportConsole && GameViewport->ViewportConsole->ConsoleState != NAME_None;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
bool SCogImguiWidget::IsCurrentContext() const
|
||||
{
|
||||
return ImGui::GetCurrentContext() == ImGuiContext;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::SetAsCurrentContext()
|
||||
{
|
||||
ImGui::SetCurrentContext(ImGuiContext);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::SetDPIScale(float Scale)
|
||||
{
|
||||
if (DpiScale == Scale)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DpiScale = Scale;
|
||||
OnDpiChanged();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::OnDpiChanged()
|
||||
{
|
||||
if (FontAtlas == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FontAtlas->Clear();
|
||||
|
||||
ImFontConfig FontConfig = {};
|
||||
FontConfig.SizePixels = FMath::RoundFromZero(13.f * DpiScale);
|
||||
FontAtlas->AddFontDefault(&FontConfig);
|
||||
|
||||
unsigned char* Pixels;
|
||||
int Width, Height, Bpp;
|
||||
FontAtlas->GetTexDataAsRGBA32(&Pixels, &Width, &Height, &Bpp);
|
||||
const CogTextureIndex FontsTexureIndex = FCogImguiModule::Get().GetTextureManager().CreateTexture("xx", Width, Height, Bpp, Pixels);
|
||||
FontAtlas->TexID = FCogImguiHelper::ToImTextureID(FontsTexureIndex);
|
||||
|
||||
ImGuiStyle NewStyle = ImGuiStyle();
|
||||
ImGui::GetStyle() = MoveTemp(NewStyle);
|
||||
NewStyle.ScaleAllSizes(DpiScale);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnKeyChar(const FGeometry& MyGeometry, const FCharacterEvent& CharacterEvent)
|
||||
{
|
||||
if (FCogImguiModule::Get().GetEnableInput())
|
||||
{
|
||||
ImGui::GetIO().AddInputCharacter(FCogImguiInputHelper::CastInputChar(CharacterEvent.GetCharacter()));
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent)
|
||||
{
|
||||
if (FCogImguiInputHelper::IsKeyEventHandled(KeyEvent) == false)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
ImGuiIO& IO = ImGui::GetIO();
|
||||
IO.AddKeyEvent(FCogImguiInputHelper::KeyEventToImGuiKey(KeyEvent), true);
|
||||
IO.AddKeyEvent(ImGuiMod_Ctrl, KeyEvent.IsControlDown());
|
||||
IO.AddKeyEvent(ImGuiMod_Shift, KeyEvent.IsShiftDown());
|
||||
IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown());
|
||||
IO.AddKeyEvent(ImGuiMod_Super, KeyEvent.IsCommandDown());
|
||||
|
||||
return FReply::Handled();
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent)
|
||||
{
|
||||
if (FCogImguiInputHelper::IsKeyEventHandled(KeyEvent) == false)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
ImGuiIO& IO = ImGui::GetIO();
|
||||
IO.AddKeyEvent(FCogImguiInputHelper::KeyEventToImGuiKey(KeyEvent), false);
|
||||
IO.AddKeyEvent(ImGuiMod_Ctrl, KeyEvent.IsControlDown());
|
||||
IO.AddKeyEvent(ImGuiMod_Shift, KeyEvent.IsShiftDown());
|
||||
IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown());
|
||||
IO.AddKeyEvent(ImGuiMod_Super, KeyEvent.IsCommandDown());
|
||||
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnAnalogValueChanged(const FGeometry& MyGeometry, const FAnalogInputEvent& AnalogInputEvent)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||
{
|
||||
if (FCogImguiModule::Get().GetEnableInput() == false)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse);
|
||||
ImGui::GetIO().AddMouseButtonEvent(FCogImguiInputHelper::MouseButtonToImGuiMouseButton(MouseEvent.GetEffectingButton()), true);
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||
{
|
||||
if (FCogImguiModule::Get().GetEnableInput() == false)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse);
|
||||
ImGui::GetIO().AddMouseButtonEvent(FCogImguiInputHelper::MouseButtonToImGuiMouseButton(MouseEvent.GetEffectingButton()), false);
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||
{
|
||||
if (FCogImguiModule::Get().GetEnableInput() == false)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse);
|
||||
ImGui::GetIO().AddMouseWheelEvent(0, MouseEvent.GetWheelDelta());
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||
{
|
||||
if (FCogImguiModule::Get().GetEnableInput() == false)
|
||||
{
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
|
||||
ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse);
|
||||
const FVector2D Pos = TransformScreenPointToImGui(MyGeometry, MouseEvent.GetScreenSpacePosition());
|
||||
ImGui::GetIO().AddMousePosEvent(Pos.X, Pos.Y);
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& FocusEvent)
|
||||
{
|
||||
return Super::OnFocusReceived(MyGeometry, FocusEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::OnFocusLost(const FFocusEvent& FocusEvent)
|
||||
{
|
||||
return Super::OnFocusLost(FocusEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
||||
{
|
||||
Super::OnMouseEnter(MyGeometry, MouseEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void SCogImguiWidget::OnMouseLeave(const FPointerEvent& MouseEvent)
|
||||
{
|
||||
Super::OnMouseLeave(MouseEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnTouchStarted(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent)
|
||||
{
|
||||
return Super::OnTouchStarted(MyGeometry, TouchEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnTouchMoved(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent)
|
||||
{
|
||||
return Super::OnTouchMoved(MyGeometry, TouchEvent);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FReply SCogImguiWidget::OnTouchEnded(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent)
|
||||
{
|
||||
return Super::OnTouchEnded(MyGeometry, TouchEvent);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CogImguiHelper.h"
|
||||
#include "imgui.h"
|
||||
#include "Rendering/RenderingCommon.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
class FCogImguiDrawList
|
||||
{
|
||||
public:
|
||||
|
||||
struct DrawCommand
|
||||
{
|
||||
uint32 NumElements;
|
||||
FSlateRect ClippingRect;
|
||||
CogTextureIndex TextureId;
|
||||
};
|
||||
|
||||
// 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
|
||||
// @param Transform - Transform to apply to clipping rectangle
|
||||
// @returns Draw command data
|
||||
DrawCommand GetCommand(int CommandCount, const FTransform2D& Transform) const;
|
||||
|
||||
// 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
|
||||
void CopyVertexData(TArray<FSlateVertex>& OutVertexBuffer, const FTransform2D& Transform) const;
|
||||
|
||||
// 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
|
||||
// @param StartIndex - Start copying source data starting from this index
|
||||
// @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;
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "imgui.h"
|
||||
#include "Layout/SlateRect.h"
|
||||
|
||||
struct ImGuiWindow;
|
||||
|
||||
using CogTextureIndex = int32;
|
||||
|
||||
class COGIMGUI_API FCogImguiHelper
|
||||
{
|
||||
public:
|
||||
|
||||
static FString GetIniSaveDirectory();
|
||||
|
||||
static FString GetIniFilePath(const FString& Filename);
|
||||
|
||||
static ImGuiWindow* GetCurrentWindow();
|
||||
|
||||
static FColor UnpackImU32Color(ImU32 Color);
|
||||
|
||||
static FSlateRect ToSlateRect(const ImVec4& Value);
|
||||
|
||||
static FVector2D ToVector2D(const ImVec2& Value);
|
||||
|
||||
static ImVec2 ToImVec2(const FVector2D& Value);
|
||||
|
||||
static ImColor ToImColor(const FColor& Value);
|
||||
|
||||
static ImColor ToImColor(const FLinearColor& Value);
|
||||
|
||||
static ImVec4 ToImVec4(const FColor& Value);
|
||||
|
||||
static ImVec4 ToImVec4(const FLinearColor& Value);
|
||||
|
||||
static ImVec4 ToImVec4(const FVector4f& Value);
|
||||
|
||||
static ImU32 ToImU32(const FColor& Value);
|
||||
|
||||
static ImU32 ToImU32(const FVector4f& Value);
|
||||
|
||||
static CogTextureIndex ToTextureIndex(ImTextureID Index);
|
||||
|
||||
static ImTextureID ToImTextureID(CogTextureIndex Index);
|
||||
|
||||
static FVector2D RoundVector(const FVector2D& Vector);
|
||||
|
||||
static FSlateRenderTransform RoundTranslation(const FSlateRenderTransform& Transform);
|
||||
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CogImguiInputHelper.h"
|
||||
#include "imgui.h"
|
||||
|
||||
struct FCogImGuiKeyInfo;
|
||||
|
||||
class COGIMGUI_API FCogImguiInputHelper
|
||||
{
|
||||
public:
|
||||
|
||||
static APlayerController* GetFirstLocalPlayerController(UWorld& World);
|
||||
|
||||
static bool IsKeyEventHandled(const FKeyEvent& KeyEvent);
|
||||
|
||||
static bool WasKeyInfoJustPressed(APlayerController& PlayerController, const FCogImGuiKeyInfo& KeyInfo);
|
||||
|
||||
static bool IsCheckBoxStateMatchingValue(ECheckBoxState CheckBoxState, bool bValue);
|
||||
|
||||
static bool IsKeyEventMatchingKeyInfo(const FKeyEvent& KeyEvent, const FCogImGuiKeyInfo& InputChord);
|
||||
|
||||
static bool IsConsoleEvent(const FKeyEvent& KeyEvent);
|
||||
|
||||
static bool IsImGuiToggleInputEvent(const FKeyEvent& KeyEvent);
|
||||
|
||||
static bool IsStopPlaySessionEvent(const FKeyEvent& KeyEvent);
|
||||
|
||||
static ImGuiKey KeyEventToImGuiKey(const FKeyEvent& KeyEvent);
|
||||
|
||||
static uint32 MouseButtonToImGuiMouseButton(const FKey& MouseButton);
|
||||
|
||||
static EMouseCursor::Type ToSlateMouseCursor(ImGuiMouseCursor MouseCursor);
|
||||
|
||||
template<typename T, std::enable_if_t<(sizeof(T) <= sizeof(ImWchar)), T>* = nullptr>
|
||||
static ImWchar CastInputChar(T Char)
|
||||
{
|
||||
return static_cast<ImWchar>(Char);
|
||||
}
|
||||
|
||||
static void InitializeKeyMap();
|
||||
|
||||
static TMap<FKey, ImGuiKey> KeyMap;
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "InputCoreTypes.h"
|
||||
#include "CogImGuiKeyInfo.generated.h"
|
||||
|
||||
USTRUCT()
|
||||
struct FCogImGuiKeyInfo
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Input")
|
||||
FKey Key = EKeys::Invalid;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Input")
|
||||
ECheckBoxState Shift = ECheckBoxState::Undetermined;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Input")
|
||||
ECheckBoxState Ctrl = ECheckBoxState::Undetermined;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Input")
|
||||
ECheckBoxState Alt = ECheckBoxState::Undetermined;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "Input")
|
||||
ECheckBoxState Cmd = ECheckBoxState::Undetermined;
|
||||
|
||||
FCogImGuiKeyInfo()
|
||||
{
|
||||
}
|
||||
|
||||
FCogImGuiKeyInfo(const FKey InKey,
|
||||
const ECheckBoxState InShift = ECheckBoxState::Undetermined,
|
||||
const ECheckBoxState InCtrl = ECheckBoxState::Undetermined,
|
||||
const ECheckBoxState InAlt = ECheckBoxState::Undetermined,
|
||||
const ECheckBoxState InCmd = ECheckBoxState::Undetermined)
|
||||
: Key(InKey)
|
||||
, Shift(InShift)
|
||||
, Ctrl(InCtrl)
|
||||
, Alt(InAlt)
|
||||
, Cmd(InCmd)
|
||||
{
|
||||
}
|
||||
|
||||
friend bool operator==(const FCogImGuiKeyInfo& Lhs, const FCogImGuiKeyInfo& Rhs)
|
||||
{
|
||||
return Lhs.Key == Rhs.Key
|
||||
&& Lhs.Shift == Rhs.Shift
|
||||
&& Lhs.Ctrl == Rhs.Ctrl
|
||||
&& Lhs.Alt == Rhs.Alt
|
||||
&& Lhs.Cmd == Rhs.Cmd;
|
||||
}
|
||||
|
||||
friend bool operator!=(const FCogImGuiKeyInfo& Lhs, const FCogImGuiKeyInfo& Rhs)
|
||||
{
|
||||
return !(Lhs == Rhs);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CogImguiWidget.h"
|
||||
#include "CogImguiKeyInfo.h"
|
||||
#include "CogImguiTextureManager.h"
|
||||
#include "imgui.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
class COGIMGUI_API FCogImguiModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
static inline FCogImguiModule& Get()
|
||||
{
|
||||
return FModuleManager::LoadModuleChecked<FCogImguiModule>("CogImgui");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// IModuleInterface implementation
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TSharedPtr<SCogImguiWidget> CreateImGuiViewport(UGameViewportClient* GameViewport, FCogImguiRender Render, ImFontAtlas* FontAtlas = nullptr);
|
||||
|
||||
FCogImguiTextureManager& GetTextureManager() { return TextureManager; }
|
||||
ImFontAtlas& GetDefaultFontAtlas() { return DefaultFontAtlas; }
|
||||
|
||||
bool GetEnableInput() const { return bEnabledInput; }
|
||||
void SetEnableInput(bool Value) { bEnabledInput = Value; }
|
||||
void ToggleEnableInput() { bEnabledInput = !bEnabledInput; }
|
||||
|
||||
const FCogImGuiKeyInfo& GetToggleInputKey() const { return ToggleInputKey; }
|
||||
void SetToggleInputKey(const FCogImGuiKeyInfo& Value) { ToggleInputKey = Value; }
|
||||
|
||||
private:
|
||||
|
||||
void Initialize();
|
||||
|
||||
FCogImguiTextureManager TextureManager;
|
||||
ImFontAtlas DefaultFontAtlas;
|
||||
bool bEnabledInput = true;
|
||||
bool bIsInitialized = false;
|
||||
FCogImGuiKeyInfo ToggleInputKey;
|
||||
};
|
||||
@@ -0,0 +1,147 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CogImguiHelper.h"
|
||||
#include "Engine/Texture2D.h"
|
||||
#include "Styling/SlateBrush.h"
|
||||
#include "Textures/SlateShaderResource.h"
|
||||
#include "UObject/WeakObjectPtr.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
class FCogImguiTextureManager
|
||||
{
|
||||
public:
|
||||
|
||||
// Creates an empty manager.
|
||||
FCogImguiTextureManager() = default;
|
||||
|
||||
// Copying is disabled to protected resource ownership.
|
||||
FCogImguiTextureManager(const FCogImguiTextureManager&) = delete;
|
||||
FCogImguiTextureManager& operator=(const FCogImguiTextureManager&) = delete;
|
||||
|
||||
// Moving transfers ownership and leaves source empty.
|
||||
FCogImguiTextureManager(FCogImguiTextureManager&&) = delete;
|
||||
FCogImguiTextureManager& operator=(FCogImguiTextureManager&&) = delete;
|
||||
|
||||
void InitializeErrorTexture();
|
||||
|
||||
// Find texture index by name.
|
||||
// @param Name - The name of a texture to find
|
||||
// @returns The index of a texture with given name or INDEX_NONE if there is no such texture
|
||||
CogTextureIndex FindTextureIndex(const FName& Name) const
|
||||
{
|
||||
return TextureResources.IndexOfByPredicate([&](const auto& Entry) { return Entry.GetName() == Name; });
|
||||
}
|
||||
|
||||
// Get the name of a texture at given index. Returns NAME_None, if index is out of range.
|
||||
// @param Index - Index of a texture
|
||||
// @returns The name of a texture at given index or NAME_None if index is out of range.
|
||||
FName GetTextureName(CogTextureIndex Index) const
|
||||
{
|
||||
return IsInRange(Index) ? TextureResources[Index].GetName() : NAME_None;
|
||||
}
|
||||
|
||||
// Get the Slate Resource Handle to a texture at given index. If index is out of range or resources are not valid
|
||||
// it returns a handle to the error texture.
|
||||
// @param Index - Index of a texture
|
||||
// @returns The Slate Resource Handle for a texture at given index or to error texture, if no valid resources were
|
||||
// found at given index
|
||||
const FSlateResourceHandle& GetTextureHandle(CogTextureIndex Index) const
|
||||
{
|
||||
return IsValidTexture(Index) ? TextureResources[Index].GetResourceHandle() : ErrorTexture.GetResourceHandle();
|
||||
}
|
||||
|
||||
// Create a texture from raw data.
|
||||
// @param Name - The texture name
|
||||
// @param Width - The texture width
|
||||
// @param Height - The texture height
|
||||
// @param SrcBpp - The size in bytes of one pixel
|
||||
// @param SrcData - The source data
|
||||
// @param SrcDataCleanup - Optional function called to release source data after texture is created (only needed, if data need to be released)
|
||||
// @returns The index of a texture that was created
|
||||
CogTextureIndex CreateTexture(const FName& Name, int32 Width, int32 Height, uint32 SrcBpp, uint8* SrcData, TFunction<void(uint8*)> SrcDataCleanup = [](uint8*) {});
|
||||
|
||||
// Create a plain texture.
|
||||
// @param Name - The texture name
|
||||
// @param Width - The texture width
|
||||
// @param Height - The texture height
|
||||
// @param Color - The texture color
|
||||
// @returns The index of a texture that was created
|
||||
CogTextureIndex CreatePlainTexture(const FName& Name, int32 Width, int32 Height, FColor Color);
|
||||
|
||||
// Create Slate resources to an existing texture, managed externally.
|
||||
// @param Name - The texture name
|
||||
// @param Texture - The texture
|
||||
// @returns The index to created/updated texture resources
|
||||
CogTextureIndex CreateTextureResources(const FName& Name, UTexture2D* Texture);
|
||||
|
||||
// Release resources for given texture. Ignores invalid indices.
|
||||
// @param Index - The index of a texture resources
|
||||
void ReleaseTextureResources(CogTextureIndex Index);
|
||||
|
||||
private:
|
||||
|
||||
// See CreateTexture for general description.
|
||||
// Internal implementations doesn't validate name or resource uniqueness. Instead it uses NAME_ErrorTexture
|
||||
// (aka NAME_None) and INDEX_ErrorTexture (aka INDEX_NONE) to identify ErrorTexture.
|
||||
CogTextureIndex CreateTextureInternal(const FName& Name, int32 Width, int32 Height, uint32 SrcBpp, uint8* SrcData, TFunction<void(uint8*)> SrcDataCleanup = [](uint8*) {});
|
||||
|
||||
// See CreatePlainTexture for general description.
|
||||
// Internal implementations doesn't validate name or resource uniqueness. Instead it uses NAME_ErrorTexture
|
||||
// (aka NAME_None) and INDEX_ErrorTexture (aka INDEX_NONE) to identify ErrorTexture.
|
||||
CogTextureIndex CreatePlainTextureInternal(const FName& Name, int32 Width, int32 Height, const FColor& Color);
|
||||
|
||||
// Add or reuse texture entry.
|
||||
// @param Name - The texture name
|
||||
// @param Texture - The texture
|
||||
// @param bAddToRoot - If true, we should add texture to root to prevent garbage collection (use for own textures)
|
||||
// @returns The index of the entry that we created or reused
|
||||
CogTextureIndex AddTextureEntry(const FName& Name, UTexture2D* Texture, bool bAddToRoot);
|
||||
|
||||
// Check whether index is in range allocated for TextureResources (it doesn't mean that resources are valid).
|
||||
FORCEINLINE bool IsInRange(CogTextureIndex Index) const
|
||||
{
|
||||
return static_cast<uint32>(Index) < static_cast<uint32>(TextureResources.Num());
|
||||
}
|
||||
|
||||
// Check whether index is in range and whether texture resources are valid (using NAME_None sentinel).
|
||||
FORCEINLINE bool IsValidTexture(CogTextureIndex Index) const
|
||||
{
|
||||
return IsInRange(Index) && TextureResources[Index].GetName() != NAME_None;
|
||||
}
|
||||
|
||||
// Entry for texture resources. Only supports explicit construction.
|
||||
struct FTextureEntry
|
||||
{
|
||||
FTextureEntry() = default;
|
||||
FTextureEntry(const FName& InName, UTexture2D* InTexture, bool bAddToRoot);
|
||||
~FTextureEntry();
|
||||
|
||||
// Copying is not supported.
|
||||
FTextureEntry(const FTextureEntry&) = delete;
|
||||
FTextureEntry& operator=(const FTextureEntry&) = delete;
|
||||
|
||||
// We rely on TArray and don't implement custom move constructor...
|
||||
FTextureEntry(FTextureEntry&&) = delete;
|
||||
// ... but we need move assignment to support reusing entries.
|
||||
FTextureEntry& operator=(FTextureEntry&& Other);
|
||||
|
||||
const FName& GetName() const { return Name; }
|
||||
const FSlateResourceHandle& GetResourceHandle() const;
|
||||
|
||||
private:
|
||||
|
||||
void Reset(bool bReleaseResources);
|
||||
|
||||
FName Name = NAME_None;
|
||||
mutable FSlateResourceHandle CachedResourceHandle;
|
||||
TWeakObjectPtr<UTexture2D> Texture;
|
||||
FSlateBrush Brush;
|
||||
};
|
||||
|
||||
TArray<FTextureEntry> TextureResources;
|
||||
FTextureEntry ErrorTexture;
|
||||
|
||||
static constexpr EName NAME_ErrorTexture = NAME_None;
|
||||
static constexpr CogTextureIndex INDEX_ErrorTexture = INDEX_NONE;
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "CogImguiDrawList.h"
|
||||
#include "Rendering/RenderingCommon.h"
|
||||
#include "UObject/WeakObjectPtr.h"
|
||||
#include "Widgets/DeclarativeSyntaxSupport.h"
|
||||
#include "Widgets/SCompoundWidget.h"
|
||||
|
||||
class UGameViewportClient;
|
||||
class ULocalPlayer;
|
||||
struct ImFontAtlas;
|
||||
struct ImGuiContext;
|
||||
struct ImPlotContext;
|
||||
|
||||
using FCogImguiRender = TFunction<void(float DeltaTime)>;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
class COGIMGUI_API SCogImguiWidget : public SCompoundWidget
|
||||
{
|
||||
typedef SCompoundWidget Super;
|
||||
|
||||
public:
|
||||
|
||||
SLATE_BEGIN_ARGS(SCogImguiWidget) {}
|
||||
SLATE_ARGUMENT(UGameViewportClient*, GameViewport)
|
||||
SLATE_ARGUMENT(ImFontAtlas*, FontAtlas)
|
||||
SLATE_ARGUMENT(FCogImguiRender, Render)
|
||||
SLATE_END_ARGS()
|
||||
|
||||
void Construct(const FArguments& InArgs);
|
||||
|
||||
~SCogImguiWidget();
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// SWidget overrides
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
|
||||
virtual bool SupportsKeyboardFocus() const override { return true; }
|
||||
virtual FReply OnKeyChar(const FGeometry& MyGeometry, const FCharacterEvent& CharacterEvent) override;
|
||||
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) override;
|
||||
virtual FReply OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) override;
|
||||
virtual FReply OnAnalogValueChanged(const FGeometry& MyGeometry, const FAnalogInputEvent& AnalogInputEvent) override;
|
||||
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||||
virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||||
virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||||
virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||||
virtual FReply OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& FocusEvent) override;
|
||||
virtual void OnFocusLost(const FFocusEvent& FocusEvent) override;
|
||||
virtual void OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
||||
virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
|
||||
virtual FReply OnTouchStarted(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent) override;
|
||||
virtual FReply OnTouchMoved(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent) override;
|
||||
virtual FReply OnTouchEnded(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent) override;
|
||||
virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& WidgetStyle, bool bParentEnabled) const override;
|
||||
virtual FVector2D ComputeDesiredSize(float Scale) const override;
|
||||
|
||||
ULocalPlayer* SCogImguiWidget::GetLocalPlayer() const;
|
||||
|
||||
float GetDpiScale() const { return DpiScale; }
|
||||
|
||||
void SetDPIScale(float Scale);
|
||||
|
||||
bool IsCurrentContext() const;
|
||||
|
||||
void SetAsCurrentContext();
|
||||
|
||||
protected:
|
||||
|
||||
FVector2D TransformScreenPointToImGui(const FGeometry& MyGeometry, const FVector2D& Point) const;
|
||||
|
||||
virtual void TickKeyModifiers();
|
||||
|
||||
virtual void TickImGui(float InDeltaTime);
|
||||
|
||||
virtual void TickFocus();
|
||||
|
||||
virtual void TakeFocus();
|
||||
|
||||
virtual void ReturnFocus();
|
||||
|
||||
virtual void OnDpiChanged();
|
||||
|
||||
bool IsConsoleOpened() const;
|
||||
|
||||
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
||||
|
||||
ImFontAtlas* FontAtlas;
|
||||
|
||||
TWeakPtr<SWidget> PreviousUserFocusedWidget;
|
||||
|
||||
bool bEnableInput = false;
|
||||
|
||||
FSlateRenderTransform ImGuiRenderTransform;
|
||||
|
||||
mutable TArray<FSlateVertex> VertexBuffer;
|
||||
|
||||
mutable TArray<SlateIndex> IndexBuffer;
|
||||
|
||||
TArray<FCogImguiDrawList> DrawLists;
|
||||
|
||||
ImGuiContext* ImGuiContext = nullptr;
|
||||
|
||||
ImPlotContext* ImPlotContext = nullptr;
|
||||
|
||||
FCogImguiRender Render;
|
||||
|
||||
float DpiScale = 1.f;
|
||||
|
||||
char IniFilename[512];
|
||||
};
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// DEAR IMGUI COMPILE-TIME OPTIONS
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||
//-----------------------------------------------------------------------------
|
||||
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||
// 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()
|
||||
// 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( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
|
||||
|
||||
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||||
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
|
||||
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
|
||||
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
|
||||
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||
//#define IMGUI_USE_WCHAR32
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
|
||||
|
||||
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
|
||||
//#define IMGUI_USE_STB_SPRINTF
|
||||
|
||||
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||
//#define IMGUI_ENABLE_FREETYPE
|
||||
|
||||
//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
|
||||
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
|
||||
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
||||
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||||
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
||||
|
||||
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
//---- ...Or use Dear ImGui's own very basic math operators.
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||
//struct ImDrawList;
|
||||
//struct ImDrawCmd;
|
||||
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||
//#define ImDrawCallback MyImDrawCallback
|
||||
|
||||
//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase)
|
||||
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||
//#define IM_DEBUG_BREAK __debugbreak()
|
||||
|
||||
//---- Debug Tools: Enable slower asserts
|
||||
//#define IMGUI_DEBUG_PARANOID
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, MyMatrix44* mtx);
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
using UnrealBuildTool;
|
||||
using System.IO;
|
||||
|
||||
public class ImGui : ModuleRules
|
||||
{
|
||||
public ImGui(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
Type = ModuleType.External;
|
||||
}
|
||||
}
|
||||
+20767
File diff suppressed because it is too large
Load Diff
+3474
File diff suppressed because it is too large
Load Diff
+8553
File diff suppressed because it is too large
Load Diff
+4254
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,627 @@
|
||||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
//
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1<<30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Evan Pezent
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
# ImPlot
|
||||
ImPlot is an immediate mode, GPU accelerated plotting library for [Dear ImGui](https://github.com/ocornut/imgui). It aims to provide a first-class API that ImGui fans will love. ImPlot is well suited for visualizing program data in real-time or creating interactive plots, and requires minimal code to integrate. Just like ImGui, it does not burden the end user with GUI state management, avoids STL containers and C++ headers, and has no external dependencies except for ImGui itself.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/controls.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/dnd.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/pie.gif" width="270">
|
||||
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/query.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/bars.gif" width="270">
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/rt.gif" width="270">
|
||||
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/stem.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/markers.gif" width="270">
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/shaded.gif" width="270">
|
||||
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/candle.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/heat.gif" width="270">
|
||||
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/tables.gif" width="270">
|
||||
|
||||
## Features
|
||||
|
||||
- GPU accelerated rendering
|
||||
- multiple plot types:
|
||||
- line plots
|
||||
- shaded plots
|
||||
- scatter plots
|
||||
- vertical/horizontal/stacked bars graphs
|
||||
- vertical/horizontal error bars
|
||||
- stem plots
|
||||
- stair plots
|
||||
- pie charts
|
||||
- heatmap charts
|
||||
- 1D/2D histograms
|
||||
- images
|
||||
- and more likely to come
|
||||
- mix/match multiple plot items on a single plot
|
||||
- configurable axes ranges and scaling (linear/log)
|
||||
- subplots
|
||||
- time formatted x-axes (US formatted or ISO 8601)
|
||||
- reversible and lockable axes
|
||||
- multiple x-axes and y-axes
|
||||
- controls for zooming, panning, box selection, and auto-fitting data
|
||||
- controls for creating persistent query ranges (see demo)
|
||||
- several plot styling options: 10 marker types, adjustable marker sizes, line weights, outline colors, fill colors, etc.
|
||||
- 16 built-in colormaps and support for and user-added colormaps
|
||||
- optional plot titles, axis labels, and grid labels
|
||||
- optional and configurable legends with toggle buttons to quickly show/hide plot items
|
||||
- default styling based on current ImGui theme, or completely custom plot styles
|
||||
- customizable data getters and data striding (just like ImGui:PlotLine)
|
||||
- accepts data as float, double, and 8, 16, 32, and 64-bit signed/unsigned integral types
|
||||
- and more! (see Announcements [2022](https://github.com/epezent/implot/discussions/370)/[2021](https://github.com/epezent/implot/issues/168)/[2020](https://github.com/epezent/implot/issues/48))
|
||||
|
||||
## Usage
|
||||
|
||||
The API is used just like any other ImGui `BeginX`/`EndX` pair. First, start a new plot with `ImPlot::BeginPlot()`. Next, plot as many items as you want with the provided `PlotX` functions (e.g. `PlotLine()`, `PlotBars()`, `PlotScatter()`, etc). Finally, wrap things up with a call to `ImPlot::EndPlot()`. That's it!
|
||||
|
||||
```cpp
|
||||
int bar_data[11] = ...;
|
||||
float x_data[1000] = ...;
|
||||
float y_data[1000] = ...;
|
||||
|
||||
ImGui::Begin("My Window");
|
||||
if (ImPlot::BeginPlot("My Plot")) {
|
||||
ImPlot::PlotBars("My Bar Plot", bar_data, 11);
|
||||
ImPlot::PlotLine("My Line Plot", x_data, y_data, 1000);
|
||||
...
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
ImGui::End();
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
Of course, there's much more you can do with ImPlot...
|
||||
|
||||
## Demos
|
||||
|
||||
A comprehensive example of ImPlot's features can be found in `implot_demo.cpp`. Add this file to your sources and call `ImPlot::ShowDemoWindow()` somewhere in your update loop. You are encouraged to use this file as a reference when needing to implement various plot types. The demo is always updated to show new plot types and features as they are added, so check back with each release!
|
||||
|
||||
An online version of the demo is hosted [here](https://traineq.org/implot_demo/src/implot_demo.html). You can view the plots and the source code that generated them. Note that this demo may not always be up to date and is not as performant as a desktop implementation, but it should give you a general taste of what's possible with ImPlot. Special thanks to [pthom](https://github.com/pthom) for creating and hosting this!
|
||||
|
||||
More sophisticated demos requiring lengthier code and/or third-party libraries can be found in a separate repository: [implot_demos](https://github.com/epezent/implot_demos). Here, you will find advanced signal processing and ImPlot usage in action. Please read the `Contributing` section of that repository if you have an idea for a new demo!
|
||||
|
||||
## Integration
|
||||
|
||||
0) Set up an [ImGui](https://github.com/ocornut/imgui) environment if you don't already have one.
|
||||
1) Add `implot.h`, `implot_internal.h`, `implot.cpp`, `implot_items.cpp` and optionally `implot_demo.cpp` to your sources. Alternatively, you can get ImPlot using [vcpkg](https://github.com/microsoft/vcpkg/tree/master/ports/implot).
|
||||
2) Create and destroy an `ImPlotContext` wherever you do so for your `ImGuiContext`:
|
||||
|
||||
```cpp
|
||||
ImGui::CreateContext();
|
||||
ImPlot::CreateContext();
|
||||
...
|
||||
ImPlot::DestroyContext();
|
||||
ImGui::DestroyContext();
|
||||
```
|
||||
|
||||
You should be good to go!
|
||||
|
||||
## Installing ImPlot using vcpkg
|
||||
|
||||
You can download and install ImPlot using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install implot
|
||||
```
|
||||
|
||||
The ImPlot port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
## Extremely Important Note
|
||||
|
||||
Dear ImGui uses **16-bit indexing by default**, so high-density ImPlot widgets like `ImPlot::PlotHeatmap()` may produce too many vertices into `ImDrawList`, which causes an assertion failure and will result in data truncation and/or visual glitches. Therefore, it is **HIGHLY** recommended that you EITHER:
|
||||
|
||||
- **Option 1:** Enable 32-bit indices by uncommenting `#define ImDrawIdx unsigned int` in your ImGui [`imconfig.h`](https://github.com/ocornut/imgui/blob/master/imconfig.h#L89) file.
|
||||
- **Option 2:** Handle the `ImGuiBackendFlags_RendererHasVtxOffset` flag in your renderer if you must use 16-bit indices. Many of the default ImGui rendering backends already support `ImGuiBackendFlags_RendererHasVtxOffset`. Refer to [this issue](https://github.com/ocornut/imgui/issues/2591) for more information.
|
||||
|
||||
## FAQ
|
||||
|
||||
**Q: Why?**
|
||||
|
||||
A: ImGui is an incredibly powerful tool for rapid prototyping and development, but provides only limited mechanisms for data visualization. Two dimensional plots are ubiquitous and useful to almost any application. Being able to visualize your data in real-time will give you insight and better understanding of your application.
|
||||
|
||||
**Q: Is ImPlot the right plotting library for me?**
|
||||
|
||||
A: If you're looking to generate publication quality plots and/or export plots to a file, ImPlot is NOT the library for you! ImPlot is geared toward plotting application data at realtime speeds with high levels of interactivity. ImPlot does its best to create pretty plots (indeed, there are quite a few styling options available), but it will always favor function over form.
|
||||
|
||||
**Q: Where is the documentation?**
|
||||
|
||||
A: The API is thoroughly commented in `implot.h`, and the demo in `implot_demo.cpp` should be more than enough to get you started. Also take a look at the [implot_demos](https://github.com/epezent/implot_demos) repository.
|
||||
|
||||
**Q: Is ImPlot suitable for plotting large datasets?**
|
||||
|
||||
A: Yes, within reason. You can plot tens to hundreds of thousands of points without issue, but don't expect millions to be a buttery smooth experience. That said, you can always downsample extremely large datasets by telling ImPlot to stride your data at larger intervals if needed. Also try the experimental `backends` branch which aims to provide GPU acceleration support.
|
||||
|
||||
**Q: What data types can I plot?**
|
||||
|
||||
A: ImPlot plotting functions accept most scalar types:
|
||||
`float`, `double`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`. Arrays of custom structs or classes (e.g. `Vector2f` or similar) are easily passed to ImPlot functions using the built-in striding features (see `implot.h` for documentation), and many plotters provide a "getter" overload which accepts data generating callbacks. You can fully customize the list of accepted types by defining `IMPLOT_CUSTOM_NUMERIC_TYPES` at compile time: see doc in `implot_items.cpp`.
|
||||
|
||||
**Q: Can plot styles be modified?**
|
||||
|
||||
A: Yes. Data colormaps and various styling colors and variables can be pushed/popped or modified permanently on startup. Three default styles are available, as well as an automatic style that attempts to match you ImGui style.
|
||||
|
||||
**Q: Does ImPlot support logarithmic scaling or time formatting?**
|
||||
|
||||
A: Yep! Both logscale and timescale are supported.
|
||||
|
||||
**Q: Does ImPlot support multiple y-axes? x-axes?**
|
||||
|
||||
A: Yes. Up to three x-axes and three y-axes can be enabled.
|
||||
|
||||
**Q: Does ImPlot support [insert plot type]?**
|
||||
|
||||
A: Maybe. Check the demo, gallery, or Announcements ([2020](https://github.com/epezent/implot/issues/48)/[2021](https://github.com/epezent/implot/issues/168))to see if your desired plot type is shown. If not, consider submitting an issue or better yet, a PR!
|
||||
|
||||
**Q: Does ImPlot support 3D plots?**
|
||||
|
||||
A: No, and likely never will since ImGui only deals in 2D rendering.
|
||||
|
||||
**Q: Does ImPlot provide analytic tools?**
|
||||
|
||||
A: Not exactly, but it does give you the ability to query plot sub-ranges, with which you can process your data however you like.
|
||||
|
||||
**Q: Can plots be exported/saved to image?**
|
||||
|
||||
A: Not currently. Use your OS's screen capturing mechanisms if you need to capture a plot. ImPlot is not suitable for rendering publication quality plots; it is only intended to be used as a visualization tool. Post-process your data with MATLAB or matplotlib for these purposes.
|
||||
|
||||
**Q: Why are my plot lines showing aliasing?**
|
||||
|
||||
A: You probably need to enable `ImGuiStyle::AntiAliasedLinesUseTex` (or possibly `ImGuiStyle:AntiAliasedLines`). If those settings are already enabled, then you must ensure your backend supports texture based anti-aliasing (i.e. uses bilinear sampling). Most of the default ImGui backends support this feature out of the box. Learn more [here](https://github.com/ocornut/imgui/issues/3245). Alternatively, you can enable MSAA at the application level if your hardware supports it (4x should do).
|
||||
|
||||
**Q: Can I compile ImPlot as a dynamic library?**
|
||||
|
||||
A: Like ImGui, it is recommended that you compile and link ImPlot as a *static* library or directly as a part of your sources. However, if you must and are compiling ImPlot and ImGui as separate DLLs, make sure you set the current *ImGui* context with `ImPlot::SetImGuiContext(ImGuiContext* ctx)`. This ensures that global ImGui variables are correctly shared across the DLL boundary.
|
||||
|
||||
**Q: Can ImPlot be used with other languages/bindings?**
|
||||
|
||||
A: Yes, you can use the generated C binding, [cimplot](https://github.com/cimgui/cimplot) with most high level languages. [DearPyGui](https://github.com/hoffstadt/DearPyGui) provides a Python wrapper, among other things. [DearImGui/DearImPlot](https://github.com/aybe/DearImGui) provides bindings for .NET. [imgui-java](https://github.com/SpaiR/imgui-java) provides bindings for Java. [ImPlot.jl](https://github.com/wsphillips/ImPlot.jl) provides bindings for Julia. A Rust binding, [implot-rs](https://github.com/4bb4/implot-rs), is currently in the works. An example using Emscripten can be found [here](https://github.com/pthom/implot_demo).
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
The list below represents a combination of high-priority work, nice-to-have features, and random ideas. We make no guarantees that all of this work will be completed or even started. If you see something that you need or would like to have, let us know, or better yet consider submitting a PR for the feature.
|
||||
|
||||
## API
|
||||
|
||||
## Axes
|
||||
|
||||
- add flag to remove weekends on Time axis
|
||||
- pixel space scale (`ImPlotTransform_Display`), normalized space scale (`ImPlotTransform_Axes`), data space scale (`ImPlotTransform_Data`)
|
||||
- make ImPlotFlags_Equal not a flag -> `SetupEqual(ImPlotAxis x, ImPlotAxis y)`
|
||||
- allow inverted arguments `SetAxes` to transpose data?
|
||||
- `SetupAxisColors()`
|
||||
- `SetupAxisHome()`
|
||||
|
||||
## Plot Items
|
||||
|
||||
- add `PlotBubbles` (see MATLAB bubble chart)
|
||||
- add non-zero references for `PlotBars` etc.
|
||||
- add exploding to `PlotPieChart` (on hover-highlight?)
|
||||
- fix appearance of `PlotBars` spacing
|
||||
|
||||
## Styling
|
||||
|
||||
- support gradient and/or colormap sampled fills (e.g. ImPlotFillStyle_)
|
||||
- API for setting different fonts for plot elements
|
||||
|
||||
## Colormaps
|
||||
|
||||
- gradient editing tool
|
||||
- `RemoveColormap`
|
||||
- `enum ImPlotColorRule_ { Solid, Faded, XValue, YValue, ZValue }`
|
||||
|
||||
## Legend
|
||||
|
||||
- improve legend icons (e.g. adopt markers, gradients, etc)
|
||||
- generalize legend rendering for plots and subplots
|
||||
- add draggable scroll bar if users need it
|
||||
|
||||
## Tools / Misc.
|
||||
|
||||
- add `IsPlotChanging` to detect change in limits
|
||||
- add ability to extend plot/axis context menus
|
||||
- add LTTB downsampling for lines
|
||||
- add box selection to axes
|
||||
- first frame render delay might fix "fit pop" effect
|
||||
- move some code to new `implot_tools.cpp`
|
||||
- ColormapSlider (see metrics)
|
||||
- FillAlpha should not affect markers?
|
||||
- fix mouse text for time axes
|
||||
|
||||
## Optimizations
|
||||
|
||||
- find faster way to buffer data into ImDrawList (very slow)
|
||||
- reduce number of calls to `PushClipRect`
|
||||
- explore SIMD operations for high density plot items
|
||||
|
||||
## Plotter Pipeline
|
||||
|
||||
Ideally every `PlotX` function should use our faster rendering pipeline when it is applicable.
|
||||
|
||||
` User Data > Getter > Fitter > Renderer > RenderPrimitives`
|
||||
|
||||
|Plotter|Getter|Fitter|Renderer|RenderPrimitives|
|
||||
|---|:-:|:-:|:-:|:-:|
|
||||
|PlotLine|Yes|Yes|Yes|Yes|
|
||||
|PlotScatter|Yes|Yes|Yes|Yes|
|
||||
|PlotStairs|Yes|Yes|Yes|Yes|
|
||||
|PlotShaded|Yes|Yes|Yes|Yes|
|
||||
|PlotBars|Yes|Yes|Yes|Yes|
|
||||
|PlotBarGroups|:|:|:|:|
|
||||
|PlotHistogram|:|:|:|:|
|
||||
|PlotErrorBars|Yes|Yes|No|No|
|
||||
|PlotStems|Yes|Yes|Yes|Yes|
|
||||
|PlotInfLines|Yes|Yes|Yes|Yes|
|
||||
|PlotPieChart|No|No|No|No|
|
||||
|PlotHeatmap|Yes|No|Yes|Mixed|
|
||||
|PlotHistogram2D|:|:|:|:|
|
||||
|PlotDigital|Yes|No|No|No|
|
||||
|PlotImage|-|-|-|-|
|
||||
|PlotText|-|-|-|-|
|
||||
|PlotDummy|-|-|-|-|
|
||||
|
||||
## Completed
|
||||
- make BeginPlot take fewer args:
|
||||
- make query a tool -> `DragRect`
|
||||
- rework DragLine/Point to use ButtonBehavior
|
||||
- add support for multiple x-axes and don't limit count to 3
|
||||
- make axis side configurable (top/left, right/bottom) via new flag `ImPlotAxisFlags_Opposite`
|
||||
- add support for setting tick label strings via callback
|
||||
- give each axis an ID, remove ad-hoc DND solution
|
||||
- allow axis to be drag to opposite side (ala ImGui Table headers)
|
||||
- legend items can be hovered even if plot is not
|
||||
- fix frame delay on DragX tools
|
||||
- remove tag from drag line/point -> add `Tag` tool
|
||||
- add shortcut/legacy overloads for BeginPlot
|
||||
- `SetupAxisConstraints()`
|
||||
- `SetupAxisScale()`
|
||||
- add `ImPlotLineFlags`, `ImPlotBarsFlags`, etc. for each plot type
|
||||
- add `PlotBarGroups` wrapper that makes rendering groups of bars easier, with stacked bar support
|
||||
- `PlotBars` restore outlines
|
||||
- add hover/active color for plot axes
|
||||
- make legend frame use ButtonBehavior
|
||||
- `ImPlotLegendFlags_Scroll` (default behavior)
|
||||
@@ -0,0 +1,10 @@
|
||||
using UnrealBuildTool;
|
||||
using System.IO;
|
||||
|
||||
public class ImPlot : ModuleRules
|
||||
{
|
||||
public ImPlot(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
Type = ModuleType.External;
|
||||
}
|
||||
}
|
||||
+5885
File diff suppressed because it is too large
Load Diff
+1295
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user