Files
UnrealEngineUWP/Engine/Source/Runtime/InteractiveToolsFramework/Private/InputBehaviorSet.cpp
Chris Gagnon 930e33cb48 Copying //UE4/Dev-Editor to Dev-Main (//UE4/Dev-Main) for 4.23 From CL 6837861
#rb none

[CL 6838042 by Chris Gagnon in Main branch]
2019-06-04 15:42:48 -04:00

165 lines
3.1 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "InputBehaviorSet.h"
UInputBehaviorSet::UInputBehaviorSet()
{
}
UInputBehaviorSet::~UInputBehaviorSet()
{
}
bool UInputBehaviorSet::IsEmpty() const
{
return Behaviors.Num() == 0;
}
void UInputBehaviorSet::Add(UInputBehavior* Behavior, void* Source, const FString& Group)
{
//if (source == null)
// source = DefaultSource;
FBehaviorInfo Info;
Info.Behavior = Behavior;
Info.Source = Source;
Info.Group = Group;
Behaviors.Add(Info);
BehaviorsModified();
}
void UInputBehaviorSet::Add(const UInputBehaviorSet* OtherSet, void* NewSource, const FString& NewGroup)
{
for (const FBehaviorInfo& OtherInfo : OtherSet->Behaviors)
{
FBehaviorInfo Info;
Info.Behavior = OtherInfo.Behavior;
Info.Source = (NewSource == nullptr) ? OtherInfo.Source : NewSource;
Info.Group = (NewGroup.IsEmpty()) ? OtherInfo.Group : NewGroup;
Behaviors.Add(Info);
}
if (OtherSet->Behaviors.Num() > 0)
{
BehaviorsModified();
}
}
bool UInputBehaviorSet::Remove(UInputBehavior* behavior)
{
int32 idx = Behaviors.IndexOfByPredicate(
[behavior] (const FBehaviorInfo& b) { return b.Behavior == behavior; }
);
if ( idx != INDEX_NONE ) {
Behaviors.RemoveAt(idx);
BehaviorsModified();
return true;
}
return false;
}
bool UInputBehaviorSet::RemoveByGroup(const FString& Group)
{
int RemovedCount = Behaviors.RemoveAll(
[Group](const FBehaviorInfo& b) { return b.Group == Group; }
);
if (RemovedCount > 0)
{
BehaviorsModified();
}
return (RemovedCount > 0);
}
bool UInputBehaviorSet::RemoveBySource(void* Source)
{
int RemovedCount = Behaviors.RemoveAll(
[Source](const FBehaviorInfo& b) { return b.Source == Source; }
);
if (RemovedCount > 0)
{
BehaviorsModified();
}
return (RemovedCount > 0);
}
void UInputBehaviorSet::RemoveAll()
{
Behaviors.Reset();
BehaviorsModified();
}
void UInputBehaviorSet::CollectWantsCapture(const FInputDeviceState& input, TArray<FInputCaptureRequest>& result)
{
for (auto b : Behaviors)
{
// only call WantsCapture if the Behavior supports the current input device
if (SupportsInputType(b.Behavior, input))
{
FInputCaptureRequest request = b.Behavior->WantsCapture(input);
if ( request.Type != EInputCaptureRequestType::Ignore )
{
request.Owner = b.Source;
result.Add(request);
}
}
}
}
bool UInputBehaviorSet::UpdateHover(const FInputDeviceState& input)
{
bool bAnyWantedHover = false;
for (auto b : Behaviors)
{
if (SupportsInputType(b.Behavior, input))
{
if (b.Behavior->WantsHoverEvents())
{
b.Behavior->UpdateHover(input);
bAnyWantedHover = true;
}
}
}
return bAnyWantedHover;
}
bool UInputBehaviorSet::EndHover(const FInputDeviceState& input)
{
bool bAnyWantedHover = false;
for (auto b : Behaviors)
{
if (SupportsInputType(b.Behavior, input))
{
if (b.Behavior->WantsHoverEvents())
{
b.Behavior->EndHover(input);
bAnyWantedHover = true;
}
}
}
return bAnyWantedHover;
}
void UInputBehaviorSet::BehaviorsModified()
{
// sort by priority
Behaviors.StableSort();
//send some kind of event...
//FUtil.SafeSendAnyEvent(OnSetChanged, this);
}