unleashedcode

RTS_HUD.cpp

Oct 24th, 2022
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | Source Code | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "HUD/RTS_HUD.h"
  5.  
  6.  
  7. /*  Constructor */
  8. ARTS_HUD::ARTS_HUD()
  9. {
  10.    
  11. }
  12.  
  13.  
  14. /*  Override - in the HUD Class, DrawHUD() is the equivelant to tick.... runs everyframe */
  15. void ARTS_HUD::DrawHUD()
  16. {
  17.     //Super::DrawHUD();
  18.     if (bStartMarqueeSelect == true)
  19.     {
  20.         CurrentPoint = GetMousePosition2D();
  21.  
  22.         //CurrentPoint XY distance from origin (initial) point of click
  23.         float DraggedWidth = CurrentPoint.X - InitialPoint.X;
  24.         float DraggedHeight = CurrentPoint.Y - InitialPoint.Y;
  25.  
  26.         UE_LOG(LogTemp, Warning, TEXT("MousePosition2D: %s "), *CurrentPoint.ToString());
  27.  
  28.         //Draw the rectangle - InitialPoint = mouse first clicked and held, CurrentPoint = where is the XY on the screen now. Then Draw.
  29.         DrawRect(FLinearColor(0, 0, 1, .22f), InitialPoint.X, InitialPoint.Y, DraggedWidth, DraggedHeight);
  30.     }
  31. }
  32.  
  33. FVector2D ARTS_HUD::GetMousePosition2D()
  34. {
  35.     float PositionX;
  36.     float PositionY;
  37.  
  38.     //Get the mouse coordinates from the player controller
  39.     FVector2D MousePosition = GetOwningPlayerController()->GetMousePosition(PositionX, PositionY); 
  40.  
  41.     return MousePosition;
  42. }
  43.  
Tags: C++
Advertisement
Add Comment
Please, Sign In to add comment