BsScriptDragDropManager.h 5.9 KB

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