guiEditCtrl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _GUIEDITCTRL_H_
  23. #define _GUIEDITCTRL_H_
  24. #include "gui/guiControl.h"
  25. #include "collection/undo.h"
  26. class GuiEditCtrl : public GuiControl
  27. {
  28. typedef GuiControl Parent;
  29. Vector<GuiControl *> mSelectedControls;
  30. GuiControl* mCurrentAddSet;
  31. GuiControl* mContentControl;
  32. Point2I mLastMousePos;
  33. Point2I mSelectionAnchor;
  34. Point2I mGridSnap;
  35. bool mUseGridSnap;
  36. Point2I mDragBeginPoint;
  37. Vector<Point2I> mDragBeginPoints;
  38. GuiControl* mMouseLockedEditCtrl;
  39. // Undo
  40. UndoManager mUndoManager;
  41. SimGroup mTrash;
  42. SimSet mSelectedSet;
  43. // Sizing Cursors
  44. GuiCursor* mDefaultCursor;
  45. GuiCursor* mLeftRightCursor;
  46. GuiCursor* mUpDownCursor;
  47. GuiCursor* mNWSECursor;
  48. GuiCursor* mNESWCursor;
  49. GuiCursor* mMoveCursor;
  50. enum mouseModes { Selecting, MovingSelection, SizingSelection, DragSelecting };
  51. enum sizingModes { sizingNone = 0, sizingLeft = 1, sizingRight = 2, sizingTop = 4, sizingBottom = 8 };
  52. mouseModes mMouseDownMode;
  53. sizingModes mSizingMode;
  54. // private methods
  55. void updateSelectedSet();
  56. public:
  57. GuiEditCtrl();
  58. DECLARE_CONOBJECT(GuiEditCtrl);
  59. bool onWake();
  60. void onSleep();
  61. void select(GuiControl *ctrl);
  62. void setRoot(GuiControl *ctrl);
  63. GuiControl* getRoot() { return mContentControl; }
  64. void setEditMode(bool value);
  65. S32 getSizingHitKnobs(const Point2I &pt, const RectI &box);
  66. void getDragRect(RectI &b);
  67. void drawNut(const Point2I &nut, ColorI &outlineColor, ColorI &nutColor);
  68. void drawNuts(RectI &box, ColorI &outlineColor, ColorI &nutColor);
  69. void onPreRender();
  70. void onRender(Point2I offset, const RectI &updateRect);
  71. void addNewControl(GuiControl *ctrl);
  72. bool selectionContains(GuiControl *ctrl);
  73. void setCurrentAddSet(GuiControl *ctrl, bool clearSelection = true);
  74. const GuiControl* getCurrentAddSet() const;
  75. void setSelection(GuiControl *ctrl);
  76. // Undo Access
  77. void undo();
  78. void redo();
  79. UndoManager& getUndoManager() { return mUndoManager; }
  80. // When a control is changed by the inspector
  81. void controlInspectPreApply(GuiControl* object);
  82. void controlInspectPostApply(GuiControl* object);
  83. // Sizing Cursors
  84. bool initCursors();
  85. void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  86. const Vector<GuiControl *> *getSelected() const { return &mSelectedControls; }
  87. SimSet& getSelectedSet() { updateSelectedSet(); return mSelectedSet; }
  88. const SimGroup& getTrash() { return mTrash; }
  89. const GuiControl* getAddSet() const { return mCurrentAddSet; };
  90. bool onKeyDown(const GuiEvent &event);
  91. void onTouchDown(const GuiEvent &event);
  92. void onTouchUp(const GuiEvent &event);
  93. void onTouchDragged(const GuiEvent &event);
  94. void onRightMouseDown(const GuiEvent &event);
  95. virtual bool onAdd();
  96. virtual void onRemove();
  97. enum Justification {
  98. JUSTIFY_LEFT,
  99. JUSTIFY_CENTER,
  100. JUSTIFY_RIGHT,
  101. JUSTIFY_TOP,
  102. JUSTIFY_BOTTOM,
  103. SPACING_VERTICAL,
  104. SPACING_HORIZONTAL
  105. };
  106. void justifySelection( Justification j);
  107. void moveSelection(const Point2I &delta);
  108. void moveAndSnapSelection(const Point2I &delta);
  109. void saveSelection(const char *filename);
  110. void loadSelection(const char *filename);
  111. void addSelection(S32 id);
  112. void removeSelection(S32 id);
  113. void deleteSelection();
  114. void clearSelection();
  115. void selectAll();
  116. void bringToFront();
  117. void pushToBack();
  118. void setSnapToGrid(U32 gridsize);
  119. bool hasSnapToGrid() { return mUseGridSnap; }
  120. S32 getGridSize() { return mGridSnap.x; }
  121. void moveSelectionToCtrl(GuiControl*);
  122. ColorI getEditorColor() { return mProfile->getFillColor(DisabledState); }
  123. //Editor Mouse Locking
  124. bool editIsMouseLocked(GuiControl* ctrl) { return ctrl == mMouseLockedEditCtrl; }
  125. void editMouseLock(GuiControl* ctrl) { mMouseLockedEditCtrl = ctrl; }
  126. void editMouseUnlock() { mMouseLockedEditCtrl = nullptr; }
  127. };
  128. #endif //_GUI_EDIT_CTRL_H