Added to ImGui Context Proxy information about context display size.

This commit is contained in:
Sebastian 2018-04-17 23:03:24 +01:00
parent f8e689561f
commit cfc76ea286
2 changed files with 9 additions and 0 deletions

View File

@ -63,6 +63,7 @@ FImGuiContextProxy::FImGuiContextProxy(const FString& InName, FSimpleMulticastDe
// Use pre-defined canvas size. // Use pre-defined canvas size.
IO.DisplaySize = { DEFAULT_CANVAS_WIDTH, DEFAULT_CANVAS_HEIGHT }; 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 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 // 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). // beforehand).
bHasActiveItem = ImGui::IsAnyItemActive(); bHasActiveItem = ImGui::IsAnyItemActive();
MouseCursor = ImGuiInterops::ToSlateMouseCursor(ImGui::GetMouseCursor()); 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. // Begin a new frame and set the context back to a state in which it allows to draw controls.
BeginFrame(DeltaSeconds); BeginFrame(DeltaSeconds);

View File

@ -49,8 +49,13 @@ public:
// Set this context as current ImGui context. // Set this context as current ImGui context.
void SetAsCurrent() { ImGui::SetCurrentContext(Context.Get()); } 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; } 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; } EMouseCursor::Type GetMouseCursor() const { return MouseCursor; }
// Delegate called right before ending the frame to allows listeners draw their controls. // Delegate called right before ending the frame to allows listeners draw their controls.
@ -72,6 +77,8 @@ private:
TUniquePtr<ImGuiContext> Context; TUniquePtr<ImGuiContext> Context;
FVector2D DisplaySize = FVector2D::ZeroVector;
EMouseCursor::Type MouseCursor = EMouseCursor::None; EMouseCursor::Type MouseCursor = EMouseCursor::None;
bool bHasActiveItem = false; bool bHasActiveItem = false;