private Path CreateCannulaHeadPath(RectF cannulaRect)
        {
            Path path = new Path();

            path.MoveTo(cannulaRect.Left, cannulaRect.Top);
            path.LineTo(cannulaRect.Right, cannulaRect.Top);
            path.MoveTo(cannulaRect.CenterX(), cannulaRect.Top);
            path.LineTo(cannulaRect.CenterX(), cannulaRect.Bottom - 0.833f * cannulaRect.Width());
            return(path);
        }
Beispiel #2
0
        private void AndroidDrawPath(GraphicsPath p)
        {
            var   path = new Android.Graphics.Path();
            float d    = density;

            for (int i = 0; i < p._segments.Count; i++)
            {
                {
                    var ln = p._segments[i] as GraphicsPath._LineSegment;
                    if (ln != null)
                    {
                        if (i == 0)
                        {
                            path.MoveTo(ln.x1 * d, ln.y1 * d);
                        }
                        else
                        {
                            path.LineTo(ln.x1 * d, ln.y1 * d);
                        }
                        path.LineTo(ln.x2 * d, ln.y2 * d);
                        continue;
                    }
                }
                {
                    var bz = p._segments[i] as GraphicsPath._BezierSegment;
                    if (bz != null)
                    {
                        if (i == 0)
                        {
                            path.MoveTo(bz.x1 * d, bz.y1 * d);
                        }
                        else
                        {
                            path.LineTo(bz.x1 * d, bz.y1 * d);
                        }

                        path.CubicTo(
                            bz.x2 * d, bz.y2 * d,
                            bz.x3 * d, bz.y3 * d,
                            bz.x4 * d, bz.y4 * d);
                        continue;
                    }
                }
            }
            if (p._closed)
            {
                path.Close();
            }
            canvas.DrawPath(path, paint);
        }
Beispiel #3
0
        private Path CreateMotherMovePath()
        {
            Path path = new Path();

            float CenterX           = mCurrentBounds.CenterX();
            float CenterY           = mCurrentBounds.CenterY();
            float currentPathLength = 0.0f;

            path.MoveTo(CenterX, CenterY);
            //forward top left
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 2.0f, CenterY, CenterX - mMotherOvalHalfWidth * 2.0f, CenterY - mMotherOvalHalfHeight);
            mStageMotherForwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageMotherForwardTopLeftLength;

            //backward top left
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 1.0f, CenterY - mMotherOvalHalfHeight, CenterX, CenterY);
            mStageMotherBackwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageMotherBackwardTopLeftLength;
            //forward bottom left
            path.QuadTo(CenterX, CenterY + mMotherOvalHalfHeight, CenterX - mMotherOvalHalfWidth / 2, CenterY + mMotherOvalHalfHeight * 1.1f);
            mStageMotherForwardBottomLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageMotherForwardBottomLeftLength;
            //backward bottom left
            path.QuadTo(CenterX - mMotherOvalHalfWidth / 2, CenterY + mMotherOvalHalfHeight * 0.6f, CenterX, CenterY);
            mStageMotherBackwardBottomLeftLength = GetRestLength(path, currentPathLength);

            return(path);
        }
Beispiel #4
0
        public override void Draw(Canvas canvas)
        {
            paint = new Android.Graphics.Paint();
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeCap  = Android.Graphics.Paint.Cap.Round;
            paint.StrokeJoin = Android.Graphics.Paint.Join.Round;

            if (_paths == null)
            {
                return;
            }
            foreach (var pathFromModel in _paths)
            {
                if (pathFromModel?.Points == null || pathFromModel.Points.Count < 2)
                {
                    continue;
                }
                paint.SetARGB(255, pathFromModel.Color.Red, pathFromModel.Color.Green, pathFromModel.Color.Blue);
                paint.StrokeWidth = pathFromModel.LineWidth;
                var path = new Android.Graphics.Path();
                path.MoveTo(pathFromModel.Points[0].X, pathFromModel.Points[0].Y);
                for (int i = 1; i < pathFromModel.Points.Count; i++)
                {
                    path.LineTo(pathFromModel.Points[i].X, pathFromModel.Points[i].Y);
                }

                canvas.DrawPath(path, paint);
            }
        }
Beispiel #5
0
 protected void DrawShape(Canvas canvas)
 {
   Paint paint = new Paint();
   paint.Color = Color;
   switch (Shape)
   {
     case ShapeEnum.RectangleShape:
       canvas.DrawRect(0, 0, ShapeWidth, ShapeHeight, paint);
       break;
     case ShapeEnum.OvalShape:
       canvas.DrawOval(new RectF(0, 0, ShapeWidth, ShapeHeight), paint);
       break;
     case ShapeEnum.TriangleShape:
         Path path = new Path();
         path.MoveTo(ShapeWidth / 2, 0);
         path.LineTo(ShapeWidth, ShapeHeight);
         path.LineTo(0,ShapeHeight);
         path.Close();
       canvas.DrawPath(path, paint);
       break;
     default:
       canvas.DrawCircle(ShapeWidth / 2, ShapeHeight / 2, ShapeWidth / 2, paint); 
       break;
   }
 }
        void CreatePath()
        {
            droidGraphics.Path path = null;

            if (points != null && points.Count > 1)
            {
                path = new droidGraphics.Path();
                path.SetFillType(fillType);

                path.MoveTo(pixelsPerDip * (float)points[0].X,
                            pixelsPerDip * (float)points[0].Y);

                for (int index = 1; index < points.Count; index++)
                {
                    path.LineTo(pixelsPerDip * (float)points[index].X,
                                pixelsPerDip * (float)points[index].Y);
                }

                if (this is PolygonDrawableView)
                {
                    path.Close();
                }
            }

            Path = path;
        }
Beispiel #7
0
 void CreatePath()
 {
     droidGraphics.Path path = new droidGraphics.Path();
     path.MoveTo(x1, y1);
     path.LineTo(x2, y2);
     Path = path;
 }
Beispiel #8
0
        private void FillPolygon(Canvas canvas, Point3[] points, Color color)
        {
            if (points.Length == 0)
            {
                return;
            }
            Android.Graphics.Path p = new Android.Graphics.Path();
            Point3 p3 = points[0];

            p.MoveTo((float)p3.X, (float)p3.Y);
            for (int i = 1; i < points.Length; i++)
            {
                p3 = points[i];
                p.LineTo((float)p3.X, (float)p3.Y);
            }
            Paint pnt = new Paint()
            {
                Color = color
            };

            canvas.DrawPath(p, pnt);
            pnt.SetStyle(Paint.Style.Stroke);
            pnt.Color       = Color.Black;
            pnt.StrokeWidth = 2;
            pnt.StrokeMiter = 1.5f;

            canvas.DrawPath(p, pnt);
        }
Beispiel #9
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            float currentX = e.GetX();
            float currentY = e.GetY();

            switch (e.Action)
            {
            case MotionEventActions.Down:
                path.MoveTo(currentX, currentY);

                previousX = currentX;
                previouxY = currentY;
                return(true);

            case MotionEventActions.Move:
            case MotionEventActions.Up:
                for (int i = 0; i < e.HistorySize; i++)
                {
                    float historicalX = e.GetHistoricalX(i);
                    float historicalY = e.GetHistoricalY(i);
                    path.LineTo(historicalX, historicalY);
                }
                path.LineTo(currentX, currentY);

                Invalidate();

                previousX = currentX;
                previouxY = currentY;
                return(true);

            default:
                return(false);
            }
        }
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            var rect = new RectF(0,0,300,300);
            switch (TheShape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Red });
                    break;
                case Shape.Triangle:
                    var path = new Path();
                    path.MoveTo(rect.CenterX(), 0);
                    path.LineTo(0, rect.Height());
                    path.LineTo(rect.Width(), rect.Height());
                    path.Close();

                    var paint = new Paint() {Color = Color.Magenta};
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #11
0
 private void touch_start(float x, float y)
 {
     mPath.Reset();
     mPath.MoveTo(x, y);
     mX = x;
     mY = y;
 }
Beispiel #12
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            var touchX = e.GetX();
            var touchY = e.GetY();

            switch (e.Action)
            {
            case MotionEventActions.Down:
                DrawPath.MoveTo(touchX, touchY);
                break;

            case MotionEventActions.Move:
                DrawPath.LineTo(touchX, touchY);
                break;

            case MotionEventActions.Up:
                DrawCanvas.DrawPath(DrawPath, DrawPaint);
                DrawPath.Reset();
                break;

            default:
                return(false);
            }

            Invalidate();

            return(true);
        }
