2017-03-26 20:32:57 +00:00
|
|
|
// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ImGuiDrawData.h"
|
|
|
|
|
2018-03-13 23:42:37 +00:00
|
|
|
#include <ICursor.h>
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
#include <string>
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
|
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
|
|
|
|
{
|
2019-03-11 19:19:32 +00:00
|
|
|
class FImGuiContextPtr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
FImGuiContextPtr() = default;
|
|
|
|
FImGuiContextPtr(ImGuiContext* InContext) : Context(InContext) {}
|
|
|
|
|
|
|
|
FImGuiContextPtr(const FImGuiContextPtr&) = delete;
|
|
|
|
FImGuiContextPtr& operator=(const FImGuiContextPtr&) = delete;
|
|
|
|
|
|
|
|
FImGuiContextPtr(FImGuiContextPtr&& Other) : Context(Other.Context) { Other.Context = nullptr; }
|
|
|
|
FImGuiContextPtr& operator=(FImGuiContextPtr&& Other) { std::swap(Context, Other.Context); return *this; }
|
|
|
|
|
|
|
|
~FImGuiContextPtr();
|
|
|
|
|
|
|
|
ImGuiContext* Get() const { return Context; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ImGuiContext* Context = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-03-26 20:32:57 +00:00
|
|
|
public:
|
|
|
|
|
2018-05-09 19:22:48 +00:00
|
|
|
FImGuiContextProxy(const FString& Name, FSimpleMulticastDelegate* InSharedDrawEvent, ImFontAtlas* InFontAtlas);
|
2017-03-26 20:32:57 +00:00
|
|
|
|
|
|
|
FImGuiContextProxy(const FImGuiContextProxy&) = delete;
|
|
|
|
FImGuiContextProxy& operator=(const FImGuiContextProxy&) = delete;
|
|
|
|
|
2019-03-11 19:19:32 +00:00
|
|
|
FImGuiContextProxy(FImGuiContextProxy&&) = default;
|
|
|
|
FImGuiContextProxy& operator=(FImGuiContextProxy&&) = default;
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
// Get the name of this context.
|
|
|
|
const FString& GetName() const { return Name; }
|
|
|
|
|
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; }
|
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
// If context is currently using input state to remove then remove that binding.
|
|
|
|
void RemoveInputState(const FImGuiInputState* InputStateToRemove) { if (InputState == InputStateToRemove) InputState = nullptr; }
|
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
// Is this context the current ImGui context.
|
2018-03-18 19:45:08 +00:00
|
|
|
bool IsCurrentContext() const { return ImGui::GetCurrentContext() == Context.Get(); }
|
2017-08-28 19:29:07 +00:00
|
|
|
|
|
|
|
// Set this context as current ImGui context.
|
2018-03-18 19:45:08 +00:00
|
|
|
void SetAsCurrent() { ImGui::SetCurrentContext(Context.Get()); }
|
2017-08-28 19:29:07 +00:00
|
|
|
|
2018-04-17 22:03:24 +00:00
|
|
|
// Context display size (read once per frame during context update and cached here for easy access).
|
|
|
|
const FVector2D& GetDisplaySize() const { return DisplaySize; }
|
|
|
|
|
|
|
|
// Whether this context has an active item (read once per frame during context update and cached here for easy access).
|
2017-09-16 20:52:14 +00:00
|
|
|
bool HasActiveItem() const { return bHasActiveItem; }
|
|
|
|
|
2018-04-17 22:03:24 +00:00
|
|
|
// Cursor type desired by this context (this is updated during ImGui frame and cached here during context update, before it is reset).
|
2018-03-13 23:42:37 +00:00
|
|
|
EMouseCursor::Type GetMouseCursor() const { return MouseCursor; }
|
|
|
|
|
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; }
|
|
|
|
|
2018-03-18 19:45:08 +00:00
|
|
|
// Call draw events to allow listeners draw their widgets. Only one call per frame is processed. If it is not
|
|
|
|
// called manually before, then it will be called from the Tick function.
|
|
|
|
void Draw();
|
|
|
|
|
|
|
|
// Tick to advance context to the next frame. Only one call per frame will be processed.
|
|
|
|
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);
|
|
|
|
|
2019-03-11 19:19:32 +00:00
|
|
|
FImGuiContextPtr Context;
|
2017-03-26 20:32:57 +00:00
|
|
|
|
2018-04-17 22:03:24 +00:00
|
|
|
FVector2D DisplaySize = FVector2D::ZeroVector;
|
|
|
|
|
2018-03-13 23:42:37 +00:00
|
|
|
EMouseCursor::Type MouseCursor = EMouseCursor::None;
|
2018-03-18 19:45:08 +00:00
|
|
|
bool bHasActiveItem = false;
|
2017-09-16 20:52:14 +00:00
|
|
|
|
2017-08-28 19:29:07 +00:00
|
|
|
bool bIsFrameStarted = false;
|
2018-03-20 23:24:03 +00:00
|
|
|
bool bIsDrawCalled = false;
|
|
|
|
|
|
|
|
uint32 LastFrameNumber = 0;
|
2019-04-11 19:06:41 +00:00
|
|
|
FString Name;
|
2017-03-26 20:32:57 +00:00
|
|
|
FSimpleMulticastDelegate DrawEvent;
|
2018-03-18 19:45:08 +00:00
|
|
|
FSimpleMulticastDelegate* SharedDrawEvent = nullptr;
|
|
|
|
|
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-09-27 20:16:54 +00:00
|
|
|
|
2019-04-11 19:06:41 +00:00
|
|
|
|
2017-09-27 20:16:54 +00:00
|
|
|
std::string IniFilename;
|
2017-03-26 20:32:57 +00:00
|
|
|
};
|