UnrealImGui/Source/ImGui/Private/ImGuiInputHandlerFactory.cpp
Sebastian c5f3759664 Moved console variables and commands to wrapper objects:
- Moved property variables to ImGui Module Properties.
- Moved console command to ImGui Module Commands (one for now but more will be added).
- ImGui Module Commands is created by ImGui Module Manager, what means that commands are registered after module is loaded and unregistered when it is unloaded.
- Updated settings to allow more convenient use: Added global pointer to default object and event raised when it is loaded.
2018-11-24 19:54:01 +00:00

54 lines
1.3 KiB
C++

// Distributed under the MIT License (MIT) (see accompanying LICENSE file)
#include "ImGuiPrivatePCH.h"
#include "ImGuiInputHandlerFactory.h"
#include "ImGuiInputHandler.h"
#include "ImGuiSettings.h"
UImGuiInputHandler* FImGuiInputHandlerFactory::NewHandler(FImGuiModuleManager* ModuleManager, UGameViewportClient* GameViewport, int32 ContextIndex)
{
UClass* HandlerClass = nullptr;
if (GImGuiSettings)
{
const auto& HandlerClassReference = GImGuiSettings->GetImGuiInputHandlerClass();
if (HandlerClassReference.IsValid())
{
HandlerClass = HandlerClassReference.TryLoadClass<UImGuiInputHandler>();
if (!HandlerClass)
{
UE_LOG(LogImGuiInputHandler, Error, TEXT("Couldn't load ImGui Input Handler class '%s'."), *HandlerClassReference.ToString());
}
}
}
if (!HandlerClass)
{
HandlerClass = UImGuiInputHandler::StaticClass();
}
UImGuiInputHandler* Handler = NewObject<UImGuiInputHandler>(GameViewport, HandlerClass);
if (Handler)
{
Handler->Initialize(ModuleManager, GameViewport, ContextIndex);
Handler->AddToRoot();
}
else
{
UE_LOG(LogImGuiInputHandler, Error, TEXT("Failed attempt to create Input Handler: HandlerClass = %s."), *GetNameSafe(HandlerClass));
}
return Handler;
}
void FImGuiInputHandlerFactory::ReleaseHandler(UImGuiInputHandler* Handler)
{
if (Handler)
{
Handler->RemoveFromRoot();
}
}