diff --git a/Source/ImGui/Private/ImGuiInputHandler.cpp b/Source/ImGui/Private/ImGuiInputHandler.cpp index fa3c845..64fec4e 100644 --- a/Source/ImGui/Private/ImGuiInputHandler.cpp +++ b/Source/ImGui/Private/ImGuiInputHandler.cpp @@ -18,7 +18,8 @@ #endif // WITH_EDITOR -DEFINE_LOG_CATEGORY_STATIC(LogImGuiInputHandler, Warning, All); +DEFINE_LOG_CATEGORY(LogImGuiInputHandler); + FImGuiInputResponse UImGuiInputHandler::OnKeyDown(const FKeyEvent& KeyEvent) { diff --git a/Source/ImGui/Private/ImGuiInputHandlerFactory.cpp b/Source/ImGui/Private/ImGuiInputHandlerFactory.cpp index ecd5061..c6b13eb 100644 --- a/Source/ImGui/Private/ImGuiInputHandlerFactory.cpp +++ b/Source/ImGui/Private/ImGuiInputHandlerFactory.cpp @@ -8,8 +8,6 @@ #include "ImGuiSettings.h" -DEFINE_LOG_CATEGORY_STATIC(LogImGuiInputHandlerFactory, Warning, All); - UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex) { UClass* HandlerClass = nullptr; @@ -22,7 +20,7 @@ UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* M if (!HandlerClass) { - UE_LOG(LogImGuiInputHandlerFactory, Error, TEXT("Couldn't load ImGui Input Handler class '%s'."), *HandlerClassReference.ToString()); + UE_LOG(LogImGuiInputHandler, Error, TEXT("Couldn't load ImGui Input Handler class '%s'."), *HandlerClassReference.ToString()); } } } @@ -40,7 +38,7 @@ UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* M } else { - UE_LOG(LogImGuiInputHandlerFactory, Error, TEXT("Failed attempt to create Input Handler: HandlerClass = %s."), *GetNameSafe(HandlerClass)); + UE_LOG(LogImGuiInputHandler, Error, TEXT("Failed attempt to create Input Handler: HandlerClass = %s."), *GetNameSafe(HandlerClass)); } return Handler; diff --git a/Source/ImGui/Private/ImGuiInputState.cpp b/Source/ImGui/Private/ImGuiInputState.cpp index 52086ef..d561b27 100644 --- a/Source/ImGui/Private/ImGuiInputState.cpp +++ b/Source/ImGui/Private/ImGuiInputState.cpp @@ -13,7 +13,7 @@ #define VALIDATE_INPUT_CHARACTERS 1 #if VALIDATE_INPUT_CHARACTERS -DEFINE_LOG_CATEGORY_STATIC(LogImGuiInputState, Warning, All); +DEFINE_LOG_CATEGORY_STATIC(LogImGuiInput, Warning, All); #endif namespace @@ -34,7 +34,7 @@ namespace // truncations. static constexpr auto MinLimit = (std::numeric_limits>::min)(); static constexpr auto MaxLimit = (std::numeric_limits>::max)(); - UE_CLOG(!(Char >= MinLimit && Char <= MaxLimit), LogImGuiInputState, Error, + UE_CLOG(!(Char >= MinLimit && Char <= MaxLimit), LogImGuiInput, Error, TEXT("TCHAR value '%c' (%#x) is out of range %d (%#x) to %u (%#x) that can be safely converted to ImWchar. ") TEXT("If you wish to disable this validation, please set VALIDATE_INPUT_CHARACTERS in ImGuiInputState.cpp to 0."), Char, Char, MinLimit, MinLimit, MaxLimit, MaxLimit); diff --git a/Source/ImGui/Private/ImGuiModuleDebug.h b/Source/ImGui/Private/ImGuiModuleDebug.h new file mode 100644 index 0000000..54a9a3d --- /dev/null +++ b/Source/ImGui/Private/ImGuiModuleDebug.h @@ -0,0 +1,16 @@ +// Distributed under the MIT License (MIT) (see accompanying LICENSE file) + +#pragma once + +#include + + +// Module-wide debug symbols and loggers. + + +// If enabled, it activates debug code and console variables that in normal usage are hidden. +#define IMGUI_MODULE_DEVELOPER 0 + + +// Input Handler logger (used also in non-developer mode to raise problems with handler extensions). +DECLARE_LOG_CATEGORY_EXTERN(LogImGuiInputHandler, Warning, All); diff --git a/Source/ImGui/Private/ImGuiPrivatePCH.h b/Source/ImGui/Private/ImGuiPrivatePCH.h index ae53c90..e193a86 100644 --- a/Source/ImGui/Private/ImGuiPrivatePCH.h +++ b/Source/ImGui/Private/ImGuiPrivatePCH.h @@ -1,8 +1,11 @@ // Distributed under the MIT License (MIT) (see accompanying LICENSE file) +// Module-wide macros +#include "VersionCompatibility.h" +#include "ImGuiModuleDebug.h" + // Module #include "ImGuiModule.h" -#include "VersionCompatibility.h" // Engine #include diff --git a/Source/ImGui/Private/SImGuiWidget.cpp b/Source/ImGui/Private/SImGuiWidget.cpp index 27caa9d..5f009e8 100644 --- a/Source/ImGui/Private/SImGuiWidget.cpp +++ b/Source/ImGui/Private/SImGuiWidget.cpp @@ -25,8 +25,12 @@ constexpr int32 IMGUI_WIDGET_Z_ORDER = 10000; +#if IMGUI_WIDGET_DEBUG + DEFINE_LOG_CATEGORY_STATIC(LogImGuiWidget, Warning, All); +#define IMGUI_WIDGET_LOG(Verbosity, Format, ...) UE_LOG(LogImGuiWidget, Verbosity, Format, __VA_ARGS__) + #define TEXT_INPUT_MODE(Val) (\ (Val) == EInputMode::Full ? TEXT("Full") :\ (Val) == EInputMode::MousePointerOnly ? TEXT("MousePointerOnly") :\ @@ -34,6 +38,11 @@ DEFINE_LOG_CATEGORY_STATIC(LogImGuiWidget, Warning, All); #define TEXT_BOOL(Val) ((Val) ? TEXT("true") : TEXT("false")) +#else + +#define IMGUI_WIDGET_LOG(...) + +#endif // IMGUI_WIDGET_DEBUG namespace { @@ -61,7 +70,11 @@ namespace CVars TEXT("2: gamepad navigation (gamepad input is consumed)\n") TEXT("3: keyboard and gamepad navigation (gamepad input is consumed)"), ECVF_Default); +} +#if IMGUI_WIDGET_DEBUG +namespace CVars +{ TAutoConsoleVariable DebugWidget(TEXT("ImGui.Debug.Widget"), 0, TEXT("Show debug for SImGuiWidget.\n") TEXT("0: disabled (default)\n") @@ -74,6 +87,7 @@ namespace CVars TEXT("1: enabled"), ECVF_Default); } +#endif // IMGUI_WIDGET_DEBUG BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void SImGuiWidget::Construct(const FArguments& InArgs) @@ -101,7 +115,9 @@ void SImGuiWidget::Construct(const FArguments& InArgs) // Bind this widget to its context proxy. auto* ContextProxy = ModuleManager->GetContextManager().GetContextProxy(ContextIndex); checkf(ContextProxy, TEXT("Missing context during widget construction: ContextIndex = %d"), ContextIndex); +#if IMGUI_WIDGET_DEBUG ContextProxy->OnDraw().AddRaw(this, &SImGuiWidget::OnDebugDraw); +#endif // IMGUI_WIDGET_DEBUG ContextProxy->SetInputState(&InputState); // Cache locally software cursor mode. @@ -126,7 +142,9 @@ SImGuiWidget::~SImGuiWidget() // Remove binding between this widget and its context proxy. if (auto* ContextProxy = ModuleManager->GetContextManager().GetContextProxy(ContextIndex)) { +#if IMGUI_WIDGET_DEBUG ContextProxy->OnDraw().RemoveAll(this); +#endif // IMGUI_WIDGET_DEBUG ContextProxy->RemoveInputState(&InputState); } @@ -323,7 +341,7 @@ FReply SImGuiWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocusEv { Super::OnFocusReceived(MyGeometry, FocusEvent); - UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Focus Received."), ContextIndex); + IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Focus Received."), ContextIndex); // If widget has a keyboard focus we always maintain mouse input. Technically, if mouse is outside of the widget // area it won't generate events but we freeze its state until it either comes back or input is completely lost. @@ -337,7 +355,7 @@ void SImGuiWidget::OnFocusLost(const FFocusEvent& FocusEvent) { Super::OnFocusLost(FocusEvent); - UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Focus Lost."), ContextIndex); + IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Focus Lost."), ContextIndex); UpdateInputMode(false, IsDirectlyHovered()); } @@ -346,7 +364,7 @@ void SImGuiWidget::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent { Super::OnMouseEnter(MyGeometry, MouseEvent); - UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Mouse Enter."), ContextIndex); + IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Mouse Enter."), ContextIndex); // If mouse enters while input is active then we need to update mouse buttons because there is a chance that we // missed some events. @@ -365,7 +383,7 @@ void SImGuiWidget::OnMouseLeave(const FPointerEvent& MouseEvent) { Super::OnMouseLeave(MouseEvent); - UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Mouse Leave."), ContextIndex); + IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Mouse Leave."), ContextIndex); // We don't get any events when application loses focus, but often this is followed by OnMouseLeave, so we can use // this event to immediately disable keyboard input if application lost focus. @@ -497,7 +515,7 @@ void SImGuiWidget::SetVisibilityFromInputEnabled() // If we don't use input disable hit test to make this widget invisible for cursors hit detection. SetVisibility(bInputEnabled ? EVisibility::Visible : EVisibility::HitTestInvisible); - UE_LOG(LogImGuiWidget, VeryVerbose, TEXT("ImGui Widget %d - Visibility updated to '%s'."), + IMGUI_WIDGET_LOG(VeryVerbose, TEXT("ImGui Widget %d - Visibility updated to '%s'."), ContextIndex, *GetVisibility().ToString()); } @@ -508,7 +526,7 @@ void SImGuiWidget::UpdateInputEnabled() { bInputEnabled = bEnabled; - UE_LOG(LogImGuiWidget, Log, TEXT("ImGui Widget %d - Input Enabled changed to '%s'."), + IMGUI_WIDGET_LOG(Log, TEXT("ImGui Widget %d - Input Enabled changed to '%s'."), ContextIndex, TEXT_BOOL(bInputEnabled)); SetVisibilityFromInputEnabled(); @@ -568,7 +586,7 @@ void SImGuiWidget::UpdateInputMode(bool bHasKeyboardFocus, bool bHasMousePointer if (InputMode != NewInputMode) { - UE_LOG(LogImGuiWidget, Verbose, TEXT("ImGui Widget %d - Input Mode changed from '%s' to '%s'."), + IMGUI_WIDGET_LOG(Verbose, TEXT("ImGui Widget %d - Input Mode changed from '%s' to '%s'."), ContextIndex, TEXT_INPUT_MODE(InputMode), TEXT_INPUT_MODE(NewInputMode)); // We need to reset input components if we are either fully shutting down or we are downgrading from full to @@ -1048,6 +1066,8 @@ FVector2D SImGuiWidget::ComputeDesiredSize(float) const return FVector2D{ 3840.f, 2160.f }; } +#if IMGUI_WIDGET_DEBUG + static TArray GetImGuiMappedKeys() { TArray Keys; @@ -1329,3 +1349,7 @@ void SImGuiWidget::OnDebugDraw() #undef TEXT_INPUT_MODE #undef TEXT_BOOL + +#endif // IMGUI_WIDGET_DEBUG + +#undef IMGUI_WIDGET_LOG diff --git a/Source/ImGui/Private/SImGuiWidget.h b/Source/ImGui/Private/SImGuiWidget.h index 0d86451..311db07 100644 --- a/Source/ImGui/Private/SImGuiWidget.h +++ b/Source/ImGui/Private/SImGuiWidget.h @@ -3,10 +3,14 @@ #pragma once #include "ImGuiInputState.h" +#include "ImGuiModuleDebug.h" #include +// Hide ImGui Widget debug in non-developer mode. +#define IMGUI_WIDGET_DEBUG IMGUI_MODULE_DEVELOPER + class FImGuiModuleManager; class UImGuiInputHandler; @@ -151,7 +155,9 @@ private: virtual FVector2D ComputeDesiredSize(float) const override; +#if IMGUI_WIDGET_DEBUG void OnDebugDraw(); +#endif // IMGUI_WIDGET_DEBUG FImGuiModuleManager* ModuleManager = nullptr; TWeakObjectPtr GameViewport;