| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- using System;
- using System.Runtime.CompilerServices;
- using bs;
- namespace bs.Editor
- {
- /** @addtogroup Utility-Editor
- * @{
- */
- /// <summary>
- /// Manages all drag and drop events within the engine. This doesn't include external OS drag and drop events.
- /// </summary>
- public static class DragDrop
- {
- /// <summary>
- /// Checks is a drag and drop operation in progress this frame.
- /// </summary>
- public static bool DragInProgress { get { return Internal_IsDragInProgress(); } }
- /// <summary>
- /// Checks has a drag and drop operation finished this frame.
- /// </summary>
- public static bool DropInProgress { get { return Internal_IsDropInProgress(); } }
- /// <summary>
- /// Data being currently dragged or dropped. Drag and drop must be currently in progress or have finished this
- /// frame for this data to be valid.
- /// </summary>
- public static DragDropData Data { get { return Internal_GetData(); } }
- /// <summary>
- /// Type of data being currently dragged or dropped.
- /// </summary>
- public static DragDropType Type { get { return Internal_GetDragType();} }
- /// <summary>
- /// Starts a new drag and drop operations. Drag and drop operation ends automatically when the mouse button is
- /// released.
- /// </summary>
- /// <param name="data">Data to drag around. This will be passed to the element that accepts the drop operation.</param>
- public static void StartDrag(DragDropData data)
- {
- if (data is SceneObjectDragDropData)
- Internal_StartSceneObjectDrag(data.GetCachedPtr());
- else if (data is ResourceDragDropData)
- Internal_StartResourceDrag(data.GetCachedPtr());
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern bool Internal_IsDragInProgress();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern bool Internal_IsDropInProgress();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern DragDropData Internal_GetData();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern DragDropType Internal_GetDragType();
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_StartSceneObjectDrag(IntPtr instance);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_StartResourceDrag(IntPtr instance);
- }
- /// <summary>
- /// Contains data about a drag and drop operation.
- /// </summary>
- public class DragDropData : ScriptObject
- {
- internal DragDropType type;
- /// <summary>
- /// Determines what kind of drag and drop operation this data belongs to.
- /// </summary>
- public DragDropType Type { get { return type; } }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_CreateInstance(DragDropData instance);
- }
- /// <summary>
- /// Drag and drop data containing one or multiple scene objects.
- /// </summary>
- public class SceneObjectDragDropData : DragDropData
- {
- /// <summary>
- /// Scene objects that are being dragged.
- /// </summary>
- public SceneObject[] Objects { get { return Internal_GetObjects(mCachedPtr); } }
- /// <summary>
- /// Creates a new scene drag and drop data.
- /// </summary>
- /// <param name="objects">A set of scene objects to drag.</param>
- public SceneObjectDragDropData(SceneObject[] objects)
- {
- this.type = DragDropType.SceneObject;
- Internal_CreateInstance(this, objects);
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_CreateInstance(SceneObjectDragDropData instance, SceneObject[] objects);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern SceneObject[] Internal_GetObjects(IntPtr thisPtr);
- }
- /// <summary>
- /// Drag and drop data containing one or multiple resource paths.
- /// </summary>
- public class ResourceDragDropData : DragDropData
- {
- /// <summary>
- /// Absolute resource paths that are being dragged.
- /// </summary>
- public string[] Paths { get { return Internal_GetPaths(mCachedPtr); } }
- /// <summary>
- /// Creates a new resource drag and drop data.
- /// </summary>
- /// <param name="paths">A set of absolute resource paths to drag.</param>
- public ResourceDragDropData(string[] paths)
- {
- this.type = DragDropType.Resource;
- Internal_CreateInstance(this, paths);
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_CreateInstance(ResourceDragDropData instance, string[] paths);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern string[] Internal_GetPaths(IntPtr thisPtr);
- }
- /// <summary>
- /// Types of available drag and drop operations.
- /// </summary>
- public enum DragDropType // Note: Must match C++ enum ScriptDragDropType
- {
- Resource,
- SceneObject,
- None
- }
- /** @} */
- }
|