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