EditorToySceneWindow.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #ifndef _EDITORTOYSCENEWINDOW_H_
  2. #define _EDITORTOYSCENEWINDOW_H_
  3. #ifndef _GUICONTROL_H_
  4. #include "gui/guiControl.h"
  5. #endif // !_GUICONTROL_H_
  6. #ifndef _SCENEWINDOW_H_
  7. #include "2d/gui/SceneWindow.h"
  8. #endif // !_SCENEWINDOW_H_
  9. #ifndef _SCENEOBJECT_H_
  10. #include "2d/sceneobject/SceneObject.h"
  11. #endif // !_SCENEOBJECT_H_
  12. #ifndef _UNDO_H_
  13. #include "collection/undo.h"
  14. #endif
  15. class SceneObject;
  16. class EditorToyTool;
  17. class EditorToySelection;
  18. class EditorToySceneWindow : public SceneWindow
  19. {
  20. private:
  21. typedef SceneWindow Parent;
  22. U32 mNutSize;
  23. // We really only want to work on sceneObjects
  24. Vector<SceneObject*> mSelectedObjs;
  25. UndoManager mUndoManager;
  26. SimGroup mTrash;
  27. SimSet mSelSet;
  28. Point2I mLastMousePt;
  29. Point2I mSelectionAnchor;
  30. Vector2 mGridSnap;
  31. Point2I mDragBegin;
  32. Vector<Vector2> mDragBeginPoints;
  33. // Store the current scene.
  34. Scene* mCurrentScene;
  35. Vector2 mOffset;
  36. RectI mSelBox;
  37. Vector2 mSelCenter;
  38. F32 mSnapThreshold;
  39. // rotation vars
  40. F32 mStartAngle;
  41. Vector2 mStartVector;
  42. // Sizing Cursors
  43. GuiCursor* mDefaultCursor;
  44. GuiCursor* mLeftRightCursor;
  45. GuiCursor* mUpDownCursor;
  46. GuiCursor* mMoveCursor;
  47. // cam vars
  48. Vector2 mMouseCamDown;
  49. Vector2 mSceneCamPos;
  50. Vector2 mSceneCamSize;
  51. RectI mSceneCamRect;
  52. bool mAllCam;
  53. bool mDrawCam;
  54. bool mDrawAspectSafety;
  55. bool mDrawSaftey;
  56. enum MouseMode
  57. {
  58. Selecting = 0,
  59. MovingSelection,
  60. SizingSelection,
  61. RotateSelection,
  62. DragSelection
  63. };
  64. enum SizingMode
  65. {
  66. SizingNone = 0,
  67. SizingLeft = 1,
  68. SizingRight = 2,
  69. SizingTop = 4,
  70. SizingBottom = 8
  71. };
  72. enum DropType
  73. {
  74. DropAtOrigin = 0,
  75. DropAtCamera,
  76. DropAtCameraWithRot,
  77. DropAtScreenCenter
  78. };
  79. EditorToyTool* mActiveTool;
  80. MouseMode mMouseMode;
  81. SizingMode mSizeMode;
  82. DropType mDropType;
  83. bool inNut(const Point2I & pt, S32 x, S32 y);
  84. void updatedSelection();
  85. public:
  86. DECLARE_CONOBJECT(EditorToySceneWindow);
  87. EditorToySceneWindow();
  88. ~EditorToySceneWindow();
  89. virtual bool onAdd();
  90. virtual void onRemove();
  91. // handle sizing nuts
  92. S32 getNutHit(const Point2I &pt, const RectI &box);
  93. S32 getDirNutHit(const Point2I &pt, SceneObject* obj);
  94. // draw visuals
  95. void drawNut(const Point2I &nut, ColorI &outlineColor, ColorI &nutColor);
  96. void drawSizingNuts(SceneObject* obj, ColorI &outlineColor, ColorI &nutColor);
  97. bool getRotateNutHit(const Point2I & pt, SceneObject * obj );
  98. void drawRotateNuts(SceneObject* obj, ColorI &outlineColor, ColorI &nutColor);
  99. // object scene to window functions
  100. void getDragRect(RectI &box);
  101. RectI objWindowBounds(const SceneObject* obj);
  102. Point2I objWindowPos(const SceneObject* obj);
  103. // Input Handling
  104. void onTouchUp(const GuiEvent& gEvt);
  105. void onTouchDown(const GuiEvent& gEvt);
  106. void onTouchDragged(const GuiEvent& gEvt);
  107. void onTouchMove(const GuiEvent& gEvt);
  108. void onRightMouseUp(const GuiEvent& gEvt);
  109. void onRightMouseDown(const GuiEvent& gEvt);
  110. void onRightMouseDragged(const GuiEvent& gEvt);
  111. void onMouseWheelUp(const GuiEvent &gEvt);
  112. void onMouseWheelDown(const GuiEvent &gEvt);
  113. // do something to objects
  114. void rotateObject(Vector2 mousePos, Vector2 origVec, F32 origAngle);
  115. void moveObject(Vector2 newPos);
  116. void scaleObject(Vector2 size, Vector2 pos, Vector2 mousePos, bool maintainAr, bool fixedPos);
  117. // Scene handling
  118. void setEditScene(Scene* pScene);
  119. RectI updateSceneCamera();
  120. void resetEditScene(void);
  121. // Find out stuff about selection.
  122. void updateSelectionBounds();
  123. Vector2 getSelectionCenter();
  124. bool selectionContains(SceneObject * obj);
  125. // render
  126. virtual void onRender(Point2I offset, const RectI &updateRect);
  127. // camera
  128. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  129. // tool system.
  130. void setTool(EditorToyTool* tool);
  131. void deactivateTool();
  132. EditorToyTool* getTool() { return mActiveTool; }
  133. const SimSet& getSelectionSet() { updatedSelection(); return mSelSet; }
  134. // Sizing Cursors
  135. bool initCursors();
  136. void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &gEvt);
  137. };
  138. #endif // !_EDITORTOYSCENEWINDOW_H_