//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; namespace BansheeEngine { /** @addtogroup GUI_Engine * @{ */ /// /// GUI button that can be clicked. Has normal, hover and active states with an optional label. /// public sealed class GUIButton : GUIElement { public delegate void OnClickDelegate(); public delegate void OnDoubleClickDelegate(); public delegate void OnHoverDelegate(); public delegate void OnOutDelegate(); /// /// Triggered when button is clicked. /// public event OnClickDelegate OnClick; /// /// Triggered when button is clicked twice in rapid succession. /// public event OnDoubleClickDelegate OnDoubleClick; /// /// Triggered when pointer hovers over the button. /// public event OnHoverDelegate OnHover; /// /// Triggered when pointer that was previously hovering leaves the button. /// public event OnOutDelegate OnOut; /// /// Creates a new button with the specified label. /// /// Content to display on the button. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUIButton(GUIContent content, string style, params GUIOption[] options) { Internal_CreateInstance(this, ref content, style, options); } /// /// Creates a new button with the specified label. /// /// Content to display on the button. /// Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used. public GUIButton(GUIContent content, string style) { Internal_CreateInstance(this, ref content, style, new GUIOption[0]); } /// /// Creates a new button with the specified label. /// /// Content to display on the button. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUIButton(GUIContent content, params GUIOption[] options) { Internal_CreateInstance(this, ref content, "", options); } /// /// Updates the contents displayed on the button. /// /// Content to display on the button. public void SetContent(GUIContent content) { Internal_SetContent(mCachedPtr, ref content); } /// /// Colors the element with a specific tint. /// /// Tint to apply to the element. public void SetTint(Color color) { Internal_SetTint(mCachedPtr, ref color); } /// /// Triggered by the native interop object when a click occurs. /// private void DoOnClick() { if (OnClick != null) OnClick(); } /// /// Triggered by the native interop object when a double click occurs. /// private void DoOnDoubleClick() { if (OnDoubleClick != null) OnDoubleClick(); } /// /// Triggered by the native interop object when the pointer is hovered over the element. /// private void DoOnHover() { if (OnHover != null) OnHover(); } /// /// Triggered by the native interop object when the pointer leaves the element. /// private void DoOnOut() { if (OnOut != null) OnOut(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUIButton instance, ref GUIContent content, string style, GUIOption[] options); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetContent(IntPtr nativeInstance, ref GUIContent content); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color); } /** @} */ }