guiRiverEditorCtrl.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 _GUIRIVEREDITORCTRL_H_
  23. #define _GUIRIVEREDITORCTRL_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 _RIVER_H_
  31. #include "environment/river.h"
  32. #endif
  33. #ifndef _GIZMO_H_
  34. #include "gui/worldEditor/gizmo.h"
  35. #endif
  36. struct ObjectRenderInst;
  37. class SceneManager;
  38. class SceneRenderState;
  39. class BaseMatInstance;
  40. class GuiRiverEditorCtrl : public EditTSCtrl
  41. {
  42. typedef EditTSCtrl Parent;
  43. public:
  44. friend class GuiRiverEditorUndoAction;
  45. //static StringTableEntry smNormalMode;
  46. //static StringTableEntry smAddNodeMode;
  47. String mSelectRiverMode;
  48. String mAddRiverMode;
  49. String mAddNodeMode;
  50. String mInsertPointMode;
  51. String mRemovePointMode;
  52. String mMovePointMode;
  53. String mScalePointMode;
  54. String mRotatePointMode;
  55. GuiRiverEditorCtrl();
  56. ~GuiRiverEditorCtrl();
  57. DECLARE_CONOBJECT(GuiRiverEditorCtrl);
  58. // SimObject
  59. bool onAdd();
  60. static void initPersistFields();
  61. // GuiControl
  62. virtual void onSleep();
  63. virtual void onRender(Point2I offset, const RectI &updateRect);
  64. // EditTSCtrl
  65. bool onKeyDown(const GuiEvent& event);
  66. void get3DCursor( GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event_ );
  67. void on3DMouseDown(const Gui3DMouseEvent & event);
  68. void on3DMouseUp(const Gui3DMouseEvent & event);
  69. void on3DMouseMove(const Gui3DMouseEvent & event);
  70. void on3DMouseDragged(const Gui3DMouseEvent & event);
  71. void on3DMouseEnter(const Gui3DMouseEvent & event);
  72. void on3DMouseLeave(const Gui3DMouseEvent & event);
  73. void on3DRightMouseDown(const Gui3DMouseEvent & event);
  74. void on3DRightMouseUp(const Gui3DMouseEvent & event);
  75. void updateGuiInfo();
  76. void renderScene(const RectI & updateRect);
  77. // GuiRiverEditorCtrl
  78. bool getStaticPos( const Gui3DMouseEvent & event, Point3F &tpos );
  79. void deleteSelectedNode();
  80. void deleteSelectedRiver( bool undoAble = true );
  81. void setMode( String mode, bool sourceShortcut );
  82. String getMode() { return mMode; }
  83. //void setGizmoMode( Gizmo::Mode mode ) { mGizmo->setMode( mode ); }
  84. void setSelectedRiver( River *river );
  85. River* getSelectedRiver() { return mSelRiver; };
  86. void setSelectedNode( S32 node );
  87. F32 getNodeWidth();
  88. void setNodeWidth( F32 width );
  89. F32 getNodeDepth();
  90. void setNodeDepth( F32 depth );
  91. Point3F getNodePosition();
  92. void setNodePosition(const Point3F& pos);
  93. VectorF getNodeNormal();
  94. void setNodeNormal( const VectorF &normal );
  95. protected:
  96. void _renderSelectedRiver( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *matInst );
  97. void _prepRenderImage( SceneManager* sceneGraph, const SceneRenderState* sceneState );
  98. void _drawRiverSpline( River *river, const ColorI &color );
  99. void _drawRiverControlNodes( River *river, const ColorI &color );
  100. void _process3DMouseDown( const Gui3DMouseEvent& event );
  101. void submitUndo( const UTF8 *name = "Action" );
  102. GFXStateBlockRef mZDisableSB;
  103. GFXStateBlockRef mZEnableSB;
  104. bool mSavedDrag;
  105. bool mIsDirty;
  106. SimSet *mRiverSet;
  107. S32 mSelNode;
  108. S32 mHoverNode;
  109. U32 mAddNodeIdx;
  110. SimObjectPtr<River> mSelRiver;
  111. SimObjectPtr<River> mHoverRiver;
  112. String mMode;
  113. F32 mDefaultWidth;
  114. F32 mDefaultDepth;
  115. VectorF mDefaultNormal;
  116. S32 mInsertIdx;
  117. F32 mStartHeight;
  118. F32 mStartWidth;
  119. S32 mStartX;
  120. Point3F mStartWorld;
  121. Point2I mNodeHalfSize;
  122. //Gizmo mGizmo;
  123. Gui3DMouseEvent mLastMouseEvent;
  124. F32 mNodeSphereRadius;
  125. ColorI mNodeSphereFillColor;
  126. ColorI mNodeSphereLineColor;
  127. ColorI mHoverSplineColor;
  128. ColorI mSelectedSplineColor;
  129. ColorI mHoverNodeColor;
  130. #define InvalidMousePoint Point2I(-100,-100)
  131. Point2I mStartDragMousePoint;
  132. Point3F mStartDragNodePos;
  133. //GuiCursor *mMoveNodeCursor;
  134. //GuiCursor *mAddNodeCursor;
  135. //GuiCursor *mInsertNodeCursor;
  136. //GuiCursor *mResizeNodeCursor;
  137. };
  138. class GuiRiverEditorUndoAction : public UndoAction
  139. {
  140. public:
  141. GuiRiverEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName )
  142. {
  143. mRiverEditor = NULL;
  144. mObjId = 0;
  145. mMetersPerSegment = 1.0f;
  146. mSegmentsPerBatch = 10;
  147. }
  148. GuiRiverEditorCtrl *mRiverEditor;
  149. Vector<RiverNode> mNodes;
  150. SimObjectId mObjId;
  151. F32 mMetersPerSegment;
  152. U32 mSegmentsPerBatch;
  153. virtual void undo();
  154. virtual void redo() { undo(); }
  155. };
  156. #endif