BsManagedEditorCommand.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "BsScriptObject.h"
  6. #include "UndoRedo/BsEditorCommand.h"
  7. namespace bs
  8. {
  9. class CmdManaged;
  10. /** @addtogroup ScriptInteropEditor
  11. * @{
  12. */
  13. /** Interop class between C++ & CLR for CmdManaged. */
  14. class BS_SCR_BED_EXPORT ScriptCmdManaged : public ScriptObject <ScriptCmdManaged>
  15. {
  16. public:
  17. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "UndoableCommand")
  18. ~ScriptCmdManaged();
  19. /** Returns the internal command wrapped by this object. */
  20. SPtr<CmdManaged> getInternal() const { return mManagedCommand; }
  21. private:
  22. friend class CmdManaged;
  23. ScriptCmdManaged(MonoObject* instance);
  24. /** Triggers the Commit() method on the managed object instance. */
  25. void triggerCommit();
  26. /** Triggers the Revert() method on the managed object instance. */
  27. void triggerRevert();
  28. /** Notifies the script instance that the underlying managed command was destroyed. */
  29. void notifyCommandDestroyed();
  30. SPtr<CmdManaged> mManagedCommand;
  31. /************************************************************************/
  32. /* CLR HOOKS */
  33. /************************************************************************/
  34. static void internal_CreateInstance(MonoObject* instance);
  35. static MonoMethod* sCommitMethod;
  36. static MonoMethod* sRevertMethod;
  37. };
  38. /** @} */
  39. /** @addtogroup SBansheeEditor
  40. * @{
  41. */
  42. /**
  43. * A command used for undo/redo purposes. This particular implementation provides a generic overridable base to be
  44. * implemented by script classes.
  45. */
  46. class BS_SCR_BED_EXPORT CmdManaged : public EditorCommand
  47. {
  48. public:
  49. ~CmdManaged();
  50. /** @copydoc EditorCommand::commit */
  51. void commit() override;
  52. /** @copydoc EditorCommand::revert */
  53. void revert() override;
  54. private:
  55. friend class UndoRedo;
  56. friend class ScriptCmdManaged;
  57. CmdManaged(ScriptCmdManaged* scriptObj);
  58. /** @copydoc EditorCommand::commit */
  59. void onCommandAdded() override;
  60. /** @copydoc EditorCommand::commit */
  61. void onCommandRemoved() override;
  62. /**
  63. * Notifies the command the managed script object instance it is referencing has been destroyed. Normally when this
  64. * happens the command should already be outside of the undo/redo stack, but we clear the instance just in case.
  65. */
  66. void notifyScriptInstanceDestroyed();
  67. ScriptCmdManaged* mScriptObj;
  68. uint32_t mGCHandle;
  69. UINT32 mRefCount;
  70. };
  71. /** @} */
  72. }