Mouse.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Mouse flags reported in <see cref="MouseEvent"/>.
  5. /// </summary>
  6. /// <remarks>
  7. /// They just happen to map to the ncurses ones.
  8. /// </remarks>
  9. [Flags]
  10. public enum MouseFlags {
  11. /// <summary>
  12. /// The first mouse button was pressed.
  13. /// </summary>
  14. Button1Pressed = unchecked((int)0x2),
  15. /// <summary>
  16. /// The first mouse button was released.
  17. /// </summary>
  18. Button1Released = unchecked((int)0x1),
  19. /// <summary>
  20. /// The first mouse button was clicked (press+release).
  21. /// </summary>
  22. Button1Clicked = unchecked((int)0x4),
  23. /// <summary>
  24. /// The first mouse button was double-clicked.
  25. /// </summary>
  26. Button1DoubleClicked = unchecked((int)0x8),
  27. /// <summary>
  28. /// The first mouse button was triple-clicked.
  29. /// </summary>
  30. Button1TripleClicked = unchecked((int)0x10),
  31. /// <summary>
  32. /// The second mouse button was pressed.
  33. /// </summary>
  34. Button2Pressed = unchecked((int)0x80),
  35. /// <summary>
  36. /// The second mouse button was released.
  37. /// </summary>
  38. Button2Released = unchecked((int)0x40),
  39. /// <summary>
  40. /// The second mouse button was clicked (press+release).
  41. /// </summary>
  42. Button2Clicked = unchecked((int)0x100),
  43. /// <summary>
  44. /// The second mouse button was double-clicked.
  45. /// </summary>
  46. Button2DoubleClicked = unchecked((int)0x200),
  47. /// <summary>
  48. /// The second mouse button was triple-clicked.
  49. /// </summary>
  50. Button2TripleClicked = unchecked((int)0x400),
  51. /// <summary>
  52. /// The third mouse button was pressed.
  53. /// </summary>
  54. Button3Pressed = unchecked((int)0x2000),
  55. /// <summary>
  56. /// The third mouse button was released.
  57. /// </summary>
  58. Button3Released = unchecked((int)0x1000),
  59. /// <summary>
  60. /// The third mouse button was clicked (press+release).
  61. /// </summary>
  62. Button3Clicked = unchecked((int)0x4000),
  63. /// <summary>
  64. /// The third mouse button was double-clicked.
  65. /// </summary>
  66. Button3DoubleClicked = unchecked((int)0x8000),
  67. /// <summary>
  68. /// The third mouse button was triple-clicked.
  69. /// </summary>
  70. Button3TripleClicked = unchecked((int)0x10000),
  71. /// <summary>
  72. /// The fourth mouse button was pressed.
  73. /// </summary>
  74. Button4Pressed = unchecked((int)0x80000),
  75. /// <summary>
  76. /// The fourth mouse button was released.
  77. /// </summary>
  78. Button4Released = unchecked((int)0x40000),
  79. /// <summary>
  80. /// The fourth button was clicked (press+release).
  81. /// </summary>
  82. Button4Clicked = unchecked((int)0x100000),
  83. /// <summary>
  84. /// The fourth button was double-clicked.
  85. /// </summary>
  86. Button4DoubleClicked = unchecked((int)0x200000),
  87. /// <summary>
  88. /// The fourth button was triple-clicked.
  89. /// </summary>
  90. Button4TripleClicked = unchecked((int)0x400000),
  91. /// <summary>
  92. /// Flag: the shift key was pressed when the mouse button took place.
  93. /// </summary>
  94. ButtonShift = unchecked((int)0x2000000),
  95. /// <summary>
  96. /// Flag: the ctrl key was pressed when the mouse button took place.
  97. /// </summary>
  98. ButtonCtrl = unchecked((int)0x1000000),
  99. /// <summary>
  100. /// Flag: the alt key was pressed when the mouse button took place.
  101. /// </summary>
  102. ButtonAlt = unchecked((int)0x4000000),
  103. /// <summary>
  104. /// The mouse position is being reported in this event.
  105. /// </summary>
  106. ReportMousePosition = unchecked((int)0x8000000),
  107. /// <summary>
  108. /// Vertical button wheeled up.
  109. /// </summary>
  110. WheeledUp = unchecked((int)0x10000000),
  111. /// <summary>
  112. /// Vertical button wheeled down.
  113. /// </summary>
  114. WheeledDown = unchecked((int)0x20000000),
  115. /// <summary>
  116. /// Vertical button wheeled up while pressing ButtonShift.
  117. /// </summary>
  118. WheeledLeft = ButtonShift | WheeledUp,
  119. /// <summary>
  120. /// Vertical button wheeled down while pressing ButtonShift.
  121. /// </summary>
  122. WheeledRight = ButtonShift | WheeledDown,
  123. /// <summary>
  124. /// Mask that captures all the events.
  125. /// </summary>
  126. AllEvents = unchecked((int)0x7ffffff),
  127. }
  128. // TODO: Merge MouseEvent and MouseEventEventArgs into a single class.
  129. /// <summary>
  130. /// Low-level construct that conveys the details of mouse events, such
  131. /// as coordinates and button state, from ConsoleDrivers up to <see cref="Application"/> and
  132. /// Views.
  133. /// </summary>
  134. /// <remarks>The <see cref="Application"/> class includes the <see cref="Application.MouseEvent"/>
  135. /// Action which takes a MouseEvent argument.</remarks>
  136. public class MouseEvent {
  137. /// <summary>
  138. /// The X (column) location for the mouse event.
  139. /// </summary>
  140. public int X { get; set; }
  141. /// <summary>
  142. /// The Y (column) location for the mouse event.
  143. /// </summary>
  144. public int Y { get; set; }
  145. /// <summary>
  146. /// Flags indicating the kind of mouse event that is being posted.
  147. /// </summary>
  148. public MouseFlags Flags { get; set; }
  149. /// <summary>
  150. /// The offset X (column) location for the mouse event.
  151. /// </summary>
  152. public int OfX { get; set; }
  153. /// <summary>
  154. /// The offset Y (column) location for the mouse event.
  155. /// </summary>
  156. public int OfY { get; set; }
  157. /// <summary>
  158. /// The current view at the location for the mouse event.
  159. /// </summary>
  160. public View View { get; set; }
  161. /// <summary>
  162. /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber.
  163. /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
  164. /// </summary>
  165. public bool Handled { get; set; }
  166. /// <summary>
  167. /// Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.
  168. /// </summary>
  169. /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</returns>
  170. public override string ToString ()
  171. {
  172. return $"({X},{Y}):{Flags}";
  173. }
  174. }