blaster/Source/Blaster/HUD/BlasterHUD.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

2022-05-05 15:57:57 +00:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "BlasterHUD.h"
void ABlasterHUD::DrawHUD()
{
Super::DrawHUD();
2022-05-05 16:16:59 +00:00
FVector2D ViewportSize;
if (GEngine)
{
GEngine->GameViewport->GetViewportSize(ViewportSize);
const FVector2D ViewportCenter(ViewportSize.X / 2.f, ViewportSize.Y / 2.f);
if (HUDPackage.CrosshairsCenter)
{
DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter);
}
if (HUDPackage.CrosshairsLeft)
{
DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter);
}
if (HUDPackage.CrosshairsRight)
{
DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter);
}
if (HUDPackage.CrosshairsTop)
{
DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter);
}
if (HUDPackage.CrosshairsBottom)
{
DrawCrosshair(HUDPackage.CrosshairsBottom, ViewportCenter);
}
}
}
void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter)
{
const float TextureWidth = Texture->GetSizeX();
const float TextureHeight = Texture->GetSizeY();
const FVector2D TextureDrawPoint(
ViewportCenter.X - (TextureWidth / 2.f),
ViewportCenter.Y - (TextureHeight / 2.f)
);
DrawTexture(
Texture,
TextureDrawPoint.X,
TextureDrawPoint.Y,
TextureWidth,
TextureHeight,
0.f,
0.f,
1.f,
1.f,
FLinearColor::White
);
2022-05-05 15:57:57 +00:00
}