using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace BansheeEngine
{
///
/// Handles virtual input that allows you to receive virtual input events that hide the actual physical input, allowing
/// you to easily change the input keys while being transparent to the external code.
///
public static class VirtualInput
{
public delegate void OnButtonEventDelegate(VirtualButton btn, int deviceIdx);
///
/// Triggered when a physical button combination corresponding to a virtual button is pressed.
///
public static event OnButtonEventDelegate OnButtonDown;
///
/// Triggered when a physical button combination corresponding to a virtual button is released.
///
public static event OnButtonEventDelegate OnButtonUp;
///
/// Triggered every frame while a physical button combination corresponding to a virtual button is being held down.
///
public static event OnButtonEventDelegate OnButtonHeld;
///
/// Input configuration that describes how physical keys map to virtual keys.
///
public static InputConfiguration KeyConfig
{
get
{
return Internal_GetKeyConfig();
}
set
{
Internal_SetKeyConfig(value);
}
}
///
/// Checks if the physical button combination corresponding to the specified virtual button is being pressed this
/// frame.
///
/// Virtual button to check.
/// Optional device index in case multiple input devices are available.
public static bool IsButtonDown(VirtualButton button, int deviceIdx = 0)
{
return Internal_IsButtonDown(button, deviceIdx);
}
///
/// Checks if the physical button combination corresponding to the specified virtual button is being released this
/// frame.
///
/// Virtual button to check.
/// Optional device index in case multiple input devices are available.
public static bool IsButtonUp(VirtualButton button, int deviceIdx = 0)
{
return Internal_IsButtonUp(button, deviceIdx);
}
///
/// Checks if the physical button combination corresponding to the specified virtual button is being held down.
///
/// Virtual button to check.
/// Index of the device to check.
public static bool IsButtonHeld(VirtualButton button, int deviceIdx = 0)
{
return Internal_IsButtonHeld(button, deviceIdx);
}
///
/// Returns normalized value for the specified input axis.
///
/// Virtual axis identifier.
/// Optional device index in case multiple input devices are available.
/// Axis value, normally in [-1.0, 1.0] range, but can be outside the range for devices with unbound axes
/// (e.g. mouse).
public static float GetAxisValue(VirtualAxis axis, int deviceIdx = 0)
{
return Internal_GetAxisValue(axis, deviceIdx);
}
///
/// Triggered by the runtime when the virtual button is pressed.
///
/// Virtual button that was pressed.
/// Index of the device the button was pressed on.
private static void Internal_TriggerButtonDown(VirtualButton button, int deviceIdx)
{
if (OnButtonDown != null)
OnButtonDown(button, deviceIdx);
}
///
/// Triggered by the runtime when the virtual button is released.
///
/// Virtual button that was released.
/// Index of the device the button was released on.
private static void Internal_TriggerButtonUp(VirtualButton button, int deviceIdx)
{
if (OnButtonUp != null)
OnButtonUp(button, deviceIdx);
}
///
/// Triggered by the runtime every frame while a virtual button is being held down.
///
/// Virtual button that is being held down.
/// Index of the device the button is being held down on.
private static void Internal_TriggerButtonHeld(VirtualButton button, int deviceIdx)
{
if (OnButtonHeld != null)
OnButtonHeld(button, deviceIdx);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern InputConfiguration Internal_GetKeyConfig();
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetKeyConfig(InputConfiguration inputConfig);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_IsButtonDown(VirtualButton button, int deviceIdx);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_IsButtonUp(VirtualButton button, int deviceIdx);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_IsButtonHeld(VirtualButton button, int deviceIdx);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetAxisValue(VirtualAxis button, int deviceIdx);
};
}