Ejemplo n.º 1
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            using (var g = UIGraphics.GetCurrentContext())
            {
                //create geometry
                var path1 = new CGPath();

                g.SetFillColor(UIColor.LightGray.CGColor);
                path1.AddEllipseInRect(mCircleDPLeft);
                path1.AddEllipseInRect(mCircleDPRight);

                path1.CloseSubpath();
                g.AddPath(path1);
                g.DrawPath(CGPathDrawingMode.FillStroke);

                var path2 = new CGPath();

                g.SetFillColor(UIColor.DarkGray.CGColor);
                path2.AddEllipseInRect(mCircleJSLeft);
                path2.AddEllipseInRect(mCircleJSRight);

                path2.CloseSubpath();
                g.AddPath(path2);
                g.DrawPath(CGPathDrawingMode.FillStroke);

                g.ShowTextAtPoint(mLeftJS.CenterX, 30, "LEFT JOYSTICK");
            }
        }
            private CGPath GeneratePath()
            {
                var path = new CGPath();

                path.AddEllipseInRect(new CGRect(120, 0, 160, 300));
                path.AddEllipseInRect(new CGRect(50, 200, 150, 150));
                path.AddEllipseInRect(new CGRect(200, 200, 150, 150));
                return(path);
            }
        /// <summary>
        /// Draws an ellipse.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The thickness.</param>
        public override void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
        {
            this.SetAlias(false);
            var convertedRectangle = rect.Convert();
            if (fill.IsVisible())
            {
                this.SetFill(fill);
                using (var path = new CGPath())
                {
                    path.AddEllipseInRect(convertedRectangle);
                    this.gctx.AddPath(path);
                }

                this.gctx.DrawPath(CGPathDrawingMode.Fill);
            }

            if (stroke.IsVisible() && thickness > 0)
            {
                this.SetStroke(stroke, thickness);

                using (var path = new CGPath())
                {
                    path.AddEllipseInRect(convertedRectangle);
                    this.gctx.AddPath(path);
                }

                this.gctx.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Ejemplo n.º 4
0
        void UpdateShape()
        {
            var path = new CGPath();

            path.AddEllipseInRect(new CGRect(0, 0, 1, 1));
            ShapeLayer.UpdateShape(path);
        }
Ejemplo n.º 5
0
        public override void Draw(RectangleF rect)
        {
            var element = Element as CircleView;

            if (element == null)
            {
                throw new InvalidOperationException("Element must be a Circle View type");
            }

            //get graphics context
            using (CGContext context = UIGraphics.GetCurrentContext()){
                context.SetFillColor(element.FillColor.ToCGColor());
                context.SetStrokeColor(element.StrokeColor.ToCGColor());
                context.SetLineWidth(element.StrokeThickness);

                if (element.StrokeDash > 1.0f)
                {
                    context.SetLineDash(
                        0,
                        new float[] { element.StrokeDash, element.StrokeDash });
                }

                //create geometry
                var path = new CGPath();

                path.AddEllipseInRect(rect);

                path.CloseSubpath();

                //add geometry to graphics context and draw it
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Draws an ellipse.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The thickness.</param>
        public override void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
        {
            this.SetAlias(false);
            var convertedRectangle = rect.Convert();

            if (fill.IsVisible())
            {
                this.SetFill(fill);
                using (var path = new CGPath())
                {
                    path.AddEllipseInRect(convertedRectangle);
                    this.gctx.AddPath(path);
                }

                this.gctx.DrawPath(CGPathDrawingMode.Fill);
            }

            if (stroke.IsVisible() && thickness > 0)
            {
                this.SetStroke(stroke, thickness);

                using (var path = new CGPath())
                {
                    path.AddEllipseInRect(convertedRectangle);
                    this.gctx.AddPath(path);
                }

                this.gctx.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Ejemplo n.º 7
0
        public override void Draw(CGRect rect)
        {
            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                //set up drawing attributes
                UIColor.Black.SetFill();

                //create geometry
                _overlay = new CGPath();
                
                _overlay.AddRect(new RectangleF(0f, 0f, _width, _height));
                
                if(_isRound)
                    _overlay.AddEllipseInRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height));
                else
                    _overlay.AddRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height));

                g.SetStrokeColor(UIColor.Clear.CGColor);
                g.SetAlpha(0.6f);

                //add geometry to graphics context and draw it
                g.AddPath(_overlay);
                g.DrawPath(CGPathDrawingMode.EOFillStroke);                
            }
        }
Ejemplo n.º 8
0
        public override void Draw(RectangleF rect)
        {
            var element = Element as CircleView;

            if (element == null) {
                throw new InvalidOperationException ("Element must be a Circle View type");
            }

            //get graphics context
            using(CGContext context = UIGraphics.GetCurrentContext ()){

                context.SetFillColor(element.FillColor.ToCGColor());
                context.SetStrokeColor(element.StrokeColor.ToCGColor());
                context.SetLineWidth(element.StrokeThickness);

                if (element.StrokeDash > 1.0f) {
                        context.SetLineDash (
                        0,
                        new float[] { element.StrokeDash, element.StrokeDash });
                }

                //create geometry
                var path = new CGPath ();

                path.AddEllipseInRect (rect);

                path.CloseSubpath();

                //add geometry to graphics context and draw it
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Ejemplo n.º 9
0
        void CreateNewPath()
        {
            CGPath path = new CGPath();

            path.AddEllipseInRect(new CGRect(0, 0, 1, 1));
            DrawingLayer.SetBasicPath(path);
        }
Ejemplo n.º 10
0
        public static void DrawCircle(CGContext canvas, SKPoint p, float radius, SKPaint paint)
        {
            var    path = new CGPath();
            CGRect rect = new CGRect(p.X - radius, p.Y - radius, 2 * radius, 2 * radius);

            path.AddEllipseInRect(rect);
            PaintPath(canvas, path, paint);
        }
Ejemplo n.º 11
0
        /// <summary>画实心圆
        /// </summary>
        /// <param name="ctx">图形上下文</param>
        /// <param name="rect">绘画范围</param>
        /// <param name="radio">占大圆比例</param>
        /// <param name="inCircleColor">绘制颜色</param>
        void DrawSolidCircleWithContext(CGContext ctx, CGRect rect, nfloat radio, UIColor color)
        {
            CGPath circlePath = new CGPath();

            circlePath.AddEllipseInRect(new CGRect(rect.Size.Width / 2 * (1 - radio) + PCCircleViewConst.CircleEdgeWidth, rect.Size.Height / 2 * (1 - radio) + PCCircleViewConst.CircleEdgeWidth, rect.Size.Width * radio - PCCircleViewConst.CircleEdgeWidth * 2, rect.Size.Height * radio - PCCircleViewConst.CircleEdgeWidth * 2));
            color.SetColor();
            ctx.AddPath(circlePath);
            ctx.FillPath();
            circlePath.Dispose();
        }
Ejemplo n.º 12
0
 public void AddEllipse(float x, float y, float width, float height)
 {
                 #if XAMMAC || XAMMAC2 || IOS
     Control.AddEllipseInRect(new CGRect(x, y, width, height));
                 #else
     Control.AddElipseInRect(new CGRect(x, y, width, height));
                 #endif
     startFigure   = true;
     isFirstFigure = false;
 }
Ejemplo n.º 13
0
        /// <summary> 画外圆环
        /// </summary>
        /// <param name="ctx"> 图形上下文</param>
        /// <param name="rect">绘画范围</param>
        /// <param name="outCircleColor">绘制颜色</param>
        void DrawEmptyCircleWithContext(CGContext ctx, CGRect rect, UIColor color)
        {
            CGPath circlePath = new CGPath();

            circlePath.AddEllipseInRect(rect);
            ctx.AddPath(circlePath);
            color.SetColor();
            ctx.SetLineWidth(PCCircleViewConst.CircleEdgeWidth);
            ctx.StrokePath();
            circlePath.Dispose();
        }
Ejemplo n.º 14
0
 public override void Draw(CGRect rect)
 {
     base.Draw(rect);
     using (CGContext graphics = UIGraphics.GetCurrentContext())
     {
         CGPath path = new CGPath();
         path.AddEllipseInRect(rect);
         path.CloseSubpath();
         color.SetFill();
         graphics.AddPath(path);
         graphics.DrawPath(CGPathDrawingMode.Fill);
     }
 }
Ejemplo n.º 15
0
        private void CreateAnimation(CGPoint[] points, CGContext ctx)
        {
            CGPath path = new CGPath();

            path.AddLines(points);

            CAShapeLayer pathLayer = new CAShapeLayer();

            pathLayer.Frame       = new CGRect(0, 0, 320, 250);
            pathLayer.Path        = path;
            pathLayer.StrokeColor = _color.CGColor;
            pathLayer.FillColor   = UIColor.Clear.CGColor;
            pathLayer.LineWidth   = 2.2f;
            pathLayer.LineJoin    = CAShapeLayer.JoinBevel;
            this._animationLayer.AddSublayer(pathLayer);
            this._pathLayer = pathLayer;

            CGPath circlePath = new CGPath();

            foreach (var item in points)
            {
                circlePath.AddEllipseInRect(new CGRect(item.X - _rad / 2, item.Y - _rad / 2, _rad, _rad));
            }
            CAShapeLayer cicleLayer = new CAShapeLayer();

            cicleLayer.Frame       = new CGRect(0, 0, 320, 250);
            cicleLayer.Path        = circlePath;
            cicleLayer.StrokeColor = _color.CGColor;
            cicleLayer.FillColor   = UIColor.Clear.CGColor;
            cicleLayer.LineWidth   = 2.2f;
            cicleLayer.LineJoin    = CAShapeLayer.JoinBevel;
            this._animationLayer.AddSublayer(cicleLayer);
            this._cicleLayer = cicleLayer;

            CGPath circleLayerWhitePath = new CGPath();

            foreach (var item in points)
            {
                circleLayerWhitePath.AddEllipseInRect(new CGRect(item.X - 1.5f, item.Y - 1.5f, 3, 3));
            }
            CAShapeLayer circleLayerWhite = new CAShapeLayer();

            circleLayerWhite.Frame       = new CGRect(0, 0, 320, 250);
            circleLayerWhite.Path        = circleLayerWhitePath;
            circleLayerWhite.StrokeColor = UIColor.White.CGColor;
            circleLayerWhite.FillColor   = UIColor.Clear.CGColor;
            circleLayerWhite.LineWidth   = 3f;
            circleLayerWhite.LineJoin    = CAShapeLayer.JoinBevel;
            this._animationLayer.AddSublayer(circleLayerWhite);
            this._circleLayerWhite = circleLayerWhite;
        }
Ejemplo n.º 16
0
        public void AddEllipseInRect()
        {
            var rect   = new RectangleF(0, 0, 15, 15);
            var matrix = CGAffineTransform.MakeIdentity();

            using (CGPath p1 = new CGPath())
                using (CGPath p2 = new CGPath()) {
                    Assert.IsTrue(p1.IsEmpty, "IsEmpty-1");
                    p1.AddEllipseInRect(rect);
                    p2.AddEllipseInRect(matrix, rect);
                    Assert.IsFalse(p1.IsEmpty, "IsEmpty-2");
                    Assert.That(p1, Is.EqualTo(p2), "CGPathEqualToPath");
                }
        }
        // this will draw background and circular border then it will cut the image to a circle inside the border and padding
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            // the control as it exists in the protable project
            formControl = (SelectImageButton)sender;
            // the click events form the forms control to be added to the end of the long click
            buttonevents = formControl.ClickEvents;
            // setting the colors for use in ther renderer outside of the property changed event
            iosBackgroundColor     = formControl.BackgroundColor.ToCGColor();
            iosBorderColor         = formControl.BorderColor.ToCGColor();
            iosBorderWidth         = formControl.BorderWidth;
            iosHoldBackgroundColor = formControl.HoldBackgroundColor.ToCGColor();
            iosHoldBorderColor     = formControl.HoldBorderColor.ToCGColor();
            iosHoldBorderWidth     = formControl.HoldBorderWidth;
            // background
            Xamarin.Forms.Color bgcolor = formControl.BackgroundColor;
            Layer.BackgroundColor = bgcolor.ToCGColor();
            // border
            Layer.BorderColor = formControl.BorderColor.ToCGColor();
            Layer.BorderWidth = formControl.BorderWidth;

            Layer.CornerRadius = (float)formControl.Width / 2;
            // setup for a long press gesture
            UILongPressGestureRecognizer holdGesture = new UILongPressGestureRecognizer(holdPress);

            holdGesture.MinimumPressDuration = 0.0;
            this.AddGestureRecognizer(holdGesture);
            // this need to check that the control is actually loaded as it can call this method without the control present
            if (formControl != null)
            {
                // a top left and bottom right adjustment for the clipping border
                float TLborderControl = 0;
                float BRborderControl = formControl.BorderWidth;

                // a rectangle made usiing the bounds and borders of the control that we will use the cut an elipse with
                CGRect clipRect = new CGRect();

                clipRect.X      = (float)0 + TLborderControl;
                clipRect.Y      = (float)0 + TLborderControl;
                clipRect.Width  = (float)Element.Bounds.Width;
                clipRect.Height = (float)Element.Bounds.Height;

                CAShapeLayer clipShapeLayer = new CAShapeLayer();
                CGPath       clipPath       = new CGPath();

                clipPath.AddEllipseInRect(clipRect);
                clipShapeLayer.Path = clipPath;
                Layer.Mask          = clipShapeLayer;
            }
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (CGContext graphics = UIGraphics.GetCurrentContext())
            {
                //Create ellipse geometry based on rect field.
                CGPath path = new CGPath();
                path.AddEllipseInRect(rect);
                path.CloseSubpath();

                //Add geometry to graphics context and draw it.
                color.SetFill();
                graphics.AddPath(path);
                graphics.DrawPath(CGPathDrawingMode.Fill);
            }
        }
Ejemplo n.º 19
0
        public void DidStop(CAAnimation theAnimation, bool finished)
        {
            finishedAnimationCount++;
            if (finishedAnimationCount != animationList.Count)
            {
                return;
            }

            nfloat nextPos = StartXPos;

            foreach (var result in Results.OrderByDescending(c => c.ExecutionDate))
            {
                nfloat graphPoint = this.Frame.Height - EndYPos(result.Score);
                string scoreText  = result.Score.ToString();

                var scorePath = new CGPath();
                scorePath.AddEllipseInRect(new CGRect(new CGPoint(nextPos - ScoreBubleSize.Width / 2, graphPoint), ScoreBubleSize));

                var pointLayer = new CAShapeLayer();
                pointLayer.Path        = scorePath;
                pointLayer.StrokeColor = graphColor;
                pointLayer.FillColor   = UIColor.Clear.CGColor;

                this.Layer.AddSublayer(pointLayer);

                var scoreLayer = new CATextLayer();
                scoreLayer.SetFont("System");
                scoreLayer.FontSize = 10;
                scoreLayer.Frame    = new CGRect(nextPos - ScoreSize.Width / 2,
                                                 graphPoint + ScoreBubleSize.Height / 2 - ScoreSize.Height / 2,
                                                 ScoreSize.Width,
                                                 ScoreSize.Height);
                scoreLayer.AlignmentMode   = CATextLayer.AlignmentCenter;
                scoreLayer.String          = scoreText;
                scoreLayer.ForegroundColor = graphColor;

                this.Layer.AddSublayer(scoreLayer);

                nextPos -= Offset;
            }
        }
Ejemplo n.º 20
0
        public ClockView()
        {
            // Set background to pink.
            this.BackgroundColor = UIColor.FromRGB(1.0f, 0.8f, 0.8f);

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

            // Define circle for tick marks.
            tickMarks = new CGPath();
            tickMarks.AddEllipseInRect(new CGRect(-90, -90, 180, 180));

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

            // Define hour hand.
            hourHand = new CGPath();
            hourHand.MoveToPoint(0, -60);
            hourHand.AddCurveToPoint(0, -30, 20, -30, 5, -20);
            hourHand.AddLineToPoint(5, 0);
            hourHand.AddCurveToPoint(5, 7.5f, -5, 7.5f, -5, 0);
            hourHand.AddLineToPoint(-5, -20);
            hourHand.AddCurveToPoint(-20, -30, 0, -30, 0, -60);
            hourHand.CloseSubpath();

            // Define minute hand.
            minuteHand = new CGPath();
            minuteHand.MoveToPoint(0, -80);
            minuteHand.AddCurveToPoint(0, -75, 0, -70, 2.5f, -60);
            minuteHand.AddLineToPoint(2.5f, 0);
            minuteHand.AddCurveToPoint(2.5f, 5, -2.5f, 5, -2.5f, 0);
            minuteHand.AddLineToPoint(-2.5f, -60);
            minuteHand.AddCurveToPoint(0, -70, 0, -75, 0, -80);
            minuteHand.CloseSubpath();

            // Define second hand.
            secondHand = new CGPath();
            secondHand.MoveToPoint(0, 10);
            secondHand.AddLineToPoint(0, -80);
        }
Ejemplo n.º 21
0
		public ClockView ()
		{
			// Set background to pink.
			this.BackgroundColor = UIColor.FromRGB (1.0f, 0.8f, 0.8f);

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

			// Define circle for tick marks.
			tickMarks = new CGPath ();
			tickMarks.AddEllipseInRect(new CGRect(-90, -90, 180, 180));

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

			// Define hour hand.
			hourHand = new CGPath ();
			hourHand.MoveToPoint (0, -60);
			hourHand.AddCurveToPoint (0, -30, 20, -30, 5, - 20);
			hourHand.AddLineToPoint (5, 0);
			hourHand.AddCurveToPoint (5, 7.5f, -5, 7.5f, -5, 0);
			hourHand.AddLineToPoint (-5, -20);
			hourHand.AddCurveToPoint (-20, -30, 0, -30, 0, -60);
			hourHand.CloseSubpath ();

			// Define minute hand.
			minuteHand = new CGPath ();
			minuteHand.MoveToPoint (0, -80);
			minuteHand.AddCurveToPoint (0, -75, 0, -70, 2.5f, -60);
			minuteHand.AddLineToPoint (2.5f, 0);
			minuteHand.AddCurveToPoint (2.5f, 5, -2.5f, 5, -2.5f, 0);
			minuteHand.AddLineToPoint (-2.5f, -60);
			minuteHand.AddCurveToPoint (0, -70, 0, -75, 0, -80);
			minuteHand.CloseSubpath ();

			// Define second hand.
			secondHand = new CGPath ();
			secondHand.MoveToPoint (0, 10);
			secondHand.AddLineToPoint(0, -80);
		}
Ejemplo n.º 22
0
        private void DrawSpinner(CGContext ctxt)
        {
            // --------------------------------------------------------------------
            if (pctSpinner < 0.0)
            {
                return;                // If negative, don't draw spinner.
            }
            var path = new CGPath();

            path.AddEllipseInRect(new CGRect((nfloat)(X - 6.0), (nfloat)(Y - 6.0), 12.0, 12.0));

            // Draw the main spinner shaft...
            double  a  = (pi / 2.0) - (pctSpinner * 2.0 * pi);
            var     p0 = new CGPoint(X, Y);
            CGPoint p1 = GetPoint(p0, a, rInner);

            path.MoveToPoint(p1);
            path.AddLineToPoint(p0);

            // Add the tip on the end of the spinner.
            CGPoint p2;

            p2 = GetPoint(p0, a - 0.15, rInner - 15);
            path.MoveToPoint(p2);
            path.AddLineToPoint(p1);
            p2 = GetPoint(p0, a + 0.15, rInner - 15);
            path.MoveToPoint(p2);
            path.AddLineToPoint(p1);

            path.CloseSubpath(); //Needed?

            UIColor.DarkGray.SetStroke();
            UIColor.DarkGray.SetFill();
            ctxt.SetLineWidth(3);
            ctxt.AddPath(path);
            ctxt.DrawPath(CGPathDrawingMode.EOFillStroke);
        }
Ejemplo n.º 23
0
 public void AddCircle(float xCenter, float yCenter, float radius)
 {
     path.AddEllipseInRect(new CGRect(xCenter - radius, yCenter - radius, 2 * radius, 2 * radius));
 }
Ejemplo n.º 24
0
 public void AddEllipse(float x, float y, float width, float height)
 {
     Control.AddEllipseInRect(new CGRect(x, y, width, height));
     startFigure   = true;
     isFirstFigure = false;
 }
Ejemplo n.º 25
0
		void drawLines ()
		{
			layer.RemoveAllAnimations ();

			var dot = new CGRect (0, 0, lineWidth, lineWidth);

			nfloat x, y;

			CGPoint start = CGPoint.Empty;
			CGPoint end = CGPoint.Empty;


			// Draw curved graph line
			using (UIColor color = UIColor.White.ColorWithAlpha (0.25f), dotColor = UIColor.White.ColorWithAlpha (0.70f)) {

				//color.SetStroke ();

				//dotColor.SetFill ();

				//ctx.SetLineWidth (lineWidth);

				using (CGPath path = new CGPath ()) {


					var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2);

					for (int i = 0; i < count; i++) {

						// adjusted index
						var ai = i;

						double temp;

						if (hourly) {

							temp = HourlyTemps [ai];

						} else {

							// reset start when switching from highs to lows
							if (i == Forecasts.Count) start = CGPoint.Empty;

							var highs = i < Forecasts.Count;

							ai = highs ? i : i - Forecasts.Count;

							temp = highs ? HighTemps [ai] : LowTemps [ai];
						}

						var percent = ((nfloat)temp - scaleLow) / scaleRange;


						x = padding + inset + (ai * scaleX);

						y = graphRect.GetMaxY () - (graphRect.Height * percent);

						end = new CGPoint (x, y);


						if (!hourly) {

							dot.X = end.X - (lineWidth / 2);
							dot.Y = end.Y - (lineWidth / 2);

							path.AddEllipseInRect (dot);

							//ctx.AddEllipseInRect (dot);
						}


						if (start == CGPoint.Empty) {

							path.MoveToPoint (end);

						} else {

							path.MoveToPoint (start);

							if (hourly) {

								path.AddLineToPoint (end);

							} else {

								var diff = (end.X - start.X) / 2;

								path.AddCurveToPoint (end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y);
							}
						}

						start = end;
					}

					// draw all dots to context
					//if (!hourly) ctx.DrawPath (CGPathDrawingMode.Fill);

					// add line path to context
					layer.Path = path;
					//ctx.AddPath (path);

					// draw lines
					//ctx.DrawPath (CGPathDrawingMode.Stroke);

					layer.LineWidth = lineWidth;
					layer.StrokeColor = color.CGColor;
					layer.FillColor = dotColor.CGColor;

					CABasicAnimation pathAnimation = new CABasicAnimation { KeyPath = "strokeEnd" };
					pathAnimation.Duration = 1.0;
					pathAnimation.From = NSNumber.FromNFloat (0);
					pathAnimation.To = NSNumber.FromNFloat (1);
					layer.AddAnimation (pathAnimation, "strokeEndAnimation");

				}
			}
		}
Ejemplo n.º 26
0
        public static XIR.Image RemoteRepresentation(this CGLineCap obj)
        {
            var aPath       = new CGPath();
            var lineWidth   = 10;
            var sampleWidth = 50;

            aPath.MoveToPoint(new CGPoint(lineWidth, lineWidth));
            aPath.AddLineToPoint(new CGPoint(lineWidth + sampleWidth, lineWidth));

            // let's make sure we leave a little room for the line width drawing as well by adding the lineWidth as well
            var width  = (int)aPath.PathBoundingBox.Right + lineWidth;
            var height = (int)aPath.PathBoundingBox.Bottom + lineWidth;

            var bytesPerRow = width * 4;

            using (var context = new CGBitmapContext(
                       IntPtr.Zero, width, height,
                       8, bytesPerRow, CGColorSpace.CreateDeviceRGB(),
                       CGImageAlphaInfo.PremultipliedFirst)) {
                context.SaveState();
                context.SetStrokeColor(new CGColor(0, 0, 0));
                context.SetLineWidth(lineWidth);
                context.AddPath(aPath);
                switch ((CGLineCap)obj)
                {
                case CGLineCap.Square:
                    context.SetLineCap(CGLineCap.Square);
                    break;

                case CGLineCap.Butt:
                    context.SetLineCap(CGLineCap.Butt);
                    break;

                case CGLineCap.Round:
                    context.SetLineCap(CGLineCap.Round);
                    break;
                }

                context.DrawPath(CGPathDrawingMode.Stroke);

                context.RestoreState();

                // Second, we draw the inset line to demonstrate the bounds
                aPath = new CGPath();
                aPath.MoveToPoint(new CGPoint(lineWidth, lineWidth));
                aPath.AddLineToPoint(new CGPoint(lineWidth + sampleWidth, lineWidth));
                context.SetLineCap(CGLineCap.Butt);
                context.SetStrokeColor(NSColor.White.CGColor);
                context.SetLineWidth(1);

                context.SaveState();

                context.AddPath(aPath);
                context.DrawPath(CGPathDrawingMode.Stroke);

                context.RestoreState();


                // Third, we draw the inset line endings which are two circles
                var circleWidth = 2;
                aPath = new CGPath();
                aPath.AddEllipseInRect(new CGRect(lineWidth - (int)(circleWidth / 2), lineWidth - (int)(circleWidth / 2), circleWidth, circleWidth));
                aPath.AddEllipseInRect(new CGRect(lineWidth + sampleWidth - (int)(circleWidth / 2), lineWidth - (int)(circleWidth / 2), circleWidth, circleWidth));
                context.SetLineWidth(circleWidth);
                context.SetStrokeColor(NSColor.White.CGColor);
                context.AddPath(aPath);
                context.DrawPath(CGPathDrawingMode.Stroke);

                return(RemoteRepresentation(context));
            }
        }
Ejemplo n.º 27
0
        void drawLines()
        {
            layer.RemoveAllAnimations();

            var dot = new CGRect(0, 0, lineWidth, lineWidth);

            nfloat x, y;

            CGPoint start = CGPoint.Empty;
            CGPoint end   = CGPoint.Empty;


            // Draw curved graph line
            using (UIColor color = UIColor.White.ColorWithAlpha(0.25f), dotColor = UIColor.Clear) {
                using (CGPath path = new CGPath()) {
                    var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2);

                    for (int i = 0; i < count; i++)
                    {
                        // adjusted index
                        var ai = i;

                        double temp;

                        if (hourly)
                        {
                            temp = HourlyTemps [ai];
                        }
                        else
                        {
                            // reset start when switching from highs to lows
                            if (i == Forecasts.Count)
                            {
                                start = CGPoint.Empty;
                            }

                            var highs = i < Forecasts.Count;

                            ai = highs ? i : i - Forecasts.Count;

                            temp = highs ? HighTemps [ai] : LowTemps [ai];
                        }

                        var percent = ((nfloat)temp - scaleLow) / scaleRange;


                        x = padding + inset + (ai * scaleX);

                        y = graphRect.GetMaxY() - (graphRect.Height * percent);

                        end = new CGPoint(x, y);


                        if (!hourly)
                        {
                            dot.X = end.X - (lineWidth / 2);
                            dot.Y = end.Y - (lineWidth / 2);

                            path.AddEllipseInRect(dot);
                        }


                        if (start == CGPoint.Empty)
                        {
                            path.MoveToPoint(end);
                        }
                        else
                        {
                            path.MoveToPoint(start);

                            if (hourly)
                            {
                                path.AddLineToPoint(end);
                            }
                            else
                            {
                                var diff = (end.X - start.X) / 2;

                                path.AddCurveToPoint(end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y);
                            }
                        }

                        start = end;
                    }

                    // add line path to context
                    layer.Path = path;

                    layer.LineWidth   = lineWidth;
                    layer.StrokeColor = color.CGColor;
                    layer.FillColor   = dotColor.CGColor;

                    CABasicAnimation pathAnimation = new CABasicAnimation {
                        KeyPath = "strokeEnd"
                    };
                    pathAnimation.Duration = 1.0;
                    pathAnimation.From     = NSNumber.FromNFloat(0);
                    pathAnimation.To       = NSNumber.FromNFloat(1);
                    layer.AddAnimation(pathAnimation, "strokeEndAnimation");
                }
            }
        }