BsScriptDragDropManager.h 5.7 KB

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