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.

207 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the cordon tool. The cordon tool defines a rectangular
  4. // volume that acts as a visibility filter. Only objects that intersect
  5. // the cordon are rendered in the views. When saving the MAP file while
  6. // the cordon tool is active, only brushes that intersect the cordon
  7. // bounds are saved. The cordon box is replaced by brushes in order to
  8. // seal the map.
  9. //
  10. //=============================================================================//
  11. #include "stdafx.h"
  12. #include "ChunkFile.h"
  13. #include "ToolCordon.h"
  14. #include "History.h"
  15. #include "GlobalFunctions.h"
  16. #include "MainFrm.h"
  17. #include "MapDoc.h"
  18. #include "MapDefs.h"
  19. #include "MapSolid.h"
  20. #include "MapView2D.h"
  21. #include "MapView3D.h"
  22. #include "MapWorld.h"
  23. #include "StatusBarIDs.h"
  24. #include "ToolManager.h"
  25. #include "Options.h"
  26. #include "WorldSize.h"
  27. #include "vgui/Cursor.h"
  28. // memdbgon must be the last include file in a .cpp file!!!
  29. #include <tier0/memdbgon.h>
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Constructor.
  32. //-----------------------------------------------------------------------------
  33. Cordon3D::Cordon3D(void)
  34. {
  35. SetDrawColors(RGB(0, 255, 255), RGB(255, 0, 0));
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Called when the tool is activated.
  39. // Input : eOldTool - The ID of the previously active tool.
  40. //-----------------------------------------------------------------------------
  41. void Cordon3D::OnActivate()
  42. {
  43. if (!IsActiveTool())
  44. {
  45. Vector mins,maxs;
  46. m_pDocument->GetCordon( mins, maxs );
  47. SetBounds( mins,maxs );
  48. m_bEmpty = !IsValidBox();
  49. EnableHandles( true );
  50. }
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose: Handles left mouse button down events in the 2D view.
  54. // Input : Per CWnd::OnLButtonDown.
  55. // Output : Returns true if the message was handled, false if not.
  56. //-----------------------------------------------------------------------------
  57. bool Cordon3D::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  58. {
  59. Tool3D::OnLMouseDown2D(pView, nFlags, vPoint);
  60. Vector vecWorld;
  61. pView->ClientToWorld(vecWorld, vPoint);
  62. unsigned int uConstraints = GetConstraints( nFlags );
  63. if ( HitTest(pView, vPoint, true) )
  64. {
  65. StartTranslation( pView, vPoint, m_LastHitTestHandle );
  66. }
  67. else
  68. {
  69. // getvisiblepoint fills in any coord that's still set to COORD_NOTINIT:
  70. vecWorld[pView->axThird] = COORD_NOTINIT;
  71. m_pDocument->GetBestVisiblePoint(vecWorld);
  72. // snap starting position to grid
  73. if ( uConstraints & constrainSnap )
  74. m_pDocument->Snap(vecWorld,uConstraints);
  75. StartNew( pView, vPoint, vecWorld, Vector(0,0,0) );
  76. }
  77. return true;
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose: Handles left mouse button up events in the 2D view.
  81. // Input : Per CWnd::OnLButtonUp.
  82. // Output : Returns true if the message was handled, false if not.
  83. //-----------------------------------------------------------------------------
  84. bool Cordon3D::OnLMouseUp2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  85. {
  86. Tool3D::OnLMouseUp2D(pView, nFlags, vPoint) ;
  87. if ( IsTranslating() )
  88. {
  89. FinishTranslation( true );
  90. m_pDocument->SetCordon( bmins, bmaxs );
  91. }
  92. m_pDocument->UpdateStatusbar();
  93. return true;
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Handles mouse move events in the 2D view.
  97. // Input : Per CWnd::OnMouseMove.
  98. // Output : Returns true if the message was handled, false if not.
  99. //-----------------------------------------------------------------------------
  100. bool Cordon3D::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  101. {
  102. vgui::HCursor hCursor = vgui::dc_arrow;
  103. Tool3D::OnMouseMove2D(pView, nFlags, vPoint) ;
  104. unsigned int uConstraints = GetConstraints( nFlags );
  105. // Convert to world coords.
  106. Vector vecWorld;
  107. pView->ClientToWorld(vecWorld, vPoint);
  108. // Update status bar position display.
  109. //
  110. char szBuf[128];
  111. m_pDocument->Snap(vecWorld,uConstraints);
  112. sprintf(szBuf, " @%.0f, %.0f ", vecWorld[pView->axHorz], vecWorld[pView->axVert]);
  113. SetStatusText(SBI_COORDS, szBuf);
  114. if ( IsTranslating() )
  115. {
  116. // cursor is cross here
  117. Tool3D::UpdateTranslation( pView, vPoint, uConstraints );
  118. hCursor = vgui::dc_none;
  119. }
  120. else if ( HitTest(pView, vPoint, true) )
  121. {
  122. hCursor = UpdateCursor( pView, m_LastHitTestHandle, m_TranslateMode );
  123. }
  124. if ( hCursor != vgui::dc_none )
  125. pView->SetCursor( hCursor );
  126. return true;
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose: Handles the escape key in the 2D or 3D views.
  130. //-----------------------------------------------------------------------------
  131. void Cordon3D::OnEscape(void)
  132. {
  133. if ( IsTranslating() )
  134. {
  135. FinishTranslation( false );
  136. }
  137. else
  138. {
  139. m_pDocument->GetTools()->SetTool(TOOL_POINTER);
  140. }
  141. }
  142. //-----------------------------------------------------------------------------
  143. // Purpose:
  144. // Output :
  145. //-----------------------------------------------------------------------------
  146. bool Cordon3D::OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags)
  147. {
  148. if (nChar == VK_ESCAPE)
  149. {
  150. OnEscape();
  151. return true;
  152. }
  153. return false;
  154. }
  155. //-----------------------------------------------------------------------------
  156. // Purpose:
  157. // Output :
  158. //-----------------------------------------------------------------------------
  159. bool Cordon3D::OnKeyDown3D(CMapView3D *pView, UINT nChar, UINT nRepCnt, UINT nFlags)
  160. {
  161. if (nChar == VK_ESCAPE)
  162. {
  163. OnEscape();
  164. return true;
  165. }
  166. return false;
  167. }