EditorInput.cs 8.8 KB

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