/// <summary> /// Initializes a new instance of the <see cref="SwipeRecognizer"/> class. /// </summary> /// <param name="view">The native view.</param> /// <param name="directionMask">Optional swipe direction mask.</param> /// <param name="numberOfTouchesRequired">Optional number of touches required.</param> public SwipeRecognizer(NSView view, SwipeDirection directionMask = Defaults.DirectionMask, int numberOfTouchesRequired = Defaults.NumberofTouchesRequired) : base(view, directionMask, numberOfTouchesRequired) { _recognizer = new NSPanGestureRecognizer(OnSwiping); view.AddGestureRecognizer(_recognizer); void OnSwiping(NSPanGestureRecognizer recognizer) { var point = recognizer.LocationInView(View); switch (recognizer.State) { case NSGestureRecognizerState.Began: OnTouchesBegan(point.X, point.Y); OnSwipeBegan(point.X, point.Y); break; case NSGestureRecognizerState.Cancelled: case NSGestureRecognizerState.Failed: OnSwipeCancelled(); OnTouchesEnded(point.X, point.Y); break; case NSGestureRecognizerState.Ended: OnSwipeEnded(point.X, point.Y); OnTouchesEnded(point.X, point.Y); break; } } }
void MapPanned(NSPanGestureRecognizer obj) { var p = obj.TranslationInView(CanvasView); var pp = new SKPoint((float)(_canvasSize.Width * p.X / CanvasView.Bounds.Width), (float)(_canvasSize.Height - (_canvasSize.Height * p.Y / CanvasView.Bounds.Height))); pp = _im.MapPoint(pp); if (!_isPanZoom) { StartPanZoom(new SKPoint((float)pp.X, (float)pp.Y)); } if (_isPanZoom) { _totalDistance = new SKPoint((float)p.X, 1 - (float)p.Y); DoPanZoom(_startM, _startAnchorPt, _totalDistance, _totalScale); } NSCursor.ClosedHandCursor.Set(); if (obj.State == NSGestureRecognizerState.Ended) { NSCursor.ArrowCursor.Set(); _isPanZoom = false; _m.TryInvert(out _im); } }
public override async void ViewDidLoad() { base.ViewDidLoad(); CanvasView.PaintSurface += CanvasView_PaintSurface; var pan = new NSPanGestureRecognizer(MapPanned); var zoom = new NSMagnificationGestureRecognizer(MapZoomed); _screenScale = (float)NSScreen.MainScreen.BackingScaleFactor; _canvasSize = new SKSize(20000, 2000); CanvasView.AddGestureRecognizer(zoom); CanvasView.AddGestureRecognizer(pan); //load images for (int i = 1; i < 16; i++) { var img = await ImageService.Instance.LoadFileFromApplicationBundle("img/img" + i + ".jpg").AsNSImageAsync(); var sizeRandom = rand.NextDouble() * (1.2 - 0.2) + 0.2; var size = new SKSize((float)(img.Size.Width * sizeRandom), (float)(img.Size.Height * sizeRandom)); var rect = SKRect.Empty; rect.Size = size; var pointRandomW = rand.NextDouble() * (_canvasSize.Width - 0) + 0; var pointRandomH = rand.NextDouble() * (_canvasSize.Height - 0) + 0; rect.Location = new SKPoint((float)pointRandomW, (float)pointRandomH); rects.Add(rect); imgs.Add(img.ToSKImage()); } }
/// <summary> /// Initializes a new instance of the <see cref="PanRecognizer"/> class. /// </summary> /// <param name="view">The native view.</param> public PanRecognizer(NSView view) : base(view) { _recognizer = new NSPanGestureRecognizer(OnPanning); view.AddGestureRecognizer(_recognizer); void OnPanning(NSPanGestureRecognizer recognizer) { var point = recognizer.LocationInView(View); switch (recognizer.State) { case NSGestureRecognizerState.Began: OnTouchesBegan(point.X, point.Y); OnPanningStateChanged(GestureState.Began); break; case NSGestureRecognizerState.Changed: var translation = recognizer.TranslationInView(view); OnPanningDeltaChanged(translation.X, translation.Y); break; case NSGestureRecognizerState.Cancelled: OnPanningStateChanged(GestureState.Cancelled); OnTouchesEnded(point.X, point.Y); break; case NSGestureRecognizerState.Failed: OnPanningStateChanged(GestureState.Failed); OnTouchesEnded(point.X, point.Y); break; case NSGestureRecognizerState.Ended: OnPanningStateChanged(GestureState.Ended); OnTouchesEnded(point.X, point.Y); break; } } }
NSPanGestureRecognizer CreatePanRecognizer(int numTouches, Action <NSPanGestureRecognizer> action) { var result = new NSPanGestureRecognizer(action); return(result); }