private void DetectPinchAndPanGestures(TouchActionType touchActionType) { TouchManipulationInfo[] infos = new TouchManipulationInfo[_touchDictionary.Count]; _touchDictionary.Values.CopyTo(infos, 0); if (infos.Length == 1) { SKPoint previousPoint = infos[0].PreviousPoint; SKPoint newPoint = infos[0].NewPoint; OnPan?.Invoke(this, new PanEventArgs(previousPoint, newPoint, touchActionType)); } else if (infos.Length >= 2) { int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1; SKPoint pivotPoint = infos[pivotIndex].NewPoint; SKPoint newPoint = infos[1 - pivotIndex].NewPoint; SKPoint previousPoint = infos[1 - pivotIndex].PreviousPoint; OnPinch?.Invoke(this, new PinchEventArgs(previousPoint, newPoint, pivotPoint, touchActionType)); } }
public bool ProcessTouchEvent(long id, TouchActionType type, SKPoint location) { bool centerMoved = false; // Assumes Capture property of TouchEffect is true! switch (type) { case TouchActionType.Pressed: if (!isBeingDragged && PointInCircle(location)) { isBeingDragged = true; touchId = id; previousPoint = location; centerMoved = false; } break; case TouchActionType.Moved: if (isBeingDragged && touchId == id) { Center += location - previousPoint; previousPoint = location; centerMoved = true; } break; case TouchActionType.Released: if (isBeingDragged && touchId == id) { Center += location - previousPoint; isBeingDragged = false; centerMoved = true; } break; case TouchActionType.Cancelled: isBeingDragged = false; break; } return(centerMoved); }
private void FireEvent( TouchEffect touchEffect, int id, TouchActionType actionType, Point pointerLocation, bool isInContact) { // Get the method to call for firing events Action <Element, TouchActionEventArgs> onTouchAction = touchEffect.libTouchEffect.OnTouchAction; // Get the location of the pointer within the view touchEffect.view.GetLocationOnScreen(twoIntArray); double x = pointerLocation.X - twoIntArray[0]; double y = pointerLocation.Y - twoIntArray[1]; Point point = new Point(fromPixels(x), fromPixels(y)); // Call the method onTouchAction( touchEffect.formsElement, new TouchActionEventArgs(id, actionType, point, isInContact)); }
/// <summary> /// Determines which bitmap was pressed /// </summary> /// <param name="id"> TouchActionEventArgs Id</param> /// <param name="type"> TouchActionEventArgs Type </param> /// <param name="point"> Coordinates where the user has touched their screen </param> /// <returns> True if the user has touched one of our bitmaps currently displayed, otherwise false </returns> public bool TouchActionTypePressedHelper(long id, TouchActionType type, Point point) { var image = PressOnImageHelper(point); if (image is null) { return(false); } else if (image.Equals(ScanCircle)) { imageToTranslate = ScanCircle; return(true); } else if (image.Equals(VoteCircle)) { imageToTranslate = VoteCircle; return(true); } else { return(false); } }
private void FireEvent(MyTouchEffect myTouchEffect, int id, TouchActionType actionType, Point[] pointerLocations, bool isInContact) { // Get the method to call for firing events Action <Xamarin.Forms.Element, TouchActionEventArgs> onTouchAction = myTouchEffect.libMyTouchEffect.OnTouchAction; // Get the location of the pointer within the view int[] twoIntArray = new int[2]; myTouchEffect._view.GetLocationOnScreen(twoIntArray); List <Point> locations = new List <Point>(); foreach (var loc in pointerLocations) { var x = loc.X - twoIntArray[0]; var y = loc.Y - twoIntArray[1]; var point = new Point(_fromPixels(x), _fromPixels(y)); locations.Add(point); } // Call the method onTouchAction(myTouchEffect._formsElement, new TouchActionEventArgs(id, actionType, locations.ToArray(), isInContact)); }
private void ProcessGestureDelays(ref DateTime lastGestureTime, TimeSpan minGestureDuration, TouchActionType touchActionType) { if (touchActionType != TouchActionType.Moved) { lastGestureTime = DateTime.MinValue; _invalidateViewAction(); return; } var now = DateTime.Now; if (now - lastGestureTime < minGestureDuration) { return; } lastGestureTime = now; _invalidateViewAction(); }
public TouchActionEventArgs(int id, TouchActionType type, Point point, bool isInContact) { Type = type; Point = point; IsInContact = isInContact; }
public MensajeEventArgs(long id, TouchActionType type, Point location, bool isInContact, string Mensaje, int Estado) : base(id, type, location, isInContact) { _Mensaje = Mensaje; _Estado = Estado; }
public TileEventArgs(long id, TouchActionType type, Point location, bool isInContact) : base(id, type, location, isInContact) { }
public PanEventArgs(SKPoint previousPoint, SKPoint newPoint, TouchActionType touchActionType) { PreviousPoint = previousPoint; NewPoint = newPoint; TouchActionType = touchActionType; }
public PinchEventArgs(SKPoint previousPoint, SKPoint newPoint, SKPoint pivotPoint, TouchActionType touchActionType) { PreviousPoint = previousPoint; NewPoint = newPoint; PivotPoint = pivotPoint; TouchActionType = touchActionType; }
public TouchActionEventArgs(long id, TouchActionType type, Point location, bool isInContact) { Id = id; Type = type; Location = location; }
private void OnTouchEffectAction(TouchActionType type, SKPoint point) { switch (type) { case TouchActionType.Pressed: if (ticks == 0) { ticks = DateTime.Now.Ticks; Device.StartTimer(TimeSpan.FromMilliseconds(20), () => { canvasView.InvalidateSurface(); return(ticks != 0); }); } if (completedPaths != null) { Completed last = completedPaths.Last(); if (SKPoint.Distance(last.path.LastPoint, point) > radius / 2) { break; } } inProgressPath = new SKPath(); inProgressPath.MoveTo(point); canvasView.InvalidateSurface(); break; case TouchActionType.Moved: if (inProgressPath == null) { break; } inProgressPath.LineTo(point); // adding index of circle which was touched/passed SKPoint vec = inProgressPath.LastPoint - point; bool cross = false; foreach (Circle c in circleList) { if (circleList.IndexOf(c) == numCircles - 1 && c.fill == true) { if (ticks != 0) { double s = 0.01 * Math.Floor(0.00001 * (DateTime.Now.Ticks - ticks)); main.addResult(s, numCircles); ticks = 0; } endGameAsync(); return; } if (c.fill) { continue; } if (lineCross(point, vec, c.center)) { int ind = circleList.IndexOf(c); if (ind == 0 || circleList.ElementAt(ind - 1).fill) { c.fill = true; OnTouchEffectAction(TouchActionType.Released, point); turn = !turn; OnTouchEffectAction(TouchActionType.Pressed, point); cross = true; break; } break; } } if (!cross) { canvasView.InvalidateSurface(); } break; case TouchActionType.Released: if (inProgressPath == null) { break; } // My Random Color Implementation Random rand = new Random(); Byte[] rgb = new Byte[3]; rand.NextBytes(rgb); paint.Color = new SKColor(rgb[0], rgb[1], rgb[2]); Completed completed = new Completed(inProgressPath, turn ? 0 : 1); if (completedPaths == null) { completedPaths = new List <Completed>(); } completedPaths.Add(completed); inProgressPath = null; break; case TouchActionType.Cancelled: inProgressPath = null; canvasView.InvalidateSurface(); break; } }
public void ProcessTouchEvent(long id, TouchActionType type, SKPoint location) { TouchInfo info; switch (type) { case TouchActionType.Pressed: //we only handle 2 fingers if (touches.Count < 2) { touches.Add(id, new TouchInfo { InitialTime = DateTime.UtcNow, InitialPoint = location, PreviousPoint = location, NewPoint = location }); //check for LONGTAP CheckLongTapAsync(Timings.longTapMilliseconds, id); } break; case TouchActionType.Moved: info = touches[id]; if (info == null) { break; } info.NewPoint = location; if (touches.Count == 1) { //this is PAN SKPoint diff = info.NewPoint - info.PreviousPoint; OnGestureRecognized(this, new TouchGestureEventArgs(id, TouchGestureType.Pan, diff)); } else if (touches.Count == 2) { //this is PINCH TouchInfo info1 = touches.ElementAt(0).Value; TouchInfo info2 = touches.ElementAt(1).Value; SKPoint preDiff = new SKPoint(Math.Abs(info2.PreviousPoint.X - info1.PreviousPoint.X), Math.Abs(info2.PreviousPoint.Y - info1.PreviousPoint.Y)); SKPoint postDiff = new SKPoint(Math.Abs(info2.NewPoint.X - info1.NewPoint.X), Math.Abs(info2.NewPoint.Y - info1.NewPoint.Y)); SKPoint pinchData = postDiff - preDiff; OnGestureRecognized(this, new TouchGestureEventArgs(id, TouchGestureType.Pinch, pinchData)); } info.PreviousPoint = info.NewPoint; break; case TouchActionType.Released: info = touches[id]; if (info == null) { break; } info.NewPoint = location; if (touches.Count == 1) { SKPoint diff = info.NewPoint - info.InitialPoint; if (Math.Abs(diff.X) < 5 && Math.Abs(diff.Y) < 5) { //check for TAP TimeSpan timeDiff = DateTime.UtcNow - info.InitialTime; if (timeDiff < TimeSpan.FromMilliseconds(Timings.shortTapMilliseconds)) { OnGestureRecognized(this, new TouchGestureEventArgs(id, TouchGestureType.Tap, info.InitialPoint)); } } else { //check for SWIPE SKPoint lastDiff = info.NewPoint - info.PreviousPoint; if (Math.Abs(lastDiff.X) > 5 || Math.Abs(lastDiff.Y) > 5) { OnGestureRecognized(this, new TouchGestureEventArgs(id, TouchGestureType.Swipe, lastDiff)); } } } touches.Remove(id); break; case TouchActionType.Cancelled: touches.Remove(id); break; } }