//this method when we touch or drag the finger on the screen while scratching.. private void TouchEffect_TouchAction(object sender, TouchTracking.TouchActionEventArgs args) { switch (args.Type) { case TouchActionType.Pressed: if (!inProgressPaths.ContainsKey(args.Id)) { SKPath path = new SKPath(); path.MoveTo(ConvertToPixel(args.Location)); inProgressPaths.Add(args.Id, path); canvasView.InvalidateSurface(); } break; case TouchActionType.Moved: if (inProgressPaths.ContainsKey(args.Id)) { SKPath path = inProgressPaths[args.Id]; path.LineTo(ConvertToPixel(args.Location)); canvasView.InvalidateSurface(); } break; case TouchActionType.Released: if (inProgressPaths.ContainsKey(args.Id)) { completedPaths.Add(inProgressPaths[args.Id]); inProgressPaths.Remove(args.Id); canvasView.InvalidateSurface(); } break; case TouchActionType.Cancelled: if (inProgressPaths.ContainsKey(args.Id)) { inProgressPaths.Remove(args.Id); canvasView.InvalidateSurface(); } break; } }
public void OnTouchAction(Element element, TouchActionEventArgs args) { TouchAction?.Invoke(element, args); }
private void OnTouchEffectAction(object sender, TouchTracking.TouchActionEventArgs args) { Point pt = args.Location; SKPoint point = new SKPoint((float)(canvasView.CanvasSize.Width * pt.X / canvasView.Width), (float)(canvasView.CanvasSize.Height * pt.Y / canvasView.Height)); switch (args.Type) { case TouchActionType.Pressed: if (!touchDictionary.ContainsKey(args.Id)) { touchDictionary.Add(args.Id, point); } //SetPixelsValue(args, view); break; case TouchActionType.Moved: if (touchDictionary.ContainsKey(args.Id)) { this.quickViewUpdateMode = true; if (renderingMode == RenderingMode.DoubleBuffering) { Device.StartTimer(TimeSpan.FromMilliseconds(300), () => { // MainThread.BeginInvokeOnMainThread(() => // { Draw(); // }); return(this.quickViewUpdateMode); }); } if (touchDictionary.Count == 1) { long[] keys = new long[touchDictionary.Count]; touchDictionary.Keys.CopyTo(keys, 0); // Find index of non-moving (pivot) finger int pivotIndex = (keys[0] == args.Id) ? 1 : 0; // Get the three points involved in the transform // SKPoint pivotPoint = touchDictionary[keys[pivotIndex]]; SKPoint prevPoint = touchDictionary[args.Id]; SKPoint newPoint = point; SKPoint delta = newPoint - prevPoint; // new_p = newPoint; old_p = prevPoint; SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(delta.X, delta.Y)); SKMatrix.PostConcat(ref bitmapMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y)); touchDictionary[args.Id] = point; } else if (touchDictionary.Count >= 2) { // Copy two dictionary keys into array long[] keys = new long[touchDictionary.Count]; touchDictionary.Keys.CopyTo(keys, 0); int pivotIndex = (keys[0] == args.Id) ? 1 : 0; SKPoint pivotPoint = touchDictionary[keys[pivotIndex]]; SKPoint prevPoint = touchDictionary[args.Id]; SKPoint newPoint = point; double distance = Math.Sqrt(Math.Pow(Math.Abs(pivotPoint.X - newPoint.X), 2) + Math.Pow(Math.Abs(pivotPoint.Y - newPoint.Y), 2)); double oldDistance = Math.Sqrt(Math.Pow(Math.Abs(pivotPoint.X - prevPoint.X), 2) + Math.Pow(Math.Abs(pivotPoint.Y - prevPoint.Y), 2)); double differentDistance = distance / oldDistance; SKPoint centerPoint = new SKPoint() { X = (newPoint.X + pivotPoint.X) / 2, Y = (newPoint.Y + pivotPoint.Y) / 2 }; SKPoint oldCenterPoint = new SKPoint() { X = (prevPoint.X + pivotPoint.X) / 2, Y = (prevPoint.Y + pivotPoint.Y) / 2 }; SKMatrix translationMatrix = SKMatrix.CreateTranslation((centerPoint.X - oldCenterPoint.X) /*/matrix.ScaleX*/, (centerPoint.Y - oldCenterPoint.Y) /*/ matrix.ScaleX*/); SKMatrix scaleMatrix = SKMatrix.Identity; if (!(matrix.ScaleX > 8 && differentDistance > 1)) { scaleMatrix = SKMatrix.CreateScale((float)differentDistance, (float)differentDistance, centerPoint.X, centerPoint.Y /* pivotPoint.X, pivotPoint.Y*/); } SKMatrix.PostConcat(ref matrix, scaleMatrix); // NEW "PostContact() DOES NOT WORKING CORRECTLY!!!" SKMatrix.PostConcat(ref matrix, translationMatrix); SKMatrix.PostConcat(ref bitmapMatrix, scaleMatrix); // NEW "PostContact() DOES NOT WORKING CORRECTLY!!!" SKMatrix.PostConcat(ref bitmapMatrix, translationMatrix); touchDictionary[args.Id] = point; } } break; case TouchActionType.Released: case TouchActionType.Cancelled: if (touchDictionary.ContainsKey(args.Id)) { touchDictionary.Remove(args.Id); } if (matrix.ScaleX < 0.2) { matrix = SKMatrix.MakeIdentity(); } //resetScale(); this.quickViewUpdateMode = false; updateBitmap(); break; } this.canvasView.InvalidateSurface(); }
private void OnTouch (object sender, TouchTracking.TouchActionEventArgs args) { // Convert touch point to pixel point _touch.Current = SkiaSharpHelper.ToPixel(args.Location.X, args.Location.Y, ref thumbsCanvas); // Check bounds if (_touch.Current.X < _thumbsCanvasInfo.ImageInfo.Rect.Left || _touch.Current.X > _thumbsCanvasInfo.ImageInfo.Rect.Right) { return; } // Check touch type switch (args.Type) { case TouchActionType.Pressed: _touch.Matrix = SKMatrix.MakeIdentity(); // Adjust thumbs bounds _leftThumbDraw.Bounds = new SKRect (_leftThumbDraw.Point.X - _leftThumbDraw.Radius, _leftThumbDraw.Point.Y - _leftThumbDraw.Radius , _leftThumbDraw.Point.X + _leftThumbDraw.Radius, _leftThumbDraw.Point.Y + _leftThumbDraw.Radius); _rightThumbDraw.Bounds = new SKRect (_rightThumbDraw.Point.X - _rightThumbDraw.Radius, _rightThumbDraw.Point.Y - _rightThumbDraw.Radius , _rightThumbDraw.Point.X + _rightThumbDraw.Radius, _rightThumbDraw.Point.Y + _rightThumbDraw.Radius); // Check if the inner circle was touched if (_leftThumbDraw.Bounds.Contains(_touch.Current) && _rightThumbDraw.Bounds.Contains(_touch.Current)) { _touch.Id = args.Id; _touch.Previous = _touch.Current; _activeThumb = _lastActiveThumb; } else if (_leftThumbDraw.Bounds.Contains(_touch.Current)) { _touch.Id = args.Id; _touch.Previous = _touch.Current; _activeThumb = ActiveThumb.Left; } else if (_rightThumbDraw.Bounds.Contains(_touch.Current)) { _touch.Id = args.Id; _touch.Previous = _touch.Current; _activeThumb = ActiveThumb.Right; } break; case TouchActionType.Moved: if (_touch.Id == args.Id) { // Adjust the matrix for the new position _touch.Matrix.TransX += _touch.Current.X - _touch.Previous.X; _touch.Matrix.TransY += _touch.Current.Y - _touch.Previous.Y; _touch.Previous = _touch.Current; var value = GetThumbValue(_touch.Current); // Check active thumb if (_activeThumb == ActiveThumb.Left) { Thumbs.Left.Value = value; Start = value; } else if (_activeThumb == ActiveThumb.Right) { Thumbs.Right.Value = value; End = value; } // Update value thumbsCanvas.InvalidateSurface(); } break; case TouchActionType.Released: case TouchActionType.Cancelled: { _touch.Id = -1; _lastActiveThumb = _activeThumb; } break; } }