using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using BansheeEngine;
namespace BansheeEditor
{
///
/// Base class for all drop down window implementations. Drop down windows are temporary windows that open above all
/// other GUI, and close as soon user clicks outside of them.
///
public class DropDownWindow : ScriptObject
{
private int width;
private int height;
///
/// Width of the window in pixels.
///
public int Width
{
get { return width; }
set { Internal_SetWidth(mCachedPtr, value); width = value; }
}
///
/// Height of the window in pixels.
///
public int Height
{
get { return height; }
set { Internal_SetHeight(mCachedPtr, value); height = value; }
}
protected GUIPanel GUI;
///
/// Opens a new drop down window at the specified location.
///
/// Type of the drop down window to open.
/// Parent editor window to open the drop down window in.
/// Position relative to the parent editor window at which to open the drop down window.
///
/// Instance of the opened drop down window.
public static T Open(EditorWindow parent, Vector2I position) where T : DropDownWindow, new()
{
T window = new T();
window.Initialize(parent, position);
return window;
}
///
/// Constructs a new drop down window.
///
/// Width of the window in pixels.
/// Height of the window in pixels.
protected DropDownWindow(int width = 200, int height = 200)
{
this.width = width;
this.height = height;
}
///
/// Initializes the drop down window after construction. Must be called before use.
///
/// Parent editor window to open the drop down window in.
/// Position relative to the parent editor window at which to open the drop down window.
///
private void Initialize(EditorWindow parent, Vector2I position)
{
IntPtr parentPtr = IntPtr.Zero;
if (parent != null)
parentPtr = parent.GetCachedPtr();
Internal_CreateInstance(this, parentPtr, ref position, width, height);
}
///
/// Converts coordinates in screen space to coordinates relative to the drop down window.
///
/// Coordinates in screen space.
/// Coordinates relative to the drop down window.
protected Vector2I ScreenToWindowPos(Vector2I screenPos)
{
Vector2I windowPos;
Internal_ScreenToWindowPos(mCachedPtr, ref screenPos, out windowPos);
return windowPos;
}
///
/// Converts coordinates relative to the drop down window to screen space to coordinates.
///
/// Coordinates relative to the drop down window.
/// Coordinates in screen space.
protected Vector2I WindowToScreenPos(Vector2I windowPos)
{
Vector2I screenPos;
Internal_WindowToScreenPos(mCachedPtr, ref windowPos, out screenPos);
return screenPos;
}
///
/// Closes the drop down window.
///
protected void Close()
{
Internal_Close(mCachedPtr);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(DropDownWindow instance, IntPtr parentWindow, ref Vector2I position, int width, int height);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Close(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetWidth(IntPtr nativeInstance, int value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetHeight(IntPtr nativeInstance, int value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I windowPos);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_WindowToScreenPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I screenPos);
}
}