guiEditCtrl.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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; //A list of selected controls.
  30. GuiControl* mCurrentAddSet; //The curent container (sim set) that is being worked in (controls are added to). Changed by right clicking.
  31. GuiControl* mEditorRoot; //The editor root which attempts to simulate the canvas. This can be the add set, but should never be selected.
  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 mEditorRoot; }
  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 drawControlDecoration(GuiControl* ctrl, RectI &box, ColorI &outlineColor, ColorI &nutColor);
  69. void drawDashedLine(const F32& dashLength, const S32& x1, const S32& y1, const S32& x2, const S32& y2, ColorI& color);
  70. void drawTargetLines(const S32& lx, const S32& ty, ColorI& weakColor, const S32& by, const S32& rx, ColorI& strongColor);
  71. void drawNuts(S32& lx, S32& ty, S32& rx, S32& by, ColorI& outlineColor, ColorI& nutColor, const S32& cy, const S32& cx);
  72. void onPreRender();
  73. void onRender(Point2I offset, const RectI &updateRect);
  74. void addNewControl(GuiControl *ctrl);
  75. bool selectionContains(GuiControl *ctrl);
  76. void setCurrentAddSet(GuiControl *ctrl, bool clearSelection = true);
  77. const GuiControl* getCurrentAddSet() const;
  78. void setSelection(GuiControl *ctrl);
  79. // Undo Access
  80. void undo();
  81. void redo();
  82. UndoManager& getUndoManager() { return mUndoManager; }
  83. // When a control is changed by the inspector
  84. void controlInspectPreApply(GuiControl* object);
  85. void controlInspectPostApply(GuiControl* object);
  86. // Sizing Cursors
  87. bool initCursors();
  88. void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  89. const Vector<GuiControl *> *getSelected() const { return &mSelectedControls; }
  90. SimSet& getSelectedSet() { updateSelectedSet(); return mSelectedSet; }
  91. const SimGroup& getTrash() { return mTrash; }
  92. const GuiControl* getAddSet() const { return mCurrentAddSet; };
  93. bool onKeyDown(const GuiEvent &event);
  94. void onTouchDown(const GuiEvent &event);
  95. void onTouchUp(const GuiEvent &event);
  96. void onTouchDragged(const GuiEvent &event);
  97. void onRightMouseDown(const GuiEvent &event);
  98. virtual bool onAdd();
  99. virtual void onRemove();
  100. enum Justification {
  101. JUSTIFY_LEFT,
  102. JUSTIFY_CENTER,
  103. JUSTIFY_RIGHT,
  104. JUSTIFY_TOP,
  105. JUSTIFY_BOTTOM,
  106. SPACING_VERTICAL,
  107. SPACING_HORIZONTAL
  108. };
  109. void justifySelection( Justification j);
  110. void moveSelection(const Point2I &delta);
  111. void moveAndSnapSelection(const Point2I &delta);
  112. void saveSelection(const char *filename);
  113. void loadSelection(const char *filename);
  114. void addSelection(S32 id);
  115. void removeSelection(S32 id);
  116. void deleteSelection();
  117. void clearSelection();
  118. void selectAll();
  119. void bringToFront();
  120. void pushToBack();
  121. void setSnapToGrid(U32 gridsize);
  122. bool hasSnapToGrid() { return mUseGridSnap; }
  123. S32 getGridSize() { return mGridSnap.x; }
  124. void moveSelectionToCtrl(GuiControl*);
  125. ColorI getEditorColor() { return mProfile->getFillColor(DisabledState); }
  126. //Editor Mouse Locking
  127. bool editIsMouseLocked(GuiControl* ctrl) { return ctrl == mMouseLockedEditCtrl; }
  128. void editMouseLock(GuiControl* ctrl) { mMouseLockedEditCtrl = ctrl; }
  129. void editMouseUnlock() { mMouseLockedEditCtrl = nullptr; }
  130. };
  131. #endif //_GUI_EDIT_CTRL_H