Exemplo n.º 1
0
        public OsmPath(global::Android.Graphics.Path src) : base(IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
        {
            if (Handle != IntPtr.Zero)
            {
                return;
            }

            if (GetType() != typeof(OsmPath))
            {
                SetHandle(
                    global::Android.Runtime.JNIEnv.StartCreateInstance(GetType(), "(Landroid/graphics/Path;)V", new JValue(src)),
                    JniHandleOwnership.TransferLocalRef);
                global::Android.Runtime.JNIEnv.FinishCreateInstance(Handle, "(Landroid/graphics/Path;)V", new JValue(src));
                return;
            }

            if (id_ctor_Landroid_graphics_Path_ == IntPtr.Zero)
            {
                id_ctor_Landroid_graphics_Path_ = JNIEnv.GetMethodID(class_ref, "<init>", "(Landroid/graphics/Path;)V");
            }
            SetHandle(
                global::Android.Runtime.JNIEnv.StartCreateInstance(class_ref, id_ctor_Landroid_graphics_Path_, new JValue(src)),
                JniHandleOwnership.TransferLocalRef);
            JNIEnv.FinishCreateInstance(Handle, class_ref, id_ctor_Landroid_graphics_Path_, new JValue(src));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Called right before rendering starts.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="view"></param>
 protected override void OnBeforeRender(Target2DWrapper <global::Android.Graphics.Canvas> target, View2D view)
 {
     if (_path == null)
     { // a path to work with does not exist yet.
         _path = new global::Android.Graphics.Path();
     }
     _path.Reset();
 }
Exemplo n.º 3
0
        public static global::Android.Graphics.Path ToPixels(global::Osmdroid.Views.Projection p0, global::System.Collections.Generic.IList <global::Org.Osmdroid.Util.GeoPoint> p1, global::Android.Graphics.Path p2, bool p3)
        {
            if (id_toPixels_Lorg_osmdroid_views_Projection_Ljava_util_List_Landroid_graphics_Path_Z == IntPtr.Zero)
            {
                id_toPixels_Lorg_osmdroid_views_Projection_Ljava_util_List_Landroid_graphics_Path_Z = JNIEnv.GetStaticMethodID(class_ref, "toPixels", "(Lorg/osmdroid/views/Projection;Ljava/util/List;Landroid/graphics/Path;Z)Landroid/graphics/Path;");
            }
            IntPtr native_p1 = global::Android.Runtime.JavaList <global::Org.Osmdroid.Util.GeoPoint> .ToLocalJniHandle(p1);

            global::Android.Graphics.Path __ret = global::Java.Lang.Object.GetObject <global::Android.Graphics.Path> (JNIEnv.CallStaticObjectMethod(class_ref, id_toPixels_Lorg_osmdroid_views_Projection_Ljava_util_List_Landroid_graphics_Path_Z, new JValue(p0), new JValue(native_p1), new JValue(p2), new JValue(p3)), JniHandleOwnership.TransferLocalRef);
            JNIEnv.DeleteLocalRef(native_p1);
            return(__ret);
        }
Exemplo n.º 4
0
//		/// <summary>
//		/// Holds the bitmap cache.
//		/// </summary>
//		private global::Android.Graphics.Bitmap _cache;

        /// <summary>
        /// Called right before rendering starts.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="scenes"></param>
        /// <param name="view"></param>
        protected override void OnBeforeRender(Target2DWrapper <global::Android.Graphics.Canvas> target,
                                               List <Scene2D> scenes, View2D view)
        {
//			if (_cache == null || _cache.Width != target.Width || _cache.Height != target.Height) {
//				// create a bitmap and render there.
//				_cache = global::Android.Graphics.Bitmap.CreateBitmap ((int)target.Width, (int)target.Height,
//				                                                       global::Android.Graphics.Bitmap.Config.Argb8888);
//			} else {
//				// clear the cache???
//			}
//			target.BackTarget = target.Target;
//			target.Target = new global::Android.Graphics.Canvas(_cache);
//			target.Target.DrawColor(global::Android.Graphics.Color.Transparent);
//
//			target.Tag = _cache;
            _path = new global::Android.Graphics.Path();
        }
Exemplo n.º 5
0
        private void DrawPath(Canvas canvas, global::Android.Graphics.Path path)
        {
            var scale = Context.DpToPixels(1);

            canvas.Save();

            var strokeThickness = Element.StrokeThickness;

            if (Element.RenderTransform is ScaleTransform scaleTransform)
            {
                strokeThickness = System.Math.Min(scaleTransform.ScaleX, scaleTransform.ScaleY);
            }

            try
            {
                var paint = new Paint(PaintFlags.AntiAlias);
                canvas.Scale(scale, scale);
                if (Element.Fill.A > 0)
                {
                    paint.StrokeWidth = strokeThickness;
                    paint.StrokeMiter = 10f;

                    paint.SetStyle(Paint.Style.Fill);
                    paint.Color = Element.Fill.ToAndroid();
                    canvas.DrawPath(path, paint);
                }

                paint.StrokeWidth = strokeThickness;
                paint.StrokeMiter = 10f;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = Element.Stroke.ToAndroid();
                canvas.DrawPath(path, paint);
            }
            finally
            {
                canvas.Restore();
            }
        }
Exemplo n.º 6
0
		void UpdatePathInside()
		{
			if (_size <= 0)
				return;

			if (_pathInside == null)
				_pathInside = new global::Android.Graphics.Path ();
			else
				_pathInside.Reset ();

			_pathInside.AddCircle(_centerX, _centerY, _size * 0.5f, Path.Direction.Cw);
//			float x1 = _centerX + _size / 1.41f;
//			float x2 = _centerX + _size / 2.82f;
//			float x3 = _centerX - _size / 2.82f;
//			float x4 = _centerX - _size / 1.41f;
//
//			float y1 = _centerY + _size / 1.41f;
//			float y2 = _centerY + _size / 2.82f;
//			float y3 = _centerY - _size / 2.82f;
//			float y4 = _centerY - _size / 1.41f;
//
//			_pathInside.MoveTo (x1, y2);
//			_pathInside.LineTo (x2, y1);
//			_pathInside.LineTo (_centerX, y2);
//			_pathInside.LineTo (x3, y1);
//			_pathInside.LineTo (x4, y2);
//			_pathInside.LineTo (x3, _centerY);
//			_pathInside.LineTo (x4, y3);
//			_pathInside.LineTo (x3, y4);
//			_pathInside.LineTo (_centerX, y3);
//			_pathInside.LineTo (x2, y4);
//			_pathInside.LineTo (x1, y3);
//			_pathInside.LineTo (x2, _centerY);
//			_pathInside.LineTo (x1, y2);
		}
Exemplo n.º 7
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            using (var path = new global::Android.Graphics.Path ()) {

                var bb = new BoundingBoxBuilder ();

                Point? prevPoint = null;

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        path.MoveTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        prevPoint = p;
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        path.LineTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        prevPoint = p;
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;

                        if (!prevPoint.HasValue) {
                            throw new NotSupportedException("Cannot begin path with Arc.");
                        }

                        var pp = prevPoint.Value;

                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);

                        var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1;
                        var rect = new Rect(circleCenter - at.Radius, at.Radius * 2);

                        var startAngle = Conversions.RadToDeg((float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X));
                        var endAngle = Conversions.RadToDeg((float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X));

                        var sweepAngle = endAngle - startAngle;

                        if (at.SweepClockwise && sweepAngle < 0) {
                            // If we want to go CW, sweepAngle needs to be positive
                            sweepAngle += 360.0f;
                        }
                        else if (!at.SweepClockwise && sweepAngle > 0) {
                            // If we want to go CCW, sweepAngle needs to be negative
                            sweepAngle -= 360.0f;
                        }

                        path.AddArc(Conversions.GetRectF(rect), startAngle, sweepAngle);

                        bb.Add (p);
                        prevPoint = p;
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo ((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        prevPoint = p;
                        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 paint = GetBrushPaint (brush, frame);
                    graphics.DrawPath (path, paint);
                }
                if (pen != null) {
                    var paint = GetPenPaint (pen);
                    graphics.DrawPath (path, paint);
                }
            }
        }
Exemplo n.º 8
0
		public Bitmap DrawArrow (double direction)
		{
			int w = 48;
			int h = 48;
			int w2 = w / 2;
			int h2 = w / 2;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF((float) (w2 + w2 * Math.Sin (rad1)), (float) (h2 + h2 * Math.Cos (rad1)));
			PointF p2 = new PointF((float) (w2 + w2 * Math.Sin (rad2)), (float) (h2 + h2 * Math.Cos (rad2)));
			PointF p3 = new PointF((float) (w2 + w2 * Math.Sin (rad3)), (float) (h2 + h2 * Math.Cos (rad3)));
			PointF p4 = new PointF((float) (w2 + w / 3 * Math.Sin (rad4)), (float) (h2 + h / 3 * Math.Cos (rad4)));

			Bitmap b = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
			Canvas c = new Canvas(b);
			Paint light = new Paint (PaintFlags.AntiAlias);
			Paint dark = new Paint (PaintFlags.AntiAlias);
			Paint black = new Paint (PaintFlags.AntiAlias);

			light.Color = new Color (128, 0, 0, 255);
			light.StrokeWidth = 0f;
			light.SetStyle (Paint.Style.FillAndStroke);

			dark.Color = new Color (255, 0, 0, 255);
			dark.StrokeWidth = 0f;
			dark.SetStyle (Paint.Style.FillAndStroke);

			black.Color = new Color (0, 0, 0, 255);
			black.StrokeWidth = 0f;
			black.SetStyle (Paint.Style.Stroke);

			int cx = c.Width / 2 - 1;
			int cy = c.Height / 2 - 1;

			global::Android.Graphics.Path path1 = new global::Android.Graphics.Path ();
			global::Android.Graphics.Path path2 = new global::Android.Graphics.Path ();
			global::Android.Graphics.Path path3 = new global::Android.Graphics.Path ();

			path1.MoveTo (p1.X,p1.Y);
			path1.LineTo (p2.X,p2.Y);
			path1.LineTo (p4.X,p4.Y);
			path1.LineTo (p1.X,p1.Y);

			path2.MoveTo (p1.X,p1.Y);
			path2.LineTo (p3.X,p3.Y);
			path2.LineTo (p4.X,p4.Y);
			path2.LineTo (p1.X,p1.Y);

			path3.MoveTo (p1.X,p1.Y);
			path3.LineTo (p2.X,p2.Y);
			path3.LineTo (p4.X,p4.Y);
			path3.LineTo (p1.X,p1.Y);
			path3.LineTo (p3.X,p3.Y);
			path3.LineTo (p4.X,p4.Y);

			c.DrawPath (path1, light);
			c.DrawPath (path2, dark);
			c.DrawPath (path3, black);

//			UIGraphics.BeginImageContext (new SizeF(64, 64));
//
//			using (CGContext cont = UIGraphics.GetCurrentContext()) {
//
//				using (CGPath path = new CGPath()) {
//
//					cont.SetLineWidth (1f);
//					cont.SetRGBStrokeColor (0f, 0, 0, 1);
//					cont.SetRGBFillColor (1f, 0, 0, 1);
//					path.AddLines (new PointF[] { p1, p2, p4 });
//					path.CloseSubpath ();
//
//					cont.AddPath (path);
//					cont.DrawPath (CGPathDrawingMode.FillStroke);
//
//				}
//
//				using (CGPath path = new CGPath()) {
//
//					cont.SetRGBStrokeColor (0f, 0, 0, 1);
//					cont.SetRGBFillColor (.5f, 0, 0, 1);
//					path.AddLines (new PointF[] { p1, p3, p4 });
//					path.CloseSubpath ();
//
//					cont.AddPath (path);
//					cont.DrawPath (CGPathDrawingMode.FillStroke);
//
//				}
//
//				return UIGraphics.GetImageFromCurrentImageContext ();
//
//			}
//
//			UIGraphics.EndImageContext ();
			return b;
		}
Exemplo n.º 9
0
        protected override void OnDraw(Canvas canvas)
        {
            var trans = Element.RenderTransform ?? new IdentityTransform();

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

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

                case PathDataParser.CommandType.LineTo:
                {
                    var pt = trans.TransformPoint(
                        new System.Drawing.PointF(command.Arguments[0], command.Arguments[1]));
                    path.LineTo(pt.X, pt.Y);
                }
                break;

                case PathDataParser.CommandType.QBezier:
                {
                    var pt = trans.TransformPoint(
                        new System.Drawing.PointF(command.Arguments[0], command.Arguments[1]));
                    var pt2 = trans.TransformPoint(
                        new System.Drawing.PointF(command.Arguments[2], command.Arguments[3]));

                    path.QuadTo(pt.X, pt.Y, pt2.X, pt2.Y);
                }

                break;

                case PathDataParser.CommandType.Bezier:
                {
                    var pt = trans.TransformPoint(
                        new System.Drawing.PointF(command.Arguments[0], command.Arguments[1]));
                    var pt2 = trans.TransformPoint(
                        new System.Drawing.PointF(command.Arguments[2], command.Arguments[3]));
                    var pt3 = trans.TransformPoint(
                        new System.Drawing.PointF(command.Arguments[4], command.Arguments[5]));

                    path.CubicTo(pt.X, pt.Y, pt2.X, pt2.Y, pt3.X, pt3.Y);
                }
                break;

                case PathDataParser.CommandType.Close:
                    path.Close();
                    DrawPath(canvas, path);
                    path = new global::Android.Graphics.Path();
                    break;
                }
            }

            if (!path.IsEmpty)
            {
                DrawPath(canvas, path);
            }
        }
