MouseEventArgs.cs 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.ComponentModel;
  2. namespace Terminal.Gui.Input;
  3. /// <summary>
  4. /// Specifies the event arguments for <see cref="MouseEventArgs"/>.
  5. /// </summary>
  6. public class MouseEventArgs : HandledEventArgs
  7. {
  8. /// <summary>
  9. /// Flags indicating the state of the mouse buttons and the type of event that occurred.
  10. /// </summary>
  11. public MouseFlags Flags { get; set; }
  12. /// <summary>
  13. /// The screen-relative mouse position.
  14. /// </summary>
  15. public Point ScreenPosition { get; set; }
  16. /// <summary>The deepest View who's <see cref="View.Frame"/> contains <see cref="ScreenPosition"/>.</summary>
  17. public View? View { get; set; }
  18. /// <summary>
  19. /// The position of the mouse in <see cref="View"/>'s Viewport-relative coordinates. Only valid if <see cref="View"/>
  20. /// is set.
  21. /// </summary>
  22. public Point Position { get; set; }
  23. /// <summary>
  24. /// Gets whether <see cref="Flags"/> contains any of the button pressed related flags.
  25. /// </summary>
  26. public bool IsPressed => Flags.HasFlag (MouseFlags.Button1Pressed)
  27. || Flags.HasFlag (MouseFlags.Button2Pressed)
  28. || Flags.HasFlag (MouseFlags.Button3Pressed)
  29. || Flags.HasFlag (MouseFlags.Button4Pressed);
  30. /// <summary>
  31. /// Gets whether <see cref="Flags"/> contains any of the button released related flags.
  32. /// </summary>
  33. public bool IsReleased => Flags.HasFlag (MouseFlags.Button1Released)
  34. || Flags.HasFlag (MouseFlags.Button2Released)
  35. || Flags.HasFlag (MouseFlags.Button3Released)
  36. || Flags.HasFlag (MouseFlags.Button4Released);
  37. /// <summary>
  38. /// Gets whether <see cref="Flags"/> contains any of the single-clicked related flags.
  39. /// </summary>
  40. public bool IsSingleClicked => Flags.HasFlag (MouseFlags.Button1Clicked)
  41. || Flags.HasFlag (MouseFlags.Button2Clicked)
  42. || Flags.HasFlag (MouseFlags.Button3Clicked)
  43. || Flags.HasFlag (MouseFlags.Button4Clicked);
  44. /// <summary>
  45. /// Gets whether <see cref="Flags"/> contains any of the double-clicked related flags.
  46. /// </summary>
  47. public bool IsDoubleClicked => Flags.HasFlag (MouseFlags.Button1DoubleClicked)
  48. || Flags.HasFlag (MouseFlags.Button2DoubleClicked)
  49. || Flags.HasFlag (MouseFlags.Button3DoubleClicked)
  50. || Flags.HasFlag (MouseFlags.Button4DoubleClicked);
  51. /// <summary>
  52. /// Gets whether <see cref="Flags"/> contains any of the triple-clicked related flags.
  53. /// </summary>
  54. public bool IsTripleClicked => Flags.HasFlag (MouseFlags.Button1TripleClicked)
  55. || Flags.HasFlag (MouseFlags.Button2TripleClicked)
  56. || Flags.HasFlag (MouseFlags.Button3TripleClicked)
  57. || Flags.HasFlag (MouseFlags.Button4TripleClicked);
  58. /// <summary>
  59. /// Gets whether <see cref="Flags"/> contains any of the mouse button clicked related flags.
  60. /// </summary>
  61. public bool IsSingleDoubleOrTripleClicked =>
  62. Flags.HasFlag (MouseFlags.Button1Clicked)
  63. || Flags.HasFlag (MouseFlags.Button2Clicked)
  64. || Flags.HasFlag (MouseFlags.Button3Clicked)
  65. || Flags.HasFlag (MouseFlags.Button4Clicked)
  66. || Flags.HasFlag (MouseFlags.Button1DoubleClicked)
  67. || Flags.HasFlag (MouseFlags.Button2DoubleClicked)
  68. || Flags.HasFlag (MouseFlags.Button3DoubleClicked)
  69. || Flags.HasFlag (MouseFlags.Button4DoubleClicked)
  70. || Flags.HasFlag (MouseFlags.Button1TripleClicked)
  71. || Flags.HasFlag (MouseFlags.Button2TripleClicked)
  72. || Flags.HasFlag (MouseFlags.Button3TripleClicked)
  73. || Flags.HasFlag (MouseFlags.Button4TripleClicked);
  74. /// <summary>
  75. /// Gets whether <see cref="Flags"/> contains any of the mouse wheel related flags.
  76. /// </summary>
  77. public bool IsWheel => Flags.HasFlag (MouseFlags.WheeledDown)
  78. || Flags.HasFlag (MouseFlags.WheeledUp)
  79. || Flags.HasFlag (MouseFlags.WheeledLeft)
  80. || Flags.HasFlag (MouseFlags.WheeledRight);
  81. /// <summary>Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEventArgs"/>.</summary>
  82. /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEventArgs"/>.</returns>
  83. public override string ToString () { return $"({ScreenPosition}):{Flags}:{View?.Id}:{Position}"; }
  84. }