using System; using System.Runtime.CompilerServices; using BansheeEngine; namespace BansheeEditor { /// /// Editor GUI element that displays a integer input field and an optional label. /// public sealed class GUIIntField : GUIElement { public delegate void OnChangedDelegate(int newValue); /// /// Triggered when the value in the field changes. /// public event OnChangedDelegate OnChanged; /// /// Value displayed by the field input box. /// public int Value { get { int value; Internal_GetValue(mCachedPtr, out value); return value; } set { Internal_SetValue(mCachedPtr, value); } } /// /// Creates a new integer field element with a label. /// /// Content to display on the label. /// Width of the title label in pixels. /// 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 GUIIntField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, title, titleWidth, style, options, true); } /// /// Creates a new integer field element without a label. /// /// 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 GUIIntField(string style = "", params GUIOption[] options) { Internal_CreateInstance(this, null, 0, style, options, false); } /// /// Checks does the element currently has input focus. Input focus means the element has an input caret displayed /// and will accept input from the keyboard. /// /// True if the element has input focus. public bool HasInputFocus() { bool value; Internal_HasInputFocus(mCachedPtr, out value); return value; } /// /// Sets a range that will input field values will be clamped to. Set to large negative/positive values if clamping /// is not required. /// /// Minimum boundary of the range to clamp values to. /// Maximum boundary of the range to clamp values to. public void SetRange(int min, int max) { Internal_SetRange(mCachedPtr, min, max); } /// /// Colors the element with a specific tint. /// /// Tint to apply to the element. public void SetTint(Color color) { Internal_SetTint(mCachedPtr, color); } /// /// Triggered by the runtime when the value of the float field changes. /// /// New value of the float field. private void DoOnChanged(int newValue) { if (OnChanged != null) OnChanged(newValue); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUIIntField instance, GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetValue(IntPtr nativeInstance, out int value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetValue(IntPtr nativeInstance, int value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_HasInputFocus(IntPtr nativeInstance, out bool value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetRange(IntPtr nativeInstance, int min, int max); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, Color color); } }