//********************************** 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
* @{
*/
///
/// A GUI element that represents a horizontal slider with a draggable handle.
///
public sealed class GUISliderH : GUIElement
{
public delegate void OnChangedDelegate(float percent);
///
/// Triggered when the slider handle moves. Provided parameter represents
/// the position of the handle, in percent ranging [0, 1].
///
public event OnChangedDelegate OnChanged;
///
/// Returns the position of the slider handle, in percent ranging [0, 1].
///
public float Percent
{
get { return Internal_GetPercent(mCachedPtr); }
set { Internal_SetPercent(mCachedPtr, value); }
}
///
/// Returns the position of the slider handle, in range determined by . If range is not defined
/// set to [0, 1] this is equivalent of .
///
public float Value
{
get { return Internal_GetValue(mCachedPtr); }
set { Internal_SetValue(mCachedPtr, value); }
}
///
/// Creates a new horizontal slider.
///
/// 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 GUISliderH(string style, params GUIOption[] options)
{
Internal_CreateInstance(this, style, options);
}
///
/// Creates a new vertical slider.
///
/// 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.
public GUISliderH(string style = "")
{
Internal_CreateInstance(this, style, new GUIOption[0]);
}
///
/// 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);
}
///
/// The upper bound of the slider range
///
/// The upper bound of the slider range
public float GetRangeMaximum()
{
return Internal_GetRangeMaximum(mCachedPtr);
}
///
/// The lower bound of the slider range
///
/// The lower bound of the slider range
public float GetRangeMinimum()
{
return Internal_GetRangeMinimum(mCachedPtr);
}
///
/// A step value that determines the minimal increment the slider can be increased or decreased by.
///
public float Step
{
get { return Internal_GetStep(mCachedPtr); }
set { Internal_SetStep(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 slider handle is moved.
///
/// New position of the slider handle, in percent ranging [0, 1].
private void DoOnChanged(float percent)
{
if (OnChanged != null)
OnChanged(percent);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(GUISliderH instance, string style, GUIOption[] options);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetPercent(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetPercent(IntPtr nativeInstance, float percent);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetValue(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetValue(IntPtr nativeInstance, float percent);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetRange(IntPtr nativeInstance, float min, float max);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetRangeMaximum(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetRangeMinimum(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetStep(IntPtr nativeInstance, float step);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetStep(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
}
///
/// A GUI element that represents a vertical slider with a draggable handle.
///
public sealed class GUISliderV : GUIElement
{
public delegate void OnChangedDelegate(float percent);
///
/// Triggered when the slider handle moves. Provided parameter represents
/// the position of the handle, in percent ranging [0, 1].
///
public event OnChangedDelegate OnChanged;
///
/// Returns the position of the slider handle, in percent ranging [0, 1].
///
public float Percent
{
get { return Internal_GetPercent(mCachedPtr); }
set { Internal_SetPercent(mCachedPtr, value); }
}
///
/// Returns the position of the slider handle, in range determined by . If range is not defined
/// set to [0, 1] this is equivalent of .
///
public float Value
{
get { return Internal_GetValue(mCachedPtr); }
set { Internal_SetValue(mCachedPtr, value); }
}
///
/// Creates a new vertical slider.
///
/// 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 GUISliderV(string style, params GUIOption[] options)
{
Internal_CreateInstance(this, style, options);
}
///
/// Creates a new vertical slider.
///
/// 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.
public GUISliderV(string style = "")
{
Internal_CreateInstance(this, style, new GUIOption[0]);
}
///
/// 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);
}
///
/// The upper bound of the slider range
///
/// The upper bound of the slider range
public float GetRangeMaximum()
{
return Internal_GetRangeMaximum(mCachedPtr);
}
///
/// The lower bound of the slider range
///
/// The lower bound of the slider range
public float GetRangeMinimum()
{
return Internal_GetRangeMinimum(mCachedPtr);
}
///
/// A step value that determines the minimal increment the slider can be increased or decreased by.
///
public float Step
{
get { return Internal_GetStep(mCachedPtr); }
set { Internal_SetStep(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 slider handle is moved.
///
/// New position of the slider handle, in percent ranging [0, 1].
private void DoOnChanged(float percent)
{
if (OnChanged != null)
OnChanged(percent);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(GUISliderV instance, string style, GUIOption[] options);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetPercent(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetPercent(IntPtr nativeInstance, float percent);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetValue(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetValue(IntPtr nativeInstance, float percent);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetRange(IntPtr nativeInstance, float min, float max);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetRangeMaximum(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetRangeMinimum(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetStep(IntPtr nativeInstance, float step);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetStep(IntPtr nativeInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetTint(IntPtr nativeInstance, ref Color color);
}
/** @} */
}