guiMeshRoadEditorCtrl.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUIMESHROADEDITORCTRL_H_
  23. #define _GUIMESHROADEDITORCTRL_H_
  24. #ifndef _EDITTSCTRL_H_
  25. #include "gui/worldEditor/editTSCtrl.h"
  26. #endif
  27. #ifndef _UNDO_H_
  28. #include "util/undo.h"
  29. #endif
  30. #ifndef _GIZMO_H_
  31. #include "gui/worldEditor/gizmo.h"
  32. #endif
  33. #ifndef _MESHROAD_H_
  34. #include "environment/meshRoad.h"
  35. #endif
  36. #include "T3D/assets/MaterialAsset.h"
  37. class GameBase;
  38. class GuiMeshRoadEditorCtrl : public EditTSCtrl
  39. {
  40. typedef EditTSCtrl Parent;
  41. public:
  42. friend class GuiMeshRoadEditorUndoAction;
  43. String mSelectMeshRoadMode;
  44. String mAddMeshRoadMode;
  45. String mAddNodeMode;
  46. String mInsertPointMode;
  47. String mRemovePointMode;
  48. String mMovePointMode;
  49. String mScalePointMode;
  50. String mRotatePointMode;
  51. GuiMeshRoadEditorCtrl();
  52. ~GuiMeshRoadEditorCtrl();
  53. DECLARE_CONOBJECT(GuiMeshRoadEditorCtrl);
  54. // SimObject
  55. bool onAdd();
  56. static void initPersistFields();
  57. // GuiControl
  58. virtual void onSleep();
  59. // EditTSCtrl
  60. bool onKeyDown(const GuiEvent& event);
  61. void get3DCursor( GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event_ );
  62. void on3DMouseDown(const Gui3DMouseEvent & event);
  63. void on3DMouseUp(const Gui3DMouseEvent & event);
  64. void on3DMouseMove(const Gui3DMouseEvent & event);
  65. void on3DMouseDragged(const Gui3DMouseEvent & event);
  66. void on3DMouseEnter(const Gui3DMouseEvent & event);
  67. void on3DMouseLeave(const Gui3DMouseEvent & event);
  68. void on3DRightMouseDown(const Gui3DMouseEvent & event);
  69. void on3DRightMouseUp(const Gui3DMouseEvent & event);
  70. void updateGuiInfo();
  71. void renderScene(const RectI & updateRect);
  72. // GuiRiverEditorCtrl
  73. bool getStaticPos( const Gui3DMouseEvent & event, Point3F &tpos );
  74. void deleteSelectedNode();
  75. void deleteSelectedRoad( bool undoAble = true );
  76. void setMode( String mode, bool sourceShortcut );
  77. String getMode() { return mMode; }
  78. void setSelectedRoad( MeshRoad *road );
  79. MeshRoad* getSelectedRoad() { return mSelRoad; };
  80. void setSelectedNode( S32 node );
  81. F32 getNodeWidth();
  82. void setNodeWidth( F32 width );
  83. F32 getNodeDepth();
  84. void setNodeDepth( F32 depth );
  85. Point3F getNodePosition();
  86. void setNodePosition(const Point3F& pos);
  87. VectorF getNodeNormal();
  88. void setNodeNormal( const VectorF &normal );
  89. void matchTerrainToRoad();
  90. protected:
  91. enum {
  92. Top = 0,
  93. Bottom = 1,
  94. Side = 2,
  95. SurfaceCount = 3
  96. };
  97. S32 _getNodeAtScreenPos( const MeshRoad *pRoad, const Point2I &posi );
  98. S32 _getProfileNodeAtScreenPos( MeshRoadProfile *pProfile, const Point2I &posi);
  99. void _drawSpline( MeshRoad *road, const ColorI &color );
  100. void _drawControlNodes( MeshRoad *road, const ColorI &color );
  101. void submitUndo( const UTF8 *name = "Action" );
  102. GFXStateBlockRef mZDisableSB;
  103. GFXStateBlockRef mZEnableSB;
  104. bool mSavedDrag;
  105. bool mIsDirty;
  106. bool mSavedProfileDrag;
  107. bool mDeselectProfileNode;
  108. SimSet *mRoadSet;
  109. S32 mSelNode;
  110. S32 mHoverNode;
  111. S32 mProfileNode;
  112. Vector<U32> mSelProfNodeList;
  113. U32 mAddNodeIdx;
  114. SimObjectPtr<MeshRoad> mSelRoad;
  115. SimObjectPtr<MeshRoad> mHoverRoad;
  116. String mMode;
  117. F32 mDefaultWidth;
  118. F32 mDefaultDepth;
  119. VectorF mDefaultNormal;
  120. Point2I mNodeHalfSize;
  121. ColorI mHoverSplineColor;
  122. ColorI mSelectedSplineColor;
  123. ColorI mHoverNodeColor;
  124. ColorI mProfileColor;
  125. bool mHasCopied;
  126. public:
  127. DECLARE_MATERIALASSET(GuiMeshRoadEditorCtrl, TopMaterial);
  128. DECLARE_ASSET_SETGET(GuiMeshRoadEditorCtrl, TopMaterial);
  129. DECLARE_MATERIALASSET(GuiMeshRoadEditorCtrl, BottomMaterial);
  130. DECLARE_ASSET_SETGET(GuiMeshRoadEditorCtrl, BottomMaterial);
  131. DECLARE_MATERIALASSET(GuiMeshRoadEditorCtrl, SideMaterial);
  132. DECLARE_ASSET_SETGET(GuiMeshRoadEditorCtrl, SideMaterial);
  133. };
  134. class GuiMeshRoadEditorUndoAction : public UndoAction
  135. {
  136. public:
  137. GuiMeshRoadEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName )
  138. {
  139. mEditor = NULL;
  140. mObjId = 0;
  141. mMetersPerSegment = 1.0f;
  142. }
  143. GuiMeshRoadEditorCtrl *mEditor;
  144. Vector<MeshRoadNode> mNodes;
  145. Vector<MeshRoadProfileNode> mProfileNodes;
  146. Vector<U8> mProfileMtrls;
  147. SimObjectId mObjId;
  148. F32 mMetersPerSegment;
  149. virtual void undo();
  150. virtual void redo() { undo(); }
  151. };
  152. #endif // _GUIMESHROADEDITORCTRL_H_