| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using System;
- using System.Runtime.CompilerServices;
- namespace BansheeEngine
- {
- /// <summary>
- /// GUI button that can be clicked. Has normal, hover and active states with an optional label.
- /// </summary>
- public sealed class GUIButton : GUIElement
- {
- public delegate void OnClickDelegate();
- public delegate void OnDoubleClickDelegate();
- public delegate void OnHoverDelegate();
- public delegate void OnOutDelegate();
- /// <summary>
- /// Triggered when button is clicked.
- /// </summary>
- public event OnClickDelegate OnClick;
- /// <summary>
- /// Triggered when button is clicked twice in rapid succession.
- /// </summary>
- public event OnDoubleClickDelegate OnDoubleClick;
- /// <summary>
- /// Triggered when pointer hovers over the button.
- /// </summary>
- public event OnHoverDelegate OnHover;
- /// <summary>
- /// Triggered when pointer that was previously hovering leaves the button.
- /// </summary>
- public event OnOutDelegate OnOut;
- /// <summary>
- /// Creates a new button with the specified label.
- /// </summary>
- /// <param name="content">Content to display on the button.
- /// </param>
- /// <param name="style">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 button style is used.
- /// </param>
- /// <param name="options">Options that allow you to control how is the element
- /// positioned and sized. This will override any similar options set by style.
- /// </param>
- public GUIButton(GUIContent content, string style, params GUIOption[] options)
- {
- Internal_CreateInstance(this, content, style, options);
- }
- /// <summary>
- /// Creates a new button with the specified label.
- /// </summary>
- /// <param name="content">Content to display on the button.
- /// </param>
- /// <param name="style">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 button style is used.
- /// </param>
- public GUIButton(GUIContent content, string style)
- {
- Internal_CreateInstance(this, content, style, new GUIOption[0]);
- }
- /// <summary>
- /// Creates a new button with the specified label.
- /// </summary>
- /// <param name="content">Content to display on the button.
- /// </param>
- /// <param name="options">Options that allow you to control how is the element
- /// positioned and sized. This will override any similar options set by style.
- /// </param>
- public GUIButton(GUIContent content, params GUIOption[] options)
- {
- Internal_CreateInstance(this, content, "", options);
- }
- /// <summary>
- /// Creates a new button with the specified label.
- /// </summary>
- /// <param name="content">Content to display on the button.</param>
- public void SetContent(GUIContent content)
- {
- Internal_SetContent(mCachedPtr, content);
- }
- /// <summary>
- /// Colors the element with a specific tint.
- /// </summary>
- /// <param name="color">Tint to apply to the element.</param>
- public void SetTint(Color color)
- {
- Internal_SetTint(mCachedPtr, color);
- }
- /// <summary>
- /// Triggered by the native interop object when a click occurs.
- /// </summary>
- private void DoOnClick()
- {
- if (OnClick != null)
- OnClick();
- }
- /// <summary>
- /// Triggered by the native interop object when a double click occurs.
- /// </summary>
- private void DoOnDoubleClick()
- {
- if (OnDoubleClick != null)
- OnDoubleClick();
- }
- /// <summary>
- /// Triggered by the native interop object when the pointer is hovered over the element.
- /// </summary>
- private void DoOnHover()
- {
- if (OnHover != null)
- OnHover();
- }
- /// <summary>
- /// Triggered by the native interop object when the pointer leaves the element.
- /// </summary>
- private void DoOnOut()
- {
- if (OnOut != null)
- OnOut();
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_CreateInstance(GUIButton instance, GUIContent content, string style, GUIOption[] options);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
- }
- }
|