Mouse.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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>The first mouse button was pressed.</summary>
  8. Button1Pressed = 0x2,
  9. /// <summary>The first mouse button was released.</summary>
  10. Button1Released = 0x1,
  11. /// <summary>The first mouse button was clicked (press+release).</summary>
  12. Button1Clicked = 0x4,
  13. /// <summary>The first mouse button was double-clicked.</summary>
  14. Button1DoubleClicked = 0x8,
  15. /// <summary>The first mouse button was triple-clicked.</summary>
  16. Button1TripleClicked = 0x10,
  17. /// <summary>The second mouse button was pressed.</summary>
  18. Button2Pressed = 0x80,
  19. /// <summary>The second mouse button was released.</summary>
  20. Button2Released = 0x40,
  21. /// <summary>The second mouse button was clicked (press+release).</summary>
  22. Button2Clicked = 0x100,
  23. /// <summary>The second mouse button was double-clicked.</summary>
  24. Button2DoubleClicked = 0x200,
  25. /// <summary>The second mouse button was triple-clicked.</summary>
  26. Button2TripleClicked = 0x400,
  27. /// <summary>The third mouse button was pressed.</summary>
  28. Button3Pressed = 0x2000,
  29. /// <summary>The third mouse button was released.</summary>
  30. Button3Released = 0x1000,
  31. /// <summary>The third mouse button was clicked (press+release).</summary>
  32. Button3Clicked = 0x4000,
  33. /// <summary>The third mouse button was double-clicked.</summary>
  34. Button3DoubleClicked = 0x8000,
  35. /// <summary>The third mouse button was triple-clicked.</summary>
  36. Button3TripleClicked = 0x10000,
  37. /// <summary>The fourth mouse button was pressed.</summary>
  38. Button4Pressed = 0x80000,
  39. /// <summary>The fourth mouse button was released.</summary>
  40. Button4Released = 0x40000,
  41. /// <summary>The fourth button was clicked (press+release).</summary>
  42. Button4Clicked = 0x100000,
  43. /// <summary>The fourth button was double-clicked.</summary>
  44. Button4DoubleClicked = 0x200000,
  45. /// <summary>The fourth button was triple-clicked.</summary>
  46. Button4TripleClicked = 0x400000,
  47. /// <summary>Flag: the shift key was pressed when the mouse button took place.</summary>
  48. ButtonShift = 0x2000000,
  49. /// <summary>Flag: the ctrl key was pressed when the mouse button took place.</summary>
  50. ButtonCtrl = 0x1000000,
  51. /// <summary>Flag: the alt key was pressed when the mouse button took place.</summary>
  52. ButtonAlt = 0x4000000,
  53. /// <summary>The mouse position is being reported in this event.</summary>
  54. ReportMousePosition = 0x8000000,
  55. /// <summary>Vertical button wheeled up.</summary>
  56. WheeledUp = 0x10000000,
  57. /// <summary>Vertical button wheeled down.</summary>
  58. WheeledDown = 0x20000000,
  59. /// <summary>Vertical button wheeled up while pressing ButtonShift.</summary>
  60. WheeledLeft = ButtonShift | WheeledUp,
  61. /// <summary>Vertical button wheeled down while pressing ButtonShift.</summary>
  62. WheeledRight = ButtonShift | WheeledDown,
  63. /// <summary>Mask that captures all the events.</summary>
  64. AllEvents = 0x7ffffff
  65. }
  66. // TODO: Merge MouseEvent and MouseEventEventArgs into a single class.
  67. /// <summary>
  68. /// Low-level construct that conveys the details of mouse events, such as coordinates and button state, from
  69. /// ConsoleDrivers up to <see cref="Application"/> and Views.
  70. /// </summary>
  71. /// <remarks>
  72. /// The <see cref="Application"/> class includes the <see cref="Application.MouseEvent"/> Action which takes a
  73. /// MouseEvent argument.
  74. /// </remarks>
  75. public class MouseEvent
  76. {
  77. /// <summary>Flags indicating the kind of mouse event that is being posted.</summary>
  78. public MouseFlags Flags { get; set; }
  79. /// <summary>
  80. /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other
  81. /// event subscriber. Its important to set this value to true specially when updating any View's layout from inside the
  82. /// subscriber method.
  83. /// </summary>
  84. public bool Handled { get; set; }
  85. /// <summary>The offset X (column) location for the mouse event.</summary>
  86. public int OfX { get; set; }
  87. /// <summary>The offset Y (column) location for the mouse event.</summary>
  88. public int OfY { get; set; }
  89. /// <summary>The current view at the location for the mouse event.</summary>
  90. public View View { get; set; }
  91. /// <summary>The X (column) location for the mouse event.</summary>
  92. public int X { get; set; }
  93. /// <summary>The Y (column) location for the mouse event.</summary>
  94. public int Y { get; set; }
  95. /// <summary>Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</summary>
  96. /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</returns>
  97. public override string ToString () { return $"({X},{Y}):{Flags}"; }
  98. }