EditorInput.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using bs;
  4. namespace bs.Editor
  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. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  53. private static void Internal_TriggerButtonDown(ButtonCode code, int deviceIdx, bool isUsed)
  54. {
  55. ButtonEvent ev = new ButtonEvent(code, deviceIdx, isUsed);
  56. if (OnButtonDown != null)
  57. OnButtonDown(ev);
  58. }
  59. /// <summary>
  60. /// Triggered by runtime when a button is released.
  61. /// </summary>
  62. /// <param name="code">Code of the released button.</param>
  63. /// <param name="deviceIdx">Device the event originated from.</param>
  64. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  65. private static void Internal_TriggerButtonUp(ButtonCode code, int deviceIdx, bool isUsed)
  66. {
  67. ButtonEvent ev = new ButtonEvent(code, deviceIdx, isUsed);
  68. if (OnButtonUp != null)
  69. OnButtonUp(ev);
  70. }
  71. /// <summary>
  72. /// Triggered by runtime when character is input.
  73. /// </summary>
  74. /// <param name="textChar">Code of input character.</param>
  75. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  76. private static void Internal_TriggerCharInput(int textChar, bool isUsed)
  77. {
  78. TextInputEvent ev = new TextInputEvent(textChar, isUsed);
  79. if (OnCharInput != null)
  80. OnCharInput(ev);
  81. }
  82. /// <summary>
  83. /// Triggers when some pointing device (mouse cursor, touch) moves.
  84. /// </summary>
  85. /// <param name="screenPos">Screen position where the input event occurred.</param>
  86. /// <param name="delta">Change in movement since last sent event.</param>
  87. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  88. /// (for example move events don't correspond to a button.</param>
  89. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  90. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  91. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  92. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  93. /// move events.</param>
  94. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  95. private static void Internal_TriggerPointerMove(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  96. bool ctrl, bool alt, float scrollAmount, bool isUsed)
  97. {
  98. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
  99. if (OnPointerMoved != null)
  100. OnPointerMoved(ev);
  101. }
  102. /// <summary>
  103. /// Triggers when some pointing device (mouse cursor, touch) button is pressed.
  104. /// </summary>
  105. /// <param name="screenPos">Screen position where the input event occurred.</param>
  106. /// <param name="delta">Change in movement since last sent event.</param>
  107. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  108. /// (for example move events don't correspond to a button.</param>
  109. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  110. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  111. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  112. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  113. /// move events.</param>
  114. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  115. private static void Internal_TriggerPointerPressed(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  116. bool ctrl, bool alt, float scrollAmount, bool isUsed)
  117. {
  118. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
  119. if (OnPointerPressed != null)
  120. OnPointerPressed(ev);
  121. }
  122. /// <summary>
  123. /// Triggers when some pointing device (mouse cursor, touch) button is released.
  124. /// </summary>
  125. /// <param name="screenPos">Screen position where the input event occurred.</param>
  126. /// <param name="delta">Change in movement since last sent event.</param>
  127. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  128. /// (for example move events don't correspond to a button.</param>
  129. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  130. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  131. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  132. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  133. /// move events.</param>
  134. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  135. private static void Internal_TriggerPointerReleased(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  136. bool ctrl, bool alt, float scrollAmount, bool isUsed)
  137. {
  138. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
  139. if (OnPointerReleased != null)
  140. OnPointerReleased(ev);
  141. }
  142. /// <summary>
  143. /// Triggers when some pointing device (mouse cursor, touch) button is double clicked.
  144. /// </summary>
  145. /// <param name="screenPos">Screen position where the input event occurred.</param>
  146. /// <param name="delta">Change in movement since last sent event.</param>
  147. /// <param name="button">Button that triggered the pointer event. Might be irrelevant depending on event type.
  148. /// (for example move events don't correspond to a button.</param>
  149. /// <param name="shift">Is shift button on the keyboard being held down.</param>
  150. /// <param name="ctrl">Is control button on the keyboard being held down.</param>
  151. /// <param name="alt">Is alt button on the keyboard being held down.</param>
  152. /// <param name="scrollAmount">If mouse wheel is being scrolled, what is the amount. Only relevant for
  153. /// move events.</param>
  154. /// <param name="isUsed">Set to true if the event was handled previously by some internal system (like GUI).</param>
  155. private static void Internal_TriggerPointerDoubleClick(Vector2I screenPos, Vector2I delta, PointerButton button, bool shift,
  156. bool ctrl, bool alt, float scrollAmount, bool isUsed)
  157. {
  158. PointerEvent ev = new PointerEvent(screenPos, delta, button, shift, ctrl, alt, scrollAmount, isUsed);
  159. if (OnPointerDoubleClick != null)
  160. OnPointerDoubleClick(ev);
  161. }
  162. }
  163. /** @} */
  164. }