103 lines
2.7 KiB
C++
103 lines
2.7 KiB
C++
////////////////////////////////////////////////////////////
|
|
//
|
|
// InputEvents.cpp
|
|
//
|
|
////////////////////////////////////////////////////////////
|
|
|
|
#include "InputEvents.h"
|
|
#include "Common.h"
|
|
|
|
bool FlxInputModeRequest::operator==(const FlxInputModeRequest &Other) const
|
|
{
|
|
return (Widget == Other.Widget) &&
|
|
(Focus == Other.Focus) &&
|
|
(ShowPointer == Other.ShowPointer) &&
|
|
(BlockInput == Other.BlockInput);
|
|
}
|
|
|
|
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);
|
|
|
|
// This is a simple test to see if anything is going to change.
|
|
// If not, we return early and avoid setting the dirty bit.
|
|
if (IsHigh)
|
|
{
|
|
if ((High.Num() > 0) && (High[0] == NewRequest)) return;
|
|
}
|
|
else
|
|
{
|
|
if ((Low.Num() > 0) && (Low[0] == NewRequest)) return;
|
|
}
|
|
|
|
// 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(NewRequest);
|
|
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(NewRequest);
|
|
for (const FlxInputModeRequest &Req : Low)
|
|
if (Req.Widget != NewRequest.Widget) Updated.Add(Req);
|
|
|
|
Swap(Requests, Updated);
|
|
Dirty = true;
|
|
}
|
|
|
|
void FlxInputModeRequests::EnsureWidget(UUserWidget *Widget)
|
|
{
|
|
for (const FlxInputModeRequest &Req : Requests)
|
|
{
|
|
if (Req.Widget == Widget) return;
|
|
}
|
|
Request(FlxInputModeRequest(Widget, nullptr, false, false));
|
|
}
|
|
|
|
void FlxInputModeRequests::Remove(UUserWidget *Widget)
|
|
{
|
|
int32 N = Requests.Num();
|
|
Requests.RemoveAll([Widget](const FlxInputModeRequest &Entry)
|
|
{
|
|
return Entry.Widget == Widget;
|
|
});
|
|
if (Requests.Num() < N) Dirty = true;
|
|
}
|
|
|
|
void FlxInputModeRequests::GarbageCollect()
|
|
{
|
|
int32 N = Requests.Num();
|
|
Requests.RemoveAll([](const FlxInputModeRequest &Entry)
|
|
{
|
|
UUserWidget *W = Entry.Widget;
|
|
return W == nullptr || !IsValid(W) || W->GetParent() == nullptr;
|
|
});
|
|
if (Requests.Num() < N) Dirty = true;
|
|
}
|
|
|