Counter Strike : Global Offensive Source Code
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.

140 lines
3.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "Render2D.h"
  9. #include "gameconfig.h"
  10. #include "vgui_controls/Controls.h"
  11. #include "HammerVGui.h"
  12. #include "material.h"
  13. #include <VGuiMatSurface/IMatSystemSurface.h>
  14. #include "mapview2d.h"
  15. #include "camera.h"
  16. #include "vgui/IScheme.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. // Purpose: constructor - initialize all the member variables
  21. //-----------------------------------------------------------------------------
  22. CRender2D::CRender2D()
  23. {
  24. m_vCurLine.Init();
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Purpose: deconstructor - free all info that may need to be freed
  28. //-----------------------------------------------------------------------------
  29. CRender2D::~CRender2D()
  30. {
  31. }
  32. void CRender2D::MoveTo( const Vector &vPoint )
  33. {
  34. m_vCurLine = vPoint;
  35. }
  36. void CRender2D::DrawLineTo( const Vector &vPoint )
  37. {
  38. DrawLine( m_vCurLine, vPoint );
  39. m_vCurLine = vPoint;
  40. }
  41. //-----------------------------------------------------------------------------
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. // Input : ptCenter - the center point in client coordinates
  45. // nRadiusX - the x radius in pixels
  46. // nRadiusY - the y radius in pixels
  47. // bFill - Whether to fill the ellipse with the fill color or not.
  48. //-----------------------------------------------------------------------------
  49. void CRender2D::DrawCircle( const Vector &vCenter, float fRadius )
  50. {
  51. Vector vNormal;
  52. GetCamera()->GetViewForward( vNormal );
  53. CRender::DrawCircle( vCenter, vNormal, fRadius, 32 );
  54. }
  55. void CRender2D::DrawRectangle( const Vector &vMins, const Vector &vMaxs, bool bFill, int extent )
  56. {
  57. Vector2D ptMin, ptMax;
  58. TransformPoint( ptMin, vMins );
  59. TransformPoint( ptMax, vMaxs );
  60. if ( ptMin.x > ptMax.x )
  61. V_swap( ptMin.x, ptMax.x );
  62. if ( ptMin.y > ptMax.y )
  63. V_swap( ptMin.y, ptMax.y );
  64. if ( extent != 0 )
  65. {
  66. ptMin.x -= extent;
  67. ptMin.y -= extent;
  68. ptMax.x += extent;
  69. ptMax.y += extent;
  70. }
  71. bool bPopMode = BeginClientSpace();
  72. if ( bFill )
  73. {
  74. CRender::DrawFilledRect( ptMin, ptMax, (byte*)&m_DrawColor, false );
  75. }
  76. else
  77. {
  78. CRender::DrawRect( ptMin, ptMax, (byte*)&m_DrawColor );
  79. }
  80. if ( bPopMode )
  81. EndClientSpace();
  82. }
  83. void CRender2D::DrawBox( const Vector &vMins, const Vector &vMaxs, bool bFill)
  84. {
  85. Vector points[8];
  86. PointsFromBox( vMins, vMaxs, points );
  87. meshBuilder.Begin( m_pMesh, MATERIAL_LINE_LOOP, 6 );
  88. meshBuilder.Position3fv( &points[0].x );
  89. meshBuilder.Color4ubv( (byte*)&m_DrawColor );
  90. meshBuilder.AdvanceVertex();
  91. meshBuilder.Position3fv( &points[4].x );
  92. meshBuilder.Color4ubv( (byte*)&m_DrawColor );
  93. meshBuilder.AdvanceVertex();
  94. meshBuilder.Position3fv( &points[6].x );
  95. meshBuilder.Color4ubv( (byte*)&m_DrawColor );
  96. meshBuilder.AdvanceVertex();
  97. meshBuilder.Position3fv( &points[7].x );
  98. meshBuilder.Color4ubv( (byte*)&m_DrawColor );
  99. meshBuilder.AdvanceVertex();
  100. meshBuilder.Position3fv( &points[3].x );
  101. meshBuilder.Color4ubv( (byte*)&m_DrawColor );
  102. meshBuilder.AdvanceVertex();
  103. meshBuilder.Position3fv( &points[1].x );
  104. meshBuilder.Color4ubv( (byte*)&m_DrawColor );
  105. meshBuilder.AdvanceVertex();
  106. meshBuilder.End();
  107. m_pMesh->Draw();
  108. }