//********************************** 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 element representing a toggle (on/off) button. /// public sealed class GUIToggle : GUIElement { public delegate void OnClickDelegate(); public delegate void OnHoverDelegate(); public delegate void OnOutDelegate(); public delegate void OnToggleDelegate(bool toggled); public delegate void OnDoubleClickDelegate(); public event OnClickDelegate OnClick; public event OnHoverDelegate OnHover; public event OnOutDelegate OnOut; public event OnToggleDelegate OnToggled; public event OnDoubleClickDelegate OnDoubleClick; /// /// On/off state of the button. /// public bool Value { get { return Internal_GetValue(mCachedPtr); } set { Internal_SetValue(mCachedPtr, value); } } /// /// Creates a new toggle button with the specified label. /// /// Content to display on the button. /// Optional toggle group that is used for grouping multiple toggle buttons /// together. /// 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 GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, string style, params GUIOption[] options) { Internal_CreateInstance(this, content, toggleGroup, style, options); } /// /// Creates a new toggle 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 GUIToggle(GUIContent content, string style, params GUIOption[] options) { Internal_CreateInstance(this, content, null, style, options); } /// /// Creates a new toggle 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 GUIToggle(GUIContent content, string style) { Internal_CreateInstance(this, content, null, style, new GUIOption[0]); } /// /// Creates a new toggle 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 GUIToggle(GUIContent content, params GUIOption[] options) { Internal_CreateInstance(this, content, null, "", options); } /// /// Creates a new toggle button with the specified label. /// /// Content to display on the button. /// Optional toggle group that is used for grouping multiple toggle buttons /// together. /// 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 GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, string style) { Internal_CreateInstance(this, content, toggleGroup, style, new GUIOption[0]); } /// /// Creates a new toggle button with the specified label. /// /// Content to display on the button. /// Optional toggle group that is used for grouping multiple toggle buttons /// together. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUIToggle(GUIContent content, GUIToggleGroup toggleGroup, params GUIOption[] options) { Internal_CreateInstance(this, content, toggleGroup, "", options); } /// /// Updates the contents displayed on the button. /// /// Content to display on the button. public void SetContent(GUIContent content) { Internal_SetContent(mCachedPtr, 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 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(); } /// /// Triggered by the native interop object when the button is toggle on or off. /// /// New state of the element. private void DoOnToggled(bool toggled) { if (OnToggled != null) OnToggled(toggled); } /// /// Triggered by the native interop object when a double click occurs. /// private void DoOnDoubleClick() { if (OnDoubleClick != null) OnDoubleClick(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUIToggle instance, GUIContent content, GUIToggleGroup toggleGroup, string style, GUIOption[] options); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content); [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool Internal_GetValue(IntPtr nativeInstance); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetValue(IntPtr nativeInstance, bool value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color); } /** @} */ }