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.

163 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "GlobalFunctions.h"
  9. #include "History.h"
  10. #include "MapDoc.h"
  11. #include "MapDecal.h"
  12. #include "MapSolid.h"
  13. #include "MapView3D.h"
  14. #include "resource.h"
  15. #include "ToolManager.h"
  16. #include "ToolDecal.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include <tier0/memdbgon.h>
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Handles key down events in the 2D view.
  21. // Input : Per CWnd::OnKeyDown.
  22. // Output : Returns true on success, false on failure.
  23. //-----------------------------------------------------------------------------
  24. bool CToolDecal::OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags)
  25. {
  26. switch (nChar)
  27. {
  28. case VK_ESCAPE:
  29. {
  30. ToolManager()->SetTool(TOOL_POINTER);
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Handles mouse move events in the 2D view.
  38. // Input : Per CWnd::OnMouseMove.
  39. // Output : Returns true if the message was handled, false if not.
  40. //-----------------------------------------------------------------------------
  41. bool CToolDecal::OnMouseMove2D(CMapView2D *pView, UINT nFlags, const Vector2D &vPoint)
  42. {
  43. SetDecalCursor();
  44. return true;
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Purpose: Handles key down events in the 3D view.
  48. // Input : Per CWnd::OnKeyDown.
  49. // Output : Returns true if the message was handled, false if not.
  50. //-----------------------------------------------------------------------------
  51. bool CToolDecal::OnKeyDown3D(CMapView3D *pView, UINT nChar, UINT nRepCnt, UINT nFlags)
  52. {
  53. switch (nChar)
  54. {
  55. case VK_ESCAPE:
  56. {
  57. ToolManager()->SetTool(TOOL_POINTER);
  58. }
  59. }
  60. return false;
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: Handles left button down events in the 3D view.
  64. // Input : Per CWnd::OnLButtonDown.
  65. // Output : Returns true if the message was handled, false if not.
  66. //-----------------------------------------------------------------------------
  67. bool CToolDecal::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  68. {
  69. //
  70. // See if they clicked on a brush face. If so, apply a decal where they clicked.
  71. //
  72. CMapDoc *pDoc = pView->GetMapDoc();
  73. ULONG ulFace;
  74. CMapClass *pObject;
  75. if ((pObject = pView->NearestObjectAt( vPoint, ulFace)) != NULL)
  76. {
  77. CMapSolid *pSolid = dynamic_cast <CMapSolid *> (pObject);
  78. if (pSolid == NULL)
  79. {
  80. return true;
  81. }
  82. //
  83. // Build a ray to trace against the face that they clicked on to
  84. // find the point of intersection.
  85. //
  86. Vector Start,End;
  87. pView->GetCamera()->BuildRay( vPoint, Start, End);
  88. Vector HitPos, HitNormal;
  89. CMapFace *pFace = pSolid->GetFace(ulFace);
  90. if (pFace->TraceLine(HitPos, HitNormal, Start, End))
  91. {
  92. GetHistory()->MarkUndoPosition(NULL, "Create decal");
  93. CMapEntity *pEntity = new CMapEntity;
  94. pEntity->SetKeyValue("texture", GetDefaultTextureName());
  95. pEntity->SetPlaceholder(TRUE);
  96. pEntity->SetOrigin(HitPos);
  97. pEntity->SetClass("infodecal");
  98. CMapWorld *pWorld = pDoc->GetMapWorld();
  99. CMapDecal *pDecal = pEntity->GetChildOfType((CMapDecal *)NULL);
  100. if (pDecal != NULL)
  101. {
  102. pDecal->DecalAllSolids(pWorld);
  103. }
  104. pEntity->CalcBounds(TRUE);
  105. pDoc->AddObjectToWorld(pEntity);
  106. GetHistory()->KeepNew(pEntity);
  107. pDoc->SetModifiedFlag();
  108. }
  109. }
  110. return true;
  111. }
  112. //-----------------------------------------------------------------------------
  113. // Purpose: Handles mouse move events in the 3D view.
  114. // Input : Per CWnd::OnMouseMove.
  115. // Output : Returns true if the message was handled, false if not.
  116. //-----------------------------------------------------------------------------
  117. bool CToolDecal::OnMouseMove3D(CMapView3D *pView, UINT nFlags, const Vector2D &vPoint)
  118. {
  119. SetDecalCursor();
  120. return true;
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose: Sets the cursor to the decal application cursor.
  124. //-----------------------------------------------------------------------------
  125. void CToolDecal::SetDecalCursor(void)
  126. {
  127. static HCURSOR hcurDecal;
  128. if (!hcurDecal)
  129. {
  130. hcurDecal = LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_DECAL));
  131. }
  132. SetCursor(hcurDecal);
  133. }