You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
95 lines
2.6 KiB
C++
95 lines
2.6 KiB
C++
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "UMGPrivatePCH.h"
|
|
#include "Slate/SlateBrushAsset.h"
|
|
#include "WidgetLayoutLibrary.h"
|
|
#include "Runtime/Engine/Classes/Engine/UserInterfaceSettings.h"
|
|
#include "Runtime/Engine/Classes/Engine/RendererSettings.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "UMG"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// UWidgetLayoutLibrary
|
|
|
|
UWidgetLayoutLibrary::UWidgetLayoutLibrary(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
}
|
|
|
|
float UWidgetLayoutLibrary::GetViewportScale(UObject* WorldContextObject)
|
|
{
|
|
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
|
|
if ( World && World->IsGameWorld() )
|
|
{
|
|
if ( UGameViewportClient* ViewportClient = World->GetGameViewport() )
|
|
{
|
|
FVector2D ViewportSize;
|
|
ViewportClient->GetViewportSize(ViewportSize);
|
|
return GetDefault<UUserInterfaceSettings>(UUserInterfaceSettings::StaticClass())->GetDPIScaleBasedOnSize(FIntPoint(ViewportSize.X, ViewportSize.Y));
|
|
}
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
bool UWidgetLayoutLibrary::GetMousePositionScaledByDPI(APlayerController* Player, float& LocationX, float& LocationY)
|
|
{
|
|
if ( Player && Player->GetMousePosition(LocationX, LocationY) )
|
|
{
|
|
float Scale = UWidgetLayoutLibrary::GetViewportScale(Player);
|
|
LocationX = LocationX / Scale;
|
|
LocationY = LocationY / Scale;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
FVector2D UWidgetLayoutLibrary::GetViewportSize(UObject* WorldContextObject)
|
|
{
|
|
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
|
|
if ( World && World->IsGameWorld() )
|
|
{
|
|
if ( UGameViewportClient* ViewportClient = World->GetGameViewport() )
|
|
{
|
|
FVector2D ViewportSize;
|
|
ViewportClient->GetViewportSize(ViewportSize);
|
|
return ViewportSize;
|
|
}
|
|
}
|
|
|
|
return FVector2D(1, 1);
|
|
}
|
|
|
|
UCanvasPanelSlot* UWidgetLayoutLibrary::SlotAsCanvasSlot(UWidget* ChildWidget)
|
|
{
|
|
return Cast<UCanvasPanelSlot>(ChildWidget->Slot);
|
|
}
|
|
|
|
UGridSlot* UWidgetLayoutLibrary::SlotAsGridSlot(UWidget* ChildWidget)
|
|
{
|
|
return Cast<UGridSlot>(ChildWidget->Slot);
|
|
}
|
|
|
|
UHorizontalBoxSlot* UWidgetLayoutLibrary::SlotAsHorizontalBoxSlot(UWidget* ChildWidget)
|
|
{
|
|
return Cast<UHorizontalBoxSlot>(ChildWidget->Slot);
|
|
}
|
|
|
|
UOverlaySlot* UWidgetLayoutLibrary::SlotAsOverlaySlot(UWidget* ChildWidget)
|
|
{
|
|
return Cast<UOverlaySlot>(ChildWidget->Slot);
|
|
}
|
|
|
|
UUniformGridSlot* UWidgetLayoutLibrary::SlotAsUniformGridSlot(UWidget* ChildWidget)
|
|
{
|
|
return Cast<UUniformGridSlot>(ChildWidget->Slot);
|
|
}
|
|
|
|
UVerticalBoxSlot* UWidgetLayoutLibrary::SlotAsVerticalBoxSlot(UWidget* ChildWidget)
|
|
{
|
|
return Cast<UVerticalBoxSlot>(ChildWidget->Slot);
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE |