BsScriptHandleManager.h 4.5 KB

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