blaster/Source/Blaster/HUD/BlasterHUD.cpp

67 lines
1.7 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
if (GEngine)
{
2022-05-05 16:48:17 +00:00
FVector2D ViewportSize;
2022-05-05 16:16:59 +00:00
GEngine->GameViewport->GetViewportSize(ViewportSize);
const FVector2D ViewportCenter(ViewportSize.X / 2.f, ViewportSize.Y / 2.f);
2022-05-05 16:48:17 +00:00
const float SpreadScaled = CrosshairSpreadMax * HUDPackage.CrosshairSpread;
2022-05-05 16:16:59 +00:00
if (HUDPackage.CrosshairsCenter)
{
2022-05-05 16:48:17 +00:00
const FVector2D Spread(0.f, 0.f);
DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter, Spread);
2022-05-05 16:16:59 +00:00
}
if (HUDPackage.CrosshairsLeft)
{
2022-05-05 16:48:17 +00:00
const FVector2D Spread(-SpreadScaled, 0.f);
DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread);
2022-05-05 16:16:59 +00:00
}
if (HUDPackage.CrosshairsRight)
{
2022-05-05 16:48:17 +00:00
const FVector2D Spread(SpreadScaled, 0.f);
DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread);
2022-05-05 16:16:59 +00:00
}
if (HUDPackage.CrosshairsTop)
{
2022-05-05 16:48:17 +00:00
const FVector2D Spread(0.f, -SpreadScaled);
DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread);
2022-05-05 16:16:59 +00:00
}
if (HUDPackage.CrosshairsBottom)
{
2022-05-05 16:48:17 +00:00
const FVector2D Spread(0.f, SpreadScaled);
DrawCrosshair(HUDPackage.CrosshairsBottom, ViewportCenter, Spread);
2022-05-05 16:16:59 +00:00
}
}
}
2022-05-05 16:48:17 +00:00
void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread)
2022-05-05 16:16:59 +00:00
{
const float TextureWidth = Texture->GetSizeX();
const float TextureHeight = Texture->GetSizeY();
const FVector2D TextureDrawPoint(
2022-05-05 16:48:17 +00:00
ViewportCenter.X - (TextureWidth / 2.f) + Spread.X,
ViewportCenter.Y - (TextureHeight / 2.f) + Spread.Y
2022-05-05 16:16:59 +00:00
);
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
}