//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using bs;
namespace bs.Editor
{
/** @addtogroup Input-Editor
* @{
*/
///
/// Companion class to for use in editor only. Supplies events that trigger regardless whether
/// game is playing or not (unlike ) which makes them usable for editor only scripts. Pollable
/// input should still be used from .
///
public static class EditorInput
{
public delegate void ButtonEventDelegate(ButtonEvent ev);
public delegate void TextInputEventDelegate(TextInputEvent ev);
public delegate void PointerEventDelegate(PointerEvent ev);
///
/// Triggered when a button on any device is pressed.
///
public static event ButtonEventDelegate OnButtonDown;
///
/// Triggered when a button on any device is released.
///
public static event ButtonEventDelegate OnButtonUp;
///
/// Triggered when a textual character is entered.
///
public static event TextInputEventDelegate OnCharInput;
///
/// Triggered when the pointing device (mouse, touch) is moved.
///
public static event PointerEventDelegate OnPointerMoved;
///
/// Triggered when a button on the pointing device (mouse, touch) is pressed.
///
public static event PointerEventDelegate OnPointerPressed;
///
/// Triggered when a button on the pointing device (mouse, touch) is released.
///
public static event PointerEventDelegate OnPointerReleased;
///
/// Triggered when a button on the pointing device (mouse, touch) is pressed twice in rappid succession.
///
public static event PointerEventDelegate OnPointerDoubleClick;
///
/// Triggered by runtime when a button is pressed.
///
/// Code of the pressed button.
/// Device the event originated from.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerButtonDown(ButtonCode code, int deviceIdx, bool isUsed)
{
ButtonEvent ev = new ButtonEvent(code, deviceIdx, isUsed);
if (OnButtonDown != null)
OnButtonDown(ev);
}
///
/// Triggered by runtime when a button is released.
///
/// Code of the released button.
/// Device the event originated from.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerButtonUp(ButtonCode code, int deviceIdx, bool isUsed)
{
ButtonEvent ev = new ButtonEvent(code, deviceIdx, isUsed);
if (OnButtonUp != null)
OnButtonUp(ev);
}
///
/// Triggered by runtime when character is input.
///
/// Code of input character.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerCharInput(int textChar, bool isUsed)
{
TextInputEvent ev = new TextInputEvent(textChar, isUsed);
if (OnCharInput != null)
OnCharInput(ev);
}
///
/// Triggers when some pointing device (mouse cursor, touch) moves.
///
/// Screen position where the input event occurred.
/// Change in movement since last sent event.
/// Button that triggered the pointer event. Might be irrelevant depending on event type.
/// (for example move events don't correspond to a button.
/// Is shift button on the keyboard being held down.
/// Is control button on the keyboard being held down.
/// Is alt button on the keyboard being held down.
/// If mouse wheel is being scrolled, what is the amount. Only relevant for
/// move events.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerPointerMove(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
bool ctrl, bool alt, float scrollAmount, bool isUsed)
{
PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
if (OnPointerMoved != null)
OnPointerMoved(ev);
}
///
/// Triggers when some pointing device (mouse cursor, touch) button is pressed.
///
/// Screen position where the input event occurred.
/// Change in movement since last sent event.
/// Button that triggered the pointer event. Might be irrelevant depending on event type.
/// (for example move events don't correspond to a button.
/// Is shift button on the keyboard being held down.
/// Is control button on the keyboard being held down.
/// Is alt button on the keyboard being held down.
/// If mouse wheel is being scrolled, what is the amount. Only relevant for
/// move events.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerPointerPressed(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
bool ctrl, bool alt, float scrollAmount, bool isUsed)
{
PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
if (OnPointerPressed != null)
OnPointerPressed(ev);
}
///
/// Triggers when some pointing device (mouse cursor, touch) button is released.
///
/// Screen position where the input event occurred.
/// Change in movement since last sent event.
/// Button that triggered the pointer event. Might be irrelevant depending on event type.
/// (for example move events don't correspond to a button.
/// Is shift button on the keyboard being held down.
/// Is control button on the keyboard being held down.
/// Is alt button on the keyboard being held down.
/// If mouse wheel is being scrolled, what is the amount. Only relevant for
/// move events.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerPointerReleased(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
bool ctrl, bool alt, float scrollAmount, bool isUsed)
{
PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
if (OnPointerReleased != null)
OnPointerReleased(ev);
}
///
/// Triggers when some pointing device (mouse cursor, touch) button is double clicked.
///
/// Screen position where the input event occurred.
/// Change in movement since last sent event.
/// Button that triggered the pointer event. Might be irrelevant depending on event type.
/// (for example move events don't correspond to a button.
/// Is shift button on the keyboard being held down.
/// Is control button on the keyboard being held down.
/// Is alt button on the keyboard being held down.
/// If mouse wheel is being scrolled, what is the amount. Only relevant for
/// move events.
/// Set to true if the event was handled previously by some internal system (like GUI).
private static void Internal_TriggerPointerDoubleClick(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
bool ctrl, bool alt, float scrollAmount, bool isUsed)
{
PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
if (OnPointerDoubleClick != null)
OnPointerDoubleClick(ev);
}
}
/** @} */
}