getTouchPoint method
Gets the x,y
position in pixels from mouse or touch event e
.
If several fingers touched, the first touch point is returned.
x,y
is relative to the page.
Implementation
// * Supported in Chrome, the following code works in Javascript.
// * How to do it in dart? There is class Navigator without vibrate.
// */
//void vibrate(int millisecs)
//{
// var navigator = window.navigator;
//
// navigator.vibrate(1000);
// // enable vibration support
// navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
//
// if (navigator.vibrate) {
// // vibration API supported
// }
//}
/// Gets the [x,y] position in pixels from mouse or touch event [e].
/// If several fingers touched, the first touch point is returned.
/// [x,y] is relative to the page.
static Point<int> getTouchPoint(UIEvent e) {
int x, y;
if (e is MouseEvent) {
x = (e.page.x).toInt();
y = (e.page.y).toInt();
} else if (e is TouchEvent && e.touches.isNotEmpty) {
x = (e.touches[0].page.x).toInt();
y = (e.touches[0].page.y).toInt();
} else {
x = 0;
y = 0;
}
return new Point(x, y);
}