Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hud.h"
  9. #include "dod_hud_spec_crosshair.h"
  10. #include "iclientmode.h"
  11. #include "view.h"
  12. #include "vgui_controls/Controls.h"
  13. #include "vgui/ISurface.h"
  14. #include "ivrenderview.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. //ConVar crosshair( "crosshair", "1", FCVAR_ARCHIVE );
  18. //ConVar cl_observercrosshair( "cl_observercrosshair", "1", FCVAR_ARCHIVE );
  19. using namespace vgui;
  20. int ScreenTransform( const Vector& point, Vector& screen );
  21. DECLARE_HUDELEMENT( CHudSpecCrosshair );
  22. CHudSpecCrosshair::CHudSpecCrosshair( const char *pElementName ) :
  23. CHudElement( pElementName ), BaseClass( NULL, "HudSpecCrosshair" )
  24. {
  25. vgui::Panel *pParent = g_pClientMode->GetViewport();
  26. SetParent( pParent );
  27. m_pCrosshair = 0;
  28. m_clrCrosshair = Color( 255, 255, 255, 255 );
  29. SetHiddenBits( HIDEHUD_CROSSHAIR );
  30. }
  31. void CHudSpecCrosshair::ApplySchemeSettings( IScheme *scheme )
  32. {
  33. BaseClass::ApplySchemeSettings( scheme );
  34. m_pCrosshair = gHUD.GetIcon("crosshair_default");
  35. SetPaintBackgroundEnabled( false );
  36. }
  37. void CHudSpecCrosshair::Paint( void )
  38. {
  39. if ( !g_pClientMode->ShouldDrawCrosshair() )
  40. return;
  41. if ( !m_pCrosshair )
  42. return;
  43. if ( engine->IsDrawingLoadingImage() || engine->IsPaused() )
  44. return;
  45. C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer();
  46. if ( !pPlayer )
  47. return;
  48. // draw a crosshair only if alive or spectating in eye
  49. bool shouldDraw = false;
  50. if ( pPlayer->GetObserverMode() == OBS_MODE_ROAMING /*&& cl_observercrosshair.GetBool()*/ )
  51. shouldDraw = true;
  52. if ( !shouldDraw )
  53. return;
  54. if ( pPlayer->entindex() != render->GetViewEntity() )
  55. return;
  56. float x, y;
  57. x = ScreenWidth()/2;
  58. y = ScreenHeight()/2;
  59. m_pCrosshair->DrawSelf(
  60. x - 0.5f * m_pCrosshair->Width(),
  61. y - 0.5f * m_pCrosshair->Height(),
  62. m_clrCrosshair );
  63. }