BsScriptHandleManager.h 4.8 KB

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