Files
UnrealEngineUWP/Engine/Source/Runtime/IOS/IOSPlatformFeatures/Private/IOSGamepadUtils.cpp
axel riffard 18439c9e89 Remove iOS13 and Metal 2.2 , implement iOS14 and Metal 2.4
#jira UE-140926
#rb jack.porter
[FYI] will.damon, carl.lloyd, richard.wallis, laura.hermanns
#lockdown rolando.caloca
#preflight 61fb957ec431b6aac0556693

#ROBOMERGE-OWNER: axel.riffard
#ROBOMERGE-AUTHOR: axel.riffard
#ROBOMERGE-SOURCE: CL 18841574 in //UE5/Release-5.0/... via CL 18841862 via CL 18841959
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v910-18824042)
#ROBOMERGE-CONFLICT from-shelf

[CL 18842337 by axel riffard in ue5-main branch]
2022-02-03 09:10:01 -05:00

78 lines
3.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "IOSGamepadUtils.h"
#include "GameDelegates.h"
#include "IOS/IOSApplication.h"
#include "IOS/IOSPlatformApplicationMisc.h"
DEFINE_LOG_CATEGORY_STATIC(LogIOSGamepadUtils, Log, All);
//
// Implementation members
//
FIOSGamepadUtils::FIOSGamepadUtils()
{
// Bind FIOSPlatformApplicationMisc's GetGamePadGlyph delegate to us.
FIOSPlatformApplicationMisc::GetGamePadGlyphDelegate.BindRaw(this, &FIOSGamepadUtils::GetGamepadButtonGlyph);
}
FIOSGamepadUtils::~FIOSGamepadUtils()
{
FIOSPlatformApplicationMisc::GetGamePadGlyphDelegate.Unbind();
}
UTexture2D* FIOSGamepadUtils::GetGamepadButtonGlyph(const FGamepadKeyNames::Type& ButtonKey, uint32 ControllerIndex)
{
UTexture2D *NewTexture = nullptr;
FIOSInputInterface* InputInterface = static_cast<FIOSInputInterface*>(FIOSPlatformApplicationMisc::CachedApplication->GetInputInterface());
check(InputInterface);
ControllerType ControllerType = InputInterface->GetControllerType(ControllerIndex);
for (int32 Index = 0; Index != GlyphsArray.Num(); ++Index)
{
if (GlyphsArray[Index].ButtonName == ButtonKey && GlyphsArray[Index].ControllerType == ControllerType)
{
return GlyphsArray[Index].ButtonTexture;
}
NSData* RawData = InputInterface->GetGamepadGlyphRawData(ButtonKey, ControllerIndex);
UInt8 Buf[RawData.length];
[RawData getBytes:Buf length:RawData.length];
const uint8_t* Bytes = (const uint8_t*)[RawData bytes];
long Length = [RawData length];
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
if (ImageWrapper != nullptr && Length > 0)
{
TArray<uint8> RawImageData;
ImageWrapper->SetCompressed(Bytes, Length);
if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, RawImageData))
{
NewTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_B8G8R8A8);
if (NewTexture != nullptr)
{
FTexture2DMipMap& Mip0 = NewTexture->GetPlatformData()->Mips[0];
void* TextureData = Mip0.BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy(TextureData, RawImageData.GetData(), RawImageData.Num());
Mip0.BulkData.Unlock();
NewTexture->UpdateResource();
GamepadGlyph GamepadGlyph;
GamepadGlyph.ControllerType = ControllerType;
GamepadGlyph.ButtonName = ButtonKey;
GamepadGlyph.ButtonTexture = NewTexture;
GamepadGlyph.ButtonTexture->AddToRoot();
GlyphsArray.Add(GamepadGlyph);
}
}
}
}
return NewTexture;
}