//********************************** 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 Window * @{ */ /// /// Base class for all editor windows. Editor window can be docked on the main editor window or float as a separate /// window. User is allowed to reposition and resize the window as he wishes. Editor window GUI is fully customizable. /// public class EditorWindow : ScriptObject { #pragma warning disable 649 // Value assigned by the runtime private UndoRedo undoRedo; #pragma warning restore 649 /// /// Width of the window in pixels. /// public int Width { get { return Internal_GetWidth(mCachedPtr); } } /// /// Height of the window in pixels. /// public int Height { get { return Internal_GetHeight(mCachedPtr); } } /// /// Screen space bounds of the window. /// public Rect2I Bounds { get { Rect2I bounds; Internal_GetBounds(mCachedPtr, out bounds); return bounds; } } /// /// Determines whether the editor window currently has keyboard focus (has been clicked on most recently). Window /// that isn't active (is not the active tab) cannot be put into focus without activating it first. /// public bool HasFocus { get { return Internal_HasFocus(mCachedPtr); } set { Internal_SetFocus(mCachedPtr, value); } } /// /// Returns the local undo/redo stack specific to this editor window. Only windows marked with [UndoRedoLocal] /// attribute will return a non-null value. /// public UndoRedo UndoRedo { get { return undoRedo; } } /// /// Determines is the mouse pointer currently hovering over the editor window. /// public bool IsPointerHovering { get { return Internal_IsPointerHovering(mCachedPtr); } } /// /// Checks if the window's tab is currently active. If the window is floating or not sharing space with any other /// windows (just a single tab), it is always considered active. /// public bool Active { set { Internal_SetActive(mCachedPtr, value); } get { return Internal_IsActive(mCachedPtr); } } /// /// GUI panel that you may use for adding GUI elements to the window. /// public GUIPanel GUI; /// /// Returns a list of all currently open editor windows. /// public static EditorWindow[] AllWindows { get { return Internal_GetAllWindows(); } } /// /// Opens an editor window. If window is already open it returns the existing instance. /// /// Type of window to open. /// Instance of the open window. public static T OpenWindow() where T : EditorWindow { return (T)Internal_CreateOrGetInstance(typeof(T).Namespace, typeof(T).Name); } /// /// Retrieves instance of an open window. /// /// Type of window to retrieve the instance of. /// Instance of the winodow if it is open, null otherwise. public static T GetWindow() where T : EditorWindow { return (T)Internal_GetInstance(typeof(T).Namespace, typeof(T).Name); } /// /// Converts coordinates in screen space to coordinates relative to the window. /// /// Coordinates in screen space. /// Coordinates relative to the window. public Vector2I ScreenToWindowPos(Vector2I screenPos) { Vector2I windowPos; Internal_ScreenToWindowPos(mCachedPtr, ref screenPos, out windowPos); return windowPos; } /// /// Converts coordinates relative to the window to screen space to coordinates. /// /// Coordinates relative to the window. /// Coordinates in screen space. public Vector2I WindowToScreenPos(Vector2I windowPos) { Vector2I screenPos; Internal_WindowToScreenPos(mCachedPtr, ref windowPos, out screenPos); return screenPos; } /// /// Triggered whenever the window size ranges. /// /// New width of the window in pixels. /// New height of the window in pixels. protected virtual void WindowResized(int width, int height) { } /// /// Triggered whenever the window gains or loses focus. /// /// True if focus was gained, false otherwise. protected virtual void FocusChanged(bool inFocus) { } /// /// Name of the window to display in the title bar. /// /// Name of the window to display in the title bar. protected virtual LocString GetDisplayName() { return GetType().Name; } [MethodImpl(MethodImplOptions.InternalCall)] private static extern EditorWindow Internal_CreateOrGetInstance(string ns, string typeName); [MethodImpl(MethodImplOptions.InternalCall)] private static extern EditorWindow Internal_GetInstance(string ns, string typeName); [MethodImpl(MethodImplOptions.InternalCall)] private static extern EditorWindow[] Internal_GetAllWindows(); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetWidth(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern int Internal_GetHeight(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_HasFocus(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetFocus(IntPtr nativeInstance, bool focus); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_SetActive(IntPtr nativeInstance, bool active); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_IsActive(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_IsPointerHovering(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetBounds(IntPtr nativeInstance, out Rect2I bounds); [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); } /** @} */ }