BsScriptHandleManager.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "BsHandleManager.h"
  6. #include <mono/jit/jit.h>
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup SBansheeEditor
  10. * @{
  11. */
  12. /**
  13. * Renders, updates and manipulates handles declared in managed code. Managed code handles have a [CustomHandle]
  14. * attribute and must implement BansheeEditor.Handle.
  15. */
  16. class BS_SCR_BED_EXPORT ScriptHandleManager : public HandleManager
  17. {
  18. /** Contains data about a manage type that draws and handles interaction with a custom handle. */
  19. struct CustomHandleData
  20. {
  21. MonoClass* handleType;
  22. MonoClass* componentType;
  23. MonoMethod* ctor;
  24. };
  25. /**
  26. * Data about an active instance of a managed custom handle object. Active handle means its scene object is
  27. * currently selected and the handle is displayed and can be interacted with.
  28. */
  29. struct ActiveCustomHandleData
  30. {
  31. MonoObject* object;
  32. uint32_t gcHandle;
  33. };
  34. /**
  35. * Data about all active managed custom handle objects for a specific scene object. Active handle means its
  36. * scene object is currently selected and the handle is displayed and can be interacted with.
  37. */
  38. struct ActiveCustomHandles
  39. {
  40. HSceneObject selectedObject;
  41. Vector<ActiveCustomHandleData> handles;
  42. };
  43. public:
  44. ScriptHandleManager(ScriptAssemblyManager& scriptObjectManager);
  45. ~ScriptHandleManager();
  46. protected:
  47. /** @copydoc HandleManager::triggerPreInput */
  48. void triggerPreInput() override;
  49. /** @copydoc HandleManager::triggerPostInput */
  50. void triggerPostInput() override;
  51. /** @copydoc HandleManager::queueDrawCommands */
  52. void queueDrawCommands() override;
  53. /**
  54. * Clears references to all managed types and objects. Must be called before loadAssemblyData() if
  55. * loadAssemblyData() was called previously.
  56. */
  57. void clearAssemblyData();
  58. /**
  59. * Loads internal managed assembly types and finds all custom handle classes. Must be called after construction and
  60. * after assembly reload.
  61. */
  62. void loadAssemblyData();
  63. /**
  64. * Checks is the provided type a valid custom handle class. Custom handles must have a [CustomHandle] attribute and
  65. * must implement BansheeEditor.Handle.
  66. *
  67. * @param[in] type Type to check.
  68. * @param[in] componentType Component type for which the handle should be displayed for. Handle will not
  69. * be displayed unless a component of this type is selected. Only valid if method
  70. * returns true.
  71. * @param[in] ctor Constructor method for the handle type. Only valid if method returns true.
  72. * @return True if the type is a valid custom handle type.
  73. */
  74. bool isValidHandleType(MonoClass* type, MonoClass*& componentType, MonoMethod*& ctor) const;
  75. /**
  76. * Triggers the PreInput method on the provided Handle object. Pre input happens before any handles are selected
  77. * or moved and allows you to position the handles or prepare them in some other way.
  78. */
  79. void callPreInput(MonoObject* instance);
  80. /**
  81. * Triggers the PostInput method on the provided Handle object. Post input happens after we know in what way has the
  82. * user interacted with the handles this frame.
  83. */
  84. void callPostInput(MonoObject* instance);
  85. /**
  86. * Triggers the Draw method on the provided Handle object. Draw allows you to draw the visual representation of the
  87. * handles. Called after PostInput.
  88. */
  89. void callDraw(MonoObject* instance);
  90. /**
  91. * Triggers the Destroy method on the provided Handle object. Destroy is called when the handle is no longer being
  92. * displayed.
  93. */
  94. void callDestroy(MonoObject* instance);
  95. ScriptAssemblyManager& mScriptObjectManager;
  96. HEvent mDomainUnloadConn;
  97. HEvent mDomainLoadConn;
  98. Map<String, CustomHandleData> mHandles;
  99. ActiveCustomHandles mActiveHandleData;
  100. Vector<MonoClass*> mGlobalHandlesToCreate;
  101. Vector<ActiveCustomHandleData> mActiveGlobalHandles;
  102. MonoObject* mDefaultHandleManager = nullptr;
  103. uint32_t mDefaultHandleManagerGCHandle = 0;
  104. MonoClass* mCustomHandleAttribute = nullptr;
  105. MonoField* mTypeField = nullptr;
  106. MonoClass* mHandleBaseClass = nullptr;
  107. MonoClass* mDefaultHandleManagerClass = nullptr;
  108. typedef void(__stdcall *DestroyThunkDef) (MonoObject*, MonoException**);
  109. MonoMethod* mPreInputMethod;
  110. MonoMethod* mPostInputMethod;
  111. MonoMethod* mDrawMethod;
  112. DestroyThunkDef mDestroyThunk;
  113. };
  114. /** @} */
  115. }