Exemplo n.º 10
0
		/// <summary>
		/// Draws image of arrow with given direction.
		/// </summary>
		/// <returns>Bitmap of arrow.</returns>
		/// <param name="direction">Direction of the arrow.</param>
		internal Bitmap DrawArrow (double direction)
		{
			int w = 48;
			int h = 48;
			int w2 = w / 2;
			int h2 = w / 2;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF((float) (w2 + w2 * Math.Sin (rad1)), (float) (h2 + h2 * Math.Cos (rad1)));
			PointF p2 = new PointF((float) (w2 + w2 * Math.Sin (rad2)), (float) (h2 + h2 * Math.Cos (rad2)));
			PointF p3 = new PointF((float) (w2 + w2 * Math.Sin (rad3)), (float) (h2 + h2 * Math.Cos (rad3)));
			PointF p4 = new PointF((float) (w2 + w / 3 * Math.Sin (rad4)), (float) (h2 + h / 3 * Math.Cos (rad4)));

			Bitmap b = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
			using(Canvas c = new Canvas(b)) {
				int cx = c.Width / 2 - 1;
				int cy = c.Height / 2 - 1;

				global::Android.Graphics.Path path1 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path2 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path3 = new global::Android.Graphics.Path ();

				path1.MoveTo (p1.X,p1.Y);
				path1.LineTo (p2.X,p2.Y);
				path1.LineTo (p4.X,p4.Y);
				path1.LineTo (p1.X,p1.Y);

				path2.MoveTo (p1.X,p1.Y);
				path2.LineTo (p3.X,p3.Y);
				path2.LineTo (p4.X,p4.Y);
				path2.LineTo (p1.X,p1.Y);

				path3.MoveTo (p1.X,p1.Y);
				path3.LineTo (p2.X,p2.Y);
				path3.LineTo (p4.X,p4.Y);
				path3.LineTo (p1.X,p1.Y);
				path3.LineTo (p3.X,p3.Y);
				path3.LineTo (p4.X,p4.Y);

				c.DrawPath (path1, light);
				c.DrawPath (path2, dark);
				c.DrawPath (path3, black);
			}

			return b;
		}
