//********************************** 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 that accepts Unicode textual input. It can be single or multi-line and handles various types of text /// manipulation. /// public sealed class GUITextBox : GUIElement { /// /// Triggered whenever input text has changed. /// public event Action OnChanged; /// /// Triggered whenever user confirms input. /// public event Action OnConfirmed; /// /// Creates a new text box element. /// /// Determines should the input box allow text that spans multiple lines. /// 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 GUITextBox(bool multiline, string style, params GUIOption[] options) { Internal_CreateInstance(this, multiline, style, options); } /// /// Creates a new text box element. /// /// Determines should the input box allow text that spans multiple lines. /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextBox(bool multiline, params GUIOption[] options) { Internal_CreateInstance(this, multiline, "", options); } /// /// Creates a new single-line text box element. /// /// 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 GUITextBox(string style, params GUIOption[] options) { Internal_CreateInstance(this, false, style, options); } /// /// Creates a new single-line text box element. /// /// Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style. public GUITextBox(params GUIOption[] options) { Internal_CreateInstance(this, false, "", options); } /// /// Text currently entered in the text box. /// public string Text { get { string value; Internal_GetText(mCachedPtr, out value); return value; } set { Internal_SetText(mCachedPtr, value); } } /// /// 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 the text box value is changed. /// /// New value in the text box. private void Internal_DoOnChanged(string newValue) { if (OnChanged != null) OnChanged(newValue); } /// /// Triggered by the native interop object when the user confirms the input. /// private void Internal_DoOnConfirmed() { if (OnConfirmed != null) OnConfirmed(); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUITextBox instance, bool multiline, string style, GUIOption[] options); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetText(IntPtr nativeInstance, string text); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetText(IntPtr nativeInstance, out string text); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color); } /** @} */ }