2
0

EditorInput.cs 8.9 KB

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