Exemplo n.º 11
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            using (var path = new global::Android.Graphics.Path ()) {

                var bb = new BoundingBoxBuilder ();

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        path.MoveTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        path.LineTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        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 ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo ((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        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 paint = GetBrushPaint (brush, frame);
                    graphics.DrawPath (path, paint);
                }
                if (pen != null) {
                    var paint = GetPenPaint (pen);
                    graphics.DrawPath (path, paint);
                }
            }
        }
Exemplo n.º 12
0
        public void DrawLineTextSegment(Target2DWrapper <global::Android.Graphics.Canvas> target, double[] xTransformed, double[] yTransformed, string text, int color,
                                        double size, int?haloColor, int?haloRadius, double middlePosition, float[] characterWidths, double textLength,
                                        float characterHeight)
        {
            _paint.Color = new global::Android.Graphics.Color(color);
            _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill);

            // see if the text is 'upside down'.
            double   averageAngle = 0;
            double   first        = middlePosition - (textLength / 2.0);
            PointF2D current      = Polyline2D.PositionAtPosition(xTransformed, yTransformed, first);

            for (int idx = 0; idx < text.Length; idx++)
            {
                double   nextPosition = middlePosition - (textLength / 2.0) + ((textLength / (text.Length)) * (idx + 1));
                PointF2D next         = Polyline2D.PositionAtPosition(xTransformed, yTransformed, nextPosition);

                // Translate to the final position, the center of line-segment between 'current' and 'next'
                //PointF2D position = current + ((next - current) / 2.0);

                // calculate the angle.
                VectorF2D vector       = next - current;
                VectorF2D horizontal   = new VectorF2D(1, 0);
                double    angleDegrees = ((Degree)horizontal.Angle(vector)).Value;
                averageAngle = averageAngle + angleDegrees;
                current      = next;
            }
            averageAngle = averageAngle / text.Length;

            // reverse if 'upside down'.
            double[] xText = xTransformed;
            double[] yText = yTransformed;
            if (averageAngle > 90 && averageAngle < 180 + 90)
            {             // the average angle is > PI => means upside down.
                xText = xTransformed.Reverse <double>().ToArray <double>();
                yText = yTransformed.Reverse <double>().ToArray <double>();
            }

            // calculate a central position along the line.
            first   = middlePosition - (textLength / 2.0);
            current = Polyline2D.PositionAtPosition(xText, yText, first);
            double nextPosition2 = first;

            for (int idx = 0; idx < text.Length; idx++)
            {
                nextPosition2 = nextPosition2 + characterWidths[idx];
                //double nextPosition = middle - (textLength / 2.0) + ((textLength / (text.Length)) * (idx + 1));
                PointF2D next        = Polyline2D.PositionAtPosition(xText, yText, nextPosition2);
                char     currentChar = text[idx];
                global::Android.Graphics.Path characterPath = new global::Android.Graphics.Path();
                _paint.GetTextPath(text, idx, idx + 1, 0, 0, characterPath);
                using (characterPath)
                {
                    // Transformation matrix to move the character to the correct location.
                    // Note that all actions on the Matrix class are prepended, so we apply them in reverse.
                    var transform = new Matrix();

                    // Translate to the final position, the center of line-segment between 'current' and 'next'
                    PointF2D position = current;
                    //PointF2D position = current + ((next - current) / 2.0);
                    //double[] transformed = this.Tranform(position[0], position[1]);
                    transform.SetTranslate((float)position[0], (float)position[1]);

                    // calculate the angle.
                    VectorF2D vector       = next - current;
                    VectorF2D horizontal   = new VectorF2D(1, 0);
                    double    angleDegrees = ((Degree)horizontal.Angle(vector)).Value;

                    // Rotate the character
                    transform.PreRotate((float)angleDegrees);

                    // Translate the character so the centre of its base is over the origin
                    transform.PreTranslate(0, characterHeight / 2.5f);

                    //transform.Scale((float)this.FromPixels(_target, _view, 1),
                    //    (float)this.FromPixels(_target, _view, 1));
                    characterPath.Transform(transform);

                    if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0)
                    {
                        _paint.SetStyle(global::Android.Graphics.Paint.Style.FillAndStroke);
                        _paint.StrokeWidth = haloRadius.Value;
                        _paint.Color       = new global::Android.Graphics.Color(haloColor.Value);
                        using (global::Android.Graphics.Path haloPath = new global::Android.Graphics.Path())
                        {
                            _paint.GetFillPath(characterPath, haloPath);
                            // Draw the character
                            target.Target.DrawPath(haloPath, _paint);
                        }
                    }

                    // Draw the character
                    _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill);
                    _paint.StrokeWidth = 0;
                    _paint.Color       = new global::Android.Graphics.Color(color);
                    target.Target.DrawPath(characterPath, _paint);
                }
                current = next;
            }
        }
