2017-03-26 20:32:57 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ImGuiDrawData.h"
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
2017-04-22 15:38:04 +00:00
|
|
|
class FImGuiInputState;
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
// Represents a single ImGui context. All the context updates should be done through this proxy. During update it
|
2017-08-28 19:29:07 +00:00
|
|
|
// broadcasts draw events to allow listeners draw their controls. After update it stores draw data.
|
2017-03-26 20:32:57 +00:00
|
|
|
class FImGuiContextProxy
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
FImGuiContextProxy();
|
|
|
|
~FImGuiContextProxy();
|
|
|
|
|
|
|
|
FImGuiContextProxy(const FImGuiContextProxy&) = delete;
|
|
|
|
FImGuiContextProxy& operator=(const FImGuiContextProxy&) = delete;
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
FImGuiContextProxy(FImGuiContextProxy&& Other);
|
|
|
|
FImGuiContextProxy& operator=(FImGuiContextProxy&& Other);
|
2017-03-26 20:32:57 +00:00
|
|
|
|
|
|
|
// Get draw data from the last frame.
|
|
|
|
const TArray<FImGuiDrawList>& GetDrawData() const { return DrawLists; }
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
// 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; }
|
|
|
|
|
|
|
|
// 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); }
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
// 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.
|
2017-08-28 19:29:07 +00:00
|
|
|
void Tick(float DeltaSeconds);
|
2017-03-26 20:32:57 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
void BeginFrame(float DeltaTime = 1.f / 60.f);
|
2017-03-26 20:32:57 +00:00
|
|
|
void EndFrame();
|
|
|
|
|
|
|
|
void UpdateDrawData(ImDrawData* DrawData);
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
ImGuiContext* Context = nullptr;
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
bool bIsFrameStarted = false;
|
2017-03-26 20:32:57 +00:00
|
|
|
FSimpleMulticastDelegate DrawEvent;
|
2017-08-28 19:29:07 +00:00
|
|
|
const FImGuiInputState* InputState = nullptr;
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
TArray<FImGuiDrawList> DrawLists;
|
2017-03-26 20:32:57 +00:00
|
|
|
};
|