Beispiel #13
0
        private void DrawCurrentStroke(Canvas _canvas)
        {
            if (currentStroke != null && currentStroke.Points.Count > 0)
            {
                double lastX = currentStroke.Points[0].X;
                double lastY = currentStroke.Points[0].Y;

                var paint = new Paint()
                {
                    Color       = new Color((byte)(currentStroke.StrokeColor.R * 255.0), (byte)(currentStroke.StrokeColor.G * 255.0), (byte)(currentStroke.StrokeColor.B * 255.0), (byte)(currentStroke.StrokeColor.A * 255.0)),
                    StrokeWidth = (float)currentStroke.Thickness * metrics.Density,
                    AntiAlias   = true,
                    StrokeCap   = Paint.Cap.Round,
                };
                paint.SetStyle(Paint.Style.Stroke);

                var path = new Android.Graphics.Path();
                path.MoveTo((float)currentStroke.Points[0].X, (float)currentStroke.Points[0].Y);

                foreach (var p in currentStroke.Points)
                {
                    path.LineTo((float)p.X, (float)p.Y);
                }

                _canvas.DrawPath(path, paint);
            }
        }
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new RectF(0, 0, 300, 300);
            switch (Shape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Crimson });
                    break;
                case Shape.Triangle:

                    var path = new Path();
                    path.MoveTo(rect.CenterX(), rect.Top);
                    path.LineTo(rect.Left, rect.Bottom);
                    path.LineTo(rect.Right, rect.Bottom);
                    path.Close();
                    var paint = new Paint() {Color = Color.Crimson};
                    paint.Color = Color.Gold;
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        public Stream GetArcPartFromSquareImage(Stream ms, int partNumber, int nbParts)
        {
            Stream result = null;

            using (Bitmap bitmap = BitmapFactory.DecodeStream(ms))
            {
                int diameter = bitmap.Width; // (int)(AvatarSize * GetDensity());

                float arcAngle = 360 / nbParts;
                float arcStart = 90 + (partNumber - 1) * arcAngle;
                if (nbParts > 2)
                {
                    arcStart += (180 / nbParts);
                }

                float deltaX = (float)(diameter / 2 - ((diameter * Math.Cos(DegreeToRadian(arcStart + arcAngle / 2)) + diameter) / 2)) / 2;
                float deltaY = (float)(diameter / 2 - ((diameter * Math.Sin(DegreeToRadian(arcStart + arcAngle / 2)) + diameter) / 2)) / 2;

                float startX = (float)((diameter * Math.Cos(DegreeToRadian(arcStart)) + diameter) / 2);
                float startY = (float)((diameter * Math.Sin(DegreeToRadian(arcStart)) + diameter) / 2);

                //float endX = (float)((diameter * Math.Cos(DegreeToRadian(arcStart + arcAngle)) + diameter) / 2);
                //float endY = (float)((diameter * Math.Sin(DegreeToRadian(arcStart + arcAngle)) + diameter) / 2);

                using (Bitmap temp = Bitmap.CreateBitmap(diameter, diameter, Bitmap.Config.Argb8888))
                {
                    // First we get the bitmap part (we translate using deltaX/Y to have the center of the avatar)
                    using (BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
                    {
                        using (Paint paint = new Paint(PaintFlags.AntiAlias))
                        {
                            paint.SetShader(shader);

                            using (Android.Graphics.Path path = new Android.Graphics.Path())
                            {
                                using (Canvas canvas = new Canvas(temp))
                                {
                                    path.MoveTo(diameter / 2 + deltaX, diameter / 2 + deltaY);
                                    path.LineTo(startX + deltaX, startY + deltaY);
                                    path.AddArc(deltaX, deltaY, diameter + deltaX, diameter + deltaY, arcStart, arcAngle);
                                    path.LineTo(diameter / 2 + deltaX, diameter / 2 + deltaY);
                                    canvas.DrawPath(path, paint);

                                    //canvas.DrawArc(deltaX, deltaY, deltaX + diameter, deltaY + diameter, arcStart, arcAngle, true, paint);
                                }
                            }
                        }
                    }

                    // Now we translate back to have correct layout
                    result = GetTranslated(GetStreamFromBitmap(temp), -deltaX, -deltaY);

                    temp.Recycle();
                }
                bitmap.Recycle();
            }

            return(result);
        }
Beispiel #16
0
        protected override Android.Graphics.Path GetPath()
        {
            var output = new Android.Graphics.Path();

            output.MoveTo(ViewHelper.LogicalToPhysicalPixels(X1), ViewHelper.LogicalToPhysicalPixels(Y1));
            output.LineTo(ViewHelper.LogicalToPhysicalPixels(X2), ViewHelper.LogicalToPhysicalPixels(Y2));

            return(output);
        }
        private Path CreateGasTubePath(RectF gasTubeRect)
        {
            Path path = new Path();

            path.MoveTo(gasTubeRect.Left, gasTubeRect.Top);
            path.LineTo(gasTubeRect.Left, gasTubeRect.Bottom);
            path.LineTo(gasTubeRect.Right, gasTubeRect.Bottom);
            path.LineTo(gasTubeRect.Right, gasTubeRect.Top);
            return(path);
        }
Beispiel #18
0
		internal static Path parse(float[] pPoints) {
			Path path = new Path();
			path.MoveTo(pPoints[0], pPoints[1]);
			for (int i = 2; i < pPoints.Length; i += 2) {
				float x = pPoints[i];
				float y = pPoints[i + 1];
				path.LineTo(x, y);
			}
			return path;
		}
        public void Initialize()
        {
            _minuteHand = new Path();
            _minuteHand.MoveTo(0, 10);
            _minuteHand.LineTo(0, -55);
            _minuteHand.Close();

            _secondHand = new Path();
            _secondHand.MoveTo(0, -80);
            _secondHand.LineTo(0, 15);
            _secondHand.Close();
        }
Beispiel #20
0
        private void DrawStrokes(Canvas _canvas, List <Abstractions.Stroke> strokes, Bitmap backgroundBitmap, Abstractions.Color backgroundColor, Abstractions.Scaling backgroundScaling, int Width, int Height, float scale)
        {
            if (backgroundColor != null)
            {
                _canvas.DrawColor(new Color((byte)(backgroundColor.R * 255f), (byte)(backgroundColor.G * 255f), (byte)(backgroundColor.B * 255f)), PorterDuff.Mode.Src);
            }

            float deviceOrientation = 0;//TODO

            //TODO check the replacement for canvas.Save
            _canvas.Save(SaveFlags.Matrix);
            _canvas.Translate(_canvas.Width / 2f, _canvas.Height / 2f);
            _canvas.Rotate(deviceOrientation);
            _canvas.Translate(-(_canvas.Width / 2f), -(_canvas.Height / 2f));

            if (backgroundBitmap != null)
            {
                switch (backgroundScaling)
                {
                case Abstractions.Scaling.Absolute_None:
                case Abstractions.Scaling.Relative_None:
                    _canvas.DrawBitmap(backgroundBitmap, 0, 0, new Paint());
                    break;

                case Abstractions.Scaling.Absolute_Fit:
                case Abstractions.Scaling.Relative_Fit:
                    float backgroundScale = GetDrawingScale(backgroundScaling, backgroundBitmap, Width, Height);
                    _canvas.DrawBitmap(backgroundBitmap, new Rect(0, 0, backgroundBitmap.Width, backgroundBitmap.Height), new Rect(0, 0, (int)(backgroundBitmap.Width * backgroundScale), (int)(backgroundBitmap.Height * backgroundScale)), new Paint());
                    break;

                case Abstractions.Scaling.Absolute_Fill:
                case Abstractions.Scaling.Relative_Fill:
                    _canvas.DrawBitmap(backgroundBitmap, new Rect(0, 0, backgroundBitmap.Width, backgroundBitmap.Height), new Rect(0, 0, Width, Height), new Paint());
                    break;
                }
            }

            foreach (var stroke in strokes)
            {
                var paint = CreatePaint(stroke.StrokeColor.R, stroke.StrokeColor.G, stroke.StrokeColor.B, stroke.StrokeColor.A, stroke.Thickness, metrics.Density);

                var path = new Android.Graphics.Path();
                path.MoveTo((float)stroke.Points[0].X * scale, (float)stroke.Points[0].Y * scale);

                foreach (var p in stroke.Points)
                {
                    path.LineTo((float)p.X * scale, (float)p.Y * scale);
                }

                _canvas.DrawPath(path, paint);
            }
        }
Beispiel #21
0
        public static Bitmap GetHexagonShape(Bitmap scaleBitmapImage)
        {
            if (scaleBitmapImage == null)
            {
                return(null);
            }

            int targetWidth  = 200;
            int targetHeight = 200;
            int drawnWidth   = 140;

            Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(targetBitmap);

            Android.Graphics.Path path = new Android.Graphics.Path();

            //start top left
            path.MoveTo(0, 0);

            //move to middle top
            path.LineTo(drawnWidth, 0);

            //move to bottom right
            path.LineTo(targetWidth, targetHeight - 0);

            //move to bottom middle
            path.LineTo(targetWidth - drawnWidth, targetHeight - 0);

            //middle top left
            path.MoveTo(0, 0);


            canvas.ClipPath(path);
            Bitmap sourceBitmap = scaleBitmapImage;

            canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null);
            return(targetBitmap);
        }
		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// BoxViewのカスタマイズはDrawで行う
		/// </summary>
		/// <param name="canvas">Canvas.</param>
		public override void Draw(Android.Graphics.Canvas canvas)
		{
			// 2重に描画してしまうので、baseは描画しない
			//base.Draw(canvas);

			// ElementをキャストしてFormsで定義したCustomBoxViewを取得
			var formsBox = (CustomBoxView)Element;

			// Androidの描画はPaintを使用
			using (var paint = new Paint()) 
			{
				// 塗りつぶし色の設定
				paint.Color = formsBox.FillColor.ToAndroid();

				// 吹き出し部分の設定
				// パスの生成
				var path = new Path();

				// スタート地点の設定
				path.MoveTo(0, 0);

				// 経由地点の設定
				path.LineTo(100, 10);
				path.LineTo(100, 100);

				// パスを繋げる
				path.Close();

				// 描画
				canvas.DrawPath(path, paint);


				// 角の丸い四角の設定
				// 角丸の直径を決める
				// widthとheightを比較して小さい方を基準にする
				var minSize = Math.Min(Width, Height);

				// 指定するのは直径なので、指定半径を2倍する
				var diameter = formsBox.Radius * 2;
				// 角丸の直径はminSize以下でなければならない
				if (diameter > minSize)
					diameter = minSize;

				// 描画領域の設定
				var rect = new RectF(0, 0, (float)Width, (float)Height);

				//四角形描画
				canvas.DrawRoundRect(rect, diameter, diameter, paint);
			}
		}
Beispiel #23
0
        private Path CreateChildPath()
        {
            float bezierOffset = mChildOvalRadius * OVAL_BEZIER_FACTOR;

            Path path = new Path();

            path.MoveTo(mChildPosition[0], mChildPosition[1] - mChildOvalRadius);
            //left_top arc
            path.CubicTo(mChildPosition[0] - bezierOffset - mChildLeftXOffset, mChildPosition[1] - mChildOvalRadius, mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1] - bezierOffset + mChildLeftYOffset, mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1]);
            //left_bottom arc
            path.CubicTo(mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1] + bezierOffset - mChildLeftYOffset, mChildPosition[0] - bezierOffset - mChildLeftXOffset, mChildPosition[1] + mChildOvalRadius, mChildPosition[0], mChildPosition[1] + mChildOvalRadius);

            //right_bottom arc
            path.CubicTo(mChildPosition[0] + bezierOffset + mChildRightXOffset, mChildPosition[1] + mChildOvalRadius, mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1] + bezierOffset - mChildRightYOffset, mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1]);
            //right_top arc
            path.CubicTo(mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1] - bezierOffset + mChildRightYOffset, mChildPosition[0] + bezierOffset + mChildRightXOffset, mChildPosition[1] - mChildOvalRadius, mChildPosition[0], mChildPosition[1] - mChildOvalRadius);

            return(path);
        }
Beispiel #24
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            base.OnTouchEvent(e);
            float x = e.GetX();
            float y = e.GetY();

            switch (e.Action)
            {
            case MotionEventActions.Down:
                path.MoveTo(x, y);
                break;

            case MotionEventActions.Move:
                path.LineTo(x, y);
                break;
            }
            Invalidate(); // view更新
            return(true);
        }
Beispiel #25
0
        private void TouchMove(float x, float y)
        {
            var dx = (float)Math.Abs(x - _currentTouch.X);
            var dy = (float)Math.Abs(y - _currentTouch.Y);

            // add movement to stroke if outside the area of tolerence (a square with side length of TouchTolerance * 2, centered at currentTouch)
            if (!(dx >= TouchTolerance) && !(dy >= TouchTolerance))
            {
                return;
            }

            if (_currentStroke.IsEmpty)
            {
                _currentStroke.MoveTo((float)_currentTouch.X, (float)_currentTouch.Y);
            }

            _currentStroke.QuadTo((float)_currentTouch.X,
                                  (float)_currentTouch.Y,
                                  (float)(x + _currentTouch.X) / 2,
                                  (float)(y + _currentTouch.Y) / 2);
        }
        /// <summary>
        /// Coordinates are approximate, you have better cooperate with the designer's design draft
        /// </summary>
        private Path CreateBalloonPath(RectF balloonRect, float progress)
        {
            Path path = new Path();

            path.MoveTo(balloonRect.CenterX(), balloonRect.Bottom);

            float progressWidth  = balloonRect.Width() * progress;
            float progressHeight = balloonRect.Height() * progress;
            //draw left half
            float leftIncrementX1 = progressWidth * -0.48f;
            float leftIncrementY1 = progressHeight * 0.75f;
            float leftIncrementX2 = progressWidth * -0.03f;
            float leftIncrementY2 = progressHeight * -1.6f;
            float leftIncrementX3 = progressWidth * 0.9f;
            float leftIncrementY3 = progressHeight * -1.0f;

            path.CubicTo(balloonRect.Left + balloonRect.Width() * 0.25f + leftIncrementX1, balloonRect.CenterY() - balloonRect.Height() * 0.4f + leftIncrementY1, balloonRect.Left - balloonRect.Width() * 0.20f + leftIncrementX2, balloonRect.CenterY() + balloonRect.Height() * 1.15f + leftIncrementY2, balloonRect.Left - balloonRect.Width() * 0.4f + leftIncrementX3, balloonRect.Bottom + leftIncrementY3);

            //        the results of the left final transformation
            //        path.cubicTo(balloonRect.left - balloonRect.width() * 0.13f, balloonRect.CenterY() + balloonRect.height() * 0.35f,
            //                balloonRect.left - balloonRect.width() * 0.23f, balloonRect.CenterY() - balloonRect.height() * 0.45f,
            //                balloonRect.left + balloonRect.width() * 0.5f, balloonRect.bottom - balloonRect.height());

            //draw right half
            float rightIncrementX1 = progressWidth * 1.51f;
            float rightIncrementY1 = progressHeight * -0.05f;
            float rightIncrementX2 = progressWidth * 0.03f;
            float rightIncrementY2 = progressHeight * 0.5f;
            float rightIncrementX3 = 0.0f;
            float rightIncrementY3 = 0.0f;

            path.CubicTo(balloonRect.Left - balloonRect.Width() * 0.38f + rightIncrementX1, balloonRect.CenterY() - balloonRect.Height() * 0.4f + rightIncrementY1, balloonRect.Left + balloonRect.Width() * 1.1f + rightIncrementX2, balloonRect.CenterY() - balloonRect.Height() * 0.15f + rightIncrementY2, balloonRect.Left + balloonRect.Width() * 0.5f + rightIncrementX3, balloonRect.Bottom + rightIncrementY3);

            //        the results of the right final transformation
            //        path.cubicTo(balloonRect.left + balloonRect.width() * 1.23f, balloonRect.CenterY() - balloonRect.height() * 0.45f,
            //                balloonRect.left + balloonRect.width() * 1.13f, balloonRect.CenterY() + balloonRect.height() * 0.35f,
            //                balloonRect.left + balloonRect.width() * 0.5f, balloonRect.bottom);

            return(path);
        }
Beispiel #27
0
        private Path CreateLinkPath()
        {
            Path  path         = new Path();
            float bezierOffset = mMotherOvalHalfWidth * OVAL_BEZIER_FACTOR;

            float distance = (float)Math.Sqrt(Math.Pow(mMotherPosition[0] - mChildPosition[0], 2.0f) + Math.Pow(mMotherPosition[1] - mChildPosition[1], 2.0f));

            if (distance <= mMotherOvalHalfWidth + mChildOvalRadius * 1.2f && distance >= mMotherOvalHalfWidth - mChildOvalRadius * 1.2f)
            {
                float maxOffsetY = 2 * mChildOvalRadius * 1.2f;
                float offsetRate = (distance - (mMotherOvalHalfWidth - mChildOvalRadius * 1.2f)) / maxOffsetY;

                float mMotherOvalOffsetY = mMotherOvalHalfHeight - offsetRate * (mMotherOvalHalfHeight - mChildOvalRadius) * 0.85f;

                mMotherOvalPath.AddOval(new RectF(mMotherPosition[0] - mMotherOvalHalfWidth, mMotherPosition[1] - mMotherOvalOffsetY, mMotherPosition[0] + mMotherOvalHalfWidth, mMotherPosition[1] + mMotherOvalOffsetY), Path.Direction.Cw);

                float mMotherXOffset     = distance - mMotherOvalHalfWidth + mChildOvalRadius;
                float distanceUltraLeft  = (float)Math.Sqrt(Math.Pow(mMotherPosition[0] - mMotherOvalHalfWidth - mChildPosition[0], 2.0f) + Math.Pow(mMotherPosition[1] - mChildPosition[1], 2.0f));
                float distanceUltraRight = (float)Math.Sqrt(Math.Pow(mMotherPosition[0] + mMotherOvalHalfWidth - mChildPosition[0], 2.0f) + Math.Pow(mMotherPosition[1] - mChildPosition[1], 2.0f));

                path.MoveTo(mMotherPosition[0], mMotherPosition[1] + mMotherOvalOffsetY);
                if (distanceUltraRight < distanceUltraLeft)
                {
                    //right_bottom arc
                    path.CubicTo(mMotherPosition[0] + bezierOffset + mMotherXOffset, mMotherPosition[1] + mMotherOvalOffsetY, mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1] + mChildOvalRadius * 1.5f, mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1]);
                    //right_top arc
                    path.CubicTo(mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1] - mChildOvalRadius * 1.5f, mMotherPosition[0] + bezierOffset + mMotherXOffset, mMotherPosition[1] - mMotherOvalOffsetY, mMotherPosition[0], mMotherPosition[1] - mMotherOvalOffsetY);
                }
                else
                {
                    //left_bottom arc
                    path.CubicTo(mMotherPosition[0] - bezierOffset - mMotherXOffset, mMotherPosition[1] + mMotherOvalOffsetY, mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1] + mChildOvalRadius * 1.5f, mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1]);
                    //left_top arc
                    path.CubicTo(mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1] - mChildOvalRadius * 1.5f, mMotherPosition[0] - bezierOffset - mMotherXOffset, mMotherPosition[1] - mMotherOvalOffsetY, mMotherPosition[0], mMotherPosition[1] - mMotherOvalOffsetY);
                }
                path.LineTo(mMotherPosition[0], mMotherPosition[1] + mMotherOvalOffsetY);
            }

            return(path);
        }