Exemplo n.º 13
0
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            using (var path = new global::Android.Graphics.Path()) {
                var bb = new BoundingBoxBuilder();

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        path.MoveTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        path.LineTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        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 ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        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 paint = GetBrushPaint(brush, frame);
                    graphics.DrawPath(path, paint);
                }
                if (pen != null)
                {
                    var paint = GetPenPaint(pen);
                    graphics.DrawPath(path, paint);
                }
            }
        }
 public PathShape(global::Android.Graphics.Path path, float stdWidth, float stdHeight)                         /* MethodBuilder.Create */
 {
 }
Exemplo n.º 15
0
		void UpdatePathArrow()
		{
			if (_pathArrow == null)
				_pathArrow = new global::Android.Graphics.Path ();
			else
				_pathArrow.Reset ();

			// Create arrow
			// We have a direction, so draw an arrow
			var direction = 180.0 - ((DirectionArrow)Element).Direction;
			if (direction < 0)
				direction += 360.0;
			direction = direction % 360.0;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF ((float)(_centerX + _size * Math.Sin (rad1)), (float)(_centerY + _size * Math.Cos (rad1)));
			PointF p2 = new PointF ((float)(_centerX + _size * Math.Sin (rad2)), (float)(_centerY + _size * Math.Cos (rad2)));
			PointF p3 = new PointF ((float)(_centerX + _size * Math.Sin (rad3)), (float)(_centerY + _size * Math.Cos (rad3)));
			PointF p4 = new PointF ((float)(_centerX + _sizeSmall * Math.Sin (rad4)), (float)(_centerY + _sizeSmall * Math.Cos (rad4)));

			_pathArrow.MoveTo (p1.X, p1.Y);
			_pathArrow.LineTo (p2.X, p2.Y);
			_pathArrow.LineTo (p4.X, p4.Y);
			_pathArrow.LineTo (p3.X, p3.Y);
			_pathArrow.LineTo (p1.X, p1.Y);
		}
        public static Bitmap Draw(int width, int height, double direction)
        {
            if (width == 0 || height == 0)
            {
                return(null);
            }

            int w2 = width / 2;
            int h2 = height / 2;

            Paint light = new Paint(PaintFlags.AntiAlias);
            Paint dark  = new Paint(PaintFlags.AntiAlias);
            Paint black = new Paint(PaintFlags.AntiAlias);

            light.Color       = new Color(128, 0, 0, 255);
            light.StrokeWidth = 0f;
            light.SetStyle(Paint.Style.FillAndStroke);

            dark.Color       = new Color(255, 0, 0, 255);
            dark.StrokeWidth = 0f;
            dark.SetStyle(Paint.Style.FillAndStroke);

            black.Color       = new Color(0, 0, 0, 255);
            black.StrokeWidth = 0f;
            black.SetStyle(Paint.Style.Stroke);

            // Values of direction are between 0° and 360°, but for drawing we need -180° to +180°
            direction -= 180;

            double rad1 = direction / 180.0 * Math.PI;
            double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
            double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI;
            double rad4 = (direction + 180.0) / 180.0 * Math.PI;

            PointF p1 = new PointF((float)(w2 + w2 * Math.Sin(rad1)), (float)(h2 + h2 * Math.Cos(rad1)));
            PointF p2 = new PointF((float)(w2 + w2 * Math.Sin(rad2)), (float)(h2 + h2 * Math.Cos(rad2)));
            PointF p3 = new PointF((float)(w2 + w2 * Math.Sin(rad3)), (float)(h2 + h2 * Math.Cos(rad3)));
            PointF p4 = new PointF((float)(w2 + width / 3 * Math.Sin(rad4)), (float)(h2 + height / 3 * Math.Cos(rad4)));

            Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

            using (Canvas c = new Canvas(b)) {
                int cx = c.Width / 2 - 1;
                int cy = c.Height / 2 - 1;

                global::Android.Graphics.Path path1 = new global::Android.Graphics.Path();
                global::Android.Graphics.Path path2 = new global::Android.Graphics.Path();
                global::Android.Graphics.Path path3 = new global::Android.Graphics.Path();

                path1.MoveTo(p1.X, p1.Y);
                path1.LineTo(p2.X, p2.Y);
                path1.LineTo(p4.X, p4.Y);
                path1.LineTo(p1.X, p1.Y);

                path2.MoveTo(p1.X, p1.Y);
                path2.LineTo(p3.X, p3.Y);
                path2.LineTo(p4.X, p4.Y);
                path2.LineTo(p1.X, p1.Y);

                path3.MoveTo(p1.X, p1.Y);
                path3.LineTo(p2.X, p2.Y);
                path3.LineTo(p4.X, p4.Y);
                path3.LineTo(p1.X, p1.Y);
                path3.LineTo(p3.X, p3.Y);
                path3.LineTo(p4.X, p4.Y);

                light.Color = new Color(128, 0, 0, 255);
                dark.Color  = new Color(255, 0, 0, 255);
                black.Color = new Color(0, 0, 0, 255);

                c.DrawPath(path1, light);
                c.DrawPath(path2, dark);
                c.DrawPath(path3, black);
            }

            return(b);
        }
