public void Transform(ref SKMatrix matrix) { pointTopLeft = matrix.MapPoint(pointTopLeft); pointTopRight = matrix.MapPoint(pointTopRight); pointBottomRight = matrix.MapPoint(pointBottomRight); pointBottomLeft = matrix.MapPoint(pointBottomLeft); }
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 Quad Transform(ref SKMatrix matrix) { pointTopLeft = matrix.MapPoint(pointTopLeft); pointTopRight = matrix.MapPoint(pointTopRight); pointBottomRight = matrix.MapPoint(pointBottomRight); pointBottomLeft = matrix.MapPoint(pointBottomLeft); return(this); }
private Color WheelPointToColor(SKPoint pointSV, SKPoint pointH) { if (RotateTriangleByHue) { SKMatrix rotationHue = SKMatrix.MakeRotation((float)(2D * Math.PI * lastHue + Math.PI / 2D)); pointSV = rotationHue.MapPoint(pointSV); } var polarH = ToPolar(pointH); var h = (-polarH.Angle + Math.PI) / (2 * Math.PI); pointSV.Y = -pointSV.Y + triangleVerticalOffset; pointSV.X += triangleSide; var x1 = triangleSide; var y1 = triangleHeight; var x2 = x1 * 2; var y2 = 0F; var vCurrent = ((pointSV.X * (y2 - y1)) - (pointSV.Y * (x2 - x1)) + (x2 * y1) - (y2 * x1)) / Math.Sqrt(Math.Pow(y2 - y1, 2) + Math.Pow(x2 - x1, 2)); var v = (y1 - vCurrent) / y1; var sMax = x2 - (vCurrent / Math.Sin(Math.PI / 3)); var sCurrent = pointSV.Y / Math.Sin(Math.PI / 3); var s = sCurrent / sMax; lastHue = h; var result = ColorFromHSV(h, s, v, SelectedColor.A); return(result); }
public static double MatrixToRadian(ref SKMatrix martrix, float pivotX = 0, float pivotY = 0) { SKPoint minuteFirstPoint = new SKPoint(1, 0); SKPoint minuteMapPoint = martrix.MapPoint(minuteFirstPoint); return(CaculateRotatedRadian(minuteFirstPoint, minuteMapPoint, new SKPoint(pivotX, pivotY))); }
private void OnCursorPosChanged(IntPtr window, double xPos, double yPos) { var localPos = _invViewTransform.MapPoint((float)xPos, (float)yPos); MousePositionX = localPos.X; MousePositionY = localPos.Y; }
public CalloutLine(Page page, SKPoint start, SKPoint?knee, SKPoint end) : base(new PdfArray()) { SKMatrix matrix = page.InRotateMatrix; PdfArray baseDataObject = BaseDataObject; { start = matrix.MapPoint(start); baseDataObject.Add(PdfReal.Get(start.X)); baseDataObject.Add(PdfReal.Get(start.Y)); if (knee.HasValue) { knee = matrix.MapPoint(knee.Value); baseDataObject.Add(PdfReal.Get(knee.Value.X)); baseDataObject.Add(PdfReal.Get(knee.Value.Y)); } end = matrix.MapPoint(end); baseDataObject.Add(PdfReal.Get(end.X)); baseDataObject.Add(PdfReal.Get(end.Y)); } }
private void Manipulate() { TouchManipulationInfo[] infos = new TouchManipulationInfo[touchDictionary.Count]; touchDictionary.Values.CopyTo(infos, 0); SKMatrix touchMatrix = SKMatrix.MakeIdentity(); if (infos.Length == 1) { SKPoint prevPoint = infos[0].PreviousPoint; SKPoint newPoint = infos[0].NewPoint; SKPoint pivotPoint = Matrix.MapPoint(_info.Width / 2, _info.Height / 2); OneFingerManipulate(prevPoint, newPoint, pivotPoint); } else if (infos.Length >= 2) { int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1; SKPoint pivotPoint = Matrix.MapPoint(_info.Width / 2, _info.Height / 2); SKPoint newPoint = infos[1 - pivotIndex].NewPoint; SKPoint prevPoint = infos[1 - pivotIndex].PreviousPoint; TwoFingerManipulate(prevPoint, newPoint, pivotPoint); } }
void OnTouchEffectTouchAction(object sender, TouchActionEventArgs args) { SKPoint pixelLocation = ConvertToPixel(args.Location); SKPoint bitmapLocation = inverseBitmapMatrix.MapPoint(pixelLocation); switch (args.Type) { case TouchActionType.Pressed: // Convert radius to bitmap/cropping scale float radius = inverseBitmapMatrix.ScaleX * RADIUS; // Find corner that the finger is touching int cornerIndex = croppingRect.HitTest(bitmapLocation, radius); if (cornerIndex != -1 && !touchPoints.ContainsKey(args.Id)) { TouchPoint touchPoint = new TouchPoint { CornerIndex = cornerIndex, Offset = bitmapLocation - croppingRect.Corners[cornerIndex] }; touchPoints.Add(args.Id, touchPoint); } break; case TouchActionType.Moved: if (touchPoints.ContainsKey(args.Id)) { TouchPoint touchPoint = touchPoints[args.Id]; croppingRect.MoveCorner(touchPoint.CornerIndex, bitmapLocation - touchPoint.Offset); InvalidateSurface(); } break; case TouchActionType.Released: case TouchActionType.Cancelled: if (touchPoints.ContainsKey(args.Id)) { touchPoints.Remove(args.Id); } break; } }
private void UpdateLocations(Color color, float canvasRadius) { ColorToHSV(color, out _, out double saturation, out double value); var luminosityX = -(float)((2 * triangleSide * saturation) - (triangleSide)); var luminosityY = triangleHeight; var tmp = ToPolar(new SKPoint(luminosityX, luminosityY)); tmp.Radius *= (float)value; locationSV = FromPolar(tmp); locationSV.X = -locationSV.X; locationSV.Y -= 1; locationSV.X *= WheelSVRadius(canvasRadius); locationSV.Y *= WheelSVRadius(canvasRadius); var tmp4 = ToPolar(new SKPoint(locationSV.X, locationSV.Y)); tmp4.Angle -= (float)(2 * Math.PI / 3); locationSV = FromPolar(tmp4); locationSV.X += canvasRadius; locationSV.Y += canvasRadius; if (RotateTriangleByHue) { SKMatrix rotationHue = SKMatrix.MakeRotation(-(float)((2D * Math.PI * lastHue) + (Math.PI / 2D)), canvasRadius, canvasRadius); locationSV = rotationHue.MapPoint(locationSV); } var angleH = lastHue * Math.PI * 2; locationMiddleH = FromPolar(new PolarPoint(WheelHRadius(canvasRadius), (float)(Math.PI - angleH))); locationMiddleH.X += canvasRadius; locationMiddleH.Y += canvasRadius; locationH1 = FromPolar(new PolarPoint(WheelHRadius(canvasRadius) + GetPickerRadiusPixels(), (float)(Math.PI - angleH))); locationH1.X += canvasRadius; locationH1.Y += canvasRadius; locationH2 = FromPolar(new PolarPoint(WheelHRadius(canvasRadius) - GetPickerRadiusPixels(), (float)(Math.PI - angleH))); locationH2.X += canvasRadius; locationH2.Y += canvasRadius; }
// Every 1/60th second, update bitmap with user drawings bool OnTimerTick() { if (bitmap == null) { return(true); } // Determine the current color. float tColor = stopwatch.ElapsedMilliseconds % 10000 / 10000f; fingerPaint.Color = SKColor.FromHsl(360 * tColor, 100, 50); titleLabel.TextColor = fingerPaint.Color.ToFormsColor(); // Determine the rotation angle. float tAngle = stopwatch.ElapsedMilliseconds % 5000 / 5000f; angle = 360 * tAngle; SKMatrix matrix = SKMatrix.MakeRotationDegrees(-angle, bitmap.Width / 2, bitmap.Height / 2); // Loop trough the fingers touching the screen. foreach (long id in idDictionary.Keys) { FingerInfo fingerInfo = idDictionary[id]; // Get the canvas size in pixels. It's square so it's only one number. float canvasSize = 0; if (canvasView is SKCanvasView) { canvasSize = (canvasView as SKCanvasView).CanvasSize.Width; } else { canvasSize = (canvasView as SKGLView).CanvasSize.Width; } // Convert Xamarin.Forms coordinates to pixels for drawing on the bitmap. // Also, make an offset factor if there's been resizing and the bitmap // is now larger than the canvas. (It's never smaller.) float factor = canvasSize / (float)canvasView.Width; // scaling factor float offset = (bitmapSize - canvasSize) / 2; // bitmap always >= canvas SKPoint convertedPoint = new SKPoint(factor * (float)fingerInfo.ThisPosition.X + offset, factor * (float)fingerInfo.ThisPosition.Y + offset); // Now rotate the point based on the rotation angle SKPoint pt0 = matrix.MapPoint(convertedPoint); if (!float.IsPositiveInfinity(fingerInfo.LastPosition.X)) { // Draw four lines in four quadrants. SKPoint pt1 = fingerInfo.LastPosition; bitmapCanvas.DrawLine(pt0.X, pt0.Y, pt1.X, pt1.Y, fingerPaint); float x0Flip = bitmap.Width - pt0.X; float y0Flip = bitmap.Height - pt0.Y; float x1Flip = bitmap.Width - pt1.X; float y1Flip = bitmap.Height - pt1.Y; bitmapCanvas.DrawLine(x0Flip, pt0.Y, x1Flip, pt1.Y, fingerPaint); bitmapCanvas.DrawLine(pt0.X, y0Flip, pt1.X, y1Flip, fingerPaint); bitmapCanvas.DrawLine(x0Flip, y0Flip, x1Flip, y1Flip, fingerPaint); } // Save the current point for next time through. fingerInfo.LastPosition = pt0; } // Redraw the canvas. if (canvasView is SKCanvasView) { (canvasView as SKCanvasView).InvalidateSurface(); } else { (canvasView as SKGLView).InvalidateSurface(); } return(true); }
internal void OnTouchEffectTouchAction(TouchActionEventArgs args) { SKPoint pixelLocation = new SKPoint((float)(CanvasSize.Width * args.Location.X / Width), (float)(CanvasSize.Height * args.Location.Y / Height));; SKPoint bitmapLocation = inverseBitmapMatrix.MapPoint(pixelLocation); switch (args.Type) { case TouchActionType.Pressed: // 将半径转换为位图/裁剪比例 float radius = inverseBitmapMatrix.ScaleX * 50; // 找到手指碰到的角落 int cornerIndex = croppingRect.HitTest(bitmapLocation, radius); if (cornerIndex != -1 && !touchPoints.ContainsKey(args.Id)) { TouchPoint touchPoint = new TouchPoint { CornerIndex = cornerIndex, Offset = bitmapLocation - croppingRect.Corners[cornerIndex] }; touchPoints.Add(args.Id, touchPoint); } else { //当你点击字典,我们写的ID和一个变量记录第一点的有效性。 if (croppingRect.TestPointInsideSquare(bitmapLocation) && !touchPointsInside.ContainsKey(args.Id)) { touchPointsInside.Add(args.Id, bitmapLocation); bitmapLocationfirst = bitmapLocation; } } break; case TouchActionType.Moved: if (touchPoints.ContainsKey(args.Id)) { TouchPoint touchPoint = touchPoints[args.Id]; croppingRect.MoveCorner(touchPoint.CornerIndex, bitmapLocation - touchPoint.Offset); InvalidateSurface(); } if (touchPointsInside.ContainsKey(args.Id)) { bitmapLocationlast = bitmapLocation; SKPoint point = new SKPoint(bitmapLocationlast.X - bitmapLocationfirst.X, bitmapLocationlast.Y - bitmapLocationfirst.Y); //移动 croppingRect.MoveAllCorner(point); bitmapLocationfirst = bitmapLocationlast; InvalidateSurface(); } break; case TouchActionType.Released: case TouchActionType.Cancelled: if (touchPoints.ContainsKey(args.Id)) { touchPoints.Remove(args.Id); } else if (touchPointsInside.ContainsKey(args.Id)) { touchPointsInside.Remove(args.Id); } break; } }
internal void OnTouchEffectTouchAction(TouchActionEventArgs args) { SKPoint pixelLocation = new SKPoint((float)(CanvasSize.Width * args.Location.X / Width), (float)(CanvasSize.Height * args.Location.Y / Height));; SKPoint bitmapLocation = inverseBitmapMatrix.MapPoint(pixelLocation); switch (args.Type) { case TouchActionType.Pressed: // Convert radius to bitmap/cropping scale float radius = inverseBitmapMatrix.ScaleX * 50; // Find corner that the finger is touching int cornerIndex = croppingRect.HitTest(bitmapLocation, radius); if (cornerIndex != -1 && !touchPoints.ContainsKey(args.Id)) { TouchPoint touchPoint = new TouchPoint { CornerIndex = cornerIndex, Offset = bitmapLocation - croppingRect.Corners[cornerIndex] }; touchPoints.Add(args.Id, touchPoint); } else { //При получении нажатия в словарь пишем его ID и в переменную записываем коардинаты первой точки if (croppingRect.TestPointInsideSquare(bitmapLocation) && !touchPointsInside.ContainsKey(args.Id)) { touchPointsInside.Add(args.Id, bitmapLocation); bitmapLocationfirst = bitmapLocation; } } break; case TouchActionType.Moved: if (touchPoints.ContainsKey(args.Id)) { TouchPoint touchPoint = touchPoints[args.Id]; croppingRect.MoveCorner(touchPoint.CornerIndex, bitmapLocation - touchPoint.Offset); InvalidateSurface(); } if (touchPointsInside.ContainsKey(args.Id)) { //Если перемещение соответсвует айдишнику от его кардинат вычитаем корадинаты начальной точки и передаем в метод перемещения bitmapLocationlast = bitmapLocation; SKPoint point = new SKPoint(bitmapLocationlast.X - bitmapLocationfirst.X, bitmapLocationlast.Y - bitmapLocationfirst.Y); croppingRect.MoveAllCorner(point); bitmapLocationfirst = bitmapLocationlast; InvalidateSurface(); } break; case TouchActionType.Released: case TouchActionType.Cancelled: if (touchPoints.ContainsKey(args.Id)) { touchPoints.Remove(args.Id); } else if (touchPointsInside.ContainsKey(args.Id)) { touchPointsInside.Remove(args.Id); } break; } }