1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5part of dart.ui; 6 7/// How the pointer has changed since the last report. 8enum PointerChange { 9 /// The input from the pointer is no longer directed towards this receiver. 10 cancel, 11 12 /// The device has started tracking the pointer. 13 /// 14 /// For example, the pointer might be hovering above the device, having not yet 15 /// made contact with the surface of the device. 16 add, 17 18 /// The device is no longer tracking the pointer. 19 /// 20 /// For example, the pointer might have drifted out of the device's hover 21 /// detection range or might have been disconnected from the system entirely. 22 remove, 23 24 /// The pointer has moved with respect to the device while not in contact with 25 /// the device. 26 hover, 27 28 /// The pointer has made contact with the device. 29 down, 30 31 /// The pointer has moved with respect to the device while in contact with the 32 /// device. 33 move, 34 35 /// The pointer has stopped making contact with the device. 36 up, 37} 38 39/// The kind of pointer device. 40enum PointerDeviceKind { 41 /// A touch-based pointer device. 42 touch, 43 44 /// A mouse-based pointer device. 45 mouse, 46 47 /// A pointer device with a stylus. 48 stylus, 49 50 /// A pointer device with a stylus that has been inverted. 51 invertedStylus, 52 53 /// An unknown pointer device. 54 unknown 55} 56 57/// The kind of [PointerDeviceKind.signal]. 58enum PointerSignalKind { 59 /// The event is not associated with a pointer signal. 60 none, 61 62 /// A pointer-generated scroll (e.g., mouse wheel or trackpad scroll). 63 scroll, 64 65 /// An unknown pointer signal kind. 66 unknown 67} 68 69/// Information about the state of a pointer. 70class PointerData { 71 /// Creates an object that represents the state of a pointer. 72 const PointerData({ 73 this.timeStamp = Duration.zero, 74 this.change = PointerChange.cancel, 75 this.kind = PointerDeviceKind.touch, 76 this.signalKind, 77 this.device = 0, 78 this.physicalX = 0.0, 79 this.physicalY = 0.0, 80 this.buttons = 0, 81 this.obscured = false, 82 this.pressure = 0.0, 83 this.pressureMin = 0.0, 84 this.pressureMax = 0.0, 85 this.distance = 0.0, 86 this.distanceMax = 0.0, 87 this.size = 0.0, 88 this.radiusMajor = 0.0, 89 this.radiusMinor = 0.0, 90 this.radiusMin = 0.0, 91 this.radiusMax = 0.0, 92 this.orientation = 0.0, 93 this.tilt = 0.0, 94 this.platformData = 0, 95 this.scrollDeltaX = 0.0, 96 this.scrollDeltaY = 0.0, 97 }); 98 99 /// Time of event dispatch, relative to an arbitrary timeline. 100 final Duration timeStamp; 101 102 /// How the pointer has changed since the last report. 103 final PointerChange change; 104 105 /// The kind of input device for which the event was generated. 106 final PointerDeviceKind kind; 107 108 /// The kind of signal for a pointer signal event. 109 final PointerSignalKind signalKind; 110 111 /// Unique identifier for the pointing device, reused across interactions. 112 final int device; 113 114 /// X coordinate of the position of the pointer, in physical pixels in the 115 /// global coordinate space. 116 final double physicalX; 117 118 /// Y coordinate of the position of the pointer, in physical pixels in the 119 /// global coordinate space. 120 final double physicalY; 121 122 /// Bit field using the *Button constants (primaryMouseButton, 123 /// secondaryStylusButton, etc). For example, if this has the value 6 and the 124 /// [kind] is [PointerDeviceKind.invertedStylus], then this indicates an 125 /// upside-down stylus with both its primary and secondary buttons pressed. 126 final int buttons; 127 128 /// Set if an application from a different security domain is in any way 129 /// obscuring this application's window. (Aspirational; not currently 130 /// implemented.) 131 final bool obscured; 132 133 /// The pressure of the touch as a number ranging from 0.0, indicating a touch 134 /// with no discernible pressure, to 1.0, indicating a touch with "normal" 135 /// pressure, and possibly beyond, indicating a stronger touch. For devices 136 /// that do not detect pressure (e.g. mice), returns 1.0. 137 final double pressure; 138 139 /// The minimum value that [pressure] can return for this pointer. For devices 140 /// that do not detect pressure (e.g. mice), returns 1.0. This will always be 141 /// a number less than or equal to 1.0. 142 final double pressureMin; 143 144 /// The maximum value that [pressure] can return for this pointer. For devices 145 /// that do not detect pressure (e.g. mice), returns 1.0. This will always be 146 /// a greater than or equal to 1.0. 147 final double pressureMax; 148 149 /// The distance of the detected object from the input surface (e.g. the 150 /// distance of a stylus or finger from a touch screen), in arbitrary units on 151 /// an arbitrary (not necessarily linear) scale. If the pointer is down, this 152 /// is 0.0 by definition. 153 final double distance; 154 155 /// The maximum value that a distance can return for this pointer. If this 156 /// input device cannot detect "hover touch" input events, then this will be 157 /// 0.0. 158 final double distanceMax; 159 160 /// The area of the screen being pressed, scaled to a value between 0 and 1. 161 /// The value of size can be used to determine fat touch events. This value 162 /// is only set on Android, and is a device specific approximation within 163 /// the range of detectable values. So, for example, the value of 0.1 could 164 /// mean a touch with the tip of the finger, 0.2 a touch with full finger, 165 /// and 0.3 the full palm. 166 final double size; 167 168 /// The radius of the contact ellipse along the major axis, in logical pixels. 169 final double radiusMajor; 170 171 /// The radius of the contact ellipse along the minor axis, in logical pixels. 172 final double radiusMinor; 173 174 /// The minimum value that could be reported for radiusMajor and radiusMinor 175 /// for this pointer, in logical pixels. 176 final double radiusMin; 177 178 /// The minimum value that could be reported for radiusMajor and radiusMinor 179 /// for this pointer, in logical pixels. 180 final double radiusMax; 181 182 /// For PointerDeviceKind.touch events: 183 /// 184 /// The angle of the contact ellipse, in radius in the range: 185 /// 186 /// -pi/2 < orientation <= pi/2 187 /// 188 /// ...giving the angle of the major axis of the ellipse with the y-axis 189 /// (negative angles indicating an orientation along the top-left / 190 /// bottom-right diagonal, positive angles indicating an orientation along the 191 /// top-right / bottom-left diagonal, and zero indicating an orientation 192 /// parallel with the y-axis). 193 /// 194 /// For PointerDeviceKind.stylus and PointerDeviceKind.invertedStylus events: 195 /// 196 /// The angle of the stylus, in radians in the range: 197 /// 198 /// -pi < orientation <= pi 199 /// 200 /// ...giving the angle of the axis of the stylus projected onto the input 201 /// surface, relative to the positive y-axis of that surface (thus 0.0 202 /// indicates the stylus, if projected onto that surface, would go from the 203 /// contact point vertically up in the positive y-axis direction, pi would 204 /// indicate that the stylus would go down in the negative y-axis direction; 205 /// pi/4 would indicate that the stylus goes up and to the right, -pi/2 would 206 /// indicate that the stylus goes to the left, etc). 207 final double orientation; 208 209 /// For PointerDeviceKind.stylus and PointerDeviceKind.invertedStylus events: 210 /// 211 /// The angle of the stylus, in radians in the range: 212 /// 213 /// 0 <= tilt <= pi/2 214 /// 215 /// ...giving the angle of the axis of the stylus, relative to the axis 216 /// perpendicular to the input surface (thus 0.0 indicates the stylus is 217 /// orthogonal to the plane of the input surface, while pi/2 indicates that 218 /// the stylus is flat on that surface). 219 final double tilt; 220 221 /// Opaque platform-specific data associated with the event. 222 final int platformData; 223 224 /// For events with signalKind of PointerSignalKind.scroll: 225 /// 226 /// The amount to scroll in the x direction, in physical pixels. 227 final double scrollDeltaX; 228 229 /// For events with signalKind of PointerSignalKind.scroll: 230 /// 231 /// The amount to scroll in the y direction, in physical pixels. 232 final double scrollDeltaY; 233 234 @override 235 String toString() => 'PointerData(x: $physicalX, y: $physicalY)'; 236 237 /// Returns a complete textual description of the information in this object. 238 String toStringFull() { 239 return '$runtimeType(' 240 'timeStamp: $timeStamp, ' 241 'change: $change, ' 242 'kind: $kind, ' 243 'signalKind: $signalKind, ' 244 'device: $device, ' 245 'physicalX: $physicalX, ' 246 'physicalY: $physicalY, ' 247 'buttons: $buttons, ' 248 'pressure: $pressure, ' 249 'pressureMin: $pressureMin, ' 250 'pressureMax: $pressureMax, ' 251 'distance: $distance, ' 252 'distanceMax: $distanceMax, ' 253 'size: $size, ' 254 'radiusMajor: $radiusMajor, ' 255 'radiusMinor: $radiusMinor, ' 256 'radiusMin: $radiusMin, ' 257 'radiusMax: $radiusMax, ' 258 'orientation: $orientation, ' 259 'tilt: $tilt, ' 260 'platformData: $platformData, ' 261 'scrollDeltaX: $scrollDeltaX, ' 262 'scrollDeltaY: $scrollDeltaY' 263 ')'; 264 } 265} 266 267/// A sequence of reports about the state of pointers. 268class PointerDataPacket { 269 /// Creates a packet of pointer data reports. 270 const PointerDataPacket({ this.data = const <PointerData>[] }); 271 272 /// Data about the individual pointers in this packet. 273 /// 274 /// This list might contain multiple pieces of data about the same pointer. 275 final List<PointerData> data; 276} 277