DragDrop.cs 5.6 KB

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