editTSCtrl.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 _EDITTSCTRL_H_
  23. #define _EDITTSCTRL_H_
  24. #ifndef _GUITSCONTROL_H_
  25. #include "gui/3d/guiTSControl.h"
  26. #endif
  27. #ifndef _GIZMO_H_
  28. #include "gizmo.h"
  29. #endif
  30. class TerrainBlock;
  31. class MissionArea;
  32. class Gizmo;
  33. class EditManager;
  34. struct ObjectRenderInst;
  35. class SceneRenderState;
  36. class BaseMatInstance;
  37. class EditTSCtrl : public GuiTSCtrl
  38. {
  39. typedef GuiTSCtrl Parent;
  40. protected:
  41. void make3DMouseEvent(Gui3DMouseEvent & gui3Devent, const GuiEvent &event);
  42. // GuiControl
  43. void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent) override;
  44. void onMouseUp(const GuiEvent & event) override;
  45. void onMouseDown(const GuiEvent & event) override;
  46. void onMouseMove(const GuiEvent & event) override;
  47. void onMouseDragged(const GuiEvent & event) override;
  48. void onMouseEnter(const GuiEvent & event) override;
  49. void onMouseLeave(const GuiEvent & event) override;
  50. void onRightMouseDown(const GuiEvent & event) override;
  51. void onRightMouseUp(const GuiEvent & event) override;
  52. void onRightMouseDragged(const GuiEvent & event) override;
  53. void onMiddleMouseDown(const GuiEvent & event) override;
  54. void onMiddleMouseUp(const GuiEvent & event) override;
  55. void onMiddleMouseDragged(const GuiEvent & event) override;
  56. bool onInputEvent(const InputEventInfo & event) override;
  57. bool onMouseWheelUp(const GuiEvent &event) override;
  58. bool onMouseWheelDown(const GuiEvent &event) override;
  59. virtual void updateGuiInfo() {};
  60. virtual void renderScene(const RectI &){};
  61. void renderMissionArea();
  62. virtual void renderCameraAxis();
  63. virtual void renderGrid();
  64. // GuiTSCtrl
  65. void renderWorld(const RectI & updateRect) override;
  66. void _renderScene(ObjectRenderInst*, SceneRenderState *state, BaseMatInstance*);
  67. /// Zoom in/out in ortho views by "steps".
  68. void orthoZoom( F32 steps );
  69. protected:
  70. enum DisplayType
  71. {
  72. DisplayTypeTop,
  73. DisplayTypeBottom,
  74. DisplayTypeFront,
  75. DisplayTypeBack,
  76. DisplayTypeLeft,
  77. DisplayTypeRight,
  78. DisplayTypePerspective,
  79. DisplayTypeIsometric,
  80. };
  81. S32 mDisplayType;
  82. F32 mOrthoFOV;
  83. Point3F mOrthoCamTrans;
  84. EulerF mIsoCamRot;
  85. Point3F mIsoCamRotCenter;
  86. F32 mIsoCamAngle;
  87. Point3F mRawCamPos;
  88. Point2I mLastMousePos;
  89. bool mLastMouseClamping;
  90. bool mAllowBorderMove;
  91. S32 mMouseMoveBorder;
  92. F32 mMouseMoveSpeed;
  93. U32 mLastBorderMoveTime;
  94. Gui3DMouseEvent mLastEvent;
  95. bool mLeftMouseDown;
  96. bool mRightMouseDown;
  97. bool mMiddleMouseDown;
  98. bool mMiddleMouseTriggered;
  99. bool mMouseLeft;
  100. SimObjectPtr<Gizmo> mGizmo;
  101. GizmoProfile *mGizmoProfile;
  102. public:
  103. EditTSCtrl();
  104. ~EditTSCtrl();
  105. // SimObject
  106. bool onAdd() override;
  107. void onRemove() override;
  108. //
  109. bool mRenderMissionArea;
  110. ColorI mMissionAreaFillColor;
  111. ColorI mMissionAreaFrameColor;
  112. F32 mMissionAreaHeightAdjust;
  113. //
  114. ColorI mConsoleFrameColor;
  115. ColorI mConsoleFillColor;
  116. S32 mConsoleSphereLevel;
  117. S32 mConsoleCircleSegments;
  118. S32 mConsoleLineWidth;
  119. static void initPersistFields();
  120. static void consoleInit();
  121. //
  122. bool mConsoleRendering;
  123. bool mRightMousePassThru;
  124. bool mMiddleMousePassThru;
  125. // all editors will share a camera
  126. static Point3F smCamPos;
  127. static MatrixF smCamMatrix;
  128. static bool smCamOrtho;
  129. static F32 smCamNearPlane;
  130. static F32 smCamFOV;
  131. static F32 smVisibleDistanceScale;
  132. static U32 smSceneBoundsMask;
  133. static Point3F smMinSceneBounds;
  134. bool mRenderGridPlane;
  135. ColorI mGridPlaneColor;
  136. F32 mGridPlaneSize;
  137. F32 mGridPlaneSizePixelBias;
  138. S32 mGridPlaneMinorTicks;
  139. ColorI mGridPlaneMinorTickColor;
  140. ColorI mGridPlaneOriginColor;
  141. GFXStateBlockRef mBlendSB;
  142. // GuiTSCtrl
  143. virtual bool getCameraTransform(MatrixF* cameraMatrix);
  144. virtual void computeSceneBounds(Box3F& bounds);
  145. bool processCameraQuery(CameraQuery * query) override;
  146. // guiControl
  147. void onRender(Point2I offset, const RectI &updateRect) override;
  148. virtual void on3DMouseUp(const Gui3DMouseEvent &){};
  149. virtual void on3DMouseDown(const Gui3DMouseEvent &){};
  150. virtual void on3DMouseMove(const Gui3DMouseEvent &){};
  151. virtual void on3DMouseDragged(const Gui3DMouseEvent &){};
  152. virtual void on3DMouseEnter(const Gui3DMouseEvent &){};
  153. virtual void on3DMouseLeave(const Gui3DMouseEvent &){};
  154. virtual void on3DRightMouseDown(const Gui3DMouseEvent &){};
  155. virtual void on3DRightMouseUp(const Gui3DMouseEvent &){};
  156. virtual void on3DRightMouseDragged(const Gui3DMouseEvent &){};
  157. virtual void on3DMouseWheelUp(const Gui3DMouseEvent &){};
  158. virtual void on3DMouseWheelDown(const Gui3DMouseEvent &){};
  159. virtual void get3DCursor(GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &);
  160. virtual bool isLeftMouseDown() { return mLeftMouseDown; }
  161. virtual bool isMiddleMouseDown() {return mMiddleMouseDown;}
  162. virtual bool isRightMouseDown() { return mLeftMouseDown; }
  163. bool resize(const Point2I& newPosition, const Point2I& newExtent) override;
  164. S32 getDisplayType() const {return mDisplayType;}
  165. virtual void setDisplayType(S32 type);
  166. /// Return true if the current view is an ortho projection along one of the world axes.
  167. bool isOrthoDisplayType() const { return ( mDisplayType != DisplayTypePerspective && mDisplayType != DisplayTypeIsometric ); }
  168. F32 getOrthoFOV() const { return mOrthoFOV; }
  169. void setOrthoFOV( F32 fov ) { mOrthoFOV = fov; }
  170. virtual TerrainBlock* getActiveTerrain();
  171. virtual void calcOrthoCamOffset(F32 mousex, F32 mousey, U8 modifier=0);
  172. Gizmo* getGizmo() { return mGizmo; }
  173. /// Set flags or other Gizmo state appropriate for the current situation.
  174. /// For example derived classes may override this to disable certain
  175. /// axes of modes of manipulation.
  176. virtual void updateGizmo();
  177. DECLARE_CONOBJECT(EditTSCtrl);
  178. DECLARE_CATEGORY( "Gui Editor" );
  179. };
  180. #endif // _EDITTSCTRL_H_