Beispiel #28
0
		void Initialize ()
		{
			// Create Paint for all drawing
			paint = new Paint ();

			// All paths are based on 100-unit clock radius
			//		centered at (0, 0).

			// Define circle for tick marks.
			tickMarks = new Path ();
			tickMarks.AddCircle (0, 0, 90, Path.Direction.Cw);

			// Hour, minute, second hands defined to point straight up.

			// Define hour hand.
			hourHand = new Path ();
			hourHand.MoveTo (0, -60);
			hourHand.CubicTo (0, -30, 20, -30, 5, -20);
			hourHand.LineTo (5, 0);
			hourHand.CubicTo (5, 7.5f, -5, 7.5f, -5, 0);
			hourHand.LineTo (-5, -20);
			hourHand.CubicTo (-20, -30, 0, -30, 0, -60);
			hourHand.Close ();

			// Define minute hand.
			minuteHand = new Path ();
			minuteHand.MoveTo (0, -80);
			minuteHand.CubicTo (0, -75, 0, -70, 2.5f, -60);
			minuteHand.LineTo (2.5f, 0);
			minuteHand.CubicTo (2.5f, 5, -2.5f, 5, -2.5f, 0);
			minuteHand.LineTo (-2.5f, -60);
			minuteHand.CubicTo (0, -70, 0, -75, 0, -80);
			minuteHand.Close ();

			// Define second hand.
			secondHand = new Path ();
			secondHand.MoveTo (0, 10);
			secondHand.LineTo (0, -80);
		}
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var path = new Path();
            path.MoveTo(_points[0].X, _points[0].Y);
            for (var i = 1; i < _points.Length; i++)
            {
                path.LineTo(_points[i].X, _points[i].Y);
            }

            var paint = new Paint
                            {
                                Color = Color.White
                            };

            // We can use Paint.Style.Stroke if we want to draw a "hollow" polygon,
            // But then we had better set the .StrokeWidth property on the paint.
            paint.SetStyle(Paint.Style.Fill);

            canvas.DrawPath(path, paint);
        }
Beispiel #30
0
        private Path CreateChildMovePath()
        {
            Path path = new Path();

            float CenterX           = mCurrentBounds.CenterX();
            float CenterY           = mCurrentBounds.CenterY();
            float currentPathLength = 0.0f;

            //start
            path.MoveTo(CenterX, CenterY);
            //pre forward top left
            path.LineTo(CenterX + mMotherOvalHalfWidth * 0.75f, CenterY);
            mStageChildPreForwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildPreForwardTopLeftLength;
            //forward top left
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 0.5f, CenterY, CenterX - mMotherOvalHalfWidth * 2.0f, CenterY - mMotherOvalHalfHeight);
            mStageChildForwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildForwardTopLeftLength;
            //pre backward top left
            path.LineTo(CenterX - mMotherOvalHalfWidth * 2.0f + mMotherOvalHalfWidth * 0.2f, CenterY - mMotherOvalHalfHeight);
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 2.5f, CenterY - mMotherOvalHalfHeight * 2, CenterX - mMotherOvalHalfWidth * 1.5f, CenterY - mMotherOvalHalfHeight * 2.25f);
            mStageChildPreBackwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildPreBackwardTopLeftLength;
            //backward top left
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 0.2f, CenterY - mMotherOvalHalfHeight * 2.25f, CenterX, CenterY);
            mStageChildBackwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildBackwardTopLeftLength;
            //forward bottom left
            path.CubicTo(CenterX, CenterY + mMotherOvalHalfHeight, CenterX - mMotherOvalHalfWidth, CenterY + mMotherOvalHalfHeight * 2.5f, CenterX - mMotherOvalHalfWidth * 1.5f, CenterY + mMotherOvalHalfHeight * 2.5f);
            mStageChildForwardBottomLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildForwardBottomLeftLength;
            //backward bottom left
            path.CubicTo(CenterX - mMotherOvalHalfWidth * 2.0f, CenterY + mMotherOvalHalfHeight * 2.5f, CenterX - mMotherOvalHalfWidth * 3.0f, CenterY + mMotherOvalHalfHeight * 0.8f, CenterX, CenterY);
            mStageChildBackwardBottomLeftLength = GetRestLength(path, currentPathLength);

            return(path);
        }
        private Path Calculate(int size, Direction direction)
        {
            Point p1, p2, p3;

            if (direction == Direction.Up)
            {
                p1 = new Point(0, size);
                p2 = new Point(size, size);
                p3 = new Point(size / 2, 0);
            }
            else
            {
                p1 = new Point(0, 0);
                p2 = new Point(size, 0);
                p3 = new Point(size / 2, size);
            }

            var path = new Path();
            path.MoveTo(p1.X, p1.Y);
            path.LineTo(p2.X, p2.Y);
            path.LineTo(p3.X, p3.Y);

            return path;
        }
Beispiel #32
0
        ObjectAnimator PrepareAnimation(View view, int multiplier)
        {
            var path = new Path();

            var metrics = Resources.DisplayMetrics;
            var tx = multiplier * (metrics.WidthPixels - view.PaddingRight);
            var ty = -TypedValue.ApplyDimension(ComplexUnitType.Dip, 64, metrics);

            path.MoveTo(tx, ty);
            path.QuadTo(2 * tx / 3, 0, 0, 0);
            view.TranslationX = tx;
            view.TranslationY = ty;

            var anim = ObjectAnimator.OfFloat(view, "translationX", "translationY", path);
            anim.SetDuration(600);
            anim.SetInterpolator(AnimationUtils.LoadInterpolator(this, Android.Resource.Interpolator.FastOutSlowIn));
            return anim;
        }
		public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			// Inflate the interpolator_fragment layout
			var v = inflater.Inflate (Resource.Layout.interpolator_fragment, container, false);

			// Set up the "animate" button
			// When it is clicked, the view is animatied with the options selected
			var button = v.FindViewById<Button> (Resource.Id.animateButton);
			button.Click += delegate {
				// Interpolator selected in the spinner
				var interpolator = interpolators [interpolatorSpinner.SelectedItemPosition];
				// Duration selected in SeekBar
				long duration = (long)durationSeekbar.Progress;
				// Animation path is based on whether animating in or out
				var path = isOut ? pathIn : pathOut;

				// Log animation details
				Log.Info (TAG, string.Format ("Starting animation: [{0} ms, {1}, {2}",
					duration, interpolatorSpinner.SelectedItem.ToString (),
					((isOut) ? "Out (growing)" : "In (shrinking)")));

				// Start the animation with the selected options
				StartAnimation(interpolator,duration,path);

				// Toggle direction of the animation
				isOut = !isOut;

			};
				
			durationLabel = v.FindViewById<TextView> (Resource.Id.durationLabel);

			// Initialize the Interpolators programmatically by loading them from their XML definitions
			// provided by the framework.
			interpolators = new IInterpolator[]
			{
				AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.Linear),
				AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.FastOutLinearIn),
				AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.FastOutSlowIn),
				AnimationUtils.LoadInterpolator(Activity,Android.Resource.Interpolator.LinearOutSlowIn)
			};

			// Load names of interpolators
			var interpolatorNames = Resources.GetStringArray (Resource.Array.interpolator_names);

			// Set up the Spinner with the names of interpolators
			interpolatorSpinner = v.FindViewById<Spinner> (Resource.Id.interpolatorSpinner);
			var spinnerAdapter = new ArrayAdapter<string> (Activity, Android.Resource.Layout.SimpleSpinnerDropDownItem, interpolatorNames);
			interpolatorSpinner.Adapter = spinnerAdapter;

			// Set up SeekBar that defines the duration of the animation
			durationSeekbar = v.FindViewById<SeekBar> (Resource.Id.durationSeek);
			durationSeekbar.ProgressChanged+=delegate {
				durationLabel.SetText(Resources.GetString(Resource.String.animation_duration,durationSeekbar.Progress),TextView.BufferType.Normal);
			};

			// Set default duration
			durationSeekbar.Progress = INITIAL_DURATION_MS;

			// Get the view that will be animated
			view = v.FindViewById (Resource.Id.square);

			// Path for the "in" animation
			pathIn = new Path ();
			pathIn.MoveTo (0.2f, 0.2f);
			pathIn.LineTo (1f, 1f);

			// Path for the "out" animation
			pathOut = new Path ();
			pathOut.MoveTo (1f, 1f);
			pathOut.LineTo (0.2f, 0.2f);
			return v;

		}
