DragDrop.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using bs;
  6. namespace bs.Editor
  7. {
  8. /** @addtogroup Utility-Editor
  9. * @{
  10. */
  11. /// <summary>
  12. /// Manages all drag and drop events within the engine. This doesn't include external OS drag and drop events.
  13. /// </summary>
  14. public static class DragDrop
  15. {
  16. /// <summary>
  17. /// Checks is a drag and drop operation in progress this frame.
  18. /// </summary>
  19. public static bool DragInProgress { get { return Internal_IsDragInProgress(); } }
  20. /// <summary>
  21. /// Checks has a drag and drop operation finished this frame.
  22. /// </summary>
  23. public static bool DropInProgress { get { return Internal_IsDropInProgress(); } }
  24. /// <summary>
  25. /// Data being currently dragged or dropped. Drag and drop must be currently in progress or have finished this
  26. /// frame for this data to be valid.
  27. /// </summary>
  28. public static DragDropData Data { get { return Internal_GetData(); } }
  29. /// <summary>
  30. /// Type of data being currently dragged or dropped.
  31. /// </summary>
  32. public static DragDropType Type { get { return Internal_GetDragType();} }
  33. /// <summary>
  34. /// Starts a new drag and drop operations. Drag and drop operation ends automatically when the mouse button is
  35. /// released.
  36. /// </summary>
  37. /// <param name="data">Data to drag around. This will be passed to the element that accepts the drop operation.</param>
  38. public static void StartDrag(DragDropData data)
  39. {
  40. if (data is SceneObjectDragDropData)
  41. Internal_StartSceneObjectDrag(data.GetCachedPtr());
  42. else if (data is ResourceDragDropData)
  43. Internal_StartResourceDrag(data.GetCachedPtr());
  44. }
  45. [MethodImpl(MethodImplOptions.InternalCall)]
  46. private static extern bool Internal_IsDragInProgress();
  47. [MethodImpl(MethodImplOptions.InternalCall)]
  48. private static extern bool Internal_IsDropInProgress();
  49. [MethodImpl(MethodImplOptions.InternalCall)]
  50. private static extern DragDropData Internal_GetData();
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern DragDropType Internal_GetDragType();
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern void Internal_StartSceneObjectDrag(IntPtr instance);
  55. [MethodImpl(MethodImplOptions.InternalCall)]
  56. private static extern void Internal_StartResourceDrag(IntPtr instance);
  57. }
  58. /// <summary>
  59. /// Contains data about a drag and drop operation.
  60. /// </summary>
  61. public class DragDropData : ScriptObject
  62. {
  63. internal DragDropType type;
  64. /// <summary>
  65. /// Determines what kind of drag and drop operation this data belongs to.
  66. /// </summary>
  67. public DragDropType Type { get { return type; } }
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern void Internal_CreateInstance(DragDropData instance);
  70. }
  71. /// <summary>
  72. /// Drag and drop data containing one or multiple scene objects.
  73. /// </summary>
  74. public class SceneObjectDragDropData : DragDropData
  75. {
  76. /// <summary>
  77. /// Scene objects that are being dragged.
  78. /// </summary>
  79. public SceneObject[] Objects { get { return Internal_GetObjects(mCachedPtr); } }
  80. /// <summary>
  81. /// Creates a new scene drag and drop data.
  82. /// </summary>
  83. /// <param name="objects">A set of scene objects to drag.</param>
  84. public SceneObjectDragDropData(SceneObject[] objects)
  85. {
  86. this.type = DragDropType.SceneObject;
  87. Internal_CreateInstance(this, objects);
  88. }
  89. [MethodImpl(MethodImplOptions.InternalCall)]
  90. private static extern void Internal_CreateInstance(SceneObjectDragDropData instance, SceneObject[] objects);
  91. [MethodImpl(MethodImplOptions.InternalCall)]
  92. private static extern SceneObject[] Internal_GetObjects(IntPtr thisPtr);
  93. }
  94. /// <summary>
  95. /// Drag and drop data containing one or multiple resource paths.
  96. /// </summary>
  97. public class ResourceDragDropData : DragDropData
  98. {
  99. /// <summary>
  100. /// Absolute resource paths that are being dragged.
  101. /// </summary>
  102. public string[] Paths { get { return Internal_GetPaths(mCachedPtr); } }
  103. /// <summary>
  104. /// Creates a new resource drag and drop data.
  105. /// </summary>
  106. /// <param name="paths">A set of absolute resource paths to drag.</param>
  107. public ResourceDragDropData(string[] paths)
  108. {
  109. this.type = DragDropType.Resource;
  110. Internal_CreateInstance(this, paths);
  111. }
  112. [MethodImpl(MethodImplOptions.InternalCall)]
  113. private static extern void Internal_CreateInstance(ResourceDragDropData instance, string[] paths);
  114. [MethodImpl(MethodImplOptions.InternalCall)]
  115. private static extern string[] Internal_GetPaths(IntPtr thisPtr);
  116. }
  117. /// <summary>
  118. /// Types of available drag and drop operations.
  119. /// </summary>
  120. public enum DragDropType // Note: Must match C++ enum ScriptDragDropType
  121. {
  122. Resource,
  123. SceneObject,
  124. None
  125. }
  126. /** @} */
  127. }