Exemplo n.º 17
0
 public PaintView(Context c, global::Android.Util.IAttributeSet att) : base(c, att)
 {
     mPath        = new global::Android.Graphics.Path();
     mBitmapPaint = new Paint(PaintFlags.AntiAlias);
 }
		public static Bitmap Draw(int width, int height, double direction)
		{
			if(width == 0 || height == 0)
					return null;

			int w2 = width / 2;
			int h2 = height / 2;

			Paint light = new Paint(PaintFlags.AntiAlias);
			Paint dark = new Paint(PaintFlags.AntiAlias);
			Paint black = new Paint(PaintFlags.AntiAlias);

			light.Color = new Color(128, 0, 0, 255);
			light.StrokeWidth = 0f;
			light.SetStyle(Paint.Style.FillAndStroke);

			dark.Color = new Color(255, 0, 0, 255);
			dark.StrokeWidth = 0f;
			dark.SetStyle(Paint.Style.FillAndStroke);

			black.Color = new Color(0, 0, 0, 255);
			black.StrokeWidth = 0f;
			black.SetStyle(Paint.Style.Stroke);

			// Values of direction are between 0° and 360°, but for drawing we need -180° to +180°
			direction -= 180;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF((float) (w2 + w2 * Math.Sin (rad1)), (float) (h2 + h2 * Math.Cos (rad1)));
			PointF p2 = new PointF((float) (w2 + w2 * Math.Sin (rad2)), (float) (h2 + h2 * Math.Cos (rad2)));
			PointF p3 = new PointF((float) (w2 + w2 * Math.Sin (rad3)), (float) (h2 + h2 * Math.Cos (rad3)));
			PointF p4 = new PointF((float) (w2 + width / 3 * Math.Sin (rad4)), (float) (h2 + height / 3 * Math.Cos (rad4)));

			Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

			using(Canvas c = new Canvas(b)) {
				int cx = c.Width / 2 - 1;
				int cy = c.Height / 2 - 1;

				global::Android.Graphics.Path path1 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path2 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path3 = new global::Android.Graphics.Path ();

				path1.MoveTo (p1.X,p1.Y);
				path1.LineTo (p2.X,p2.Y);
				path1.LineTo (p4.X,p4.Y);
				path1.LineTo (p1.X,p1.Y);

				path2.MoveTo (p1.X,p1.Y);
				path2.LineTo (p3.X,p3.Y);
				path2.LineTo (p4.X,p4.Y);
				path2.LineTo (p1.X,p1.Y);

				path3.MoveTo (p1.X,p1.Y);
				path3.LineTo (p2.X,p2.Y);
				path3.LineTo (p4.X,p4.Y);
				path3.LineTo (p1.X,p1.Y);
				path3.LineTo (p3.X,p3.Y);
				path3.LineTo (p4.X,p4.Y);

				light.Color = new Color (128, 0, 0, 255);
				dark.Color = new Color (255, 0, 0, 255);
				black.Color = new Color (0, 0, 0, 255);

				c.DrawPath (path1, light);
				c.DrawPath (path2, dark);
				c.DrawPath (path3, black);
			}

			return b;
		}
