using System; using System.Runtime.CompilerServices; using BansheeEngine; namespace BansheeEditor { /// /// Editor GUI element that displays a color and an optional label. Allows the user to select a color using the color /// picker. /// public sealed class GUIColorField : GUIElement { public delegate void OnChangedDelegate(Color newValue); /// /// Triggered when the color in the field changes. /// public event OnChangedDelegate OnChanged; /// /// Color displayed by the field. /// public Color Value { get { Color value; Internal_GetValue(mCachedPtr, out value); return value; } set { Internal_SetValue(mCachedPtr, value); } } /// /// Creates a new color 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 GUIColorField(GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, title, titleWidth, style, options, true); } /// /// Creates a new color 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 GUIColorField(string style = "", params GUIOption[] options) { Internal_CreateInstance(this, null, 0, style, options, false); } /// /// 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 color field changes. /// /// New value of the color field. private void DoOnChanged(Color newValue) { if (OnChanged != null) OnChanged(newValue); } /// /// Triggered by the runtime when the user clicks on the color field. /// private void DoOnClicked() { // TODO } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(GUIColorField instance, GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetValue(IntPtr nativeInstance, out Color value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetValue(IntPtr nativeInstance, Color value); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetTint(IntPtr nativeInstance, Color color); } }