mirror of
https://github.com/kevinporetti/UnrealImGui.git
synced 2025-01-18 16:30:32 +00:00
1a6aa98f51
- Added to ImGui Context Proxy a name that is mapped to ini file set in ImGui context. - ImGui Context Manager generates unique context names from world type and context index. - Refactored ImGui Context Manager to have a cleaner separation between editor and non-editor bits. - Fixed context update rules in ImGui Context Manager. - Changed widgets management in ImGui Module Manager to allow automatic garbage collection after viewports are closed and manual removal when module is shutting down. - ImGui Widgets are in full control of communication with context proxies. - Added basic world context utilities. - Refactored world context index utilities and replaced ambiguous 'default context index' with 'editor' and 'game' ones.
78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
#pragma once
|
|
|
|
#include "ImGuiDrawData.h"
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
class FImGuiInputState;
|
|
|
|
// Represents a single ImGui context. All the context updates should be done through this proxy. During update it
|
|
// broadcasts draw events to allow listeners draw their controls. After update it stores draw data.
|
|
class FImGuiContextProxy
|
|
{
|
|
public:
|
|
|
|
FImGuiContextProxy(const FString& Name);
|
|
~FImGuiContextProxy();
|
|
|
|
FImGuiContextProxy(const FImGuiContextProxy&) = delete;
|
|
FImGuiContextProxy& operator=(const FImGuiContextProxy&) = delete;
|
|
|
|
FImGuiContextProxy(FImGuiContextProxy&& Other);
|
|
FImGuiContextProxy& operator=(FImGuiContextProxy&& Other);
|
|
|
|
// Get the name of this context.
|
|
const FString& GetName() const { return Name; }
|
|
|
|
// Get draw data from the last frame.
|
|
const TArray<FImGuiDrawList>& GetDrawData() const { return DrawLists; }
|
|
|
|
// Get input state used by this context.
|
|
const FImGuiInputState* GetInputState() const { return InputState; }
|
|
|
|
// Set input state to be used by this context.
|
|
void SetInputState(const FImGuiInputState* SourceInputState) { InputState = SourceInputState; }
|
|
|
|
// If context is currently using input state to remove then remove that binding.
|
|
void RemoveInputState(const FImGuiInputState* InputStateToRemove) { if (InputState == InputStateToRemove) InputState = nullptr; }
|
|
|
|
// Is this context the current ImGui context.
|
|
bool IsCurrentContext() const { return ImGui::GetCurrentContext() == Context; }
|
|
|
|
// Set this context as current ImGui context.
|
|
void SetAsCurrent() { ImGui::SetCurrentContext(Context); }
|
|
|
|
bool HasActiveItem() const { return bHasActiveItem; }
|
|
|
|
// Delegate called right before ending the frame to allows listeners draw their controls.
|
|
FSimpleMulticastDelegate& OnDraw() { return DrawEvent; }
|
|
|
|
// Tick to advance context to the next frame.
|
|
void Tick(float DeltaSeconds);
|
|
|
|
private:
|
|
|
|
void BeginFrame(float DeltaTime = 1.f / 60.f);
|
|
void EndFrame();
|
|
|
|
void UpdateDrawData(ImDrawData* DrawData);
|
|
|
|
ImGuiContext* Context = nullptr;
|
|
|
|
bool bHasActiveItem = false;
|
|
|
|
bool bIsFrameStarted = false;
|
|
FSimpleMulticastDelegate DrawEvent;
|
|
const FImGuiInputState* InputState = nullptr;
|
|
|
|
TArray<FImGuiDrawList> DrawLists;
|
|
|
|
FString Name;
|
|
std::string IniFilename;
|
|
};
|