Lots of work on focus management
This commit is contained in:
97
Source/Integration/InputModeRequest.cpp
Normal file
97
Source/Integration/InputModeRequest.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// InputModeRequest.cpp
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "InputModeRequest.h"
|
||||
#include "Common.h"
|
||||
|
||||
bool FlxInputModeRequest::operator==(const FlxInputModeRequest &Other) const
|
||||
{
|
||||
return (Widget == Other.Widget) &&
|
||||
(Focus == Other.Focus) &&
|
||||
(ShowPointer == Other.ShowPointer) &&
|
||||
(BlockInput == Other.BlockInput) &&
|
||||
(EnableInputComponent == Other.EnableInputComponent);
|
||||
}
|
||||
|
||||
bool FlxInputModeRequests::SanityCheck(const FlxInputModeRequest &Request)
|
||||
{
|
||||
if (Request.Widget == nullptr)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("RequestEvents called with null widget."));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlxInputModeRequests::SplitHighLow(View &High, View &Low)
|
||||
{
|
||||
int32 NumHigh = 0;
|
||||
while ((NumHigh < Requests.Num()) && (Requests[NumHigh].IsHighPrio())) NumHigh++;
|
||||
int32 NumLow = Requests.Num() - NumHigh;
|
||||
High = View(Requests.GetData(), NumHigh);
|
||||
Low = View(Requests.GetData() + NumHigh, NumLow);
|
||||
}
|
||||
|
||||
void FlxInputModeRequests::Request(const FlxInputModeRequest &NewRequest)
|
||||
{
|
||||
bool IsHigh = NewRequest.IsHighPrio();
|
||||
|
||||
// Divide the array into a high-priority slice and a low-priority slice.
|
||||
View High, Low;
|
||||
SplitHighLow(High, Low);
|
||||
|
||||
// Stamp this request with a fresh sequence number.
|
||||
FlxInputModeRequest Stamped = NewRequest;
|
||||
Stamped.SequenceNumber = ++NextSequenceNumber;
|
||||
|
||||
// We're going to build a new version of the requests array.
|
||||
TArray<FlxInputModeRequest> Updated;
|
||||
|
||||
// Add all high priority requests to the updated array, new request first.
|
||||
if (IsHigh) Updated.Add(Stamped);
|
||||
for (const FlxInputModeRequest &Req : High)
|
||||
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
||||
|
||||
// Add all low priority requests to the updated array, new request first.
|
||||
if (!IsHigh) Updated.Add(Stamped);
|
||||
for (const FlxInputModeRequest &Req : Low)
|
||||
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
||||
|
||||
Swap(Requests, Updated);
|
||||
}
|
||||
|
||||
void FlxInputModeRequests::SetEnableInputComponent(UUserWidget *Widget, bool EnableInputComponent)
|
||||
{
|
||||
for (FlxInputModeRequest &Req : Requests)
|
||||
{
|
||||
if (Req.Widget == Widget)
|
||||
{
|
||||
Req.EnableInputComponent = EnableInputComponent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
FlxInputModeRequest NewReq;
|
||||
NewReq.Widget = Widget;
|
||||
NewReq.EnableInputComponent = EnableInputComponent;
|
||||
Request(NewReq);
|
||||
}
|
||||
|
||||
void FlxInputModeRequests::Remove(UUserWidget *Widget)
|
||||
{
|
||||
Requests.RemoveAll([Widget](const FlxInputModeRequest &Entry)
|
||||
{
|
||||
return Entry.Widget == Widget;
|
||||
});
|
||||
}
|
||||
|
||||
void FlxInputModeRequests::GarbageCollect()
|
||||
{
|
||||
Requests.RemoveAll([](const FlxInputModeRequest &Entry)
|
||||
{
|
||||
return !IsValid(Entry.Widget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user