forestUndo.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 _FOREST_EDITOR_UNDO_H_
  23. #define _FOREST_EDITOR_UNDO_H_
  24. #ifndef _UNDO_H_
  25. #include "util/undo.h"
  26. #endif
  27. #ifndef _FORESTITEM_H_
  28. #include "forest/forestItem.h"
  29. #endif
  30. #ifndef __RESOURCE_H__
  31. #include "core/resource.h"
  32. #endif
  33. class ForestData;
  34. class ForestEditorCtrl;
  35. class ForestUndoAction : public UndoAction
  36. {
  37. typedef UndoAction Parent;
  38. public:
  39. ForestUndoAction( const Resource<ForestData> &data, ForestEditorCtrl *editor, const char *description );
  40. // UndoAction
  41. virtual void undo() {}
  42. virtual void redo() {}
  43. protected:
  44. ForestEditorCtrl *mEditor;
  45. Vector<ForestItem> mItems;
  46. Resource<ForestData> mData;
  47. };
  48. class ForestCreateUndoAction : public ForestUndoAction
  49. {
  50. typedef ForestUndoAction Parent;
  51. public:
  52. ForestCreateUndoAction( const Resource<ForestData> &data,
  53. ForestEditorCtrl *editor );
  54. /// Adds the item to the Forest and stores
  55. /// its info for undo later.
  56. void addItem( ForestItemData *data,
  57. const Point3F &position,
  58. F32 rotation,
  59. F32 scale );
  60. // UndoAction
  61. virtual void undo();
  62. virtual void redo();
  63. };
  64. class ForestDeleteUndoAction : public ForestUndoAction
  65. {
  66. typedef ForestUndoAction Parent;
  67. public:
  68. ForestDeleteUndoAction( const Resource<ForestData> &data,
  69. ForestEditorCtrl *editor );
  70. ///
  71. void removeItem( const ForestItem &item );
  72. void removeItem( const Vector<ForestItem> &itemList );
  73. // UndoAction
  74. virtual void undo();
  75. virtual void redo();
  76. };
  77. class ForestUpdateAction : public ForestUndoAction
  78. {
  79. typedef ForestUndoAction Parent;
  80. public:
  81. ForestUpdateAction( const Resource<ForestData> &data,
  82. ForestEditorCtrl *editor );
  83. void saveItem( const ForestItem &item );
  84. virtual void undo() { _swapState(); }
  85. virtual void redo() { _swapState(); }
  86. protected:
  87. void _swapState();
  88. };
  89. #endif // _FOREST_EDITOR_UNDO_H_