Beispiel #34
0
        public static APath AsAndroidPath(this PathF path)
        {
            var nativePath = new APath();

            int pointIndex        = 0;
            int arcAngleIndex     = 0;
            int arcClockwiseIndex = 0;

            foreach (var operation in path.PathOperations)
            {
                if (operation == PathOperation.MoveTo)
                {
                    var point = path[pointIndex++];
                    nativePath.MoveTo(point.X, point.Y);
                }
                else if (operation == PathOperation.Line)
                {
                    var point = path[pointIndex++];
                    nativePath.LineTo(point.X, point.Y);
                }

                else if (operation == PathOperation.Quad)
                {
                    var controlPoint = path[pointIndex++];
                    var point        = path[pointIndex++];
                    nativePath.QuadTo(controlPoint.X, controlPoint.Y, point.X, point.Y);
                }
                else if (operation == PathOperation.Cubic)
                {
                    var controlPoint1 = path[pointIndex++];
                    var controlPoint2 = path[pointIndex++];
                    var point         = path[pointIndex++];
                    nativePath.CubicTo(controlPoint1.X, controlPoint1.Y, controlPoint2.X, controlPoint2.Y, point.X,
                                       point.Y);
                }
                else if (operation == PathOperation.Arc)
                {
                    var topLeft     = path[pointIndex++];
                    var bottomRight = path[pointIndex++];
                    var startAngle  = path.GetArcAngle(arcAngleIndex++);
                    var endAngle    = path.GetArcAngle(arcAngleIndex++);
                    var clockwise   = path.IsArcClockwise(arcClockwiseIndex++);

                    while (startAngle < 0)
                    {
                        startAngle += 360;
                    }

                    while (endAngle < 0)
                    {
                        endAngle += 360;
                    }

                    var rect  = new RectF(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
                    var sweep = GraphicsOperations.GetSweep(startAngle, endAngle, clockwise);

                    startAngle *= -1;
                    if (!clockwise)
                    {
                        sweep *= -1;
                    }

                    nativePath.ArcTo(rect, startAngle, sweep);
                }
                else if (operation == PathOperation.Close)
                {
                    nativePath.Close();
                }
            }

            return(nativePath);
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw (canvas);

            if (mViewPager == null) {
                return;
            }
            int count = mViewPager.Adapter.Count;
            if (count == 0) {
                return;
            }

            //Calculate views bounds
            var bounds = CalculateAllBounds(mPaintText);
            int boundsSize = bounds.Count;

            //Make sure we're on a page that still exists
            if (mCurrentPage >= boundsSize) {
                SetCurrentItem(boundsSize - 1);
                return;
            }

            int countMinusOne = count - 1;
            float halfWidth = Width / 2f;
            int left = Left;
            float leftClip = left + mClipPadding;
            int width = Width;
            int height = Height;
            int right = left + width;
            float rightClip = right - mClipPadding;

            int page = mCurrentPage;
            float offsetPercent;
            if (mCurrentOffset <= halfWidth) {
                offsetPercent = 1.0f * mCurrentOffset / width;
            } else {
                page += 1;
                offsetPercent = 1.0f * (width - mCurrentOffset) / width;
            }
            bool currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE);
            bool currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE);
            float selectedPercent = (SELECTION_FADE_PERCENTAGE - offsetPercent) / SELECTION_FADE_PERCENTAGE;

            //Verify if the current view must be clipped to the screen
            RectF curPageBound = bounds[mCurrentPage];
            float curPageWidth = curPageBound.Right - curPageBound.Left;
            if (curPageBound.Left < leftClip) {
                //Try to clip to the screen (left side)
                ClipViewOnTheLeft(curPageBound, curPageWidth, left);
            }
            if (curPageBound.Right > rightClip) {
                //Try to clip to the screen (right side)
                ClipViewOnTheRight(curPageBound, curPageWidth, right);
            }

            //Left views starting from the current position
            if (mCurrentPage > 0) {
                for (int i = mCurrentPage - 1; i >= 0; i--) {
                    RectF bound = bounds[i];
                    //Is left side is outside the screen
                    if (bound.Left < leftClip) {
                        float w = bound.Right - bound.Left;
                        //Try to clip to the screen (left side)
                        ClipViewOnTheLeft(bound, w, left);
                        //Except if there's an intersection with the right view
                        RectF rightBound = bounds[i + 1];
                        //Intersection
                        if (bound.Right + mTitlePadding > rightBound.Left) {
                            bound.Left = rightBound.Left - w - mTitlePadding;
                            bound.Right = bound.Left + w;
                        }
                    }
                }
            }
            //Right views starting from the current position
            if (mCurrentPage < countMinusOne) {
                for (int i = mCurrentPage + 1 ; i < count; i++) {
                    RectF bound = bounds[i];
                    //If right side is outside the screen
                    if (bound.Right > rightClip) {
                        float w = bound.Right - bound.Left;
                        //Try to clip to the screen (right side)
                        ClipViewOnTheRight(bound, w, right);
                        //Except if there's an intersection with the left view
                        RectF leftBound = bounds[i - 1];
                        //Intersection
                        if (bound.Left - mTitlePadding < leftBound.Right) {
                            bound.Left = leftBound.Right + mTitlePadding;
                            bound.Right = bound.Left + w;
                        }
                    }
                }
            }

            //Now draw views
            //int colorTextAlpha = mColorText >>> 24;
            int colorTextAlpha = mColorText >> 24;
            for (int i = 0; i < count; i++) {
                //Get the title
                RectF bound = bounds[i];
                //Only if one side is visible
                if ((bound.Left > left && bound.Left < right) || (bound.Right > left && bound.Right < right)) {
                    bool currentPage = (i == page);
                    //Only set bold if we are within bounds
                    mPaintText.FakeBoldText = (currentPage && currentBold && mBoldText);

                    //Draw text as unselected
                    mPaintText.Color = (mColorText);
                    if(currentPage && currentSelected) {
                        //Fade out/in unselected text as the selected text fades in/out
                        mPaintText.Alpha = (colorTextAlpha - (int)(colorTextAlpha * selectedPercent));
                    }
                    canvas.DrawText(mTitleProvider.GetTitle(i), bound.Left, bound.Bottom + mTopPadding, mPaintText);

                    //If we are within the selected bounds draw the selected text
                    if (currentPage && currentSelected) {
                        mPaintText.Color = mColorSelected;
                        mPaintText.Alpha = ((int)((mColorSelected >> 24) * selectedPercent));
                        canvas.DrawText(mTitleProvider.GetTitle(i), bound.Left, bound.Bottom + mTopPadding, mPaintText);
                    }
                }
            }

            //Draw the footer line
            mPath = new Path();
            mPath.MoveTo(0, height - mFooterLineHeight / 2f);
            mPath.LineTo(width, height - mFooterLineHeight / 2f);
            mPath.Close();
            canvas.DrawPath(mPath, mPaintFooterLine);

            switch (mFooterIndicatorStyle) {
                case IndicatorStyle.Triangle:
                    mPath = new Path();
                    mPath.MoveTo(halfWidth, height - mFooterLineHeight - mFooterIndicatorHeight);
                    mPath.LineTo(halfWidth + mFooterIndicatorHeight, height - mFooterLineHeight);
                    mPath.LineTo(halfWidth - mFooterIndicatorHeight, height - mFooterLineHeight);
                    mPath.Close();
                    canvas.DrawPath(mPath, mPaintFooterIndicator);
                    break;

                case IndicatorStyle.Underline:
                    if (!currentSelected || page >= boundsSize) {
                        break;
                    }

                    RectF underlineBounds = bounds[page];
                    mPath = new Path();
                    mPath.MoveTo(underlineBounds.Left  - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
                    mPath.LineTo(underlineBounds.Right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight);
                    mPath.LineTo(underlineBounds.Right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight);
                    mPath.LineTo(underlineBounds.Left  - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight);
                    mPath.Close();

                    mPaintFooterIndicator.Alpha = ((int)(0xFF * selectedPercent));
                    canvas.DrawPath(mPath, mPaintFooterIndicator);
                    mPaintFooterIndicator.Alpha = (0xFF);
                    break;
            }
        }
        public void DrawPolygon(IList<Point> points, Color fill, Color stroke, double thickness = 1, double[] dashArray = null, PenLineJoin lineJoin = PenLineJoin.Miter, bool aliased = false)
        {
            using (var paint = new Paint())
            {
                paint.AntiAlias = !aliased;
                paint.StrokeWidth = (float)thickness;
                using (var path = new Path())
                {
                    path.MoveTo((float)points[0].X, (float)points[0].Y);
                    for (int i = 1; i <= points.Count; i++)
                    {
                        path.LineTo((float)points[i % points.Count].X, (float)points[i % points.Count].Y);
                    }

                    if (fill != null)
                    {
                        paint.SetStyle(Paint.Style.Fill);
                        paint.Color = fill;
                        canvas.DrawPath(path, paint);
                    }

                    if (stroke != null)
                    {
                        paint.SetStyle(Paint.Style.Stroke);
                        paint.Color = stroke;
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Beispiel #37
0
        private void DrawGraphics(Canvas canvas)
        {
            if (!(PointsCloud.x || PointsCloud.y || PointsCloud.z || PointsCloud.v))
                return;

            Paint mPaint = new Paint();
            mPaint.Dither = true;
            mPaint.SetStyle (Paint.Style.Stroke);
            mPaint.Color = Color.White;
            mPaint.StrokeJoin = Paint.Join.Bevel;
            mPaint.StrokeCap = Paint.Cap.Round;
            mPaint.StrokeWidth = 3;

            Path x = new Path ();
            Path y = new Path ();
            Path z = new Path ();
            Path v = new Path ();

            // max min
            DateTime MaxX = PointsCloud.MaxX;
            DateTime MinX = PointsCloud.MinX;

            // разметка вертикальные линии
            if (MaxX.Equals (MinX))
                return;

            //
            List<Point> d = points.GetVisible ();
            for (int i = 0; i<d.Count; i++) {
                Point cur = d.ElementAt(i);
                if (PointsCloud.x) {
                    if (i == 0) x.MoveTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.x));
                    else        x.LineTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.x));
                }
                if (PointsCloud.y) {
                    if (i == 0) y.MoveTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.y));
                    else        y.LineTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.y));
                }
                if (PointsCloud.z) {
                    if (i == 0) z.MoveTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.z));
                    else        z.LineTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.z));
                }
                if (PointsCloud.v) {
                    if (i == 0) v.MoveTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.v));
                    else        v.LineTo(ConvertXtoX(canvas, cur.GetTime()),
                                         ConvertYtoY(canvas, cur.v));
                }
            }

            mPaint.Color = Color.Yellow;
            if (PointsCloud.x) canvas.DrawPath (x, mPaint);
            mPaint.Color = Color.Green;
            if (PointsCloud.y) canvas.DrawPath (y, mPaint);
            mPaint.Color = Color.White;
            if (PointsCloud.z) canvas.DrawPath (z, mPaint);
            mPaint.Color = Color.Red;
            if (PointsCloud.v) canvas.DrawPath (v, mPaint);
        }
		public DrawerArrowDrawable(Resources resources, Boolean rounded1) {
			rounded = rounded1;
			float density = resources.DisplayMetrics.Density;
			float strokeWidthPixel = STROKE_WIDTH_DP * density;
			halfStrokeWidthPixel = strokeWidthPixel / 2;

			linePaint = new Paint(Android.Graphics.PaintFlags.SubpixelText | Android.Graphics.PaintFlags.AntiAlias);
			linePaint.StrokeCap=rounded ? Android.Graphics.Paint.Cap.Round : Android.Graphics.Paint.Cap.Butt;
			linePaint.Color=Android.Graphics.Color.Black;
			linePaint.SetStyle (Android.Graphics.Paint.Style.Stroke);
			linePaint.StrokeWidth=strokeWidthPixel;

			int dimen = (int) (DIMEN_DP * density);
			bounds = new Rect(0, 0, dimen, dimen);

			Path first, second;
			JoinedPath joinedA, joinedB;

			// Top
			first = new Path();
			first.MoveTo(5.042f, 20f);
			first.RCubicTo(8.125f, -16.317f, 39.753f, -27.851f, 55.49f, -2.765f);
			second = new Path();
			second.MoveTo(60.531f, 17.235f);
			second.RCubicTo(11.301f, 18.015f, -3.699f, 46.083f, -23.725f, 43.456f);
			scalePath(first, density);
			scalePath(second, density);
			joinedA = new JoinedPath(first, second);

			first = new Path();
			first.MoveTo(64.959f, 20f);
			first.RCubicTo(4.457f, 16.75f, 1.512f, 37.982f, -22.557f, 42.699f);
			second = new Path();
			second.MoveTo(42.402f, 62.699f);
			second.CubicTo(18.333f, 67.418f, 8.807f, 45.646f, 8.807f, 32.823f);
			scalePath(first, density);
			scalePath(second, density);
			joinedB = new JoinedPath(first, second);
			topLine = new BridgingLine(joinedA, joinedB);

			// Middle
			first = new Path();
			first.MoveTo(5.042f, 35f);
			first.CubicTo(5.042f, 20.333f, 18.625f, 6.791f, 35f, 6.791f);
			second = new Path();
			second.MoveTo(35f, 6.791f);
			second.RCubicTo(16.083f, 0f, 26.853f, 16.702f, 26.853f, 28.209f);
			scalePath(first, density);
			scalePath(second, density);
			joinedA = new JoinedPath(first, second);

			first = new Path();
			first.MoveTo(64.959f, 35f);
			first.RCubicTo(0f, 10.926f, -8.709f, 26.416f, -29.958f, 26.416f);
			second = new Path();
			second.MoveTo(35f, 61.416f);
			second.RCubicTo(-7.5f, 0f, -23.946f, -8.211f, -23.946f, -26.416f);
			scalePath(first, density);
			scalePath(second, density);
			joinedB = new JoinedPath(first, second);
			middleLine = new BridgingLine(joinedA, joinedB);

			// Bottom
			first = new Path();
			first.MoveTo(5.042f, 50f);
			first.CubicTo(2.5f, 43.312f, 0.013f, 26.546f, 9.475f, 17.346f);
			second = new Path();
			second.MoveTo(9.475f, 17.346f);
			second.RCubicTo(9.462f, -9.2f, 24.188f, -10.353f, 27.326f, -8.245f);
			scalePath(first, density);
			scalePath(second, density);
			joinedA = new JoinedPath(first, second);

			first = new Path();
			first.MoveTo(64.959f, 50f);
			first.RCubicTo(-7.021f, 10.08f, -20.584f, 19.699f, -37.361f, 12.74f);
			second = new Path();
			second.MoveTo(27.598f, 62.699f);
			second.RCubicTo(-15.723f, -6.521f, -18.8f, -23.543f, -18.8f, -25.642f);
			scalePath(first, density);
			scalePath(second, density);
			joinedB = new JoinedPath(first, second);
			bottomLine = new BridgingLine(joinedA, joinedB);
		}
