//********************************** 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
* @{
*/
///
/// Drop targets allow you to register a certain portion of a window as a drop target that accepts file drops from the
/// OS (platform) specific drag and drop system. You will receive events with the specified drop area as long as it is
/// active.
///
public class OSDropTarget : ScriptObject
{
///
/// Triggered when the user completes a drop while pointer is over the drop area. Provides window coordinates of
/// the pointer position.
///
public Action OnDrop;
///
/// Triggered when a pointer enters the drop area. Provides window coordinates of the pointer position.
///
public Action OnEnter;
///
/// Triggered when a pointer leaves the drop area.
///
public Action OnLeave;
///
/// Triggered when a pointer is being dragged over the drop area. Provides window coordinates of the pointer
/// position.
///
public Action OnDrag;
///
/// Creates a new OS drop target.
///
/// Window on which the drop target is on.
public OSDropTarget(EditorWindow window)
{
IntPtr nativeWindow = window.GetCachedPtr();;
Internal_CreateInstance(this, nativeWindow);
}
///
/// Destroys the drop target, stopping any further events.
///
public void Destroy()
{
Internal_Destroy(mCachedPtr);
}
///
/// Allows you to set the drop target bounds, relative to the parent window.
///
public Rect2I Bounds
{
set { Internal_SetBounds(mCachedPtr, ref value); }
}
///
/// Returns a list of files received by the drop target. Only valid after a drop has been triggered.
///
public string[] FilePaths
{
get { return Internal_GetFilePaths(mCachedPtr); }
}
///
/// Triggered internally by the runtime when a pointer enters the drop area.
///
/// X coordinate of the pointer position, relative to the parent window.
/// Y coordinate of the pointer position, relative to the parent window.
private void InternalDoOnEnter(int x, int y)
{
if (OnEnter != null)
OnEnter(x, y);
}
///
/// Triggered internally by the runtime when a pointer leaves the drop area.
///
private void InternalDoOnLeave()
{
if (OnLeave != null)
OnLeave();
}
///
/// Triggered internally by the runtime when a pointer is being dragged over the drop area.
///
/// X coordinate of the pointer position, relative to the parent window.
/// Y coordinate of the pointer position, relative to the parent window.
private void InternalDoOnDrag(int x, int y)
{
if (OnDrag != null)
OnDrag(x, y);
}
///
/// Triggered internally by the runtime when the user completes a drop while pointer is over the drop area.
///
/// X coordinate of the pointer position, relative to the parent window.
/// Y coordinate of the pointer position, relative to the parent window.
private void InternalDoOnDrop(int x, int y)
{
if (OnDrop != null)
OnDrop(x, y);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(OSDropTarget instance, IntPtr editorWindow);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Destroy(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetBounds(IntPtr nativeInstance, ref Rect2I bounds);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string[] Internal_GetFilePaths(IntPtr nativeInstance);
}
/** @} */
}