67 lines
1.8 KiB
C++
67 lines
1.8 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, HUDPackage.CrosshairColor);
|
|
}
|
|
if (HUDPackage.CrosshairsLeft)
|
|
{
|
|
const FVector2D Spread(-SpreadScaled, 0.f);
|
|
DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
|
}
|
|
if (HUDPackage.CrosshairsRight)
|
|
{
|
|
const FVector2D Spread(SpreadScaled, 0.f);
|
|
DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
|
}
|
|
if (HUDPackage.CrosshairsTop)
|
|
{
|
|
const FVector2D Spread(0.f, -SpreadScaled);
|
|
DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
|
}
|
|
if (HUDPackage.CrosshairsBottom)
|
|
{
|
|
const FVector2D Spread(0.f, SpreadScaled);
|
|
DrawCrosshair(HUDPackage.CrosshairsBottom, ViewportCenter, Spread, HUDPackage.CrosshairColor);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread, FLinearColor CrosshairColor)
|
|
{
|
|
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,
|
|
CrosshairColor
|
|
);
|
|
}
|