Detect single tap on mobile as mouse click.
This commit is contained in:
parent
712b75e208
commit
6e9eea126a
@ -164,6 +164,11 @@ OV.TouchInteraction = class
|
|||||||
return this.fingers;
|
return this.fingers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetPosition ()
|
||||||
|
{
|
||||||
|
return this.currPos;
|
||||||
|
}
|
||||||
|
|
||||||
GetMoveDiff ()
|
GetMoveDiff ()
|
||||||
{
|
{
|
||||||
return this.diffPos;
|
return this.diffPos;
|
||||||
@ -204,21 +209,41 @@ OV.ClickDetector = class
|
|||||||
constructor ()
|
constructor ()
|
||||||
{
|
{
|
||||||
this.isClick = false;
|
this.isClick = false;
|
||||||
|
this.startPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Down ()
|
Start (startPosition)
|
||||||
{
|
{
|
||||||
this.isClick = true;
|
this.isClick = true;
|
||||||
|
this.startPosition = startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
Move ()
|
Move (currentPosition)
|
||||||
{
|
{
|
||||||
this.isClick = false;
|
if (!this.isClick) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.startPosition !== null) {
|
||||||
|
const maxClickDistance = 3.0;
|
||||||
|
const currentDistance = OV.CoordDistance2D (this.startPosition, currentPosition);
|
||||||
|
if (currentDistance > maxClickDistance) {
|
||||||
|
this.isClick = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.isClick = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Leave ()
|
End ()
|
||||||
|
{
|
||||||
|
this.startPosition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cancel ()
|
||||||
{
|
{
|
||||||
this.isClick = false;
|
this.isClick = false;
|
||||||
|
this.startPosition = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsClick ()
|
IsClick ()
|
||||||
@ -395,13 +420,13 @@ OV.Navigation = class
|
|||||||
ev.preventDefault ();
|
ev.preventDefault ();
|
||||||
|
|
||||||
this.mouse.Down (this.canvas, ev);
|
this.mouse.Down (this.canvas, ev);
|
||||||
this.clickDetector.Down ();
|
this.clickDetector.Start (this.mouse.GetPosition ());
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseMove (ev)
|
OnMouseMove (ev)
|
||||||
{
|
{
|
||||||
this.mouse.Move (this.canvas, ev);
|
this.mouse.Move (this.canvas, ev);
|
||||||
this.clickDetector.Move ();
|
this.clickDetector.Move (this.mouse.GetPosition ());
|
||||||
if (this.onMouseMove) {
|
if (this.onMouseMove) {
|
||||||
let mouseCoords = OV.GetClientCoordinates (this.canvas, ev.clientX, ev.clientY);
|
let mouseCoords = OV.GetClientCoordinates (this.canvas, ev.clientX, ev.clientY);
|
||||||
this.onMouseMove (mouseCoords);
|
this.onMouseMove (mouseCoords);
|
||||||
@ -445,6 +470,7 @@ OV.Navigation = class
|
|||||||
OnMouseUp (ev)
|
OnMouseUp (ev)
|
||||||
{
|
{
|
||||||
this.mouse.Up (this.canvas, ev);
|
this.mouse.Up (this.canvas, ev);
|
||||||
|
this.clickDetector.End ();
|
||||||
|
|
||||||
if (this.clickDetector.IsClick ()) {
|
if (this.clickDetector.IsClick ()) {
|
||||||
let mouseCoords = this.mouse.GetPosition ();
|
let mouseCoords = this.mouse.GetPosition ();
|
||||||
@ -455,7 +481,7 @@ OV.Navigation = class
|
|||||||
OnMouseLeave (ev)
|
OnMouseLeave (ev)
|
||||||
{
|
{
|
||||||
this.mouse.Leave (this.canvas, ev);
|
this.mouse.Leave (this.canvas, ev);
|
||||||
this.clickDetector.Leave ();
|
this.clickDetector.Cancel ();
|
||||||
}
|
}
|
||||||
|
|
||||||
OnTouchStart (ev)
|
OnTouchStart (ev)
|
||||||
@ -463,6 +489,7 @@ OV.Navigation = class
|
|||||||
ev.preventDefault ();
|
ev.preventDefault ();
|
||||||
|
|
||||||
this.touch.Start (this.canvas, ev);
|
this.touch.Start (this.canvas, ev);
|
||||||
|
this.clickDetector.Start (this.touch.GetPosition ());
|
||||||
}
|
}
|
||||||
|
|
||||||
OnTouchMove (ev)
|
OnTouchMove (ev)
|
||||||
@ -470,6 +497,7 @@ OV.Navigation = class
|
|||||||
ev.preventDefault ();
|
ev.preventDefault ();
|
||||||
|
|
||||||
this.touch.Move (this.canvas, ev);
|
this.touch.Move (this.canvas, ev);
|
||||||
|
this.clickDetector.Move (this.touch.GetPosition ());
|
||||||
if (!this.touch.IsFingerDown ()) {
|
if (!this.touch.IsFingerDown ()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -495,6 +523,14 @@ OV.Navigation = class
|
|||||||
ev.preventDefault ();
|
ev.preventDefault ();
|
||||||
|
|
||||||
this.touch.End (this.canvas, ev);
|
this.touch.End (this.canvas, ev);
|
||||||
|
this.clickDetector.End ();
|
||||||
|
|
||||||
|
if (this.clickDetector.IsClick ()) {
|
||||||
|
let touchCoords = this.touch.GetPosition ();
|
||||||
|
if (this.touch.GetFingerCount () === 1) {
|
||||||
|
this.Click (1, touchCoords);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnMouseWheel (ev)
|
OnMouseWheel (ev)
|
||||||
@ -519,6 +555,7 @@ OV.Navigation = class
|
|||||||
|
|
||||||
if (this.clickDetector.IsClick ()) {
|
if (this.clickDetector.IsClick ()) {
|
||||||
this.Context (ev.clientX, ev.clientY);
|
this.Context (ev.clientX, ev.clientY);
|
||||||
|
this.clickDetector.Cancel ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user