using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace BansheeEngine
{
///
/// Contains virtual to physical key mappings.
///
public sealed class InputConfiguration : ScriptObject
{
///
/// Creates a new empty key configuration.
///
public InputConfiguration()
{
Internal_CreateInstance(this);
}
///
/// Repeat interval for held virtual buttons. Buttons will be continously triggered in interval increments as long
/// as they button is being held.
///
public UInt64 RepeatInternal
{
get
{
return Internal_GetRepeatInterval(mCachedPtr);
}
set
{
Internal_SetRepeatInterval(mCachedPtr, value);
}
}
///
/// Registers a new virtual button.
///
/// Unique name used to access the virtual button.
/// Physical button the virtual button is triggered by.
/// Modifiers required to be pressed with the physical button to trigger the virtual button.
///
/// If true, the virtual button events will be sent continually while the physical button
/// is being held.
public void RegisterButton(String name, ButtonCode buttonCode,
ButtonModifier modifiers = ButtonModifier.None, bool repeatable = false)
{
Internal_RegisterButton(mCachedPtr, name, buttonCode, modifiers, repeatable);
}
///
/// Unregisters a virtual button with the specified name. Events will no longer be generated for that button.
///
/// Unique name used to access the virtual button.
public void UnregisterButton(String name)
{
Internal_UnregisterButton(mCachedPtr, name);
}
///
/// Registers a new virtual axis.
///
/// Unique name used to access the virtual axis.
/// Type of physical axis to map to.
/// Value below which to ignore axis value and consider it 0.
/// Higher sensitivity means the axis will more easily reach its maximum values.
/// Should axis values be inverted.
public void RegisterAxis(String name, InputAxis type, float deadZone = 0.0001f,
float sensitivity = 1.0f, bool invert = false)
{
Internal_RegisterAxis(mCachedPtr, name, type, deadZone, sensitivity, invert);
}
///
/// Unregisters a virtual axis with the specified name. You will no longer be able to retrieve valid values for
/// that axis.
///
/// Unique name used to access the virtual axis.
public void UnregisterAxis(String name)
{
Internal_UnregisterAxis(mCachedPtr, name);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(InputConfiguration inputConfig);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_RegisterButton(IntPtr thisPtr, String name, ButtonCode buttonCode,
ButtonModifier modifiers, bool repeatable);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_UnregisterButton(IntPtr thisPtr, String name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_RegisterAxis(IntPtr thisPtr, String name, InputAxis type, float deadZone,
float sensitivity, bool invert);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_UnregisterAxis(IntPtr thisPtr, String name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetRepeatInterval(IntPtr thisPtr, UInt64 milliseconds);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern UInt64 Internal_GetRepeatInterval(IntPtr thisPtr);
}
///
/// Button modifiers used with along with keyboard buttons.
///
public enum ButtonModifier // Note: Must match C++ enum ButtonModifier
{
None = 0x00,
Shift = 0x01,
Ctrl = 0x02,
Alt = 0x04,
ShiftCtrl = 0x03,
CtrlAlt = 0x06,
ShiftAlt = 0x05,
ShiftCtrlAlt = 0x07
};
///
/// Handle for a virtual button. Virtual buttons allow you to map custom buttons to physical buttons and deal with them
/// without knowing the underlying physical buttons, allowing easy input remapping.
///
[StructLayout(LayoutKind.Sequential)]
public struct VirtualButton // Note: Must match C++ class VirtualButton
{
private readonly int buttonId;
///
/// Creates a new virtual button handle.
///
/// Unique name of the virtual button.
public VirtualButton(string name)
{
buttonId = Internal_InitVirtualButton(name);
}
public static bool operator ==(VirtualButton lhs, VirtualButton rhs)
{
return lhs.buttonId == rhs.buttonId;
}
public static bool operator !=(VirtualButton lhs, VirtualButton rhs)
{
return !(lhs == rhs);
}
///
public override int GetHashCode()
{
return buttonId.GetHashCode();
}
///
public override bool Equals(object other)
{
if (!(other is VirtualButton))
return false;
VirtualButton otherBtn = (VirtualButton)other;
if (buttonId.Equals(otherBtn.buttonId))
return true;
return false;
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int Internal_InitVirtualButton(String name);
}
///
/// Handle for a virtual axis. Virtual axes allow you to map custom axes without needing to know the actual physical
/// device handling those axes.
///
[StructLayout(LayoutKind.Sequential)]
public struct VirtualAxis // Note: Must match C++ class VirtualAxis
{
private readonly int axisId;
///
/// Creates a new virual axis handle.
///
/// Unique name of the virtual axis.
public VirtualAxis(string name)
{
axisId = Internal_InitVirtualAxis(name);
}
public static bool operator ==(VirtualAxis lhs, VirtualAxis rhs)
{
return lhs.axisId == rhs.axisId;
}
public static bool operator !=(VirtualAxis lhs, VirtualAxis rhs)
{
return !(lhs == rhs);
}
///
public override int GetHashCode()
{
return axisId.GetHashCode();
}
///
public override bool Equals(object other)
{
if (!(other is VirtualAxis))
return false;
VirtualAxis otherAxis = (VirtualAxis)other;
if (axisId.Equals(otherAxis.axisId))
return true;
return false;
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int Internal_InitVirtualAxis(String name);
}
}