guiEditCtrl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. Point2I mDragBeginPoint;
  36. Vector<Point2I> mDragBeginPoints;
  37. // Undo
  38. UndoManager mUndoManager;
  39. SimGroup mTrash;
  40. SimSet mSelectedSet;
  41. // Sizing Cursors
  42. GuiCursor* mDefaultCursor;
  43. GuiCursor* mLeftRightCursor;
  44. GuiCursor* mUpDownCursor;
  45. GuiCursor* mNWSECursor;
  46. GuiCursor* mNESWCursor;
  47. GuiCursor* mMoveCursor;
  48. enum mouseModes { Selecting, MovingSelection, SizingSelection, DragSelecting };
  49. enum sizingModes { sizingNone = 0, sizingLeft = 1, sizingRight = 2, sizingTop = 4, sizingBottom = 8 };
  50. mouseModes mMouseDownMode;
  51. sizingModes mSizingMode;
  52. // private methods
  53. void updateSelectedSet();
  54. public:
  55. GuiEditCtrl();
  56. DECLARE_CONOBJECT(GuiEditCtrl);
  57. bool onWake();
  58. void onSleep();
  59. void select(GuiControl *ctrl);
  60. void setRoot(GuiControl *ctrl);
  61. void setEditMode(bool value);
  62. S32 getSizingHitKnobs(const Point2I &pt, const RectI &box);
  63. void getDragRect(RectI &b);
  64. void drawNut(const Point2I &nut, ColorI &outlineColor, ColorI &nutColor);
  65. void drawNuts(RectI &box, ColorI &outlineColor, ColorI &nutColor);
  66. void onPreRender();
  67. void onRender(Point2I offset, const RectI &updateRect);
  68. void addNewControl(GuiControl *ctrl);
  69. bool selectionContains(GuiControl *ctrl);
  70. void setCurrentAddSet(GuiControl *ctrl, bool clearSelection = true);
  71. const GuiControl* getCurrentAddSet() const;
  72. void setSelection(GuiControl *ctrl, bool inclusive = false);
  73. // Undo Access
  74. void undo();
  75. void redo();
  76. UndoManager& getUndoManager() { return mUndoManager; }
  77. // When a control is changed by the inspector
  78. void controlInspectPreApply(GuiControl* object);
  79. void controlInspectPostApply(GuiControl* object);
  80. // Sizing Cursors
  81. bool initCursors();
  82. void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  83. const Vector<GuiControl *> *getSelected() const { return &mSelectedControls; }
  84. const SimSet& getSelectedSet() { updateSelectedSet(); return mSelectedSet; }
  85. const SimGroup& getTrash() { return mTrash; }
  86. const GuiControl *getAddSet() const { return mCurrentAddSet; }; //JDD
  87. bool onKeyDown(const GuiEvent &event);
  88. void onTouchDown(const GuiEvent &event);
  89. void onTouchUp(const GuiEvent &event);
  90. void onTouchDragged(const GuiEvent &event);
  91. void onRightMouseDown(const GuiEvent &event);
  92. virtual bool onAdd();
  93. virtual void onRemove();
  94. enum Justification {
  95. JUSTIFY_LEFT,
  96. JUSTIFY_CENTER,
  97. JUSTIFY_RIGHT,
  98. JUSTIFY_TOP,
  99. JUSTIFY_BOTTOM,
  100. SPACING_VERTICAL,
  101. SPACING_HORIZONTAL
  102. };
  103. void justifySelection( Justification j);
  104. void moveSelection(const Point2I &delta);
  105. void moveAndSnapSelection(const Point2I &delta);
  106. void saveSelection(const char *filename);
  107. void loadSelection(const char *filename);
  108. void addSelection(S32 id);
  109. void removeSelection(S32 id);
  110. void deleteSelection();
  111. void clearSelection();
  112. void selectAll();
  113. void bringToFront();
  114. void pushToBack();
  115. void setSnapToGrid(U32 gridsize);
  116. void moveSelectionToCtrl(GuiControl*);
  117. };
  118. #endif //_GUI_EDIT_CTRL_H