Hello, I’m trying to scale a widget to exactly 0.9 times the size of the screen.
I found some code to get the dpi, then I made a function which to me seems like it should give the correct values. But I wouldn’t be here if it did.
.cpp
float UMiscBlueprintNodes::GetUMG_DPI_Scale() {
FVector2D viewportSize;
GEngine->GameViewport->GetViewportSize(viewportSize);
int32 X = FGenericPlatformMath::FloorToInt(viewportSize.X);
int32 Y = FGenericPlatformMath::FloorToInt(viewportSize.Y);
return GetDefault<UUserInterfaceSettings>(UUserInterfaceSettings::StaticClass())->GetDPIScaleBasedOnSize(FIntPoint(X, Y));
}
FVector2D UMiscBlueprintNodes::GetViewportResScaledByDPI(float ExtraScaleAmount) {
float DPI_Scale = GetUMG_DPI_Scale();
FVector2D viewportSize;
GEngine->GameViewport->GetViewportSize(viewportSize);
if (DPI_Scale < 1.0) {
DPI_Scale = abs(DPI_Scale - 1.0) + 1;
}
else {
DPI_Scale = abs(DPI_Scale - 2.0);
}
return ExtraScaleAmount * (viewportSize * DPI_Scale);
}
The dpi scaling seems to be throwing off what to give a widget to size it properly manually.
Thanks!