Beispiel #39
0
        internal void Draw(Canvas canvas, bool isRound)
        {
            if (Hidden)
            {
                return;
            }

            canvas.Save();
            var resizerPaint = new Paint { Color = new Color(255, 255, 255, 200) };

            //if (!Focused)
            //{
            //    outlinePaint.Color = Color.White;
            //    canvas.DrawRect(DrawRect, outlinePaint);
            //    //canvas.DrawCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width(), resizerPaint);
            //}
            //else
            //{
            Rect viewDrawingRect = new Rect();
            context.GetDrawingRect(viewDrawingRect);

            outlinePaint.Color = Color.White;// new Color(0XFF, 0xFF, 0x8A, 0x00);
            focusPaint.Color = new Color(50, 50, 50, 125);

            Path path = new Path();

            if (isRound)
            {
                path.AddCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width() / 2, Path.Direction.Cw);
                canvas.ClipPath(path, Region.Op.Difference);
                canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint);
            }
            else
            {
                path.AddRect(new RectF(DrawRect), Path.Direction.Cw);
                canvas.ClipPath(path, Region.Op.Difference);
                canvas.DrawRect(viewDrawingRect, focusPaint);

            }

            //canvas.ClipPath(path, Region.Op.Difference);

            //if (isRound)
            //    canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint);
            //else
            //    canvas.DrawRect(viewDrawingRect, focusPaint);

            canvas.Restore();
            canvas.DrawPath(path, outlinePaint);

            var resizerTriangle = new Path();
            var resizerOffset = 4;
            var triangleSize = resizerSize + resizerOffset;
            resizerTriangle.MoveTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - triangleSize);
            resizerTriangle.LineTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - resizerOffset);
            resizerTriangle.LineTo(DrawRect.Right - triangleSize, DrawRect.Bottom - resizerOffset);
            resizerPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(resizerTriangle, resizerPaint);

            if (isRound)
            {
                // Draw the rectangle around the round cropper                
                var roundCropperRectangle = new Path();
                roundCropperRectangle.MoveTo(DrawRect.Left, DrawRect.Top);
                roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Top);
                roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Bottom);
                roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Bottom);
                roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Top);

                resizerPaint.SetStyle(Paint.Style.Stroke);
                canvas.DrawPath(roundCropperRectangle, resizerPaint);
            }
        }
		protected override void OnDraw(Canvas ca)  {
			if (fullImage == null || shouldUpdate) {
				fullImage = Bitmap.CreateBitmap (Width, Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(fullImage);
				String max = (int)maxY+"";// used to display max
				String min = (int)minY+"";// used to display min
				paint.Reset ();
				Path path = new Path();

				float bottomPadding = 1, topPadding = 0;
				float sidePadding = 10;
				if (this.showMinAndMax)
					sidePadding = txtPaint.MeasureText(max);

				float usableHeight = Height - bottomPadding - topPadding;
				float usableWidth = Width - sidePadding*2;
				float lineSpace = usableHeight/10;

				int lineCount = 0;
				foreach (Line line in lines) {
					int count = 0;
					float lastXPixels = 0, newYPixels;
					float lastYPixels = 0, newXPixels;
					float maxYd = getMaxY ();
					float minYd = getMinY();
					float maxXd = getMaxX();
					float minXd = getMinX();

					if (lineCount == lineToFill){
						paint.Color = Color.White;
						paint.Alpha = 30;	
						paint.StrokeWidth = 2;
						for (int i = 10; i-Width < Height; i = i+20){
							canvas.DrawLine(i, Height-bottomPadding, 0, Height-bottomPadding-i, paint);
						}

						paint.Reset();

						paint.SetXfermode (new PorterDuffXfermode (Android.Graphics.PorterDuff.Mode.Clear));
						foreach (LinePoint p  in line.getPoints()) {
							float yPercent = (p.getY()-minY)/(maxYd - minYd);
							float xPercent = (p.getX()-minX)/(maxXd - minXd);
							if (count == 0){
								lastXPixels = sidePadding + (xPercent*usableWidth);
								lastYPixels = Height - bottomPadding - (usableHeight*yPercent);
								path.MoveTo(lastXPixels, lastYPixels);
							} else {
								newXPixels = sidePadding + (xPercent*usableWidth);
								newYPixels = Height - bottomPadding - (usableHeight*yPercent);
								path.LineTo(newXPixels, newYPixels);
								Path pa = new Path();
								pa.MoveTo(lastXPixels, lastYPixels);
								pa.LineTo(newXPixels, newYPixels);
								pa.LineTo(newXPixels, 0);
								pa.LineTo(lastXPixels, 0);
								pa.Close();
								canvas.DrawPath(pa, paint);
								lastXPixels = newXPixels;
								lastYPixels = newYPixels;
							}
							count++;
						}

						path.Reset();

						path.MoveTo(0, Height-bottomPadding);
						path.LineTo(sidePadding, Height-bottomPadding);
						path.LineTo(sidePadding, 0);
						path.LineTo(0, 0);
						path.Close();
						canvas.DrawPath(path, paint);

						path.Reset();

						path.MoveTo(Width, Height-bottomPadding);
						path.LineTo(Width-sidePadding, Height-bottomPadding);
						path.LineTo(Width-sidePadding, 0);
						path.LineTo(Width, 0);
						path.Close();

						canvas.DrawPath(path, paint);

					}

					lineCount++;
				}

				paint.Reset();

				paint.Color = Color.White;
				//paint.setColor(this.gridColor);
				paint.Alpha = 50;
				paint.AntiAlias = true;
				canvas.DrawLine(sidePadding, Height - bottomPadding, Width, Height-bottomPadding, paint);
				if(this.showHorizontalGrid1)
					for(int i=1;i<=10;i++)
					{
						canvas.DrawLine(sidePadding, Height - bottomPadding-(i*lineSpace), Width, Height-bottomPadding-(i*lineSpace), paint);
					}
				paint.Alpha = 255;

				foreach (Line line in lines) {
					int count = 0;
					float lastXPixels = 0, newYPixels;
					float lastYPixels = 0, newXPixels;
					float maxYd = getMaxY();
					float minYd = getMinY();
					float maxXd = getMaxX();
					float minXd = getMinX();

					paint.Color = Color.Yellow;
					//paint.setColor(line.getColor());
					paint.StrokeWidth = 6;

					foreach (LinePoint p in line.getPoints()) {
						float yPercent = (p.getY()-minY)/(maxYd - minYd);
						float xPercent = (p.getX()-minX)/(maxXd - minXd);
						if (count == 0){
							lastXPixels = sidePadding + (xPercent*usableWidth);
							lastYPixels = Height - bottomPadding - (usableHeight*yPercent);
						} else {
							newXPixels = sidePadding + (xPercent*usableWidth);
							newYPixels = Height - bottomPadding - (usableHeight*yPercent);
							canvas.DrawLine(lastXPixels, lastYPixels, newXPixels, newYPixels, paint);
							lastXPixels = newXPixels;
							lastYPixels = newYPixels;
						}
						count++;
					}
				}


				int pointCount = 0;

				foreach (Line line  in lines) {
					float maxYd = getMaxY();
					float minYd = getMinY();
					float maxXd = getMaxX();
					float minXd = getMinX();

					paint.Color = Color.Yellow;
					//paint.setColor(line.getColor());
					paint.StrokeWidth = 6;
					paint.StrokeCap = Paint.Cap.Round;

					if (line.isShowingPoints()){
						foreach (LinePoint p in line.getPoints()) {
							float yPercent = (p.getY()-minYd)/(maxYd - minYd);
							float xPercent = (p.getX()-minXd)/(maxXd - minXd);
							float xPixels = sidePadding + (xPercent*usableWidth);
							float yPixels = Height - bottomPadding - (usableHeight*yPercent);

							paint.Color = Color.Gray;
							canvas.DrawCircle(xPixels, yPixels, 10, paint);
							paint.Color = Color.White;
							canvas.DrawCircle(xPixels, yPixels, 5, paint);

							Path path2 = new Path();
							path2.AddCircle(xPixels, yPixels, 30, Android.Graphics.Path.Direction.Cw);
							p.setPath(path2);
							p.setRegion(new Region((int)(xPixels-30), (int)(yPixels-30), (int)(xPixels+30), (int)(yPixels+30)));
							if (indexSelected == pointCount && listener != null){
								paint.Color=Color.ParseColor("#33B5E5");
								paint.Alpha = 100;
								canvas.DrawPath(p.getPath(), paint);
								paint.Alpha = 255;
							}

							pointCount++;
						}
					}
				}

				shouldUpdate = false;
				if (this.showMinAndMax) {
					ca.DrawText(max, 0, txtPaint.TextSize, txtPaint);
					ca.DrawText(min,0,this.Height,txtPaint);
				}
			}
			ca.DrawBitmap(fullImage, 0, 0, null);
		}
		public static Bitmap ToTransformedCorners(Bitmap source, double topLeftCornerSize, double topRightCornerSize, double bottomLeftCornerSize, double bottomRightCornerSize, 
			CornerTransformType cornersTransformType, double cropWidthRatio, double cropHeightRatio)
		{
			double sourceWidth = source.Width;
			double sourceHeight = source.Height;

			double desiredWidth = sourceWidth;
			double desiredHeight = sourceHeight;

			double desiredRatio = cropWidthRatio / cropHeightRatio;
			double currentRatio = sourceWidth / sourceHeight;

			if (currentRatio > desiredRatio)
			{
				desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
			}
			else if (currentRatio < desiredRatio)
			{
				desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
			}

			topLeftCornerSize = topLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			topRightCornerSize = topRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			bottomLeftCornerSize = bottomLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			bottomRightCornerSize = bottomRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;

			float cropX = (float)((sourceWidth - desiredWidth) / 2);
			float cropY = (float)((sourceHeight - desiredHeight) / 2);

			Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			using (var path = new Path())
			{
				if (cropX != 0 || cropY != 0)
				{
					matrix.SetTranslate(-cropX, -cropY);
					shader.SetLocalMatrix(matrix);
				}

				paint.SetShader(shader);
				paint.AntiAlias = true;

				// TopLeft
				if (cornersTransformType.HasFlag(CornerTransformType.TopLeftCut)) 
				{
					path.MoveTo(0, (float)topLeftCornerSize);
					path.LineTo((float)topLeftCornerSize, 0);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.TopLeftRounded)) 
				{
					path.MoveTo(0, (float)topLeftCornerSize);
					path.QuadTo(0, 0, (float)topLeftCornerSize, 0);
				}
				else
				{
					path.MoveTo(0, 0);
				}

				// TopRight
				if (cornersTransformType.HasFlag(CornerTransformType.TopRightCut)) 
				{
					path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
					path.LineTo((float)desiredWidth, (float)topRightCornerSize);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.TopRightRounded))
				{
					path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
					path.QuadTo((float)desiredWidth, 0, (float)desiredWidth, (float)topRightCornerSize);
				}
				else
				{
					path.LineTo((float)desiredWidth ,0);
				}

				// BottomRight
				if (cornersTransformType.HasFlag(CornerTransformType.BottomRightCut)) 
				{
					path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
					path.LineTo((float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.BottomRightRounded))
				{
					path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
					path.QuadTo((float)desiredWidth, (float)desiredHeight, (float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
				}
				else
				{
					path.LineTo((float)desiredWidth, (float)desiredHeight);
				}

				// BottomLeft
				if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftCut)) 
				{
					path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
					path.LineTo(0, (float)(desiredHeight - bottomLeftCornerSize));
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftRounded)) 
				{
					path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
					path.QuadTo(0, (float)desiredHeight, 0, (float)(desiredHeight - bottomLeftCornerSize));
				}
				else
				{
					path.LineTo(0, (float)desiredHeight);
				}

				path.Close();
				canvas.DrawPath(path, paint);

				return bitmap;				
			}
		}
Beispiel #42
0
 public void BeginFigure(float x, float y)
 {
     path.MoveTo(x, y);
 }
