mirror of
https://github.com/Ed94/Cog.git
synced 2026-08-06 15:48:48 +00:00
CogImGui: remove the scale widget containing the imgui widget
This commit is contained in:
@@ -41,16 +41,7 @@ void FImGuiInputProcessor::Tick(const float DeltaTime, FSlateApplication& SlateA
|
|||||||
UE_LOG(LogCogImGui, VeryVerbose, TEXT("FImGuiInputProcessor::Tick | HasGamePad Changed"));
|
UE_LOG(LogCogImGui, VeryVerbose, TEXT("FImGuiInputProcessor::Tick | HasGamePad Changed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
AddMousePosEvent(SlateApp.GetCursorPos());
|
||||||
{
|
|
||||||
const FVector2D MousePosition = SlateApp.GetCursorPos();
|
|
||||||
IO.AddMousePosEvent(MousePosition.X, MousePosition.Y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const FVector2D MousePosition = TransformScreenPointToImGui(MainWidget->GetTickSpaceGeometry(), SlateApp.GetCursorPos());
|
|
||||||
IO.AddMousePosEvent(MousePosition.X, MousePosition.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((IO.ConfigFlags & ImGuiConfigFlags_NoMouse) == 0)
|
if ((IO.ConfigFlags & ImGuiConfigFlags_NoMouse) == 0)
|
||||||
{
|
{
|
||||||
@@ -182,24 +173,14 @@ bool FImGuiInputProcessor::HandleAnalogInputEvent(FSlateApplication& SlateApp, c
|
|||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
bool FImGuiInputProcessor::HandleMouseMoveEvent(FSlateApplication& SlateApp, const FPointerEvent& Event)
|
bool FImGuiInputProcessor::HandleMouseMoveEvent(FSlateApplication& SlateApp, const FPointerEvent& Event)
|
||||||
{
|
{
|
||||||
ImGuiIO& IO = ImGui::GetIO();
|
AddMousePosEvent(Event.GetScreenSpacePosition());
|
||||||
|
|
||||||
if (IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
|
||||||
{
|
|
||||||
const FVector2D MousePosition = Event.GetScreenSpacePosition();;
|
|
||||||
IO.AddMousePosEvent(MousePosition.X, MousePosition.Y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const FVector2D MousePosition = TransformScreenPointToImGui(MainWidget->GetTickSpaceGeometry(), Event.GetScreenSpacePosition());
|
|
||||||
IO.AddMousePosEvent(MousePosition.X, MousePosition.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MainWidget->GetEnableInput() && MainWidget->GetShareMouse() == false)
|
if (MainWidget->GetEnableInput() && MainWidget->GetShareMouse() == false)
|
||||||
{
|
{
|
||||||
return TerminateEvent;
|
return TerminateEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGuiIO& IO = ImGui::GetIO();
|
||||||
const bool Result = IO.WantCaptureMouse ? TerminateEvent : ForwardEvent;
|
const bool Result = IO.WantCaptureMouse ? TerminateEvent : ForwardEvent;
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@@ -241,6 +222,20 @@ bool FImGuiInputProcessor::HandleMouseButtonEvent(FSlateApplication& SlateApp, c
|
|||||||
UE_LOG(LogCogImGui, VeryVerbose, TEXT("FImGuiInputProcessor::HandleMouseButtonEvent | Button:%d | IsButtonDown:%d | WantCaptureMouse:%d | TerminateEvent:%d"), Button, IsButtonDown, IO.WantCaptureMouse, Result);
|
UE_LOG(LogCogImGui, VeryVerbose, TEXT("FImGuiInputProcessor::HandleMouseButtonEvent | Button:%d | IsButtonDown:%d | WantCaptureMouse:%d | TerminateEvent:%d"), Button, IsButtonDown, IO.WantCaptureMouse, Result);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void FImGuiInputProcessor::AddMousePosEvent(const FVector2D& MousePosition) const
|
||||||
|
{
|
||||||
|
ImGuiIO& IO = ImGui::GetIO();
|
||||||
|
if (IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
|
{
|
||||||
|
IO.AddMousePosEvent(MousePosition.X, MousePosition.Y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const FVector2D TransformedMousePosition = MousePosition - MainWidget->GetTickSpaceGeometry().GetAbsolutePosition();
|
||||||
|
IO.AddMousePosEvent(TransformedMousePosition.X, TransformedMousePosition.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
bool FImGuiInputProcessor::HandleMouseWheelOrGestureEvent(FSlateApplication& SlateApp, const FPointerEvent& Event, const FPointerEvent* GestureEvent)
|
bool FImGuiInputProcessor::HandleMouseWheelOrGestureEvent(FSlateApplication& SlateApp, const FPointerEvent& Event, const FPointerEvent* GestureEvent)
|
||||||
|
|||||||
@@ -70,20 +70,9 @@ TSharedPtr<SCogImguiWidget> FCogImguiModule::CreateImGuiWidget(UGameViewportClie
|
|||||||
SAssignNew(ImguiWidget, SCogImguiWidget)
|
SAssignNew(ImguiWidget, SCogImguiWidget)
|
||||||
.GameViewport(GameViewport)
|
.GameViewport(GameViewport)
|
||||||
.FontAtlas(FontAtlas)
|
.FontAtlas(FontAtlas)
|
||||||
.Render(Render)
|
.Render(Render);
|
||||||
.Clipping(EWidgetClipping::ClipToBounds);
|
|
||||||
|
|
||||||
TSharedPtr<SScaleBox> ScaleWidget;
|
GameViewport->AddViewportWidgetContent(ImguiWidget.ToSharedRef(), TNumericLimits<int32>::Max());
|
||||||
SAssignNew(ScaleWidget, SScaleBox)
|
|
||||||
.IgnoreInheritedScale(true)
|
|
||||||
.HAlign(HAlign_Fill)
|
|
||||||
.VAlign(VAlign_Fill)
|
|
||||||
.Visibility(EVisibility::SelfHitTestInvisible)
|
|
||||||
[
|
|
||||||
ImguiWidget.ToSharedRef()
|
|
||||||
];
|
|
||||||
|
|
||||||
GameViewport->AddViewportWidgetContent(ScaleWidget.ToSharedRef(), Cog_ZOrder);
|
|
||||||
|
|
||||||
return ImguiWidget;
|
return ImguiWidget;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,20 +98,6 @@ void SCogImguiWidget::Tick(const FGeometry& AllottedGeometry, const double InCur
|
|||||||
TickKeyModifiers();
|
TickKeyModifiers();
|
||||||
TickFocus();
|
TickFocus();
|
||||||
TickImGui(InDeltaTime);
|
TickImGui(InDeltaTime);
|
||||||
|
|
||||||
//ImGuiIO& IO = ImGui::GetIO();
|
|
||||||
//if (GetEnableInput())
|
|
||||||
//{
|
|
||||||
// IO.ConfigFlags &= ~ImGuiConfigFlags_NoMouse;
|
|
||||||
// IO.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
||||||
// IO.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// IO.ConfigFlags |= ImGuiConfigFlags_NoMouse;
|
|
||||||
// IO.ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
|
||||||
// IO.ConfigFlags &= ~ImGuiConfigFlags_NavEnableGamepad;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -138,18 +124,18 @@ void SCogImguiWidget::TickImGui(float InDeltaTime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCurrentContext(ImGuiContext);
|
ImGui::SetCurrentContext(ImGuiContext);
|
||||||
ImGuiIO& IO = ImGui::GetIO();
|
|
||||||
IO.DeltaTime = InDeltaTime;
|
|
||||||
|
|
||||||
ImPlot::SetImGuiContext(ImGuiContext);
|
ImPlot::SetImGuiContext(ImGuiContext);
|
||||||
ImPlot::SetCurrentContext(ImPlotContext);
|
ImPlot::SetCurrentContext(ImPlotContext);
|
||||||
|
|
||||||
FVector2D DisplaySize;
|
ImGuiIO& IO = ImGui::GetIO();
|
||||||
GameViewport->GetViewportSize(DisplaySize);
|
IO.DeltaTime = FApp::GetDeltaTime();
|
||||||
IO.DisplaySize = FCogImguiHelper::ToImVec2(DisplaySize);
|
IO.DisplaySize = FCogImguiHelper::ToImVec2(GetTickSpaceGeometry().GetAbsoluteSize());
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
Render(InDeltaTime);
|
Render(InDeltaTime);
|
||||||
|
//DrawDebug();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
if ((IO.ConfigFlags & ImGuiConfigFlags_NoMouse) == 0)
|
if ((IO.ConfigFlags & ImGuiConfigFlags_NoMouse) == 0)
|
||||||
@@ -247,7 +233,7 @@ int32 SCogImguiWidget::OnPaint(
|
|||||||
bool bParentEnabled) const
|
bool bParentEnabled) const
|
||||||
{
|
{
|
||||||
|
|
||||||
const FSlateRenderTransform& WidgetToScreen = AllottedGeometry.GetAccumulatedRenderTransform();
|
const FSlateRenderTransform& WidgetToScreen = AllottedGeometry.GetAccumulatedRenderTransform().GetTranslation();
|
||||||
const FSlateRenderTransform ImGuiToScreen = FCogImguiHelper::RoundTranslation(ImGuiRenderTransform.Concatenate(WidgetToScreen));
|
const FSlateRenderTransform ImGuiToScreen = FCogImguiHelper::RoundTranslation(ImGuiRenderTransform.Concatenate(WidgetToScreen));
|
||||||
|
|
||||||
FCogImguiTextureManager& TextureManager = FCogImguiModule::Get().GetTextureManager();
|
FCogImguiTextureManager& TextureManager = FCogImguiModule::Get().GetTextureManager();
|
||||||
@@ -281,13 +267,14 @@ int32 SCogImguiWidget::OnPaint(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Super::OnPaint(Args, AllottedGeometry, MyClippingRect, OutDrawElements, LayerId, WidgetStyle, bParentEnabled);
|
return LayerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
FVector2D SCogImguiWidget::ComputeDesiredSize(float Scale) const
|
FVector2D SCogImguiWidget::ComputeDesiredSize(float Scale) const
|
||||||
{
|
{
|
||||||
return Super::ComputeDesiredSize(Scale);
|
return FVector2D::ZeroVector;
|
||||||
|
//return Super::ComputeDesiredSize(Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -419,3 +406,35 @@ FReply SCogImguiWidget::OnKeyChar(const FGeometry& MyGeometry, const FCharacterE
|
|||||||
const FReply Result = IO.WantCaptureKeyboard ? FReply::Handled() : FReply::Unhandled();
|
const FReply Result = IO.WantCaptureKeyboard ? FReply::Handled() : FReply::Unhandled();
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
|
void SCogImguiWidget::DrawDebug()
|
||||||
|
{
|
||||||
|
if (ImGui::Begin("ImGui Integration Debug"))
|
||||||
|
{
|
||||||
|
ImGui::BeginDisabled();
|
||||||
|
|
||||||
|
ImVec2 AbsPos = FCogImguiHelper::ToImVec2(GetTickSpaceGeometry().GetAbsolutePosition());
|
||||||
|
ImGui::InputFloat2("Widget Abs Pos", &AbsPos.x, "%0.1f");
|
||||||
|
|
||||||
|
ImVec2 AbsSize = FCogImguiHelper::ToImVec2(GetTickSpaceGeometry().GetAbsoluteSize());
|
||||||
|
ImGui::InputFloat2("Widget Abs Size", &AbsSize.x, "%0.1f");
|
||||||
|
|
||||||
|
ImVec2 LocalSize = FCogImguiHelper::ToImVec2(GetTickSpaceGeometry().GetLocalSize());
|
||||||
|
ImGui::InputFloat2("Widget Local Size", &LocalSize.x, "%0.1f");
|
||||||
|
|
||||||
|
FSlateApplication& SlateApp = FSlateApplication::Get();
|
||||||
|
ImVec2 MousePosition = FCogImguiHelper::ToImVec2(SlateApp.GetCursorPos());
|
||||||
|
ImGui::InputFloat2("Mouse", &MousePosition.x, "%0.1f");
|
||||||
|
|
||||||
|
ImGuiIO& IO = ImGui::GetIO();
|
||||||
|
ImGui::InputFloat2("ImGui Mouse", &IO.MousePos.x, "%0.1f");
|
||||||
|
|
||||||
|
ImGui::EndDisabled();
|
||||||
|
}
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ protected:
|
|||||||
|
|
||||||
bool HandleMouseButtonEvent(FSlateApplication& SlateApp, const FPointerEvent& Event, bool IsButtonDown);
|
bool HandleMouseButtonEvent(FSlateApplication& SlateApp, const FPointerEvent& Event, bool IsButtonDown);
|
||||||
|
|
||||||
|
void AddMousePosEvent(const FVector2D& MousePosition) const;
|
||||||
|
|
||||||
bool IsKeyBoundToCommand(const FKeyEvent& KeyEvent);
|
bool IsKeyBoundToCommand(const FKeyEvent& KeyEvent);
|
||||||
|
|
||||||
static ImGuiKey ToImKey(const FKey& Key);
|
static ImGuiKey ToImKey(const FKey& Key);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "Rendering/RenderingCommon.h"
|
#include "Rendering/RenderingCommon.h"
|
||||||
#include "UObject/WeakObjectPtr.h"
|
#include "UObject/WeakObjectPtr.h"
|
||||||
#include "Widgets/DeclarativeSyntaxSupport.h"
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
||||||
#include "Widgets/SCompoundWidget.h"
|
#include "Widgets/SLeafWidget.h"
|
||||||
|
|
||||||
class IInputProcessor;
|
class IInputProcessor;
|
||||||
class UGameViewportClient;
|
class UGameViewportClient;
|
||||||
@@ -17,9 +17,9 @@ struct ImPlotContext;
|
|||||||
using FCogImguiRenderFunction = TFunction<void(float DeltaTime)>;
|
using FCogImguiRenderFunction = TFunction<void(float DeltaTime)>;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------------------------
|
||||||
class COGIMGUI_API SCogImguiWidget : public SCompoundWidget
|
class COGIMGUI_API SCogImguiWidget : public SLeafWidget
|
||||||
{
|
{
|
||||||
typedef SCompoundWidget Super;
|
typedef SLeafWidget Super;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -88,6 +88,8 @@ protected:
|
|||||||
|
|
||||||
virtual bool IsConsoleOpened() const;
|
virtual bool IsConsoleOpened() const;
|
||||||
|
|
||||||
|
virtual void DrawDebug();
|
||||||
|
|
||||||
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
TWeakObjectPtr<UGameViewportClient> GameViewport;
|
||||||
|
|
||||||
ImFontAtlas* FontAtlas = nullptr;
|
ImFontAtlas* FontAtlas = nullptr;
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ void FCogWindow::Render(float DeltaTime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderContent();
|
RenderContent();
|
||||||
ImGui::End();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -120,6 +119,8 @@ void FCogWindow::Render(float DeltaTime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
|
||||||
PostRender();
|
PostRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ void FCogWindow_Inputs::PreSaveConfig()
|
|||||||
|
|
||||||
if (SCogImguiWidget* ImGuiWidget = GetOwner()->GetImGuiWidget().Get())
|
if (SCogImguiWidget* ImGuiWidget = GetOwner()->GetImGuiWidget().Get())
|
||||||
{
|
{
|
||||||
|
Config->bEnableInput = ImGuiWidget->GetEnableInput();
|
||||||
Config->bShareMouse = ImGuiWidget->GetShareMouse();
|
Config->bShareMouse = ImGuiWidget->GetShareMouse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user