using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace BansheeEngine
{
///
/// Base class for all GUI elements. Every GUI element can at least be positioned in it's parent layout/panel and be
/// hidden/visible, focused/unfocused and assigned a context menu.
///
public abstract class GUIElement : ScriptObject
{
///
/// Triggered when a GUI element receives or loses keyboard focus.
///
public Action OnFocusChanged;
///
/// Gets or sets non-clipped bounds of the GUI element. Relative to a parent GUI panel.
///
public Rect2I Bounds
{
get { return Internal_GetBounds(mCachedPtr); }
set { Internal_SetBounds(mCachedPtr, value); }
}
///
/// Gets or sets non-clipped bounds of the GUI element including the margins. Relative to a parent GUI panel.
///
public Rect2I VisualBounds
{
get { return Internal_GetVisualBounds(mCachedPtr); }
}
///
/// Makes the element hidden or visible.
///
public bool Visible
{
set { Internal_SetVisible(mCachedPtr, value); }
}
///
/// Assigns or removes keyboard focus on this element.
///
public bool Focus
{
set { Internal_SetFocus(mCachedPtr, value); }
}
///
/// Destroys this element and all its children. Removes the element from parent layout/panel.
///
///
/// Calling methods on a destroyed element is a no-operation. Destroyed elements aren't allowed to be assigned as
/// children of other elements, or be parents of other elements.
///
public virtual void Destroy()
{
Internal_Destroy(mCachedPtr);
}
///
/// Sets element position relative to parent GUI panel.
///
/// X position of the element in pixels, relative to parent GUI panel.
/// Y position of the element in pixels, relative to parent GUI panel.
///
/// Be aware that this value will be ignored if GUI element is part of a layout because the layout controls placement
/// of child elements.
///
public void SetPosition(int x, int y)
{
Internal_SetPosition(mCachedPtr, x, y);
}
///
/// Sets a fixed element width.
///
/// Width in pixels.
public void SetWidth(int width)
{
Internal_SetWidth(mCachedPtr, width);
}
///
/// Sets a flexible element width. Element will be resized according to its contents and parent layout but will always
/// stay within the provided range.
///
/// Minimum width in pixels. Element will never be smaller than this width.
///
/// Maximum width in pixels. Element will never be larger than this width. Specify zero for
/// unlimited width.
///
public void SetFlexibleWidth(int minWidth, int maxWidth)
{
Internal_SetFlexibleWidth(mCachedPtr, minWidth, maxWidth);
}
///
/// Sets a fixed element height.
///
/// Height in pixels.
public void SetHeight(int height)
{
Internal_SetHeight(mCachedPtr, height);
}
///
/// Sets a flexible element height. Element will be resized according to its contents and parent layout but will
/// always stay within the provided range.
///
/// Minimum height in pixels. Element will never be smaller than this height.
///
/// Maximum height in pixels. Element will never be larger than this height. Specify zero for
/// unlimited height.
///
public void SetFlexibleHeight(int minHeight, int maxHeight)
{
Internal_SetFlexibleHeight(mCachedPtr, minHeight, maxHeight);
}
///
/// Resets element bounds to their initial values dictated by the element's style.
///
public void ResetDimensions()
{
Internal_ResetDimensions(mCachedPtr);
}
///
/// Assigns a new context menu that will be opened when the element is right clicked.
///
/// Object containing context menu contents. Can be null if no menu is wanted.
public void SetContextMenu(ContextMenu menu)
{
IntPtr menuPtr = IntPtr.Zero;
if (menu != null)
menuPtr = menu.GetCachedPtr();
Internal_SetContextMenu(mCachedPtr, menuPtr);
}
///
/// Triggered by the native interop object when the keyboard focus of this element changes.
///
private void InternalOnFocusChanged(bool focus)
{
if (OnFocusChanged != null)
OnFocusChanged(focus);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetFocus(IntPtr nativeInstance, bool focus);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetPosition(IntPtr nativeInstance, int x, int y);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetWidth(IntPtr nativeInstance, int width);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetFlexibleWidth(IntPtr nativeInstance, int minWidth, int maxWidth);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetHeight(IntPtr nativeInstance, int height);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetFlexibleHeight(IntPtr nativeInstance, int minHeight, int maxHeight);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_ResetDimensions(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Rect2I Internal_GetBounds(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetBounds(IntPtr nativeInstance, Rect2I value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern Rect2I Internal_GetVisualBounds(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetContextMenu(IntPtr nativeInstance, IntPtr contextMenu);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Destroy(IntPtr nativeInstance);
}
}