RawPointerEventArgs.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Avalonia.Input.Raw
  4. {
  5. public enum RawPointerEventType
  6. {
  7. LeaveWindow,
  8. LeftButtonDown,
  9. LeftButtonUp,
  10. RightButtonDown,
  11. RightButtonUp,
  12. MiddleButtonDown,
  13. MiddleButtonUp,
  14. XButton1Down,
  15. XButton1Up,
  16. XButton2Down,
  17. XButton2Up,
  18. Move,
  19. Wheel,
  20. NonClientLeftButtonDown,
  21. TouchBegin,
  22. TouchUpdate,
  23. TouchEnd,
  24. TouchCancel,
  25. Magnify,
  26. Rotate,
  27. Swipe
  28. }
  29. /// <summary>
  30. /// A raw mouse event.
  31. /// </summary>
  32. public class RawPointerEventArgs : RawInputEventArgs
  33. {
  34. private RawPointerPoint _point;
  35. /// <summary>
  36. /// Initializes a new instance of the <see cref="RawPointerEventArgs"/> class.
  37. /// </summary>
  38. /// <param name="device">The associated device.</param>
  39. /// <param name="timestamp">The event timestamp.</param>
  40. /// <param name="root">The root from which the event originates.</param>
  41. /// <param name="type">The type of the event.</param>
  42. /// <param name="position">The mouse position, in client DIPs.</param>
  43. /// <param name="inputModifiers">The input modifiers.</param>
  44. public RawPointerEventArgs(
  45. IInputDevice device,
  46. ulong timestamp,
  47. IInputRoot root,
  48. RawPointerEventType type,
  49. Point position,
  50. RawInputModifiers inputModifiers)
  51. : base(device, timestamp, root)
  52. {
  53. Contract.Requires<ArgumentNullException>(device != null);
  54. Contract.Requires<ArgumentNullException>(root != null);
  55. Point = new RawPointerPoint();
  56. Position = position;
  57. Type = type;
  58. InputModifiers = inputModifiers;
  59. }
  60. /// <summary>
  61. /// Initializes a new instance of the <see cref="RawPointerEventArgs"/> class.
  62. /// </summary>
  63. /// <param name="device">The associated device.</param>
  64. /// <param name="timestamp">The event timestamp.</param>
  65. /// <param name="root">The root from which the event originates.</param>
  66. /// <param name="type">The type of the event.</param>
  67. /// <param name="point">The point properties and position, in client DIPs.</param>
  68. /// <param name="inputModifiers">The input modifiers.</param>
  69. public RawPointerEventArgs(
  70. IInputDevice device,
  71. ulong timestamp,
  72. IInputRoot root,
  73. RawPointerEventType type,
  74. RawPointerPoint point,
  75. RawInputModifiers inputModifiers)
  76. : base(device, timestamp, root)
  77. {
  78. Contract.Requires<ArgumentNullException>(device != null);
  79. Contract.Requires<ArgumentNullException>(root != null);
  80. Point = point;
  81. Type = type;
  82. InputModifiers = inputModifiers;
  83. }
  84. /// <summary>
  85. /// Gets the raw pointer identifier.
  86. /// </summary>
  87. public long RawPointerId { get; set; }
  88. /// <summary>
  89. /// Gets the pointer properties and position, in client DIPs.
  90. /// </summary>
  91. public RawPointerPoint Point
  92. {
  93. get => _point;
  94. set => _point = value;
  95. }
  96. /// <summary>
  97. /// Gets the mouse position, in client DIPs.
  98. /// </summary>
  99. public Point Position
  100. {
  101. get => _point.Position;
  102. set => _point.Position = value;
  103. }
  104. /// <summary>
  105. /// Gets the type of the event.
  106. /// </summary>
  107. public RawPointerEventType Type { get; set; }
  108. /// <summary>
  109. /// Gets the input modifiers.
  110. /// </summary>
  111. public RawInputModifiers InputModifiers { get; set; }
  112. /// <summary>
  113. /// Points that were traversed by a pointer since the previous relevant event,
  114. /// only valid for Move and TouchUpdate
  115. /// </summary>
  116. public Lazy<IReadOnlyList<RawPointerPoint>?>? IntermediatePoints { get; set; }
  117. internal IInputElement? InputHitTestResult { get; set; }
  118. }
  119. public struct RawPointerPoint
  120. {
  121. /// <summary>
  122. /// Pointer position, in client DIPs.
  123. /// </summary>
  124. public Point Position { get; set; }
  125. public float Twist { get; set; }
  126. public float Pressure { get; set; }
  127. public float XTilt { get; set; }
  128. public float YTilt { get; set; }
  129. public RawPointerPoint()
  130. {
  131. this = default;
  132. Pressure = 0.5f;
  133. }
  134. }
  135. }