From cfc76ea28607895d8145587dfd7b45781690dee8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 17 Apr 2018 23:03:24 +0100 Subject: [PATCH] Added to ImGui Context Proxy information about context display size. --- Source/ImGui/Private/ImGuiContextProxy.cpp | 2 ++ Source/ImGui/Private/ImGuiContextProxy.h | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Source/ImGui/Private/ImGuiContextProxy.cpp b/Source/ImGui/Private/ImGuiContextProxy.cpp index af74a46..d4d8977 100644 --- a/Source/ImGui/Private/ImGuiContextProxy.cpp +++ b/Source/ImGui/Private/ImGuiContextProxy.cpp @@ -63,6 +63,7 @@ FImGuiContextProxy::FImGuiContextProxy(const FString& InName, FSimpleMulticastDe // Use pre-defined canvas size. IO.DisplaySize = { DEFAULT_CANVAS_WIDTH, DEFAULT_CANVAS_HEIGHT }; + DisplaySize = ImGuiInterops::ToVector2D(IO.DisplaySize); // When GetTexData is called for the first time it builds atlas texture and copies mouse cursor data to context. // When multiple contexts share atlas then only the first one will get mouse data. A simple workaround is to use @@ -151,6 +152,7 @@ void FImGuiContextProxy::Tick(float DeltaSeconds) // beforehand). bHasActiveItem = ImGui::IsAnyItemActive(); MouseCursor = ImGuiInterops::ToSlateMouseCursor(ImGui::GetMouseCursor()); + DisplaySize = ImGuiInterops::ToVector2D(ImGui::GetIO().DisplaySize); // Begin a new frame and set the context back to a state in which it allows to draw controls. BeginFrame(DeltaSeconds); diff --git a/Source/ImGui/Private/ImGuiContextProxy.h b/Source/ImGui/Private/ImGuiContextProxy.h index ea8c530..caaade7 100644 --- a/Source/ImGui/Private/ImGuiContextProxy.h +++ b/Source/ImGui/Private/ImGuiContextProxy.h @@ -49,8 +49,13 @@ public: // Set this context as current ImGui context. void SetAsCurrent() { ImGui::SetCurrentContext(Context.Get()); } + // 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). bool HasActiveItem() const { return bHasActiveItem; } + // Cursor type desired by this context (this is updated during ImGui frame and cached here during context update, before it is reset). EMouseCursor::Type GetMouseCursor() const { return MouseCursor; } // Delegate called right before ending the frame to allows listeners draw their controls. @@ -72,6 +77,8 @@ private: TUniquePtr Context; + FVector2D DisplaySize = FVector2D::ZeroVector; + EMouseCursor::Type MouseCursor = EMouseCursor::None; bool bHasActiveItem = false;