blaster/Source/Blaster/HUD/BlasterHUD.cpp

67 lines
1.7 KiB
C++

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