//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
using bs;
namespace bs.Editor
{
/** @addtogroup GUI-Editor
* @{
*/
///
/// Editor GUI element that displays a slider with floating point input field and an optional label.
///
public sealed class GUISliderField : GUIElement
{
public delegate void OnChangedDelegate(float newValue);
///
/// Triggered when the value in the field changes.
///
public event OnChangedDelegate OnChanged;
///
/// Value displayed by the field input box.
///
public float Value
{
get { return Internal_GetValue(mCachedPtr); }
set { Internal_SetValue(mCachedPtr, value); }
}
///
/// A step value that determines the minimal increment the slider can be increased or decreased by.
///
/// Step value in percent if range is not defined, otherwise in same units as the range.
public float Step
{
get { return Internal_GetStep(mCachedPtr); }
set { Internal_SetStep(mCachedPtr, value); }
}
///
/// Creates a new slider field element with a label.
///
/// Minimum boundary of the range to clamp values to.
/// Maximum boundary of the range to clamp values to.
/// 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 GUISliderField(float min, float max, GUIContent title, int titleWidth = 100,
string style = "", params GUIOption[] options)
{
Internal_CreateInstance(this, min, max, ref title, titleWidth, style, options, true);
}
///
/// Creates a new slider field element without a label.
///
/// Minimum boundary of the range to clamp values to.
/// Maximum boundary of the range to clamp values to.
/// 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 GUISliderField(float min, float max, string style = "", params GUIOption[] options)
{
GUIContent emptyContent = new GUIContent();
Internal_CreateInstance(this, min, max, ref emptyContent, 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.
///
public bool HasInputFocus
{
get
{
bool value;
Internal_HasInputFocus(mCachedPtr, out value);
return value;
}
}
///
/// Colors the element with a specific tint.
///
/// Tint to apply to the element.
public void SetTint(Color color)
{
Internal_SetTint(mCachedPtr, ref color);
}
///
/// 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(float min, float max)
{
Internal_SetRange(mCachedPtr, min, max);
}
///
/// Triggered by the runtime when the value of the float field changes.
///
/// New value of the float field.
private void DoOnChanged(float newValue)
{
if (OnChanged != null)
OnChanged(newValue);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(GUISliderField instance, float min, float max,
ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetValue(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetStep(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_SetValue(IntPtr nativeInstance, float value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_HasInputFocus(IntPtr nativeInstance, out bool focus);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetRange(IntPtr nativeInstance, float min, float max);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetStep(IntPtr nativeInstance, float step);
}
/** @} */
}