Beispiel #43
0
        public object ConvertToNative(Geometry geometry)
        {
            // TODO: Can we keep this object around and reset it?
            droidGraphics.Path path = new droidGraphics.Path();
            // TODO: Might we also save a non-transformed path and a transformed path? -- No, that fails for GeometryGroup

            // Determine what type of Geometry we're dealing with
            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;

                path.MoveTo(PixelsPerDip * (float)lineGeometry.StartPoint.X,
                            PixelsPerDip * (float)lineGeometry.StartPoint.Y);

                path.LineTo(PixelsPerDip * (float)lineGeometry.EndPoint.X,
                            PixelsPerDip * (float)lineGeometry.EndPoint.Y);
            }

            else if (geometry is RectangleGeometry)
            {
                Rect rect = (geometry as RectangleGeometry).Rect;

                path.AddRect(PixelsPerDip * (float)rect.Left,
                             PixelsPerDip * (float)rect.Top,
                             PixelsPerDip * (float)rect.Right,
                             PixelsPerDip * (float)rect.Bottom,
                             droidGraphics.Path.Direction.Cw);              // TODO: Check for compatibility!
            }

            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;

                path.AddOval(new droidGraphics.RectF(
                                 PixelsPerDip * (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX),
                                 PixelsPerDip * (float)(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY),
                                 PixelsPerDip * (float)(ellipseGeometry.Center.X + ellipseGeometry.RadiusX),
                                 PixelsPerDip * (float)(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)),
                             droidGraphics.Path.Direction.Cw);              // TODO: Check for compatibility!
            }

            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;
                SetFillRule(path, geometryGroup.FillRule);

                foreach (Geometry child in geometryGroup.Children)
                {
                    droidGraphics.Path childPath = ConvertToNative(child) as droidGraphics.Path;
                    path.AddPath(childPath);
                }
            }

            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                SetFillRule(path, pathGeometry.FillRule);

                foreach (PathFigure pathFigure in pathGeometry.Figures)
                {
                    path.MoveTo(PixelsPerDip * (float)pathFigure.StartPoint.X,
                                PixelsPerDip * (float)pathFigure.StartPoint.Y);
                    Point lastPoint = pathFigure.StartPoint;

                    foreach (PathSegment pathSegment in pathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            path.LineTo(PixelsPerDip * (float)lineSegment.Point.X,
                                        PixelsPerDip * (float)lineSegment.Point.Y);
                            lastPoint = lineSegment.Point;
                        }

                        // PolylineSegment
                        else if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment polylineSegment = pathSegment as PolyLineSegment;
                            PointCollection points          = polylineSegment.Points;

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(PixelsPerDip * (float)points[i].X,
                                            PixelsPerDip * (float)points[i].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }

                        // BezierSegment
                        else if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            path.CubicTo(PixelsPerDip * (float)bezierSegment.Point1.X, PixelsPerDip * (float)bezierSegment.Point1.Y,
                                         PixelsPerDip * (float)bezierSegment.Point2.X, PixelsPerDip * (float)bezierSegment.Point2.Y,
                                         PixelsPerDip * (float)bezierSegment.Point3.X, PixelsPerDip * (float)bezierSegment.Point3.Y);

                            lastPoint = bezierSegment.Point3;
                        }

                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment;
                            PointCollection   points            = polyBezierSegment.Points;

                            for (int i = 0; i < points.Count; i += 3)
                            {
                                path.CubicTo(PixelsPerDip * (float)points[i + 0].X, PixelsPerDip * (float)points[i + 0].Y,
                                             PixelsPerDip * (float)points[i + 1].X, PixelsPerDip * (float)points[i + 1].Y,
                                             PixelsPerDip * (float)points[i + 2].X, PixelsPerDip * (float)points[i + 2].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }

                        // QuadraticBezierSegment
                        else if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment;

                            path.QuadTo(PixelsPerDip * (float)bezierSegment.Point1.X, PixelsPerDip * (float)bezierSegment.Point1.Y,
                                        PixelsPerDip * (float)bezierSegment.Point2.X, PixelsPerDip * (float)bezierSegment.Point2.Y);

                            lastPoint = bezierSegment.Point2;
                        }

                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            PointCollection            points            = polyBezierSegment.Points;

                            for (int i = 0; i < points.Count; i += 2)
                            {
                                path.QuadTo(PixelsPerDip * (float)points[i + 0].X, PixelsPerDip * (float)points[i + 0].Y,
                                            PixelsPerDip * (float)points[i + 1].X, PixelsPerDip * (float)points[i + 1].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }

                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            List <Point> points = new List <Point>();
                            Xamarin.Forms.Shapes.Shapes.FlattenArc(points,
                                                                   lastPoint,
                                                                   arcSegment.Point,
                                                                   arcSegment.Size.Width,
                                                                   arcSegment.Size.Height,
                                                                   arcSegment.RotationAngle,
                                                                   arcSegment.IsLargeArc,
                                                                   arcSegment.SweepDirection == SweepDirection.Counterclockwise,
                                                                   1);

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(PixelsPerDip * (float)points[i].X,
                                            PixelsPerDip * (float)points[i].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }
                    }

                    if (pathFigure.IsClosed)
                    {
                        path.Close();
                    }
                }
            }

            // Apply transform
            if (geometry.Transform != null)
            {
                path.Transform((droidGraphics.Matrix)geometry.Transform.GetNativeObject());
            }

            return(path);
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            switch(mShape)
            {
                case Shape.TRIANGLE:
                    {
                        if (mIsLoading)
                        {
                            mAnimPercent += 0.1611113f;
                            Path path = new Path();
                            path.MoveTo(RelativeXFromView(0.5f),
                                RelativeYFromView(0.5f));

                            if (mAnimPercent >= 1)
                            {
                                mShape = Shape.CIRCLE;
                                mIsLoading = false;
                                mAnimPercent = 1;
                            }
                            float controlX = mControlX - RelativeXFromView(mAnimPercent * triangle2Circle) * genhao3;
                            float controlY = mControlY - RelativeYFromView(mAnimPercent * triangle2Circle);
                            path.QuadTo(RelativeXFromView(1) - controlX, controlY, RelativeXFromView(0.5f + genhao3 / 4),
                                RelativeYFromView(0.75f));
                            path.QuadTo(RelativeXFromView(0.5f), RelativeYFromView(0.75f + 2 * mAnimPercent * triangle2Circle),
                                RelativeXFromView(0.5f - genhao3 / 4), RelativeYFromView(0.75f));
                            path.QuadTo(controlX, controlY, RelativeXFromView(0.5f), RelativeYFromView(0f));
                            path.Close();
                            canvas.DrawPath(path, mPaint);
                            Invalidate();
                        }
                        else
                        {
                            Path path = new Path();
                            mPaint.Color = Resources.GetColor(Resource.Color.triangle);
                            path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0f));
                            path.LineTo(RelativeXFromView(1), RelativeYFromView(genhao3 / 2f));
                            path.LineTo(RelativeXFromView(0), RelativeYFromView(genhao3 / 2f));

                            mControlX = RelativeXFromView(0.5f - genhao3 / 8f);
                            mControlY = RelativeYFromView(3 / 8f);
                            mAnimPercent = 0;
                            path.Close();
                            canvas.DrawPath(path, mPaint);
                        }
                    }
                    break;
                case Shape.CIRCLE:
                    {
                        if(mIsLoading)
                        {
                            float magicNumber = mMagicNumber + mAnimPercent;
                            mAnimPercent += 0.12f;
                            if(magicNumber + mAnimPercent > 1.9f)
                            {
                                mShape = Shape.RECT;
                                mIsLoading = false;
                            }
                            Path path = new Path();
                            path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0f));
                            path.CubicTo(RelativeXFromView(0.5f + magicNumber / 2), RelativeYFromView(0f),
                                RelativeXFromView(1), RelativeYFromView(0.5f - magicNumber / 2),
                                RelativeXFromView(1f), RelativeYFromView(0.5f));
                            path.CubicTo(RelativeXFromView(1), RelativeXFromView(0.5f + magicNumber / 2),
                                RelativeXFromView(0.5f + mMagicNumber / 2), RelativeYFromView(1f),
                                RelativeXFromView(0.5f), RelativeYFromView(1f));
                            path.CubicTo(RelativeXFromView(0.5f - magicNumber / 2), RelativeXFromView(1f),
                                RelativeXFromView(0), RelativeYFromView(0.5f + magicNumber / 2),
                                RelativeXFromView(0f), RelativeYFromView(0.5f));
                            path.CubicTo(RelativeXFromView(0f), RelativeXFromView(0.5f - magicNumber / 2),
                                RelativeXFromView(0.5f - magicNumber / 2), RelativeYFromView(0),
                                RelativeXFromView(0.5f), RelativeYFromView(0f));
                            path.Close();
                            canvas.DrawPath(path, mPaint);
                            Invalidate();
                        }
                        else
                        {
                            mPaint.Color = Resources.GetColor(Resource.Color.circle);
                            Path path = new Path();
                            float magicNumber = mMagicNumber;
                            path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0f));
                            path.CubicTo(RelativeXFromView(0.5f + magicNumber / 2), 0,
                                    RelativeXFromView(1), RelativeYFromView(magicNumber / 2),
                                    RelativeXFromView(1f), RelativeYFromView(0.5f));
                            path.CubicTo(
                                    RelativeXFromView(1), RelativeXFromView(0.5f + magicNumber / 2),
                                    RelativeXFromView(0.5f + magicNumber / 2), RelativeYFromView(1f),
                                    RelativeXFromView(0.5f), RelativeYFromView(1f));
                            path.CubicTo(RelativeXFromView(0.5f - magicNumber / 2), RelativeXFromView(1f),
                                    RelativeXFromView(0), RelativeYFromView(0.5f + magicNumber / 2),
                                    RelativeXFromView(0f), RelativeYFromView(0.5f));
                            path.CubicTo(RelativeXFromView(0f), RelativeXFromView(0.5f - magicNumber / 2),
                                    RelativeXFromView(0.5f - magicNumber / 2), RelativeYFromView(0),
                                    RelativeXFromView(0.5f), RelativeYFromView(0f));
                            mAnimPercent = 0;
                            path.Close();
                            canvas.DrawPath(path, mPaint);
                        }
                    }
                    break;
                case Shape.RECT:
                    {
                        if(mIsLoading)
                        {
                            mAnimPercent += 0.15f;
                            if(mAnimPercent >= 1)
                            {
                                mShape = Shape.TRIANGLE;
                                mIsLoading = false;
                                mAnimPercent = 1;
                            }
                            Path path = new Path();
                            path.MoveTo(RelativeXFromView(0.5f * mAnimPercent), 0);
                            path.LineTo(RelativeYFromView(1 - 0.5f * mAnimPercent), 0);
                            float distanceX = (mControlX) * mAnimPercent;
                            float distanceY = (RelativeYFromView(1f) - mControlY) * mAnimPercent;
                            path.LineTo(RelativeXFromView(1f) - distanceX, RelativeYFromView(1f) - distanceY);
                            path.LineTo(RelativeXFromView(0f) + distanceX, RelativeYFromView(1f) - distanceY);
                            path.Close();
                            canvas.DrawPath(path, mPaint);
                            Invalidate();
                        }
                        else
                        {
                            mPaint.Color = Resources.GetColor(Resource.Color.rect);
                            mControlX = RelativeXFromView(0.5f - genhao3 / 4);
                            mControlY = RelativeYFromView(0.75f);
                            Path path = new Path();
                            path.MoveTo(RelativeXFromView(0f), RelativeYFromView(0f));
                            path.LineTo(RelativeXFromView(1f), RelativeYFromView(0f));
                            path.LineTo(RelativeXFromView(1f), RelativeYFromView(1f));
                            path.LineTo(RelativeXFromView(0f), RelativeYFromView(1f));
                            path.Close();
                            mAnimPercent = 0;
                            canvas.DrawPath(path, mPaint);
                        }
                    }
                    break;
            }
        }
Beispiel #45
0
        private void DrawDecart(Canvas canvas)
        {
            canvas.DrawColor (Color.Black);
            Paint mPaint = new Paint();
            mPaint.Dither = true;
            mPaint.SetStyle (Paint.Style.Stroke);
            mPaint.Color = Color.White;
            mPaint.StrokeJoin = Paint.Join.Bevel;
            mPaint.StrokeCap = Paint.Cap.Round;
            mPaint.StrokeWidth = 3;
            Path path = null;
            // оси
            path = new Path ();
            path.MoveTo (MarginL,         MarginU);
            path.LineTo (MarginL,         canvas.Height-MarginB);
            canvas.DrawPath (path, mPaint);
            // max min
            DateTime MaxX = PointsCloud.MaxX;
            DateTime MinX = PointsCloud.MinX;

            // разметка вертикальные линии
            if (MaxX.Equals (MinX))
                return;

            double totalMills = (MaxX - MinX).TotalMilliseconds;
            int totalPixs = (canvas.Width - MarginL - MarginR);
            int delta = Convert.ToInt32(System.Math.Ceiling(1/((totalPixs * 1000 / totalMills) / 96)));

            DateTime next = MinX;
            next = next.AddMilliseconds (-next.Millisecond);
            next = next.AddSeconds (1);

            mPaint.StrokeWidth = 1;

            while (next.CompareTo(MaxX)<0) {
                double a = (next - MinX).TotalMilliseconds;
                double b = a / totalMills;
                double c = b * totalPixs;
                int pix = Convert.ToInt32 (c);
                mPaint.SetStyle (Paint.Style.Stroke);
                canvas.DrawLine (MarginL + pix, MarginU, MarginL + pix, canvas.Height-MarginB, mPaint);
                mPaint.TextSize = 20;
                mPaint.SetStyle(Paint.Style.Fill);
                canvas.DrawText (next.ToLongTimeString(),
                                 MarginL + pix , canvas.Height-MarginB + MarginB/2, mPaint );
                next = next.AddSeconds (delta);
            }

            if (!(PointsCloud.x || PointsCloud.y || PointsCloud.z || PointsCloud.v))
                return;

            double MaxY = PointsCloud.MaxY;
            double MinY = PointsCloud.MinY;

            double totalDiff = MaxY - MinY;
            totalPixs = (canvas.Height - MarginU - MarginB);

            delta = Convert.ToInt32(System.Math.Ceiling(1/((totalPixs / totalDiff) / 96)));

            if (totalDiff != 0) {
                double nextY = MaxY;
                nextY = Convert.ToDouble (System.Math.Ceiling (nextY));

                while (nextY>MinY) {
                    double a = (MaxY - nextY);
                    double b = a / totalDiff;
                    double c = b * totalPixs;
                    int pix = Convert.ToInt32 (c);
                    mPaint.SetStyle (Paint.Style.Stroke);
                    canvas.DrawLine (MarginL, MarginU + pix, canvas.Width - MarginR, MarginU + pix, mPaint);
                    mPaint.TextSize = 20;
                    mPaint.SetStyle(Paint.Style.Fill);
                    canvas.DrawText (nextY.ToString(),
                                     0 , MarginU + pix, mPaint );
                    nextY = nextY - delta;
                }
            }
        }
