Mouse.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. namespace Terminal.Gui;
  2. /// <summary>Mouse flags reported in <see cref="MouseEvent"/>.</summary>
  3. /// <remarks>They just happen to map to the ncurses ones.</remarks>
  4. [Flags]
  5. public enum MouseFlags
  6. {
  7. /// <summary>
  8. /// No mouse event. This is the default value for <see cref="MouseEvent.Flags"/> when no mouse event is being reported.
  9. /// </summary>
  10. None = 0,
  11. /// <summary>The first mouse button was pressed.</summary>
  12. Button1Pressed = 0x2,
  13. /// <summary>The first mouse button was released.</summary>
  14. Button1Released = 0x1,
  15. /// <summary>The first mouse button was clicked (press+release).</summary>
  16. Button1Clicked = 0x4,
  17. /// <summary>The first mouse button was double-clicked.</summary>
  18. Button1DoubleClicked = 0x8,
  19. /// <summary>The first mouse button was triple-clicked.</summary>
  20. Button1TripleClicked = 0x10,
  21. /// <summary>The second mouse button was pressed.</summary>
  22. Button2Pressed = 0x80,
  23. /// <summary>The second mouse button was released.</summary>
  24. Button2Released = 0x40,
  25. /// <summary>The second mouse button was clicked (press+release).</summary>
  26. Button2Clicked = 0x100,
  27. /// <summary>The second mouse button was double-clicked.</summary>
  28. Button2DoubleClicked = 0x200,
  29. /// <summary>The second mouse button was triple-clicked.</summary>
  30. Button2TripleClicked = 0x400,
  31. /// <summary>The third mouse button was pressed.</summary>
  32. Button3Pressed = 0x2000,
  33. /// <summary>The third mouse button was released.</summary>
  34. Button3Released = 0x1000,
  35. /// <summary>The third mouse button was clicked (press+release).</summary>
  36. Button3Clicked = 0x4000,
  37. /// <summary>The third mouse button was double-clicked.</summary>
  38. Button3DoubleClicked = 0x8000,
  39. /// <summary>The third mouse button was triple-clicked.</summary>
  40. Button3TripleClicked = 0x10000,
  41. /// <summary>The fourth mouse button was pressed.</summary>
  42. Button4Pressed = 0x80000,
  43. /// <summary>The fourth mouse button was released.</summary>
  44. Button4Released = 0x40000,
  45. /// <summary>The fourth button was clicked (press+release).</summary>
  46. Button4Clicked = 0x100000,
  47. /// <summary>The fourth button was double-clicked.</summary>
  48. Button4DoubleClicked = 0x200000,
  49. /// <summary>The fourth button was triple-clicked.</summary>
  50. Button4TripleClicked = 0x400000,
  51. /// <summary>Flag: the shift key was pressed when the mouse button took place.</summary>
  52. ButtonShift = 0x2000000,
  53. /// <summary>Flag: the ctrl key was pressed when the mouse button took place.</summary>
  54. ButtonCtrl = 0x1000000,
  55. /// <summary>Flag: the alt key was pressed when the mouse button took place.</summary>
  56. ButtonAlt = 0x4000000,
  57. /// <summary>The mouse position is being reported in this event.</summary>
  58. ReportMousePosition = 0x8000000,
  59. /// <summary>Vertical button wheeled up.</summary>
  60. WheeledUp = 0x10000000,
  61. /// <summary>Vertical button wheeled down.</summary>
  62. WheeledDown = 0x20000000,
  63. /// <summary>Vertical button wheeled up while pressing ButtonCtrl.</summary>
  64. WheeledLeft = ButtonCtrl | WheeledUp,
  65. /// <summary>Vertical button wheeled down while pressing ButtonCtrl.</summary>
  66. WheeledRight = ButtonCtrl | WheeledDown,
  67. /// <summary>Mask that captures all the events.</summary>
  68. AllEvents = 0x7ffffff
  69. }
  70. // TODO: Merge MouseEvent and MouseEventEventArgs into a single class.
  71. /// <summary>
  72. /// Conveys the details of mouse events, such as coordinates and button state, from
  73. /// ConsoleDrivers up to <see cref="Application"/> and Views.
  74. /// </summary>
  75. /// <remarks>
  76. /// The <see cref="Application"/> class includes the <see cref="Application.MouseEvent"/> event which takes a
  77. /// MouseEvent argument.
  78. /// </remarks>
  79. public class MouseEvent
  80. {
  81. /// <summary>Flags indicating the kind of mouse event that is being posted.</summary>
  82. public MouseFlags Flags { get; set; }
  83. /// <summary>The View at the location for the mouse event.</summary>
  84. public View View { get; set; }
  85. /// <summary>The position of the mouse in <see cref="Gui.View.Viewport"/>-relative coordinates.</summary>
  86. public Point Position { get; set; }
  87. /// <summary>
  88. /// The screen-relative mouse position.
  89. /// </summary>
  90. /// <remarks>
  91. /// <para>
  92. /// <see cref="Position"/> is <see cref="Gui.View.Viewport"/>-relative. When the mouse is grabbed by a view,
  93. /// <see cref="ScreenPosition"/> provides the mouse position screen-relative coordinates, enabling the grabbed view to know how much the
  94. /// mouse has moved.
  95. /// </para>
  96. /// <para>
  97. /// Calculated and processed in <see cref="Application.RaiseMouseEvent"/>.
  98. /// </para>
  99. /// </remarks>
  100. public Point ScreenPosition { get; set; }
  101. /// <summary>
  102. /// Indicates if the current mouse event has been processed. Set this value to <see langword="true"/> to indicate the mouse
  103. /// event was handled.
  104. /// </summary>
  105. public bool Handled { get; set; }
  106. /// <summary>Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</summary>
  107. /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</returns>
  108. public override string ToString () { return $"({Position}):{Flags}"; }
  109. }