|
|
@@ -6,31 +6,63 @@ using System.Text;
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// Contains data about a button input event.
|
|
|
+ /// </summary>
|
|
|
public struct ButtonEvent
|
|
|
{
|
|
|
internal ButtonCode buttonCode;
|
|
|
internal int deviceIdx;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a new button input event. For runtime use only.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="buttonCode">Button code this event is referring to.</param>
|
|
|
+ /// <param name="deviceIdx">Index of the device that the event originated from.</param>
|
|
|
internal ButtonEvent(ButtonCode buttonCode, int deviceIdx)
|
|
|
{
|
|
|
this.buttonCode = buttonCode;
|
|
|
this.deviceIdx = deviceIdx;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Button code this event is referring to.
|
|
|
+ /// </summary>
|
|
|
public ButtonCode Button { get { return buttonCode; } }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Index of the device that the event originated from.
|
|
|
+ /// </summary>
|
|
|
public int DeviceIndex { get { return deviceIdx; } }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query is the pressed button a keyboard button.
|
|
|
+ /// </summary>
|
|
|
public bool IsKeyboard { get { return ((int)buttonCode & 0xC0000000) == 0; }}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Query is the pressed button a mouse button.
|
|
|
+ /// </summary>
|
|
|
public bool IsMouse { get { return ((int)buttonCode & 0x80000000) != 0; } }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Query is the pressed button a gamepad button.
|
|
|
+ /// </summary>
|
|
|
public bool IsGamepad { get { return ((int)buttonCode & 0x40000000) != 0; } }
|
|
|
};
|
|
|
|
|
|
- // Do not change IDs, must match PointerEventButton C++ enum
|
|
|
- public enum PointerButton
|
|
|
+ /// <summary>
|
|
|
+ /// Pointer buttons. Generally these correspond to mouse buttons, but may be used in some form for touch input as well.
|
|
|
+ /// </summary>
|
|
|
+ public enum PointerButton // Note: Must match C++ enum PointerEventButton
|
|
|
{
|
|
|
Left, Middle, Right, Count
|
|
|
};
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Event that gets sent out when user interacts with the screen in some way, usually by moving the mouse cursor or
|
|
|
+ /// using touch input.
|
|
|
+ /// </summary>
|
|
|
public struct PointerEvent
|
|
|
{
|
|
|
internal Vector2I _screenPos;
|
|
|
@@ -43,6 +75,18 @@ namespace BansheeEngine
|
|
|
|
|
|
internal float _mouseWheelScrollAmount;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a new pointer event. For runtime use only.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="screenPos">Screen position where the input event occurred.</param>
|
|
|
+ /// <param name="delta">Change in movement since last sent event.</param>
|
|
|
+ /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
|
|
|
+ /// (e.g. move events don't correspond to a button.</param>
|
|
|
+ /// <param name="shift">Is shift button on the keyboard being held down.</param>
|
|
|
+ /// <param name="control">Is control button on the keyboard being held down.</param>
|
|
|
+ /// <param name="alt">Is alt button on the keyboard being held down.</param>
|
|
|
+ /// <param name="mouseWheelScrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
|
|
|
+ /// move events.</param>
|
|
|
internal PointerEvent(Vector2I screenPos, Vector2I delta, PointerButton button,
|
|
|
bool shift, bool control, bool alt, float mouseWheelScrollAmount)
|
|
|
{
|
|
|
@@ -57,29 +101,69 @@ namespace BansheeEngine
|
|
|
_mouseWheelScrollAmount = mouseWheelScrollAmount;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Screen position where the input event occurred.
|
|
|
+ /// </summary>
|
|
|
public Vector2I ScreenPos { get { return _screenPos; } }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Change in movement since last sent event.
|
|
|
+ /// </summary>
|
|
|
public Vector2I Delta { get { return _delta; } }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Button that triggered the pointer event. Might be irrelevant depending on event type.
|
|
|
+ /// (e.g. move events don't correspond to a button.
|
|
|
+ /// </summary>
|
|
|
public PointerButton Button { get { return _button; } }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Is shift button on the keyboard being held down.
|
|
|
+ /// </summary>
|
|
|
public bool Shift { get { return _shift; } }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Is control button on the keyboard being held down.
|
|
|
+ /// </summary>
|
|
|
public bool Control { get { return _control; } }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Is alt button on the keyboard being held down.
|
|
|
+ /// </summary>
|
|
|
public bool Alt { get { return _alt; } }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// If mouse wheel is being scrolled, what is the amount. Only relevant for move events.
|
|
|
+ /// </summary>
|
|
|
public float ScrollAmount { get { return _mouseWheelScrollAmount; } }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Event that gets sent out when user inputs some text. These events may be preceeded by normal button events if user
|
|
|
+ /// is typing on a keyboard.
|
|
|
+ /// </summary>
|
|
|
public struct TextInputEvent
|
|
|
{
|
|
|
internal int textChar;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a new text input event. For runtime use only.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="textChar">Character the that was input.</param>
|
|
|
internal TextInputEvent(int textChar)
|
|
|
{
|
|
|
this.textChar = textChar;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Character the that was input.
|
|
|
+ /// </summary>
|
|
|
public int Char { get { return textChar; } }
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Allows you to query and receive events from all connected input devices.
|
|
|
+ /// </summary>
|
|
|
public static class Input
|
|
|
{
|
|
|
public delegate void ButtonEventDelegate(ButtonEvent ev);
|
|
|
@@ -94,46 +178,93 @@ namespace BansheeEngine
|
|
|
public static event PointerEventDelegate OnPointerReleased;
|
|
|
public static event PointerEventDelegate OnPointerDoubleClick;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Returns value of the specified input axis.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="axis">Type of axis to query.</param>
|
|
|
+ /// <param name="deviceIdx">Index of the device in case more than one is hooked up (0 - primary).</param>
|
|
|
+ /// <returns>Value of the axis in range [-1.0, 1.0]. Canan be outside the range for devices with unbound axes
|
|
|
+ /// (e.g. mouse).</returns>
|
|
|
public static float GetAxisValue(InputAxis axis, int deviceIdx = 0)
|
|
|
{
|
|
|
return Internal_GetAxisValue(axis, deviceIdx);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query if the provided button is currently being held (this frame or previous frames).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the button to query.</param>
|
|
|
+ /// <param name="deviceIdx">Device to query the button on (0 - primary).</param>
|
|
|
+ /// <returns>True if the button is held.</returns>
|
|
|
public static bool IsButtonHeld(ButtonCode code, int deviceIdx = 0)
|
|
|
{
|
|
|
return Internal_IsButtonHeld(code, deviceIdx);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query if the provided button is currently being released (only true for one frame).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the button to query.</param>
|
|
|
+ /// <param name="deviceIdx">Device to query the button on (0 - primary).</param>
|
|
|
+ /// <returns>True if the button is being released.</returns>
|
|
|
public static bool IsButtonUp(ButtonCode code, int deviceIdx = 0)
|
|
|
{
|
|
|
return Internal_IsButtonUp(code, deviceIdx);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query if the provided button is currently being pressed (only true for one frame).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the button to query.</param>
|
|
|
+ /// <param name="deviceIdx">Device to query the button on (0 - primary).</param>
|
|
|
+ /// <returns>True if the button is being pressed.</returns>
|
|
|
public static bool IsButtonDown(ButtonCode code, int deviceIdx = 0)
|
|
|
{
|
|
|
return Internal_IsButtonDown(code, deviceIdx);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query if the provided pointer button is currently being held (this frame or previous frames).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the button to query.</param>
|
|
|
+ /// <returns>True if the button is being held.</returns>
|
|
|
public static bool IsPointerButtonHeld(PointerButton code)
|
|
|
{
|
|
|
return Internal_IsPointerButtonHeld(code);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query if the provided pointer button is currently being being released (only true for one frame).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the button to query.</param>
|
|
|
+ /// <returns>True if the button is being released.</returns>
|
|
|
public static bool IsPointerButtonUp(PointerButton code)
|
|
|
{
|
|
|
return Internal_IsPointerButtonUp(code);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query if the provided pointer button is currently being being pressed (only true for one frame).
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the button to query.</param>
|
|
|
+ /// <returns>True if the button is being pressed.</returns>
|
|
|
public static bool IsPointerButtonDown(PointerButton code)
|
|
|
{
|
|
|
return Internal_IsPointerButtonDown(code);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Query has the left pointer button been double-clicked this frame.
|
|
|
+ /// </summary>
|
|
|
+ /// <returns>True if double-click occurred.</returns>
|
|
|
public static bool IsPointerDoubleClicked()
|
|
|
{
|
|
|
return Internal_IsPointerDoubleClicked();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Returns position of the pointer (e.g. mouse cursor) relative to the screen.
|
|
|
+ /// </summary>
|
|
|
public static Vector2I PointerPosition
|
|
|
{
|
|
|
get
|
|
|
@@ -144,6 +275,9 @@ namespace BansheeEngine
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Returns difference between last and current pointer position.
|
|
|
+ /// </summary>
|
|
|
public static Vector2I PointerDelta
|
|
|
{
|
|
|
get
|
|
|
@@ -154,6 +288,11 @@ namespace BansheeEngine
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggered by runtime when a button is pressed.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the pressed button.</param>
|
|
|
+ /// <param name="deviceIdx">Device the event originated from.</param>
|
|
|
private static void Internal_TriggerButtonDown(ButtonCode code, int deviceIdx)
|
|
|
{
|
|
|
ButtonEvent ev = new ButtonEvent(code, deviceIdx);
|
|
|
@@ -162,6 +301,11 @@ namespace BansheeEngine
|
|
|
OnButtonDown(ev);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggered by runtime when a button is released.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="code">Code of the released button.</param>
|
|
|
+ /// <param name="deviceIdx">Device the event originated from.</param>
|
|
|
private static void Internal_TriggerButtonUp(ButtonCode code, int deviceIdx)
|
|
|
{
|
|
|
ButtonEvent ev = new ButtonEvent(code, deviceIdx);
|
|
|
@@ -170,6 +314,10 @@ namespace BansheeEngine
|
|
|
OnButtonUp(ev);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggered by runtime when character is input.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="textChar">Code of input character.</param>
|
|
|
private static void Internal_TriggerCharInput(int textChar)
|
|
|
{
|
|
|
TextInputEvent ev = new TextInputEvent(textChar);
|
|
|
@@ -178,6 +326,18 @@ namespace BansheeEngine
|
|
|
OnCharInput(ev);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggers when some pointing device (mouse cursor, touch) moves.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="screenPos">Screen position where the input event occurred.</param>
|
|
|
+ /// <param name="delta">Change in movement since last sent event.</param>
|
|
|
+ /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
|
|
|
+ /// (e.g. move events don't correspond to a button.</param>
|
|
|
+ /// <param name="shift">Is shift button on the keyboard being held down.</param>
|
|
|
+ /// <param name="ctrl">Is control button on the keyboard being held down.</param>
|
|
|
+ /// <param name="alt">Is alt button on the keyboard being held down.</param>
|
|
|
+ /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
|
|
|
+ /// move events.</param>
|
|
|
private static void Internal_TriggerPointerMove(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
|
|
|
bool ctrl, bool alt, float scrollAmount)
|
|
|
{
|
|
|
@@ -187,6 +347,18 @@ namespace BansheeEngine
|
|
|
OnPointerMoved(ev);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggers when some pointing device (mouse cursor, touch) button is pressed.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="screenPos">Screen position where the input event occurred.</param>
|
|
|
+ /// <param name="delta">Change in movement since last sent event.</param>
|
|
|
+ /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
|
|
|
+ /// (e.g. move events don't correspond to a button.</param>
|
|
|
+ /// <param name="shift">Is shift button on the keyboard being held down.</param>
|
|
|
+ /// <param name="ctrl">Is control button on the keyboard being held down.</param>
|
|
|
+ /// <param name="alt">Is alt button on the keyboard being held down.</param>
|
|
|
+ /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
|
|
|
+ /// move events.</param>
|
|
|
private static void Internal_TriggerPointerPressed(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
|
|
|
bool ctrl, bool alt, float scrollAmount)
|
|
|
{
|
|
|
@@ -196,6 +368,18 @@ namespace BansheeEngine
|
|
|
OnPointerPressed(ev);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggers when some pointing device (mouse cursor, touch) button is released.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="screenPos">Screen position where the input event occurred.</param>
|
|
|
+ /// <param name="delta">Change in movement since last sent event.</param>
|
|
|
+ /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
|
|
|
+ /// (e.g. move events don't correspond to a button.</param>
|
|
|
+ /// <param name="shift">Is shift button on the keyboard being held down.</param>
|
|
|
+ /// <param name="ctrl">Is control button on the keyboard being held down.</param>
|
|
|
+ /// <param name="alt">Is alt button on the keyboard being held down.</param>
|
|
|
+ /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
|
|
|
+ /// move events.</param>
|
|
|
private static void Internal_TriggerPointerReleased(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
|
|
|
bool ctrl, bool alt, float scrollAmount)
|
|
|
{
|
|
|
@@ -205,6 +389,18 @@ namespace BansheeEngine
|
|
|
OnPointerReleased(ev);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Triggers when some pointing device (mouse cursor, touch) button is double clicked.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="screenPos">Screen position where the input event occurred.</param>
|
|
|
+ /// <param name="delta">Change in movement since last sent event.</param>
|
|
|
+ /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
|
|
|
+ /// (e.g. move events don't correspond to a button.</param>
|
|
|
+ /// <param name="shift">Is shift button on the keyboard being held down.</param>
|
|
|
+ /// <param name="ctrl">Is control button on the keyboard being held down.</param>
|
|
|
+ /// <param name="alt">Is alt button on the keyboard being held down.</param>
|
|
|
+ /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
|
|
|
+ /// move events.</param>
|
|
|
private static void Internal_TriggerPointerDoubleClick(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
|
|
|
bool ctrl, bool alt, float scrollAmount)
|
|
|
{
|
|
|
@@ -245,8 +441,10 @@ namespace BansheeEngine
|
|
|
private static extern void Internal_GetPointerDelta(out Vector2I delta);
|
|
|
}
|
|
|
|
|
|
- // Do not change IDs, must match ButtonCode C++ enum
|
|
|
- public enum ButtonCode : uint
|
|
|
+ /// <summary>
|
|
|
+ /// Contains all possible input buttons, including keyboard scan codes, mouse buttons and gamepad buttons.
|
|
|
+ /// </summary>
|
|
|
+ public enum ButtonCode : uint // Note: Must match C++ enum ButtonCode
|
|
|
{
|
|
|
Unassigned = 0x00,
|
|
|
Escape = 0x01,
|
|
|
@@ -410,8 +608,10 @@ namespace BansheeEngine
|
|
|
NumGamepadButtons = 30,
|
|
|
};
|
|
|
|
|
|
- // Do not change IDs, must match InputAxis C++ enum
|
|
|
- public enum InputAxis
|
|
|
+ /// <summary>
|
|
|
+ /// Available types of input axes.
|
|
|
+ /// </summary>
|
|
|
+ public enum InputAxis // Note: Must match C++ enum InputBox
|
|
|
{
|
|
|
MouseX,
|
|
|
MouseY,
|