BsScriptDragDropManager.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. #include "BsScriptEditorPrerequisites.h"
  3. #include "BsScriptObject.h"
  4. #include "BsDragAndDropManager.h"
  5. namespace BansheeEngine
  6. {
  7. class ScriptSceneObjectDragDropData;
  8. class ScriptResourceDragDropData;
  9. /**
  10. * @brief Types of drag and drop operations supported
  11. * by the managed drag and drop system.
  12. */
  13. // Note: Must be equal to C# DragDropType enum
  14. enum class ScriptDragDropType
  15. {
  16. Resource,
  17. SceneObject,
  18. None
  19. };
  20. /**
  21. * @brief Interop class between C++ & CLR for DragAndDropManager.
  22. */
  23. class BS_SCR_BED_EXPORT ScriptDragDrop : public ScriptObject<ScriptDragDrop>
  24. {
  25. public:
  26. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "DragDrop");
  27. private:
  28. ScriptDragDrop(MonoObject* instance);
  29. /**
  30. * @brief Triggered when the scene object drag and drop operation ends.
  31. *
  32. * @param processed True if the drop operations was accepted by some system.
  33. */
  34. static void sceneObjectDragDropFinalize(bool processed);
  35. /**
  36. * @brief Triggered when the resource drag and drop operation ends.
  37. *
  38. * @param processed True if the drop operations was accepted by some system.
  39. */
  40. static void resourceDragDropFinalize(bool processed);
  41. /************************************************************************/
  42. /* CLR HOOKS */
  43. /************************************************************************/
  44. static bool internal_IsDragInProgress();
  45. static bool internal_IsDropInProgress();
  46. static MonoObject* internal_GetData();
  47. static ScriptDragDropType internal_GetDragType();
  48. static void internal_StartSceneObjectDrag(ScriptSceneObjectDragDropData* dragData);
  49. static void internal_StartResourceDrag(ScriptResourceDragDropData* dragData);
  50. };
  51. /**
  52. * @brief Interop class between C++ & CLR for SceneObjectDragDropData. Contains
  53. * a set of scene objects used during managed drag and drop operations.
  54. */
  55. class BS_SCR_BED_EXPORT ScriptSceneObjectDragDropData : public ScriptObject<ScriptSceneObjectDragDropData>
  56. {
  57. public:
  58. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "SceneObjectDragDropData");
  59. /**
  60. * @brief Creates a new managed instance of SceneObjectDragDropData containing
  61. * the specified scene objects.
  62. */
  63. static MonoObject* create(const Vector<HSceneObject>& sceneObjects);
  64. /**
  65. * @brief Returns the scene objects referenced by this object.
  66. */
  67. const Vector<HSceneObject>& getSceneObjects() const { return mSceneObjects; }
  68. private:
  69. ScriptSceneObjectDragDropData(MonoObject* instance, const Vector<HSceneObject>& sceneObjects);
  70. Vector<HSceneObject> mSceneObjects;
  71. /************************************************************************/
  72. /* CLR HOOKS */
  73. /************************************************************************/
  74. static void internal_CreateInstance(MonoObject* instance, MonoArray* objects);
  75. static MonoArray* internal_GetObjects(ScriptSceneObjectDragDropData* instance);
  76. };
  77. /**
  78. * @brief Interop class between C++ & CLR for ResourceDragDropData. Contains
  79. * a set of resource paths used during managed drag and drop operations.
  80. */
  81. class BS_SCR_BED_EXPORT ScriptResourceDragDropData : public ScriptObject < ScriptResourceDragDropData >
  82. {
  83. public:
  84. SCRIPT_OBJ(EDITOR_ASSEMBLY, "BansheeEditor", "ResourceDragDropData");
  85. /**
  86. * @brief Creates a new managed instance of ResourceDragDropData containing
  87. * the specified resource paths.
  88. */
  89. static MonoObject* create(const Vector<Path>& paths);
  90. /**
  91. * @brief Returns the resource paths referenced by this object.
  92. */
  93. const Vector<Path>& getPaths() const { return mPaths; }
  94. private:
  95. ScriptResourceDragDropData(MonoObject* instance, const Vector<Path>& paths);
  96. Vector<Path> mPaths;
  97. /************************************************************************/
  98. /* CLR HOOKS */
  99. /************************************************************************/
  100. static void internal_CreateInstance(MonoObject* instance, MonoArray* paths);
  101. static MonoArray* internal_GetPaths(ScriptResourceDragDropData* instance);
  102. };
  103. /**
  104. * @brief Handles managed drag and drop operations. Wraps the existing
  105. * functionality of DragAndDropManager. Essentially converts the
  106. * callback nature of DragAndDropManager into a polling based system.
  107. */
  108. class BS_SCR_BED_EXPORT ScriptDragDropManager : public Module<ScriptDragDropManager>
  109. {
  110. public:
  111. ScriptDragDropManager();
  112. ~ScriptDragDropManager();
  113. /**
  114. * @brief Called every frame. Checks for changes in drag and drop operations.
  115. *
  116. * @note Internal method.
  117. */
  118. void update();
  119. /**
  120. * @brief Checks has the user performed a drop operation this frame.
  121. */
  122. bool isDropInProgress() const { return mIsDropInProgress; }
  123. /**
  124. * @brief Returns the managed representation of currently dragged data (e.g. SceneObjectDragDropData).
  125. * This will be null if drag or drop is not in progress or of unsupported type.
  126. */
  127. MonoObject* getDropData() const;
  128. /**
  129. * @brief Checks the type of the current drag or drop operation.
  130. */
  131. ScriptDragDropType getDragType() const;
  132. private:
  133. /**
  134. * @brief Triggered when a native drag and drop operation ends.
  135. *
  136. * @param evt Pointer data regarding where the drop operation occurred.
  137. * @param callbackInfo Data whether the drop was processed or not.
  138. */
  139. void onMouseDragEnded(const PointerEvent& evt, DragCallbackInfo& callbackInfo);
  140. HEvent mDragEndedConn;
  141. bool mIsDropInProgress;
  142. UINT64 mDroppedFrameIdx;
  143. ScriptDragDropType mDropType;
  144. Vector<Path> mDroppedPaths;
  145. Vector<HSceneObject> mDroppedSceneObjects;
  146. };
  147. }