EditorInput.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using BansheeEngine;
  2. namespace BansheeEditor
  3. {
  4. /// <summary>
  5. /// Companion class to <see cref="Input"/> for use in editor only. Supplies events that trigger regardless whether
  6. /// game is playing or not (unlike <see cref="Input"/>) which makes them usable for editor only scripts. Pollable
  7. /// input should still be used from <see cref="Input"/>.
  8. /// </summary>
  9. public static class EditorInput
  10. {
  11. public delegate void ButtonEventDelegate(ButtonEvent ev);
  12. public delegate void TextInputEventDelegate(TextInputEvent ev);
  13. public delegate void PointerEventDelegate(PointerEvent ev);
  14. /// <summary>
  15. /// Triggered when a button on any device is pressed.
  16. /// </summary>
  17. public static event ButtonEventDelegate OnButtonDown;
  18. /// <summary>
  19. /// Triggered when a button on any device is released.
  20. /// </summary>
  21. public static event ButtonEventDelegate OnButtonUp;
  22. /// <summary>
  23. /// Triggered when a textual character is entered.
  24. /// </summary>
  25. public static event TextInputEventDelegate OnCharInput;
  26. /// <summary>
  27. /// Triggered when the pointing device (mouse, touch) is moved.
  28. /// </summary>
  29. public static event PointerEventDelegate OnPointerMoved;
  30. /// <summary>
  31. /// Triggered when a button on the pointing device (mouse, touch) is pressed.
  32. /// </summary>
  33. public static event PointerEventDelegate OnPointerPressed;
  34. /// <summary>
  35. /// Triggered when a button on the pointing device (mouse, touch) is released.
  36. /// </summary>
  37. public static event PointerEventDelegate OnPointerReleased;
  38. /// <summary>
  39. /// Triggered when a button on the pointing device (mouse, touch) is pressed twice in rappid succession.
  40. /// </summary>
  41. public static event PointerEventDelegate OnPointerDoubleClick;
  42. /// <summary>
  43. /// Triggered by runtime when a button is pressed.
  44. /// </summary>
  45. /// <param name="code">Code of the pressed button.</param>
  46. /// <param name="deviceIdx">Device the event originated from.</param>
  47. private static void Internal_TriggerButtonDown(ButtonCode code, int deviceIdx)
  48. {
  49. ButtonEvent ev = new ButtonEvent(code, deviceIdx);
  50. if (OnButtonDown != null)
  51. OnButtonDown(ev);
  52. }
  53. /// <summary>
  54. /// Triggered by runtime when a button is released.
  55. /// </summary>
  56. /// <param name="code">Code of the released button.</param>
  57. /// <param name="deviceIdx">Device the event originated from.</param>
  58. private static void Internal_TriggerButtonUp(ButtonCode code, int deviceIdx)
  59. {
  60. ButtonEvent ev = new ButtonEvent(code, deviceIdx);
  61. if (OnButtonUp != null)
  62. OnButtonUp(ev);
  63. }
  64. /// <summary>
  65. /// Triggered by runtime when character is input.
  66. /// </summary>
  67. /// <param name="textChar">Code of input character.</param>
  68. private static void Internal_TriggerCharInput(int textChar)
  69. {
  70. TextInputEvent ev = new TextInputEvent(textChar);
  71. if (OnCharInput != null)
  72. OnCharInput(ev);
  73. }
  74. /// <summary>
  75. /// Triggers when some pointing device (mouse cursor, touch) moves.
  76. /// </summary>
  77. /// <param name="screenPos">Screen position where the input event occurred.</param>
  78. /// <param name="delta">Change in movement since last sent event.</param>
  79. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  80. /// (e.g. move events don't correspond to a button.</param>
  81. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  82. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  83. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  84. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  85. /// move events.</param>
  86. private static void Internal_TriggerPointerMove(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  87. bool ctrl, bool alt, float scrollAmount)
  88. {
  89. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
  90. if (OnPointerMoved != null)
  91. OnPointerMoved(ev);
  92. }
  93. /// <summary>
  94. /// Triggers when some pointing device (mouse cursor, touch) button is pressed.
  95. /// </summary>
  96. /// <param name="screenPos">Screen position where the input event occurred.</param>
  97. /// <param name="delta">Change in movement since last sent event.</param>
  98. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  99. /// (e.g. move events don't correspond to a button.</param>
  100. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  101. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  102. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  103. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  104. /// move events.</param>
  105. private static void Internal_TriggerPointerPressed(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  106. bool ctrl, bool alt, float scrollAmount)
  107. {
  108. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
  109. if (OnPointerPressed != null)
  110. OnPointerPressed(ev);
  111. }
  112. /// <summary>
  113. /// Triggers when some pointing device (mouse cursor, touch) button is released.
  114. /// </summary>
  115. /// <param name="screenPos">Screen position where the input event occurred.</param>
  116. /// <param name="delta">Change in movement since last sent event.</param>
  117. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  118. /// (e.g. move events don't correspond to a button.</param>
  119. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  120. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  121. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  122. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  123. /// move events.</param>
  124. private static void Internal_TriggerPointerReleased(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  125. bool ctrl, bool alt, float scrollAmount)
  126. {
  127. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
  128. if (OnPointerReleased != null)
  129. OnPointerReleased(ev);
  130. }
  131. /// <summary>
  132. /// Triggers when some pointing device (mouse cursor, touch) button is double clicked.
  133. /// </summary>
  134. /// <param name="screenPos">Screen position where the input event occurred.</param>
  135. /// <param name="delta">Change in movement since last sent event.</param>
  136. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  137. /// (e.g. move events don't correspond to a button.</param>
  138. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  139. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  140. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  141. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  142. /// move events.</param>
  143. private static void Internal_TriggerPointerDoubleClick(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  144. bool ctrl, bool alt, float scrollAmount)
  145. {
  146. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount);
  147. if (OnPointerDoubleClick != null)
  148. OnPointerDoubleClick(ev);
  149. }
  150. }
  151. }