Beispiel #46
0
        public void DrawPath(IEnumerable <PathOperation> ops, Pen pen = null, BaseBrush brush = null)
        {
            using (var path = new Path())
            {
                var bb = new BoundingBoxBuilder();

                foreach (var op in ops)
                {
                    var moveTo = op as MoveTo;
                    if (moveTo != null)
                    {
                        var start = moveTo.Start;
                        var end   = moveTo.End;

                        path.MoveTo((float)start.X, (float)start.Y);

                        bb.Add(start);
                        bb.Add(end);
                        continue;
                    }
                    var lineTo = op as LineTo;
                    if (lineTo != null)
                    {
                        var start = lineTo.Start;
                        var end   = lineTo.End;
                        path.LineTo((float)start.X, (float)start.Y);
                        path.LineTo((float)end.X, (float)end.Y);
                        bb.Add(start);
                        bb.Add(end);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;
                        path.LineTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var curveTo = op as CurveTo;
                    if (curveTo != null)
                    {
                        var end = curveTo.End;
                        var firstControlPoint  = curveTo.FirstControlPoint;
                        var secondControlPoint = curveTo.SecondControlPoint;

                        path.CubicTo((float)firstControlPoint.X, (float)firstControlPoint.Y, (float)secondControlPoint.X,
                                     (float)secondControlPoint.Y, (float)end.X, (float)end.Y);

                        bb.Add(firstControlPoint);
                        bb.Add(secondControlPoint);
                        bb.Add(end);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null)
                    {
                        path.Close();
                        continue;
                    }

                    throw new NotSupportedException("Path Op " + op);
                }

                var frame = bb.BoundingBox;

                if (brush != null)
                {
                    var solidBrush = brush as SolidBrush;

                    if (solidBrush != null)
                    {
                        path.SetFillType(GetPathFillType(((SolidBrush)brush).FillMode));
                    }

                    var brushPaint = GetBrushPaint(brush, frame);
                    graphics.DrawPath(path, brushPaint);
                }
                if (pen != null)
                {
                    var penPaint = GetPenPaint(pen);
                    graphics.DrawPath(path, penPaint);
                }
            }
        }
		private void DrawLineChart(Canvas canvas) {
			var path = new Path ();

			var current = 0;

			var labelYPos = (float)chartPixelHeight + PaddingTop + PaddingBottom + 20f;

			foreach (var point in _chartPoints) {
				if (current == 0) {
					path.MoveTo (point.X, point.Y);
				} else {
					path.LineTo (point.X, point.Y);
				}

				canvas.DrawText (xLabels [current], point.X, labelYPos, _xLabelPaint);

				current++;
			}

			paint.SetStyle (Paint.Style.Stroke);
			paint.StrokeWidth = 4f;
			paint.Color = Color.ParseColor (RSColors.PURPLE_4);
			paint.AntiAlias = true;

			canvas.DrawPath (path, paint);

			_xLabelPaint.Color = Color.ParseColor (RSColors.RS_LIGHT_GRAY);
			canvas.DrawText ("Year", Width / 2, labelYPos + 45.0f, _xLabelPaint);
		}
Beispiel #48
0
 Path GetPolyPath(Polygon poly)
 {
     var p = poly.Tag as Path;
     if (p == null) {
         p = new Path ();
         p.MoveTo (poly.Points[0].X, poly.Points[0].Y);
         for (var i = 1; i < poly.Points.Count; i++) {
             var pt = poly.Points[i];
             p.LineTo (pt.X, pt.Y);
         }
         p.LineTo (poly.Points[0].X, poly.Points[0].Y);
         poly.Tag = p;
     }
     return p;
 }
Beispiel #49
0
        public static APath ToAPath(this Geometry geometry, Context context)
        {
            APath path = new APath();

            float density = context.Resources.DisplayMetrics.Density;

            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;

                path.MoveTo(
                    density * (float)lineGeometry.StartPoint.X,
                    density * (float)lineGeometry.StartPoint.Y);

                path.LineTo(
                    density * (float)lineGeometry.EndPoint.X,
                    density * (float)lineGeometry.EndPoint.Y);
            }
            else if (geometry is RectangleGeometry)
            {
                FormsRectangle rect = (geometry as RectangleGeometry).Rect;

                path.AddRect(
                    density * (float)rect.Left,
                    density * (float)rect.Top,
                    density * (float)rect.Right,
                    density * (float)rect.Bottom,
                    APath.Direction.Cw);
            }
            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;

                path.AddOval(new RectF(
                                 density * (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX),
                                 density * (float)(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY),
                                 density * (float)(ellipseGeometry.Center.X + ellipseGeometry.RadiusX),
                                 density * (float)(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)),
                             APath.Direction.Cw);
            }
            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;

                path.SetFillType(geometryGroup.FillRule == FillRule.Nonzero ? APath.FillType.Winding : APath.FillType.EvenOdd);

                foreach (Geometry child in geometryGroup.Children)
                {
                    APath childPath = child.ToAPath(context);
                    path.AddPath(childPath);
                }
            }
            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                path.SetFillType(pathGeometry.FillRule == FillRule.Nonzero ? APath.FillType.Winding : APath.FillType.EvenOdd);

                foreach (PathFigure pathFigure in pathGeometry.Figures)
                {
                    path.MoveTo(
                        density * (float)pathFigure.StartPoint.X,
                        density * (float)pathFigure.StartPoint.Y);

                    Point lastPoint = pathFigure.StartPoint;

                    foreach (PathSegment pathSegment in pathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            path.LineTo(
                                density * (float)lineSegment.Point.X,
                                density * (float)lineSegment.Point.Y);
                            lastPoint = lineSegment.Point;
                        }
                        // PolylineSegment
                        else if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment polylineSegment = pathSegment as PolyLineSegment;
                            PointCollection points          = polylineSegment.Points;

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(
                                    density * (float)points[i].X,
                                    density * (float)points[i].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }
                        // BezierSegment
                        else if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            path.CubicTo(
                                density * (float)bezierSegment.Point1.X, density * (float)bezierSegment.Point1.Y,
                                density * (float)bezierSegment.Point2.X, density * (float)bezierSegment.Point2.Y,
                                density * (float)bezierSegment.Point3.X, density * (float)bezierSegment.Point3.Y);

                            lastPoint = bezierSegment.Point3;
                        }
                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment;
                            PointCollection   points            = polyBezierSegment.Points;

                            if (points.Count >= 3)
                            {
                                for (int i = 0; i < points.Count; i += 3)
                                {
                                    path.CubicTo(
                                        density * (float)points[i + 0].X, density * (float)points[i + 0].Y,
                                        density * (float)points[i + 1].X, density * (float)points[i + 1].Y,
                                        density * (float)points[i + 2].X, density * (float)points[i + 2].Y);
                                }
                            }

                            lastPoint = points[points.Count - 1];
                        }
                        // QuadraticBezierSegment
                        else if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment;

                            path.QuadTo(
                                density * (float)bezierSegment.Point1.X, density * (float)bezierSegment.Point1.Y,
                                density * (float)bezierSegment.Point2.X, density * (float)bezierSegment.Point2.Y);

                            lastPoint = bezierSegment.Point2;
                        }
                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            PointCollection            points            = polyBezierSegment.Points;

                            if (points.Count >= 2)
                            {
                                for (int i = 0; i < points.Count; i += 2)
                                {
                                    path.QuadTo(
                                        density * (float)points[i + 0].X, density * (float)points[i + 0].Y,
                                        density * (float)points[i + 1].X, density * (float)points[i + 1].Y);
                                }
                            }

                            lastPoint = points[points.Count - 1];
                        }
                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            List <Point> points = new List <Point>();

                            GeometryHelper.FlattenArc(
                                points,
                                lastPoint,
                                arcSegment.Point,
                                arcSegment.Size.Width,
                                arcSegment.Size.Height,
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == SweepDirection.CounterClockwise,
                                1);

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(
                                    density * (float)points[i].X,
                                    density * (float)points[i].Y);
                            }

                            if (points.Count > 0)
                            {
                                lastPoint = points[points.Count - 1];
                            }
                        }
                    }

                    if (pathFigure.IsClosed)
                    {
                        path.Close();
                    }
                }
            }

            return(path);
        }
Beispiel #50
0
		//Allow the user to import an array of points to be used to draw a signature in the view, with new
		//lines indicated by a System.Drawing.PointF.Empty in the array.
		public void LoadPoints (System.Drawing.PointF[] loadedPoints)
		{
			if (loadedPoints == null || loadedPoints.Count () == 0)
				return;
			
			var startIndex = 0;
			var emptyIndex = loadedPoints.ToList ().IndexOf (System.Drawing.PointF.Empty);
			
			if (emptyIndex == -1)
				emptyIndex = loadedPoints.Count ();
			
			//Clear any existing paths or points.
			paths = new List<Path> ();
			points = new List<System.Drawing.PointF[]> ();
			
			do {
				//Create a new path and set the line options
				currentPath = new Path ();
				currentPoints = new List<System.Drawing.PointF> ();
				
				//Move to the first point and add that point to the current_points array.
				currentPath.MoveTo (loadedPoints [startIndex].X, loadedPoints [startIndex].Y);
				currentPoints.Add (loadedPoints [startIndex]);
				
				//Iterate through the array until an empty point (or the end of the array) is reached,
				//adding each point to the current_path and to the current_points array.
				for (var i = startIndex + 1; i < emptyIndex; i++) {
					currentPath.LineTo (loadedPoints [i].X, loadedPoints [i].Y);
					currentPoints.Add (loadedPoints [i]);
				}
				
				//Add the current_path and current_points list to their respective Lists before
				//starting on the next line to be drawn.
				paths.Add (currentPath);
				points.Add (currentPoints.ToArray ());
				
				//Obtain the indices for the next line to be drawn.
				startIndex = emptyIndex + 1;
				if (startIndex < loadedPoints.Count () - 1) {
					emptyIndex = loadedPoints.ToList ().IndexOf (System.Drawing.PointF.Empty, 
					                                             startIndex);
					
					if (emptyIndex == -1)
						emptyIndex = loadedPoints.Count ();
				} else
					emptyIndex = startIndex;
			} while (startIndex < emptyIndex);
			
			DrawStrokes ();

			//Display the clear button.
			lblClear.Visibility = ViewStates.Visible; 
			Invalidate ();
		}
        /// <summary>
        ///     Implement this to do your drawing.
        /// </summary>
        /// <param name="canvas">the canvas on which the background will be drawn</param>
        /// <since version="Added in API level 1" />
        /// <remarks>
        ///     <para tool="javadoc-to-mdoc">Implement this to do your drawing.</para>
        ///     <para tool="javadoc-to-mdoc">
        ///         <format type="text/html">
        ///             <a href="http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)"
        ///                 target="_blank">
        ///                 [Android Documentation]
        ///             </a>
        ///         </format>
        ///     </para>
        /// </remarks>
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var r = new Rect(0, 0, canvas.Width, canvas.Height);
            var dAdjustedThicnkess = (float)Thickness * _dm;

            var paint = new Paint { Color = StrokeColor, StrokeWidth = dAdjustedThicnkess, AntiAlias = true };
            paint.SetStyle(Paint.Style.Stroke);
            switch (StrokeType)
            {
                case StrokeType.Dashed:
                    paint.SetPathEffect(new DashPathEffect(new[] { 6 * _dm, 2 * _dm }, 0));
                    break;
                case StrokeType.Dotted:
                    paint.SetPathEffect(new DashPathEffect(new[] { dAdjustedThicnkess, dAdjustedThicnkess }, 0));
                    break;
            }

            var thicknessOffset = (dAdjustedThicnkess) / 2.0f;

            var p = new Path();
            if (Orientation == SeparatorOrientation.Horizontal)
            {
                p.MoveTo(0, thicknessOffset);
                p.LineTo(r.Width(), thicknessOffset);
            }
            else
            {
                p.MoveTo(thicknessOffset, 0);
                p.LineTo(thicknessOffset, r.Height());
            }
            canvas.DrawPath(p, paint);
        }
Beispiel #52
0
		Path smoothedPathWithGranularity (int granularity, out List<System.Drawing.PointF> smoothedPoints)
		{
			List<System.Drawing.PointF> pointsArray = currentPoints;
			smoothedPoints = new List<System.Drawing.PointF> ();

			//Not enough points to smooth effectively, so return the original path and points.
			if (pointsArray.Count < 4) {
				smoothedPoints = pointsArray;
				return currentPath;
			}

			//Create a new bezier path to hold the smoothed path.
			Path smoothedPath = new Path ();
	
			//Duplicate the first and last points as control points.
			pointsArray.Insert (0, pointsArray [0]);
			pointsArray.Add (pointsArray [pointsArray.Count - 1]);

			//Add the first point
			smoothedPath.MoveTo (pointsArray [0].X, pointsArray [0].Y);
			smoothedPoints.Add (pointsArray [0]);

			for (var index = 1; index < pointsArray.Count - 2; index++) {
				System.Drawing.PointF p0 = pointsArray [index - 1];
				System.Drawing.PointF p1 = pointsArray [index];
				System.Drawing.PointF p2 = pointsArray [index + 1];
				System.Drawing.PointF p3 = pointsArray [index + 2];

				//Add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines
				for (var i = 1; i < granularity; i++) {
					float t = (float)i * (1f / (float)granularity);
					float tt = t * t;
					float ttt = tt * t;

					//Intermediate point
					System.Drawing.PointF mid = new System.Drawing.PointF ();
					mid.X = 0.5f * (2f * p1.X + (p2.X - p0.X) * t + 
					                (2f * p0.X - 5f * p1.X + 4f * p2.X - p3.X) * tt + 
					                (3f * p1.X - p0.X - 3f * p2.X + p3.X) * ttt);
					mid.Y = 0.5f * (2 * p1.Y + (p2.Y - p0.Y) * t + 
					                (2 * p0.Y - 5 * p1.Y + 4 * p2.Y - p3.Y) * tt + 
					                (3 * p1.Y - p0.Y - 3 * p2.Y + p3.Y) * ttt);

					smoothedPath.LineTo (mid.X, mid.Y);
					smoothedPoints.Add (mid);
				}

				//Add p2
				smoothedPath.LineTo (p2.X, p2.Y);
				smoothedPoints.Add (p2);
			}

			//Add the last point
			System.Drawing.PointF last = pointsArray [pointsArray.Count - 1];
			smoothedPath.LineTo (last.X, last.Y);
			smoothedPoints.Add (last);

			return smoothedPath;
		}
Beispiel #53
0
        public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null)
        {
            using (var path = new Path())
              {
            var bb = new BoundingBoxBuilder();

            foreach (var op in ops)
            {
              var moveTo = op as MoveTo;
              if (moveTo != null)
              {
            var start = moveTo.Start;
            var end = moveTo.End;

            path.MoveTo((float) start.X, (float) start.Y);

            bb.Add(start);
            bb.Add(end);
            continue;
              }
              var lineTo = op as LineTo;
              if (lineTo != null)
              {
            var start = lineTo.Start;
            var end = lineTo.End;
            path.LineTo((float) start.X, (float) start.Y);
            path.LineTo((float) end.X, (float) end.Y);
            bb.Add(start);
            bb.Add(end);
            continue;
              }
              var at = op as ArcTo;
              if (at != null)
              {
            var p = at.Point;
            path.LineTo((float) p.X, (float) p.Y);
            bb.Add(p);
            continue;
              }
              var curveTo = op as CurveTo;
              if (curveTo != null)
              {
            var end = curveTo.End;
            var firstControlPoint = curveTo.FirstControlPoint;
            var secondControlPoint = curveTo.SecondControlPoint;

            path.CubicTo((float) firstControlPoint.X, (float) firstControlPoint.Y, (float) secondControlPoint.X,
              (float) secondControlPoint.Y, (float) end.X, (float) end.Y);

            bb.Add(firstControlPoint);
            bb.Add(secondControlPoint);
            bb.Add(end);
            continue;
              }
              var cp = op as ClosePath;
              if (cp != null)
              {
            path.Close();
            continue;
              }

              throw new NotSupportedException("Path Op " + op);
            }

            var frame = bb.BoundingBox;

            if (brush != null)
            {
              var solidBrush = brush as SolidBrush;

              if (solidBrush != null)
              {
            path.SetFillType(GetPathFillType(((SolidBrush)brush).FillMode));
              }

              var brushPaint = GetBrushPaint(brush, frame);
              graphics.DrawPath(path, brushPaint);
            }
            if (pen != null)
            {
              var penPaint = GetPenPaint(pen);
              graphics.DrawPath(path, penPaint);
            }
              }
        }