Exemplo n.º 19
0
		void UpdatePathUnknown()
		{
			if (_size <= 0)
				return;

			if (_pathUnknown == null)
				_pathUnknown = new global::Android.Graphics.Path ();
			else
				_pathUnknown.Reset ();

			float x1 = _centerX + _size * 0.5f;
			float x2 = _centerX - _size * 0.5f;

			float y1 = _centerY + _size * 0.5f;
			float y2 = _centerY - _size * 0.5f;

			_pathUnknown.MoveTo(x1, y1);
			_pathUnknown.LineTo(x2, y2);
			_pathUnknown.MoveTo(x1, y2);
			_pathUnknown.LineTo(x2, y1);
		}
Exemplo n.º 20
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="text"></param>
        /// <param name="size"></param>
        protected override void DrawText(Target2DWrapper <global::Android.Graphics.Canvas> target, double x, double y,
                                         string text, int color, double size, int?haloColor, int?haloRadius, string fontName)
        {
            double[] transformed = this.Tranform(x, y);
            float    xPixels     = (float)transformed[0];
            float    yPixels     = (float)transformed[1];
            float    textSize    = this.ToPixels(size);

            //transformed = this.Tranform(x + size, y);
            //float textSize = 10;

            _paint.AntiAlias    = true;
            _paint.SubpixelText = true;
            _paint.TextSize     = textSize;

            // get some metrics on the texts.
            float[] characterWidths = new float[text.Length];
            _paint.GetTextWidths(text, characterWidths);
            //for (int idx = 0; idx < characterWidths.Length; idx++)
            //{
            //    characterWidths[idx] = _target, _view, characterWidths[idx];
            //}
            var characterHeight = (float)size;
            var textLength      = characterWidths.Sum();

            // center is default.
            xPixels = xPixels - (textLength / 2.0f);

            PointF2D current = new PointF2D(xPixels, yPixels);

            for (int idx = 0; idx < text.Length; idx++)
            {
                char currentChar = text[idx];
                global::Android.Graphics.Path characterPath = new global::Android.Graphics.Path();
                _paint.GetTextPath(text, idx, idx + 1, 0, 0, characterPath);
                using (characterPath)
                {
                    // Transformation matrix to move the character to the correct location.
                    // Note that all actions on the Matrix class are prepended, so we apply them in reverse.
                    var transform = new Matrix();

                    // Translate to the final position, the center of line-segment between 'current' and 'next'
                    PointF2D position = current;
                    //transformed = this.Tranform(position[0], position[1]);
                    transform.SetTranslate((float)position[0], (float)position[1]);

                    // Translate the character so the centre of its base is over the origin
                    transform.PreTranslate(0, characterHeight / 2.5f);

                    //transform.Scale((float)this.FromPixels(_target, _view, 1),
                    //    (float)this.FromPixels(_target, _view, 1));
                    characterPath.Transform(transform);

                    if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0)
                    {
                        _paint.SetStyle(global::Android.Graphics.Paint.Style.FillAndStroke);
                        _paint.StrokeWidth = haloRadius.Value;
                        _paint.Color       = new global::Android.Graphics.Color(haloColor.Value);
                        using (global::Android.Graphics.Path haloPath = new global::Android.Graphics.Path())
                        {
                            _paint.GetFillPath(characterPath, haloPath);
                            // Draw the character
                            target.Target.DrawPath(haloPath, _paint);
                        }
                    }

                    // Draw the character
                    _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill);
                    _paint.StrokeWidth = 0;
                    _paint.Color       = new global::Android.Graphics.Color(color);
                    target.Target.DrawPath(characterPath, _paint);
                }
                current = new PointF2D(current[0] + characterWidths[idx], current[1]);
            }
        }
