2018-07-10 16:40:57 +00:00
|
|
|
// 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 (UImGuiSettings* Settings = GetMutableDefault<UImGuiSettings>())
|
|
|
|
{
|
|
|
|
const auto& HandlerClassReference = Settings->GetImGuiInputHandlerClass();
|
|
|
|
if (HandlerClassReference.IsValid())
|
|
|
|
{
|
|
|
|
HandlerClass = HandlerClassReference.TryLoadClass<UImGuiInputHandler>();
|
|
|
|
|
|
|
|
if (!HandlerClass)
|
|
|
|
{
|
2018-10-30 22:25:48 +00:00
|
|
|
UE_LOG(LogImGuiInputHandler, Error, TEXT("Couldn't load ImGui Input Handler class '%s'."), *HandlerClassReference.ToString());
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HandlerClass)
|
|
|
|
{
|
|
|
|
HandlerClass = UImGuiInputHandler::StaticClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
UImGuiInputHandler* Handler = NewObject<UImGuiInputHandler>(GameViewport, HandlerClass);
|
|
|
|
if (Handler)
|
|
|
|
{
|
|
|
|
Handler->Initialize(ModuleManager, GameViewport, ContextIndex);
|
|
|
|
Handler->AddToRoot();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-30 22:25:48 +00:00
|
|
|
UE_LOG(LogImGuiInputHandler, Error, TEXT("Failed attempt to create Input Handler: HandlerClass = %s."), *GetNameSafe(HandlerClass));
|
2018-07-10 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FImGuiInputHandlerFactory::ReleaseHandler(UImGuiInputHandler* Handler)
|
|
|
|
{
|
|
|
|
if (Handler)
|
|
|
|
{
|
|
|
|
Handler->RemoveFromRoot();
|
|
|
|
}
|
|
|
|
}
|