Beispiel #54
0
        protected override void OnDraw(Canvas canvas)
        {
            try
            {
                base.OnDraw(canvas);
            }
            catch (Java.Lang.Exception)
            {
                return;
            }
            canvas.DrawColor(Color.Black);
            if (IsSideBeyondCube(RotatingSide))
            {
                RotateSide(canvas, RotatingSide, rotatorAngle);
                DrawCubeWithoutRotating(canvas);
            }
            else
            {
                DrawCubeWithoutRotating(canvas);
                RotateSide(canvas, RotatingSide, rotatorAngle);
            }
            if (curFormula.Length > 15)
            {
                canvas.DrawText(
                    (new string(curFormula.Take(curFormula.Length / 2).ToArray())).Replace('z', '\''),
                    Width / 2,
                    Height / 8,
                    textPaint);
                canvas.DrawText(
                    (new string(curFormula.Skip(curFormula.Length / 2).ToArray())).Replace('z', '\''),
                    Width / 2,
                    Height / 8 + tsize + 5,
                    textPaint);
            }
            else
            {
                canvas.DrawText(
                    curFormula.Replace('z', '\''),
                    Width / 2,
                    Height / 8 + tsize / 2,
                    textPaint);
            }

            if (onPause)
            {
                Android.Graphics.Path p = new Android.Graphics.Path();
                p.MoveTo(Width / 20, Height * 17 / 20);
                p.LineTo(Width / 8, Height * 18 / 20);
                p.LineTo(Width / 20, Height * 19 / 20);
                canvas.DrawPath(p, new Paint()
                {
                    Color = Color.Aquamarine, StrokeWidth = 10
                });
            }
            else
            {
                canvas.DrawLine(Width / 20, Height * 17 / 20, Width / 20, Height * 19 / 20, new Paint()
                {
                    Color = Color.Aquamarine, StrokeWidth = 10
                });
                canvas.DrawLine(Width / 8, Height * 17 / 20, Width / 8, Height * 19 / 20, new Paint()
                {
                    Color = Color.Aquamarine, StrokeWidth = 10
                });
            }
            canvas.DrawText(textSpeed, Width * 7 / 8, Height * 18 / 20, textPaint);

            //canvas.DrawRect(Width * 9/11, Height * 5 / 11, Width, Height * 7 / 11, new Paint() { Color = Color.AliceBlue });

            /*
             * camera = new Point3()
             * {
             *  x = (float)(System.Math.Cos(AlphaAngle) * System.Math.Cos(BetaAngle)) * 10 * Size,
             *  y = (float)(-System.Math.Sin(AlphaAngle) * System.Math.Cos(BetaAngle)) * 10 * Size,
             *  z = (float)(-System.Math.Sin(BetaAngle)) * 10 * Size
             * };
             *
             * canvas.DrawCircle((float)camera.X, (float)camera.Y, 10, new Paint() { Color = Color.White });
             */
            /*
             * canvas.DrawCircle((float)TestPoints[0].X, (float)TestPoints[0].Y, 10, new Paint() { Color = Color.Red });
             * canvas.DrawCircle((float)TestPoints[1].X, (float)TestPoints[1].Y, 10, new Paint() { Color = Color.Green });
             * canvas.DrawCircle((float)TestPoints[2].X, (float)TestPoints[2].Y, 10, new Paint() { Color = Color.Blue });
             */
            try
            {
                SetImageBitmap(bm);
            }
            catch { }
        }
Beispiel #55
0
        private static void drawPolygonInCanvas(Canvas canvas, PointF[] polygon, Color color)
        {
            var path = new Path();
            // Set the first point, that the drawing will start from.
            path.MoveTo(polygon[0].X, polygon[0].Y);
            for (var i = 1; i < polygon.Length; i++)
            {
                // Draw a line from the previous point in the path to the new point.
                path.LineTo(polygon[i].X, polygon[i].Y);
            }

            Paint paint = new Paint {
                AntiAlias = true,
                Color = color
            };
            paint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(path, paint);

            paint.Dispose();
        }
		/// <summary>
		/// Gets the equilateral triangle.
		/// </summary>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		/// <returns>Path.</returns>
		private Path GetEquilateralTriangle(int width, int height)
		{
			PointF p1, p2, p3;
			if(_arrowDirection == ArrowDirection.LEFT)
			{
				p1 = new PointF(0, (height) / 2);
				p2 = new PointF(width, 0);
				p3 = new PointF(width, height);
			} else
			{
				p1 = new PointF(width, height / 2);
				p2 = new PointF(0, 0);
				p3 = new PointF(0, height);
			}
			Path path = new Path();
			path.MoveTo(p1.X, p1.Y);
			path.LineTo(p2.X, p2.Y);
			path.LineTo(p3.X, p3.Y);
			return path;
		}
Beispiel #57
0
		public override bool OnTouchEvent (MotionEvent e)
		{
			float touchX = e.GetX ();
			float touchY = e.GetY ();

			System.Drawing.PointF touch = new System.Drawing.PointF (touchX, touchY);

			switch (e.Action) {
			case MotionEventActions.Down:
				lastX = touchX;
				lastY = touchY;

				//Create a new path and move to the touched point.
				currentPath = new Path();
				currentPath.MoveTo (touchX, touchY);

				//Clear the list of points then add the touched point
				currentPoints.Clear ();
				currentPoints.Add (touch);

				//Display the clear button
				lblClear.Visibility = ViewStates.Visible;
				return true;
			case MotionEventActions.Move:
				handleTouch (e);
				canvasView.Invalidate(
					(int) (dirtyRect.Left - 1),
					(int) (dirtyRect.Top - 1),
					(int) (dirtyRect.Right + 1),
					(int) (dirtyRect.Bottom + 1));
				break;
			case MotionEventActions.Up:
				handleTouch (e);
				currentPath = smoothedPathWithGranularity (20, out currentPoints);

				//Add the current path and points to their respective lists.
				paths.Add (currentPath);
				points.Add (currentPoints.ToArray ());

				DrawStrokes ();
				canvasView.Invalidate ();
				break;
			default:
				return false;
			}
			
			lastX = touchX;
			lastY = touchY;
			
			return true;
		}
Beispiel #58
0
        private void DrawStrokes()
        {
            if (canvas == null)
            {
                return;
            }

            //TODO check the replacement for canvas.Save
            canvas.Save(SaveFlags.Matrix);
            canvas.Translate(canvas.Width / 2f, canvas.Height / 2f);
            canvas.Rotate(deviceOrientation);
            canvas.Translate(-(canvas.Width / 2f), -(canvas.Height / 2f));

            canvas.DrawColor(new Color((byte)(BackgroundColor.R * 255), (byte)(BackgroundColor.G * 255), (byte)(BackgroundColor.B * 255), (byte)(BackgroundColor.A * 255)), PorterDuff.Mode.Src);
            if (backgroundBitmap != null)
            {
                float scale   = GetDrawingScale();
                float offsetX = (Width - backgroundBitmap.Width * scale) / 2.0f;
                float offsetY = (Height - backgroundBitmap.Height * scale) / 2.0f;
                canvas.Translate(offsetX, offsetY);

                switch (backgroundScaling)
                {
                case Abstractions.Scaling.Absolute_None:
                case Abstractions.Scaling.Relative_None:
                    canvas.DrawBitmap(backgroundBitmap, 0, 0, new Paint());
                    break;

                case Abstractions.Scaling.Absolute_Fit:
                case Abstractions.Scaling.Relative_Fit:
                    canvas.DrawBitmap(backgroundBitmap, new Rect(0, 0, backgroundBitmap.Width, backgroundBitmap.Height), new Rect(0, 0, (int)(backgroundBitmap.Width * scale), (int)(backgroundBitmap.Height * scale)), new Paint());
                    break;

                case Abstractions.Scaling.Absolute_Fill:
                case Abstractions.Scaling.Relative_Fill:
                    canvas.DrawBitmap(backgroundBitmap, new Rect(0, 0, backgroundBitmap.Width, backgroundBitmap.Height), new Rect(0, 0, (int)(Width * scale), (int)(Height * scale)), new Paint());
                    break;
                }
            }

            if (Strokes == null)
            {
                Strokes = new List <Abstractions.Stroke>();
            }

            foreach (var stroke in Strokes)
            {
                double lastX = stroke.Points[0].X;
                double lastY = stroke.Points[0].Y;

                var paint = new Paint()
                {
                    Color       = new Color((byte)(stroke.StrokeColor.R * 255.0), (byte)(stroke.StrokeColor.G * 255.0), (byte)(stroke.StrokeColor.B * 255.0), (byte)(stroke.StrokeColor.A * 255.0)),
                    StrokeWidth = (float)stroke.Thickness * metrics.Density,
                    AntiAlias   = true,
                    StrokeCap   = Paint.Cap.Round,
                };
                paint.SetStyle(Paint.Style.Stroke);

                var path = new Android.Graphics.Path();
                path.MoveTo((float)stroke.Points[0].X, (float)stroke.Points[0].Y);

                foreach (var p in stroke.Points)
                {
                    path.LineTo((float)p.X, (float)p.Y);
                }

                canvas.DrawPath(path, paint);
            }

            canvas.Restore();
        }
        protected override void OnDraw(Canvas canvas)
        {
            var rect = new Rect();

            this.GetDrawingRect(rect);

            var path = new Android.Graphics.Path();


            var lastPoint = new PointF();

            foreach (var command in PathDataParser.Parse(Element.Data))
            {
                switch (command.Type)
                {
                case PathDataParser.CommandType.MoveTo:
                    lastPoint = new PointF(command.Arguments[0], command.Arguments[1]);
                    path.MoveTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.LineTo:
                    lastPoint = new PointF(command.Arguments[0], command.Arguments[1]);
                    path.LineTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.LineHor:
                    lastPoint = new PointF(command.Arguments[0], lastPoint.Y);
                    path.LineTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.LineVer:
                    lastPoint = new PointF(lastPoint.X, command.Arguments[0]);
                    path.LineTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.RelativeLineHor:
                    lastPoint = new PointF(command.Arguments[0] + lastPoint.X, lastPoint.Y);
                    path.LineTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.RelativeLineVer:
                    lastPoint = new PointF(lastPoint.X, lastPoint.Y + command.Arguments[0]);
                    path.LineTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.RelativeLineTo:
                    lastPoint = new PointF(lastPoint.X + command.Arguments[0], lastPoint.Y + command.Arguments[1]);
                    path.LineTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.RelativeMoveTo:
                    lastPoint = new PointF(lastPoint.X + command.Arguments[0], lastPoint.Y + command.Arguments[1]);
                    path.MoveTo(lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.QBezier:
                    path.QuadTo(command.Arguments[0], command.Arguments[1],
                                command.Arguments[2], command.Arguments[3]);
                    lastPoint = new PointF(command.Arguments[2], command.Arguments[3]);
                    break;

                case PathDataParser.CommandType.Bezier:
                    path.CubicTo(
                        command.Arguments[0], command.Arguments[1],
                        command.Arguments[2], command.Arguments[3],
                        command.Arguments[4], command.Arguments[5]);
                    lastPoint = new PointF(command.Arguments[4], command.Arguments[5]);
                    break;

                case PathDataParser.CommandType.RelativeBezier:
                    var p1 = new PointF(lastPoint.X + command.Arguments[0], lastPoint.Y + command.Arguments[1]);
                    var p2 = new PointF(p1.X + command.Arguments[2], p1.Y + command.Arguments[3]);
                    lastPoint = new PointF(p2.X + command.Arguments[4], p2.Y + command.Arguments[5]);
                    path.CubicTo(p1.X, p1.Y, p2.X, p2.Y, lastPoint.X, lastPoint.Y);
                    break;

                case PathDataParser.CommandType.Close:
                    path.Close();
                    break;
                }
            }

            var paint = new Paint(PaintFlags.AntiAlias);

            paint.StrokeWidth = Element.StrokeThickness;
            paint.StrokeMiter = 10f;
            canvas.Save();
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = Element.Stroke.ToAndroid();
            canvas.DrawPath(path, paint);
            canvas.Restore();
        }
Beispiel #60
0
        public override void Draw(Canvas canvas)
        {
            var w = width / (Count - 2);

            var path = new Path ();
            path.MoveTo (0, height - u1 [0]);
            for (int i = 1; i < Count; i += 3) {
                path.CubicTo (i * w, height - u1 [Math.Min (Count - 1, i)],
                              (i + 1) * w, height - u1 [Math.Min (Count - 1, i + 1)],
                              (i + 2) * w, height - u1 [Math.Min (Count - 1, i + 2)]);
            }

            path.LineTo (width, height);
            path.LineTo (0, height);
            path.Close ();
            canvas.DrawPath (path, paint);
            if (bubblesEnabled)
                DrawBubbles (canvas, w);
        }