ObjectSelectionBrush.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #define OBJECTSELECTIONBRUSH_CPP
  2. /*************************************************************************************************\
  3. ObjectSelectionBrush.cpp : Implementation of the ObjectSelectionBrush component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "ObjectSelectionBrush.h"
  9. #ifndef CAMERA_H
  10. #include "Camera.h"
  11. #endif
  12. #ifndef EDITOROBJECTMGR_H
  13. #include "EditorObjectMgr.h"
  14. #endif
  15. #ifndef ACTION_H
  16. #include "Action.h"
  17. #endif
  18. #include "utilities.h"
  19. #include "EditorMessages.h"
  20. ObjectSelectionBrush::ObjectSelectionBrush()
  21. {
  22. bPainting = false;
  23. pCurAction = NULL;
  24. lastPos.x = lastPos.y = lastPos.z = lastPos.w = 0.0f; //Keep the FPU exception from going off!
  25. bFirstClick = false;
  26. }
  27. ObjectSelectionBrush::~ObjectSelectionBrush()
  28. {
  29. if ( EditorObjectMgr::instance )
  30. EditorObjectMgr::instance->unselectAll();
  31. if ( land )
  32. land->unselectAll();
  33. }
  34. bool ObjectSelectionBrush::beginPaint()
  35. {
  36. lastPos.x = lastPos.y = 0.0;
  37. bPainting = true;
  38. bFirstClick = !bFirstClick;
  39. return true;
  40. }
  41. Action* ObjectSelectionBrush::endPaint()
  42. {
  43. bPainting = false;
  44. Action* pRetAction = NULL;
  45. if ( pCurAction )
  46. {
  47. if ( pCurAction->vertexInfoList.Count() )
  48. {
  49. pRetAction = pCurAction;
  50. pCurAction = NULL;
  51. land->recalcWater();
  52. land->reCalcLight();
  53. }
  54. else
  55. {
  56. delete pCurAction;
  57. pCurAction = NULL;
  58. }
  59. }
  60. return pRetAction;
  61. }
  62. bool ObjectSelectionBrush::paint( Stuff::Vector3D& worldPos, int screenX, int screenY )
  63. {
  64. Stuff::Vector4D endPos;
  65. endPos.x = screenX;
  66. endPos.y = screenY;
  67. //if ( bFirstClick ) // otherwise, do a new area select
  68. {
  69. bool bShift = GetAsyncKeyState( KEY_LSHIFT );
  70. // select the objects
  71. if ( lastPos.x != 0.0 && lastPos.y != 0.0 )
  72. {
  73. if ( !bShift )
  74. {
  75. land->unselectAll();
  76. EditorObjectMgr::instance->unselectAll();
  77. }
  78. eye->projectZ( lastWorldPos, lastPos );
  79. EditorObjectMgr::instance->select( lastPos, endPos );
  80. land->selectVerticesInRect( lastPos, endPos );
  81. }
  82. else
  83. {
  84. if ( lastPos != endPos )
  85. {
  86. land->unselectAll();
  87. EditorObjectMgr::instance->unselectAll();
  88. }
  89. lastPos = endPos;
  90. Stuff::Vector2DOf<long> screenPos;
  91. screenPos.x = screenX;
  92. screenPos.y = screenY;
  93. eye->inverseProject( screenPos, lastWorldPos );
  94. const EditorObject* pInfo = EditorObjectMgr::instance->getObjectAtPosition( worldPos );
  95. if ( pInfo )
  96. {
  97. if ( !bShift || (bShift && pInfo->isSelected() == false ) )
  98. (const_cast<EditorObject*>(pInfo))->select( true );
  99. else
  100. (const_cast<EditorObject*>(pInfo))->select( false );
  101. }
  102. else
  103. {
  104. long tileR, tileC;
  105. land->worldToTile( worldPos, tileR, tileC );
  106. if ( tileR > -1 && tileR < land->realVerticesMapSide
  107. && tileC > -1 && tileC < land->realVerticesMapSide )
  108. {
  109. // figure out which vertex is closest
  110. if ( fabs(worldPos.x - land->tileColToWorldCoord[tileC]) >= land->worldUnitsPerVertex/2 )
  111. tileC++;
  112. if ( fabs(worldPos.y - land->tileRowToWorldCoord[tileR]) >= land->worldUnitsPerVertex/2 )
  113. tileR++;
  114. if (!bShift || (bShift && !land->isVertexSelected( tileR, tileC ) ) )
  115. land->selectVertex( tileR, tileC );
  116. else // shift key, object is selected
  117. land->selectVertex( tileR, tileC, false );
  118. }
  119. }
  120. }
  121. }
  122. return true;
  123. }
  124. void ObjectSelectionBrush::render( int screenX, int screenY )
  125. {
  126. if ( bPainting )
  127. {
  128. //------------------------------------------
  129. Stuff::Vector4D Screen;
  130. eye->projectZ( lastWorldPos, Screen );
  131. GUI_RECT rect = { screenX, screenY, Screen.x, Screen.y };
  132. drawRect( rect, 0x30ffffff );
  133. drawEmptyRect( rect, 0xff000000, 0xff000000 );
  134. }
  135. if ( !bPainting )
  136. {
  137. EditorInterface::instance()->ChangeCursor( IDC_TARGET );
  138. }
  139. }
  140. EditorObjectPointerList ObjectSelectionBrush::selectedObjectPointerList()
  141. {
  142. return EditorObjectMgr::instance->getSelectedObjectPointerList();
  143. }
  144. //*************************************************************************************************
  145. // end of file ( ObjectSelectionBrush.cpp )