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.

95 lines
2.4 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 "RenderUtils.h"
  10. #include "mapview2d.h"
  11. #include "toolinterface.h"
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Draws the measurements of a brush in the 2D view.
  14. // Input : pRender -
  15. // Mins -
  16. // Maxs -
  17. // nFlags -
  18. //-----------------------------------------------------------------------------
  19. void DrawBoundsText(CRender2D *pRender, const Vector &Mins, const Vector &Maxs, int nFlags)
  20. {
  21. CMapView2D *pView = (CMapView2D*) pRender->GetView();
  22. // Calculate the solid's extents along our 2D view axes.
  23. Vector Extents = Maxs - Mins;
  24. Vector Center = (Mins + Maxs ) * 0.5f;
  25. for ( int i=0; i<3;i++ )
  26. Extents[i] = fabs(Extents[i]);
  27. // Transform the solids mins and maxs to 2D view space. These are used
  28. // for placing the text in the view.
  29. Vector2D projMins, projMaxs, projCenter;
  30. pRender->TransformPoint( projMins, Mins );
  31. pRender->TransformPoint( projMaxs, Maxs );
  32. pRender->TransformPoint( projCenter, Center );
  33. if( projMins.x > projMaxs.x )
  34. {
  35. V_swap( projMins.x, projMaxs.x );
  36. }
  37. if( projMins.y > projMaxs.y )
  38. {
  39. V_swap( projMins.y, projMaxs.y );
  40. }
  41. //
  42. // display the extents of this brush
  43. //
  44. char extentText[30];
  45. int nTextX, nTextY;
  46. int nTextFlags;
  47. pRender->SetTextColor( 255, 255, 255 );
  48. // horz
  49. sprintf( extentText, "%.1f", Extents[pView->axHorz] );
  50. nTextFlags = CRender2D::TEXT_JUSTIFY_HORZ_CENTER;
  51. nTextX = projCenter.x;
  52. if ( nFlags & DBT_TOP )
  53. {
  54. nTextY = projMins.y - (HANDLE_RADIUS*3);
  55. nTextFlags |= CRender2D::TEXT_JUSTIFY_TOP;
  56. }
  57. else
  58. {
  59. nTextY = projMaxs.y + (HANDLE_RADIUS*3);
  60. nTextFlags |= CRender2D::TEXT_JUSTIFY_BOTTOM;
  61. }
  62. pRender->DrawText( extentText, nTextX, nTextY, nTextFlags );
  63. // vert
  64. sprintf( extentText, "%.1f", Extents[pView->axVert] );
  65. nTextFlags = CRender2D::TEXT_JUSTIFY_VERT_CENTER;
  66. nTextY = projCenter.y;
  67. if ( nFlags & DBT_LEFT )
  68. {
  69. nTextX = projMins.x - (HANDLE_RADIUS*3);
  70. nTextFlags |= CRender2D::TEXT_JUSTIFY_LEFT;
  71. }
  72. else
  73. {
  74. nTextX = projMaxs.x + (HANDLE_RADIUS*3);
  75. nTextFlags |= CRender2D::TEXT_JUSTIFY_RIGHT;
  76. }
  77. pRender->DrawText( extentText, nTextX, nTextY, nTextFlags );
  78. }