Exemplo n.º 21
0
 public virtual global::Android.Graphics.Path ToPath(global::Android.Graphics.Path path)                         /* MethodBuilder.Create */
 {
     return(default(global::Android.Graphics.Path));
 }
Exemplo n.º 22
0
 public virtual global::Android.Graphics.Path ToPath(global::Android.Graphics.Path path, int width, int height, int edge, int numSample)                         /* MethodBuilder.Create */
 {
     return(default(global::Android.Graphics.Path));
 }
Exemplo n.º 23
0
        public static Bitmap getRoundedShape(Bitmap scaleBitmapImage,int targetint)
        {
            int targetWidth = targetint;
            int targetHeight = targetint;
            Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth,
                targetHeight,Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(targetBitmap);
            global::Android.Graphics.Path path = new global::Android.Graphics.Path();
            path.AddCircle(((float) targetWidth - 1) / 2,
                ((float) targetHeight - 1) / 2,
                (Math.Min(((float) targetWidth),
                    ((float) targetHeight)) / 2),
                global::Android.Graphics.Path.Direction.Ccw);

            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;
        }
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            using (var path = new global::Android.Graphics.Path()) {
                var bb = new BoundingBoxBuilder();

                Point?prevPoint = null;

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        path.MoveTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        prevPoint = p;
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        path.LineTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        prevPoint = p;
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;

                        if (!prevPoint.HasValue)
                        {
                            throw new NotSupportedException("Cannot begin path with Arc.");
                        }

                        var pp = prevPoint.Value;

                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);

                        var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1;
                        var rect         = new Rect(circleCenter - at.Radius, at.Radius * 2);

                        var startAngle = Conversions.RadToDeg((float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X));
                        var endAngle   = Conversions.RadToDeg((float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X));

                        var sweepAngle = endAngle - startAngle;

                        if (at.SweepClockwise && sweepAngle < 0)
                        {
                            // If we want to go CW, sweepAngle needs to be positive
                            sweepAngle += 360.0f;
                        }
                        else if (!at.SweepClockwise && sweepAngle > 0)
                        {
                            // If we want to go CCW, sweepAngle needs to be negative
                            sweepAngle -= 360.0f;
                        }

                        path.AddArc(Conversions.GetRectF(rect), startAngle, sweepAngle);

                        bb.Add(p);
                        prevPoint = p;
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        prevPoint = p;
                        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 paint = GetBrushPaint(brush, frame);
                    graphics.DrawPath(path, paint);
                }
                if (pen != null)
                {
                    var paint = GetPenPaint(pen);
                    graphics.DrawPath(path, paint);
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Called right before rendering starts.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="scenes"></param>
 /// <param name="view"></param>
 protected override void OnBeforeRender(Target2DWrapper <global::Android.Graphics.Canvas> target, View2D view)
 {
     _path = new global::Android.Graphics.Path();
 }