guiRoadEditorCtrl.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 _GUIROADEDITORCTRL_H_
  23. #define _GUIROADEDITORCTRL_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 _DECALROAD_H_
  31. #include "environment/decalRoad.h"
  32. #endif
  33. class GameBase;
  34. class DecalRoad;
  35. class GuiRoadEditorCtrl : public EditTSCtrl
  36. {
  37. typedef EditTSCtrl Parent;
  38. public:
  39. friend class GuiRoadEditorUndoAction;
  40. String mSelectRoadMode;
  41. String mAddRoadMode;
  42. String mAddNodeMode;
  43. String mInsertPointMode;
  44. String mRemovePointMode;
  45. String mMovePointMode;
  46. String mScalePointMode;
  47. GuiRoadEditorCtrl();
  48. ~GuiRoadEditorCtrl();
  49. DECLARE_CONOBJECT(GuiRoadEditorCtrl);
  50. // SimObject
  51. bool onAdd();
  52. static void initPersistFields();
  53. // GuiControl
  54. virtual void onSleep();
  55. virtual void onRender(Point2I offset, const RectI &updateRect);
  56. // EditTSCtrl
  57. bool onKeyDown(const GuiEvent& event);
  58. void get3DCursor( GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event_ );
  59. void on3DMouseDown(const Gui3DMouseEvent & event);
  60. void on3DMouseUp(const Gui3DMouseEvent & event);
  61. void on3DMouseMove(const Gui3DMouseEvent & event);
  62. void on3DMouseDragged(const Gui3DMouseEvent & event);
  63. void on3DMouseEnter(const Gui3DMouseEvent & event);
  64. void on3DMouseLeave(const Gui3DMouseEvent & event);
  65. void on3DRightMouseDown(const Gui3DMouseEvent & event);
  66. void on3DRightMouseUp(const Gui3DMouseEvent & event);
  67. void updateGuiInfo();
  68. void renderScene(const RectI & updateRect);
  69. void renderGui(Point2I offset, const RectI &updateRect);
  70. bool getTerrainPos( const Gui3DMouseEvent & event, Point3F &tpos );
  71. void deleteSelectedNode();
  72. void deleteSelectedRoad( bool undoAble = true );
  73. void setMode( String mode, bool sourceShortcut );
  74. String getMode() { return mMode; }
  75. void setSelectedRoad( DecalRoad *road );
  76. DecalRoad* getSelectedRoad() { return mSelRoad; };
  77. void setSelectedNode( S32 node );
  78. S32 getSelectedNode() { return mSelNode; };
  79. F32 getNodeWidth();
  80. void setNodeWidth( F32 width );
  81. Point3F getNodePosition();
  82. void setNodePosition(const Point3F& pos);
  83. void setTextureFile( StringTableEntry file );
  84. public:
  85. DECLARE_MATERIALASSET(GuiRoadEditorCtrl, Material);
  86. DECLARE_ASSET_SETGET(GuiRoadEditorCtrl, Material);
  87. protected:
  88. void _drawRoadSpline( DecalRoad *road, const ColorI &color );
  89. void _drawRoadControlNodes( DecalRoad *road, const ColorI &color );
  90. void submitUndo( const UTF8 *name );
  91. bool mSavedDrag;
  92. bool mIsDirty;
  93. SimSet *mRoadSet;
  94. S32 mSelNode;
  95. S32 mHoverNode;
  96. U32 mAddNodeIdx;
  97. SimObjectPtr<DecalRoad> mSelRoad;
  98. SimObjectPtr<DecalRoad> mHoverRoad;
  99. ColorI mHoverSplineColor;
  100. ColorI mSelectedSplineColor;
  101. ColorI mHoverNodeColor;
  102. String mMode;
  103. F32 mDefaultWidth;
  104. S32 mInsertIdx;
  105. F32 mStartWidth;
  106. S32 mStartX;
  107. Point3F mStartWorld;
  108. Point2I mNodeHalfSize;
  109. // StateBlock for rendering road splines.
  110. GFXStateBlockRef mZDisableSB;
  111. };
  112. class GuiRoadEditorUndoAction : public UndoAction
  113. {
  114. public:
  115. GuiRoadEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName )
  116. {
  117. mRoadEditor = NULL;
  118. mObjId = 0;
  119. mBreakAngle = 3.0f;
  120. mSegmentsPerBatch = 0;
  121. mTextureLength = 0.0f;
  122. }
  123. GuiRoadEditorCtrl *mRoadEditor;
  124. Vector<RoadNode> mNodes;
  125. SimObjectId mObjId;
  126. StringTableEntry mMaterialAssetId;
  127. F32 mBreakAngle;
  128. U32 mSegmentsPerBatch;
  129. F32 mTextureLength;
  130. virtual void undo();
  131. virtual void redo() { undo(); }
  132. };
  133. #endif