mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-03 05:08:13 +00:00
CogImgui: Fix imgui windows not correctly placed at startup when using imgui viewports
This commit is contained in:
@@ -60,6 +60,7 @@ void FCogImguiContext::Initialize()
|
|||||||
IO.ConfigFlags |= ImGuiConfigFlags_NavNoCaptureKeyboard;
|
IO.ConfigFlags |= ImGuiConfigFlags_NavNoCaptureKeyboard;
|
||||||
IO.ConfigFlags |= ImGuiConfigFlags_NavEnableSetMousePos;
|
IO.ConfigFlags |= ImGuiConfigFlags_NavEnableSetMousePos;
|
||||||
IO.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
IO.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
|
IO.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||||
|
|
||||||
IO.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
IO.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
|
||||||
IO.BackendFlags |= ImGuiBackendFlags_HasSetMousePos;
|
IO.BackendFlags |= ImGuiBackendFlags_HasSetMousePos;
|
||||||
@@ -174,8 +175,19 @@ void FCogImguiContext::OnDisplayMetricsChanged(const FDisplayMetrics& DisplayMet
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void FCogImguiContext::BeginFrame(float InDeltaTime)
|
bool FCogImguiContext::BeginFrame(float InDeltaTime)
|
||||||
{
|
{
|
||||||
|
//-------------------------------------------------------------------------------------------------------
|
||||||
|
// Skip the first frame, to let the main widget update its TickSpaceGeometry which is returned by the
|
||||||
|
// plateform callback ImGui_GetWindowPos. When using viewports Imgui needs to know the main viewport
|
||||||
|
// absolute position to correctly place the initial imgui windows.
|
||||||
|
//-------------------------------------------------------------------------------------------------------
|
||||||
|
if (bIsFirstFrame)
|
||||||
|
{
|
||||||
|
bIsFirstFrame = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SetCurrentContext(ImGuiContext);
|
ImGui::SetCurrentContext(ImGuiContext);
|
||||||
ImPlot::SetImGuiContext(ImGuiContext);
|
ImPlot::SetImGuiContext(ImGuiContext);
|
||||||
ImPlot::SetCurrentContext(PlotContext);
|
ImPlot::SetCurrentContext(PlotContext);
|
||||||
@@ -275,10 +287,11 @@ void FCogImguiContext::BeginFrame(float InDeltaTime)
|
|||||||
NewStyle.ScaleAllSizes(DpiScale);
|
NewStyle.ScaleAllSizes(DpiScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
//DrawDebug();
|
//DrawDebug();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -581,7 +594,7 @@ void FCogImguiContext::SetEnableInput(bool Value)
|
|||||||
if (bEnableInput)
|
if (bEnableInput)
|
||||||
{
|
{
|
||||||
FSlateThrottleManager::Get().DisableThrottle(true);
|
FSlateThrottleManager::Get().DisableThrottle(true);
|
||||||
IsThrottleDisabled = true;
|
bIsThrottleDisabled = true;
|
||||||
|
|
||||||
FSlateApplication& SlateApp = FSlateApplication::Get();
|
FSlateApplication& SlateApp = FSlateApplication::Get();
|
||||||
|
|
||||||
@@ -594,7 +607,7 @@ void FCogImguiContext::SetEnableInput(bool Value)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IsThrottleDisabled)
|
if (bIsThrottleDisabled)
|
||||||
{
|
{
|
||||||
FSlateThrottleManager::Get().DisableThrottle(false);
|
FSlateThrottleManager::Get().DisableThrottle(false);
|
||||||
}
|
}
|
||||||
@@ -628,6 +641,12 @@ void FCogImguiContext::SetDPIScale(float Value)
|
|||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
void FCogImguiContext::BuildFont()
|
void FCogImguiContext::BuildFont()
|
||||||
{
|
{
|
||||||
|
if (FontAtlasTexture != nullptr)
|
||||||
|
{
|
||||||
|
FontAtlasTexture->RemoveFromRoot();
|
||||||
|
FontAtlasTexture->ConditionalBeginDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
ImGuiIO& IO = ImGui::GetIO();
|
ImGuiIO& IO = ImGui::GetIO();
|
||||||
IO.Fonts->Clear();
|
IO.Fonts->Clear();
|
||||||
|
|
||||||
@@ -639,7 +658,7 @@ void FCogImguiContext::BuildFont()
|
|||||||
int32 TextureWidth, TextureHeight, BytesPerPixel;
|
int32 TextureWidth, TextureHeight, BytesPerPixel;
|
||||||
IO.Fonts->GetTexDataAsRGBA32(&TextureDataRaw, &TextureWidth, &TextureHeight, &BytesPerPixel);
|
IO.Fonts->GetTexDataAsRGBA32(&TextureDataRaw, &TextureWidth, &TextureHeight, &BytesPerPixel);
|
||||||
|
|
||||||
UTexture2D* FontAtlasTexture = UTexture2D::CreateTransient(TextureWidth, TextureHeight, PF_R8G8B8A8, TEXT("ImGuiFontAtlas"));
|
FontAtlasTexture = UTexture2D::CreateTransient(TextureWidth, TextureHeight, PF_R8G8B8A8, TEXT("ImGuiFontAtlas"));
|
||||||
FontAtlasTexture->Filter = TF_Bilinear;
|
FontAtlasTexture->Filter = TF_Bilinear;
|
||||||
FontAtlasTexture->AddressX = TA_Wrap;
|
FontAtlasTexture->AddressX = TA_Wrap;
|
||||||
FontAtlasTexture->AddressY = TA_Wrap;
|
FontAtlasTexture->AddressY = TA_Wrap;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ struct COGIMGUI_API FImGuiViewportData
|
|||||||
class COGIMGUI_API FCogImguiContext : public TSharedFromThis<FCogImguiContext>
|
class COGIMGUI_API FCogImguiContext : public TSharedFromThis<FCogImguiContext>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
@@ -37,7 +38,7 @@ public:
|
|||||||
|
|
||||||
void SetShareMouse(bool Value);
|
void SetShareMouse(bool Value);
|
||||||
|
|
||||||
void BeginFrame(float InDeltaTime);
|
bool BeginFrame(float InDeltaTime);
|
||||||
|
|
||||||
void EndFrame();
|
void EndFrame();
|
||||||
|
|
||||||
@@ -87,6 +88,9 @@ private:
|
|||||||
|
|
||||||
static void ImGui_RenderWindow(ImGuiViewport* Viewport, void* Data);
|
static void ImGui_RenderWindow(ImGuiViewport* Viewport, void* Data);
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UTexture2D* FontAtlasTexture = nullptr;
|
||||||
|
|
||||||
TMap<TWeakPtr<SWindow>, ImGuiID> WindowToViewportMap;
|
TMap<TWeakPtr<SWindow>, ImGuiID> WindowToViewportMap;
|
||||||
|
|
||||||
TSharedPtr<IInputProcessor> InputProcessor = nullptr;
|
TSharedPtr<IInputProcessor> InputProcessor = nullptr;
|
||||||
@@ -109,9 +113,12 @@ private:
|
|||||||
|
|
||||||
bool bShareMouse = true;
|
bool bShareMouse = true;
|
||||||
|
|
||||||
float DpiScale = 1.f;
|
|
||||||
|
|
||||||
bool bRefreshDPIScale = false;
|
bool bRefreshDPIScale = false;
|
||||||
|
|
||||||
bool IsThrottleDisabled = false;
|
bool bIsThrottleDisabled = false;
|
||||||
|
|
||||||
|
bool bIsFirstFrame = true;
|
||||||
|
|
||||||
|
float DpiScale = 1.f;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -152,9 +152,11 @@ void UCogWindowManager::Tick(float DeltaTime)
|
|||||||
Window->GameTick(DeltaTime);
|
Window->GameTick(DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
Context.BeginFrame(DeltaTime);
|
if (Context.BeginFrame(DeltaTime))
|
||||||
Render(DeltaTime);
|
{
|
||||||
Context.EndFrame();
|
Render(DeltaTime);
|
||||||
|
Context.EndFrame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user