/// <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);
            }
        }
Esempio n. 2
0
        public override void CreateShape(CGPath path, CGContext gctx)
        {
            path.AddRect (new RectangleF (_origin, new SizeF (100, 100)));
            gctx.AddPath (path);

            gctx.DrawPath (CGPathDrawingMode.FillStroke);
        }
        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);
            }
        }
        public override void Draw(System.Drawing.RectangleF rect)
        {
            //Get the current context
            CGContext ctxt = UIGraphics.GetCurrentContext();
            ctxt.ClearRect(rect);

            //Set up the stroke and fill characteristics
            ctxt.SetLineWidth(3.0f);
            float[] gray = { 0.5f, 0.5f, 0.5f, 1.0f};
            ctxt.SetStrokeColor(gray);
            float[] red = { 0.75f, 0.25f, 0.25f, 1.0f};
            ctxt.SetFillColor(red);

            //Draw a line between the two location points
            ctxt.MoveTo(Loc1.X, Loc1.Y);
            ctxt.AddLineToPoint(Loc2.X, Loc2.Y);
            ctxt.StrokePath();

            var p1Box = new RectangleF(Loc1.X, Loc1.Y, 0.0f, 0.0f);
            var p2Box = new RectangleF(Loc2.X, Loc2.Y, 0.0f, 0.0f);
            var offset = -8.0f;

            foreach(var r in new RectangleF[] {p1Box, p2Box})
            {
                using(var path = new CGPath())
                {
                    var cpath = new CGPath();
                    r.Inflate (new SizeF (offset, offset));
                    cpath.AddElipseInRect(r);
                    ctxt.AddPath(cpath);
                    ctxt.FillPath();
                }
            }
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			animationPath = new CGPath ();
			backgroundImage = new UIImageView (View.Frame);
			View.AddSubview (backgroundImage);

			CreatePath ();

			btnContents.TouchUpInside += (sender, e) => {
				if(ContentsButtonClicked != null)
					ContentsButtonClicked(sender, e);
			};

			btnAnimate.TouchUpInside += (s, e) => {
				
				// create a keyframe animation
				var keyFrameAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath ("position");
				keyFrameAnimation.Path =  animationPath;
				keyFrameAnimation.Duration = 3;
				
				keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseInEaseOut);
				
				imgToAnimate.Layer.AddAnimation (keyFrameAnimation, "MoveImage");
				imgToAnimate.Layer.Position = new PointF (700f, 900f);
			};
		}
Esempio n. 6
0
        public override void Draw(CGRect rect)
        {
            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext())
            {                
                g.SetLineWidth(_lineWidth);
                //set up drawing attributes
                UIColor.Clear.SetFill();

                if (_isRound)
                {
                    var circle = new CGPath();
                    var circleSize = rect.Size.Width / 2;
                    circle.AddArc(circleSize, circleSize, circleSize, 0, endangle, true);
                    Console.WriteLine("circleSize: {0}", circleSize);
                    g.AddPath(circle);
                }
                else
                {
                    //create geometry
                    var rectangle = new CGPath();
                    rectangle.AddRect(new RectangleF(0f, 0f, (float)rect.Size.Width, (float)rect.Size.Height));
                    rectangle.CloseSubpath();
                    //add geometry to graphics context and draw it
                    g.AddPath(rectangle);
                }

                g.SetStrokeColor(_color.CGColor);
                g.SetAlpha(_transparancy);
                
                g.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
        void initialize()
        {
            _fps = 0;            
            _path = null;

            Frame = new System.Drawing.RectangleF(0, 0, 320, 480 - 54);
            // important - it needs to be transparent so the camera preview shows through!
            Opaque = false;
            BackgroundColor = UIColor.Clear;

            // allocating bitmap buffer
            _buffer     = new RawBitmap((int)Frame.Width, (int)Frame.Height);
            _drawnImage = new RawBitmap((int)Frame.Width, (int)Frame.Height);
            // creating checkerboard mask image
            using (var checkerBoardImage = new RawBitmap((int)Bounds.Size.Width, (int)Bounds.Size.Height))
            {
                for (int y = 0; y < checkerBoardImage.Height; y += 2)
                {
                    for (int x = 0; x < checkerBoardImage.Width; x += 2)
                    {
                        checkerBoardImage.WritePixel(x, y, 255);                        
                    }
                }
                for (int y = 1; y < checkerBoardImage.Height; y += 2)
                {
                    for (int x = 1; x < checkerBoardImage.Width; x += 2)
                    {
                        checkerBoardImage.WritePixel(x, y, 255);
                    }
                }
                _maskImage = checkerBoardImage.Context.ToImage();
			}
		}
Esempio n. 8
0
        public override void Draw(CGRect rect)
        {
            base.Draw (rect);

            var gctx = UIGraphics.GetCurrentContext ();

            // setting blend mode to clear and filling with
            // a clear color results in a transparent fill
            gctx.SetFillColor (UIColor.Purple.CGColor);
            gctx.FillRect (rect);

            gctx.SetBlendMode (CGBlendMode.Clear);
            UIColor.Clear.SetColor ();

            // create some cutout geometry
            var path = new CGPath ();
            path.AddLines(new CGPoint[]{
                new CGPoint(100,200),
                new CGPoint(160,100),
                new CGPoint(220,200)});
            path.CloseSubpath();

            gctx.AddPath(path);
            gctx.DrawPath(CGPathDrawingMode.Fill);
        }
Esempio n. 9
0
 // clear the canvas
 public void Clear()
 {
     drawPath.Dispose ();
     drawPath = new CGPath ();
     fingerDraw = false;
     SetNeedsDisplay ();
 }
        private UIImage CreatePieSegment(CGSize size, nfloat endAngle)
        {
            // Add the arc
            var arc = new CGPath();

            arc.MoveToPoint(size.Width / 2.0f, size.Height / 2.0f);
            arc.AddLineToPoint(size.Width / 2.0f, 0);
            arc.AddArc(size.Width / 2.0f, size.Height / 2.0f, size.Width / 2.0f, _startAngle, endAngle, false);
            arc.AddLineToPoint(size.Width / 2.0f, size.Height / 2.0f);

            // Stroke the arc
            UIGraphics.BeginImageContextWithOptions(size, false, 0);

            var context = UIGraphics.GetCurrentContext();

            context.AddPath(arc);
            context.SetFillColor(UIColor.FromRGBA(0f, 0f, 0f, 1f).CGColor);
            context.FillPath();

            // Get the mask image
            var image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return image;
        }
Esempio n. 11
0
		public DrawView (CGRect frame) : base (frame)
		{
			DrawPath = new CGPath ();
			CurrentLineColor = UIColor.Yellow;
			PenWidth = 5.0f;
			Lines = new List<VESLine> ();
		}
Esempio n. 12
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);                
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Draws the map rectangle.
 /// </summary>
 /// <param name="mapRect">Map rectangle.</param>
 /// <param name="zoomScale">Zoom scale.</param>
 /// <param name="context"> Graphics context.</param>
 public override void DrawMapRect(MKMapRect mapRect, nfloat zoomScale, CGContext context)
 {
     base.DrawMapRect(mapRect, zoomScale, context);
     var multiPolygons = (MultiPolygon)this.polygonOverlay;
     foreach (var item in multiPolygons.Polygons)
     {
         var path = new CGPath();
         this.InvokeOnMainThread(() =>
             {
                 path = PolyPath(item.Polygon);
             });
         if (path != null)
         {
             context.SetFillColor(item.FillColor);
             context.BeginPath();
             context.AddPath(path);
             context.DrawPath(CGPathDrawingMode.EOFill);
             if (item.DrawOutlines)
             {
                 context.BeginPath();
                 context.AddPath(path);
                 context.StrokePath();
             }
         }
     }
 }
Esempio n. 14
0
		public override void Draw (CGRect rect)
		{
			base.Draw (rect);

			var gctx = UIGraphics.GetCurrentContext ();

			// setting blend mode to clear and filling with
			// a clear color results in a transparent fill
			gctx.SetFillColor (UIColor.Clear.CGColor);
			gctx.FillRect (rect);

			//gctx.SetBlendMode (CGBlendMode.Clear);
			UIColor.Black.SetColor ();

			// create some cutout geometry
			var path = new CGPath ();   
			path.AddLines(new CGPoint[]{
				new CGPoint(0,rect.Height * (1.0/4.0)),
				new CGPoint(rect.Width * (3.0/5.0),rect.Height * (1.0/4.0)),
				new CGPoint(rect.Width * (3.0/5.0),0),
				new CGPoint(rect.Width,rect.Height / 2),
				new CGPoint(rect.Width * (3.0/5.0), rect.Height),
				new CGPoint(rect.Width * (3.0/5.0),rect.Height * (3.0/4.0)),
				new CGPoint(0, rect.Height * (3.0/4.0))
			}); 
			path.CloseSubpath();

			gctx.AddPath(path);
			gctx.DrawPath(CGPathDrawingMode.Fill);  
		}
Esempio n. 15
0
        public ShipSprite(PointF initialPosition)
            : base(NSBundle.MainBundle.PathForResource ("spaceship", "png"))
        {
            CGPath boundingPath = new CGPath ();
            boundingPath.MoveToPoint (-12f, -38f);
            boundingPath.AddLineToPoint (12f, -38f);
            boundingPath.AddLineToPoint (9f, 18f);
            boundingPath.AddLineToPoint (2f, 38f);
            boundingPath.AddLineToPoint (-2f, 38f);
            boundingPath.AddLineToPoint (-9f, 18f);
            boundingPath.AddLineToPoint (-12f, -38f);
            #if false
            // Debug overlay
            SKShapeNode shipOverlayShape = new SKShapeNode () {
                Path = boundingPath,
                StrokeColor = UIColor.Clear,
                FillColor = UIColor.FromRGBA (0f, 1f, 0f, 0.5f)
            };
            ship.AddChild (shipOverlayShape);
            #endif
            var body = SKPhysicsBody.BodyWithPolygonFromPath (boundingPath);
            body.CategoryBitMask = Category.Ship;
            body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
            body.ContactTestBitMask = body.CollisionBitMask;
            body.LinearDamping = 0;
            body.AngularDamping = 0.5f;

            PhysicsBody = body;
            Position = initialPosition;
        }
 public override void Draw (RectangleF rect)
 {
     base.Draw (rect);
     
     //get graphics context
     CGContext gctx = UIGraphics.GetCurrentContext ();
     
     //set up drawing attributes
     gctx.SetLineWidth (2);
     UIColor.Gray.SetFill ();
     UIColor.Black.SetStroke ();
     
     //create geometry
     _path = new CGPath ();
     
     _path.AddLines (new PointF[] { new PointF (110, 100), new PointF (210, 100), new PointF (210, 200), new PointF (110, 200) });
     
     _path.CloseSubpath ();
     
     //add geometry to graphics context and draw it
     gctx.AddPath (_path);
     gctx.DrawPath (CGPathDrawingMode.FillStroke);
     
     _titleLabel.Frame = new RectangleF (5, 5, Bounds.Width - 10, 25);
     this.AddSubview (_titleLabel);
 }
		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			// get the initial value to start the animation from
			PointF fromPt = layer.Position;

			// set the position to coincide with the final animation value
			// to prevent it from snapping back to the starting position
			// after the animation completes
			layer.Position = new PointF (200, 300);

			// create a path for the animation to follow
			CGPath path = new CGPath ();
			path.AddLines (new PointF[] { fromPt, new PointF (50, 300), new PointF (200, 50), new PointF (200, 300) });

			// create a keyframe animation for the position using the path
			CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("position");
			animPosition.Path = path;
			animPosition.Duration = 2;

			// add the animation to the layer
			// the "position" key is used to overwrite the implicit animation created
			// when the layer positino is set above
			layer.AddAnimation (animPosition, "position");
		}
Esempio n. 18
0
		public DrawView (RectangleF frame) : base (frame)
		{
			DrawPath = new CGPath ();
			CurrentLineColor = UIColor.Black;
			PenWidth = 5.0f;
			Lines = new List<VESLine> ();
		}
Esempio n. 19
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            this.BackgroundColor = UIColor.Clear;

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

                //set up drawing attributes
                g.SetLineWidth(_lineWidth);
                _color.SetFill();
                //_color.SetStroke();
                UIColor.Clear.SetStroke();
                g.SetAlpha(_transparancy);

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

                path.AddLines(new CGPoint[]{
					new CGPoint (rect.X + rect.Width, rect.Y),
					new CGPoint (rect.X + rect.Width, rect.Y + rect.Height), 
					new CGPoint (rect.X, rect.Y + rect.Height)});

                path.CloseSubpath();

                //add geometry to graphics context and draw it
                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
		public override void AnimateTransition (IUIViewControllerContextTransitioning transitionContext)
		{
			_transitionContext = transitionContext;

			var containerView = transitionContext.ContainerView;

			FlashCardViewController toViewController;
			UIViewController fromViewController;

			if (Presenting) {
				fromViewController = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as UIViewController;
				toViewController = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as FlashCardViewController;
			} else {
				toViewController = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey) as FlashCardViewController;
				fromViewController = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey) as UIViewController;
			}

			if(Presenting)
				containerView.AddSubview(toViewController.View);

			var originRect = toViewController.SourceFrame;

			var circleRect = new CGRect (originRect.GetMidX(), originRect.GetMidY(), 10, 10);

			var circleMaskPathInitial = UIBezierPath.FromOval(circleRect); //(ovalInRect: button.frame);
			var extremePoint = new CGPoint(circleRect.X - toViewController.View.Bounds.Width, circleRect.Y - toViewController.View.Bounds.Height ); //CGRect.GetHeight (toViewController.view.bounds));
			var radius = (float)Math.Sqrt((extremePoint.X * extremePoint.X) + (extremePoint.Y * extremePoint.Y));
			var largeCircleRect = circleRect.Inset (-radius, -radius);
			var circleMaskPathFinal = UIBezierPath.FromOval (largeCircleRect);

			CGPath fromPath;
			CGPath toPath;

			if (Presenting) {
				fromPath = circleMaskPathInitial.CGPath;
				toPath = circleMaskPathFinal.CGPath;
			} else {
				var path = new CGPath ();
				fromPath = circleMaskPathFinal.CGPath;
				toPath = circleMaskPathInitial.CGPath;
			}

			var maskLayer = new CAShapeLayer();
			maskLayer.Path = fromPath;
			if (Presenting) {
				toViewController.View.Layer.Mask = maskLayer;
			} else {
				toViewController.View.Layer.Mask = maskLayer;
			}

			var maskLayerAnimation = CABasicAnimation.FromKeyPath("path");
			maskLayerAnimation.From = ObjCRuntime.Runtime.GetNSObject(fromPath.Handle);
			maskLayerAnimation.To = ObjCRuntime.Runtime.GetNSObject(toPath.Handle);
			maskLayerAnimation.Duration = this.TransitionDuration(transitionContext);
			_animDoneDelegate = new AnimDoneDelegate (transitionContext);
			maskLayerAnimation.Delegate = _animDoneDelegate;
			maskLayer.AddAnimation(maskLayerAnimation, "path");

		}
Esempio n. 21
0
        public PathView(WallCollision wc)
        {
            BackgroundColor = UIColor.Clear;

            path = new CGPath();
            wallCol = wc;

        }
		void Initialize()
		{
			initialPoint = CGPoint.Empty;
			latestPoint = CGPoint.Empty;
			BackgroundColor = UIColor.Clear;
			Opaque = false;
			path = new CGPath();
			SetNeedsDisplay();
		}
		public override void Draw (CGRect rect)
		{
			WeatherForecastAnnotation annotation;
			CGPath path;

			base.Draw (rect);

			annotation = Annotation as WeatherForecastAnnotation;
			if (annotation == null)
				return;

			// Get the current graphics context
			using (var context = UIGraphics.GetCurrentContext ()) {

				context.SetLineWidth (1.0f);

				// Draw the gray pointed shape:
				path = new CGPath ();
				path.MoveToPoint (14.0f, 0.0f);
				path.AddLineToPoint (0.0f, 0.0f);
				path.AddLineToPoint (55.0f, 50.0f);
				context.AddPath (path);

				context.SetFillColor (UIColor.LightGray.CGColor);
				context.SetStrokeColor (UIColor.Gray.CGColor);
				context.DrawPath (CGPathDrawingMode.FillStroke);

				// Draw the cyan rounded box
				path = new CGPath ();
				path.MoveToPoint (15.0f, 0.5f);
				path.AddArcToPoint (59.5f, 00.5f, 59.5f, 05.0f, 5.0f);
				path.AddArcToPoint (59.5f, 69.5f, 55.5f, 69.5f, 5.0f);
				path.AddArcToPoint (10.5f, 69.5f, 10.5f, 64.0f, 5.0f);
				path.AddArcToPoint (10.5f, 00.5f, 15.5f, 00.5f, 5.0f);
				context.AddPath (path);

				context.SetFillColor (UIColor.Cyan.CGColor);
				context.SetStrokeColor (UIColor.Blue.CGColor);
				context.DrawPath (CGPathDrawingMode.FillStroke);

				// Create the location & temperature string
				WeatherForecast forecast = annotation.Forecast;
				NSString temperature = new NSString (string.Format ("{0}\n{1} / {2}", forecast.Place, forecast.High, forecast.Low));

				// Draw the text in black
				UIColor.Black.SetColor ();
				temperature.DrawString (new CGRect (15.0f, 5.0f, 50.0f, 40.0f), UIFont.SystemFontOfSize (11.0f));
				temperature.Dispose ();

				// Draw the icon for the weather condition
				string imageName = string.Format ("WeatherMap.WeatherIcons.{0}.png", forecast.Condition);
				UIImage image = UIImage.FromResource (typeof(WeatherAnnotationView).Assembly, imageName);
				image.Draw (new CGRect (12.5f, 28.0f, 45.0f, 45.0f));
				image.Dispose ();
			}
		}
Esempio n. 24
0
        public override void CreateShape(CGPath path, CGContext gctx)
        {
            path.AddLines (new PointF[] { _origin, new PointF (_origin.X + 50, _origin.Y + 100), new PointF (_origin.X - 50, _origin.Y + 100) });

            path.CloseSubpath ();

            gctx.AddPath (path);

            gctx.DrawPath (CGPathDrawingMode.FillStroke);
        }
Esempio n. 25
0
		public DrawView (RectangleF frame) : base (frame)
		{
			DrawPath = new CGPath ();
			CurrentLineColor = UIColor.Black;
			PenWidth = 5.0f;
			Lines = new List<VESLine> ();
			/*var documentsDirectory = Environment.GetFolderPath
				(Environment.SpecialFolder.Personal);
			string jpgFilename = System.IO.Path.Combine (documentsDirectory, "Writing.png");
			System.IO.File.Delete (jpgFilename);*/
		}
        public BezierSignatureView(RectangleF frame, bool isSigning = true)
            : base(frame)
        {
            IsSigning = isSigning;
            _drawPath = new CGPath ();
            BackgroundColor = UIColor.White;
            MultipleTouchEnabled = false;

            _panner = new UIPanGestureRecognizer (this, new MonoTouch.ObjCRuntime.Selector("BezierSignatureViewPan"));
            _panner.MaximumNumberOfTouches = _panner.MinimumNumberOfTouches = 1;
            AddGestureRecognizer (_panner);
        }
Esempio n. 27
0
        public DrawingView()
        {
            BackgroundColor = UIColor.White;

            path = new CGPath ();

            layer = new CALayer ();
            layer.Bounds = new RectangleF (0, 0, 50, 50);
            layer.Position = new PointF (50, 50);
            layer.Contents = UIImage.FromFile ("monkey.png").CGImage;
            layer.ContentsGravity = CALayer.GravityResizeAspect;
        }
Esempio n. 28
0
        public override void Draw (RectangleF rect)
        {
            base.Draw (rect);
            
            // get graphics context
            CGContext gctx = UIGraphics.GetCurrentContext ();
            
            // set up drawing attributes
            gctx.SetLineWidth (4);
            UIColor.Yellow.SetStroke ();
            
            // stroke with a dashed line
            gctx.SetLineDash (3, new float[] {6,2});     
            
            // create geometry
            var path = new CGPath ();
            
            PointF origin = new PointF (Bounds.GetMidX (), 
                                        Bounds.GetMinY () + 10);
            
            path.AddLines (new PointF[] { 
                origin, 
                new PointF (origin.X + 35, origin.Y + 80), 
                new PointF (origin.X - 50, origin.Y + 30), 
                new PointF (origin.X + 50, origin.Y + 30), 
                new PointF (origin.X - 35, origin.Y + 80) });
            
            path.CloseSubpath ();
            
            // add geometry to graphics context and draw it
            gctx.AddPath (path);
         
            gctx.DrawPath (CGPathDrawingMode.Stroke);

            // fill the star with a gradient          
            gctx.AddPath (path);          
            gctx.Clip ();
                 
            RectangleF starBoundingBox = path.BoundingBox;
            
            float[] locations = { 0.0f, 1.0f };
            float[] components = { 1.0f, 0.0f, 0.0f, 1.0f,
                                   0.0f, 0.0f, 1.0f, 1.0f };
            
            using (var rgb = CGColorSpace.CreateDeviceRGB()) {
                CGGradient gradient = new CGGradient (rgb, components, locations);  
 
                PointF gradientStart = new PointF (starBoundingBox.Left, starBoundingBox.Top);
                PointF gradientEnd = new PointF (starBoundingBox.Right, starBoundingBox.Bottom);
                gctx.DrawLinearGradient (gradient, gradientStart, gradientEnd, CGGradientDrawingOptions.DrawsBeforeStartLocation);
            }
        }
		void AddAnchorDotToSprite (SKSpriteNode sprite)
		{
			CGPath myPath = new CGPath ();
			myPath.AddArc (0, 0, 10, 0, (float) Math.PI * 2, true);
			myPath.CloseSubpath ();

			SKShapeNode dot = new SKShapeNode () {
				Path = myPath,
				FillColor = UIColor.Green,
				LineWidth = 0.0f
			};
			sprite.AddChild (dot);
		}
Esempio n. 30
0
		// rect changes depending on if the whole view is being redrawn, or just a section
		public override void Draw (CGRect rect)
		{
			Console.WriteLine ("Draw() Called");
			base.Draw (rect);

			using (CGContext context = UIGraphics.GetCurrentContext ()) {
				// draw a rectangle using a path
				myRectangleButtonPath = new CGPath ();
				myRectangleButtonPath.AddRect (new CGRect (new CGPoint (100, 10), new CGSize (200, 400)));
				context.AddPath (myRectangleButtonPath);
				context.DrawPath (CGPathDrawingMode.Stroke);
			}
		}
Esempio n. 31
0
        void DrawPathOnLayer(CAShapeLayer layer)
        {
            var offset = Math.Abs(CurrentStartPosition.X - CurrentEndPosition.X) / 5;

            var ctrlPointA = new CGPoint(CurrentEndPosition.X - offset, CurrentStartPosition.Y);
            var ctrlPointB = new CGPoint(CurrentStartPosition.X + offset, CurrentEndPosition.Y);

            var path = new CGPath();

            path.MoveToPoint(CurrentStartPosition);
            path.AddCurveToPoint(
                ctrlPointA.X, ctrlPointA.Y,
                ctrlPointB.X, ctrlPointB.Y,
                CurrentEndPosition.X, CurrentEndPosition.Y);

            layer.Path = path;
        }
        public override void Draw(CGRect rect)
        {
            GLabBoxView boxView = (GLabBoxView)Element;

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetFillColor(boxView.Color.ToCGColor());
                context.SetStrokeColor(boxView.BorderColor.ToCGColor());
                context.SetLineWidth((float)boxView.BorderThickness);

                var rectangle = Bounds.Inset((int)boxView.BorderThickness, (int)boxView.BorderThickness);

                var path = CGPath.FromRect(rectangle);
                context.AddPath(path);
                context.DrawPath((CGPathDrawingMode.FillStroke));
            }
        }
Esempio n. 33
0
        //TODO: we should move this to a shared place
        public static CGPath ToCGPath(this NSBezierPath path)
        {
            var numElements = path.ElementCount;

            if (numElements == 0)
            {
                return(null);
            }

            CGPath result       = new CGPath();
            bool   didClosePath = true;


            for (int i = 0; i < numElements; i++)
            {
                CGPoint[] points;
                var       element = path.ElementAt(i, out points);
                if (element == NSBezierPathElement.MoveTo)
                {
                    result.MoveToPoint(points[0].X, points[0].Y);
                }
                else if (element == NSBezierPathElement.LineTo)
                {
                    result.AddLineToPoint(points[0].X, points[0].Y);
                    didClosePath = false;
                }
                else if (element == NSBezierPathElement.CurveTo)
                {
                    result.AddCurveToPoint(points[0].X, points[0].Y,
                                           points[1].X, points[1].Y,
                                           points[2].X, points[2].Y);
                    didClosePath = false;
                }
                else if (element == NSBezierPathElement.ClosePath)
                {
                    result.CloseSubpath();
                }
            }

            // Be sure the path is closed or Quartz may not do valid hit detection.
            if (!didClosePath)
            {
                result.CloseSubpath();
            }
            return(result);
        }
Esempio n. 34
0
        private void DrawForwardRight()
        {
            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext()) {
                //set up drawing attributes
                g.SetLineWidth(STROKE_WIDTH);
                //g.SetFillColor (0, 0, 178, 255);
                FILL.SetFill();
                STROKE.SetStroke();

                var outline = new CGPath();
                var body    = new CGPath();

                var x0 = 0;
                var x1 = this.Frame.Width * GUTTER;
                var x2 = this.Frame.Width - x1;
                var x3 = this.Frame.Width;
                var y0 = 0;
                var y1 = this.Frame.Height * GUTTER;
                var y2 = this.Frame.Height - y1;
                var y3 = this.Frame.Height;

                var trPoints = new CGPoint[] {
                    new CGPoint(x2, y0),
                    new CGPoint(x2, y1),
                    new CGPoint(x3, y1),
                };
                var blPoints = new CGPoint[] {
                    new CGPoint(x3, y2),
                    new CGPoint(x1, y2),
                    new CGPoint(x1, y0),
                };

                body.AddLines(trPoints.Union(blPoints).ToArray());
                body.CloseSubpath();

                outline.AddLines(trPoints);
                outline.AddLines(blPoints);

                g.AddPath(body);
                g.DrawPath(CGPathDrawingMode.Fill);

                g.AddPath(outline);
                g.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Esempio n. 35
0
        public DemoView()
        {
            BackgroundColor = UIColor.White;

            path = new CGPath();

            //create layer
            layer                 = new CALayer();
            layer.Bounds          = new RectangleF(0, 0, 50, 50);
            layer.Position        = new PointF(50, 50);
            layer.Contents        = UIImage.FromFile("monkey.png").CGImage;
            layer.ContentsGravity = CALayer.GravityResizeAspect;
            layer.BorderWidth     = 1.5f;
            layer.CornerRadius    = 5;
            layer.BorderColor     = UIColor.Blue.CGColor;
            layer.BackgroundColor = UIColor.Purple.CGColor;
        }
Esempio n. 36
0
 void Initialize()
 {
     path = new CGPath();
     _timeLeftTextColor = UIColor.Gray;
     color112           = new UIColor[] {
         UIColor.FromRGB(246, 147, 38),  // orange
         UIColor.FromRGB(251, 58, 87),   // rose
         UIColor.FromRGB(251, 13, 23),   // dark rose
         UIColor.FromRGB(250, 203, 148), // light orange
         UIColor.FromRGB(246, 147, 38),  // orange
     };
     positions = new float[]
     {
         0.000f, 0.25f, 0.50f,
         0.75f, 0.999f
     };
 }
Esempio n. 37
0
 partial void EnsureClip(Rect rect)
 {
     if (rect.IsEmpty ||
         double.IsPositiveInfinity(rect.X) ||
         double.IsPositiveInfinity(rect.Y) ||
         double.IsPositiveInfinity(rect.Width) ||
         double.IsPositiveInfinity(rect.Height)
         )
     {
         this.Layer.Mask = null;
         return;
     }
     this.Layer.Mask = new CAShapeLayer
     {
         Path = CGPath.FromRect(ToCGRect(rect))
     };
 }
Esempio n. 38
0
        public void MakeEmpty()
        {
            regionObject = RectangleF.Empty;

            var path = RectangleToPath(RectangleF.Empty);

            // clear out our containers.
            regionList.Clear();
            solution.Clear();

            solution.Add(path);
            regionList.Add(new RegionEntry(RegionType.Empty, RectangleF.Empty, path));

            regionPath = new CGPath();

            regionBounds = CGRect.Empty;
        }
Esempio n. 39
0
        /* */
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            CustomBoxView boxView = (CustomBoxView)Element;

            using (var context = UIGraphics.GetCurrentContext())           //using bloc to set the context
            {
                context.SetFillColor(boxView.Color.ToCGColor());           //fill color
                context.SetStrokeColor(boxView.BorderColor.ToCGColor());   //border color
                context.SetLineWidth((float)boxView.BorderThikness);       //width of border
                var rectangle = Bounds.Inset((int)boxView.BorderThikness,
                                             (int)boxView.BorderThikness); //
                var path = CGPath.FromRect(rectangle);
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
        private void DrawRectangle(CGContext context, double width, double height, CGColor fillColor, double strokeWidth,
                                   CGColor strokeColor, double left = 0, double top = 0)
        {
            var bottom   = top + height;
            var right    = left + width;
            var rectPath = new CGPath();

            rectPath.AddLines(new CGPoint[]
            {
                new CGPoint(left, top),
                new CGPoint(right, top),
                new CGPoint(right, bottom),
                new CGPoint(left, bottom),
            });
            rectPath.CloseSubpath();
            DrawPath(context, rectPath, fillColor, strokeWidth, strokeColor);
        }
        /// <summary>
        /// Draws a polyline.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">if set to <c>true</c> the shape will be aliased.</param>
        public override void DrawLine(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased)
        {
            if (stroke.IsVisible() && thickness > 0)
            {
                this.SetAlias(aliased);
                this.SetStroke(stroke, thickness, dashArray, lineJoin);

                using (var path = new CGPath())
                {
                    var convertedPoints = (aliased ? points.Select(p => p.ConvertAliased()) : points.Select(p => p.Convert())).ToArray();
                    path.AddLines(convertedPoints);
                    this.gctx.AddPath(path);
                }

                this.gctx.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Esempio n. 42
0
        /// <summary>
        /// Draws the specified rect.
        /// </summary>
        /// <param name="rect">The rect.</param>
        public override void Draw(CGRect rect)
        {
            using (var g = UIGraphics.GetCurrentContext()) {
                g.SetLineWidth(10);
                UIColor.FromRGB(64, 30, 168).SetStroke();
                UIColor.Clear.SetFill();

                //create geometry
                var path = new CGPath();
                path.AddRect(rect);
                path.CloseSubpath();

                //add geometry to graphics context and draw it
                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Esempio n. 43
0
        public CustomLayerBasedView(CGRect rect) : base(rect)
        {
            WantsLayer = true;

            CAShapeLayer shapeLayer = new CAShapeLayer();

            // Create a circle path
            CGPath path = new CGPath();

            path.AddArc(rect.Width / 2, rect.Height / 2, (rect.Height / 2) - 10, (float)(-(Math.PI / 2)), (float)(3 * Math.PI / 2), false);
            shapeLayer.Path        = path;
            shapeLayer.Position    = new CGPoint(Bounds.Width / 2, Bounds.Height / 2);
            shapeLayer.FillColor   = NSColor.LightGray.CGColor;
            shapeLayer.StrokeColor = NSColor.Blue.CGColor;
            shapeLayer.LineWidth   = 2;
            Layer = shapeLayer;
        }
Esempio n. 44
0
        public override void Draw(CGRect rect)
        {
            FiapBoxView boxView = (FiapBoxView)Element;

            using (var context = UIGraphics.GetCurrentContext()) {
                context.SetFillColor(boxView.Color.ToCGColor());
                context.SetStrokeColor(boxView.CorDaBorda.ToCGColor());
                context.SetLineWidth((float)boxView.EspessuraDaBorda);

                var ret = Bounds.Inset((int)boxView.EspessuraDaBorda,
                                       (int)boxView.EspessuraDaBorda);

                var path = CGPath.FromRect(ret);
                context.AddPath(path);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Esempio n. 45
0
        public void DrawHeatZone(CGContext canvas, SKRect zone, float halo, float groove, SKColor color, Swipe swipe)
        {
            var radialGradient = SKShader.CreateRadialGradient(swipe % new SKPoint(zone.MidX, zone.MidY), swipe % groove, new SKColor[2] {
                color, KDeviceHandler.deviceBackColor
            }, null, SKShaderTileMode.Mirror);                                                                                                                                                                      //, scaleMatrix);

            using (var gradientPaint = new SKPaint {
                Style = SKPaintStyle.Fill, Shader = radialGradient
            })
            {
                var path = new CGPath();
                path.AddRoundedRect(CG.Rect(swipe % InflateRect(zone, halo)), swipe % halo, swipe % halo);
                canvas.AddPath(path);
                canvas.SetFillColor(CG.Color(color));
                canvas.FillPath();
            }
        }
Esempio n. 46
0
        void step(NSTimer timer)
        {
            if (sessionManager.Barcodes == null || sessionManager.Barcodes.Count < 1)
            {
                return;
            }

            lock (sessionManager) {
                barcodeIndex = (barcodeIndex + 1) % sessionManager.Barcodes.Count;
                var barcode = (AVMetadataMachineReadableCodeObject)sessionManager.Barcodes [barcodeIndex];

                if (barcodeTimer != null)
                {
                    barcodeTimer.Invalidate();
                }
                barcodeTimer = NSTimer.CreateScheduledTimer(0.5, this, new Selector("removeDetectedBarcodeUI"), null, false);
                var transformedBarcode =
                    (AVMetadataMachineReadableCodeObject)previewLayer.GetTransformedMetadataObject(barcode);
                CGPath barcodeBoundary = createPathForPoints(transformedBarcode.Corners);

                CATransaction.Begin();
                CATransaction.DisableActions = true;
                removeDetectedBarcodeUI();
                barcodeTargetLayer.AddSublayer(barcodeOverlayLayer(barcodeBoundary, OverlayColor));
                CATransaction.Commit();

                string noteString = barcode.StringValue;
                int    note       = 0;
                if (int.TryParse(noteString, out note))
                {
                    // barcode data is a MIDI note (or at least an int that we presume can be a note
                    note -= 24;
                    if (note >= 0 && note <= 127)
                    {
                        synth.StartPlayNoteNumber(note);
                        Thread.Sleep(TimeSpan.FromMilliseconds(0.5));
                        synth.StopPlayNoteNumber(note);
                    }
                }
                else
                {
                    // barcode data is something else
                    Console.WriteLine("Barcode string data: " + noteString);
                }
            }
        }
        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);
            }
        }
Esempio n. 48
0
        public void DrawContentView()
        {
            if (!Highlighted || Element.Theme.DrawWhenHighlighted)
            {
                var borderRect = Bounds;

                var innerRect = CalculateInnerRect();

                CGPath path = null;

                var backgroundColor = TableView.BackgroundColor;

                CGContext context = UIGraphics.GetCurrentContext();
                context.SaveState();

                context.SetFillColorWithColor(backgroundColor.CGColor);

                if (TableView.Style == UITableViewStyle.Grouped)
                {
                    borderRect = CalculateInnerRect();
                    path       = GetCellBorderPath(borderRect);
                }
                else
                {
                    path = new CGPath();
                    path.AddRect(borderRect);
                }

                context.AddPath(path);
                context.Clip();

                ShouldDrawBorder = false;

                if (Element.Theme.DrawContentViewAction != null)
                {
                    Element.Theme.DrawContentViewAction(innerRect, context, this);
                }

                context.RestoreState();

                if (ShouldDrawBorder)
                {
                    DrawBorder(context, path);
                }
            }
        }
Esempio n. 49
0
        public PlanetNode(PointF initialPosition, float size = defaultSize)
        {
            var path = new CGPath();

            path.AddArc(0, 0, size, 0, (float)Math.PI * 2f, true);
            Path        = path;
            StrokeColor = UIColor.Clear;
            FillColor   = UIColor.Green;
            Position    = initialPosition;
            // use a local variable to avoid multiple virtual call to the `PhysicsBody` property
            var body = SKPhysicsBody.BodyWithCircleOfRadius(size);

            body.CategoryBitMask    = Category.Planet;
            body.CollisionBitMask   = Category.Planet | Category.Edge;
            body.ContactTestBitMask = 0;
            PhysicsBody             = body;
        }
Esempio n. 50
0
        private void DrawRays(CGContext drawingContext)
        {
            var radius = maxGraphWidth / 2;

            for (int i = 0; i < numberOfDataPoints; i++)
            {
                var x = radius * Math.Cos(2 * Math.PI * i / (numberOfDataPoints)) + width / 2;
                var y = radius * Math.Sin(2 * Math.PI * i / (numberOfDataPoints)) + height / 2;

                // generate path to draw net step
                var path = new CGPath();
                path.AddLines(new CGPoint[] { new CGPoint(width / 2, height / 2), new CGPoint(x, y) });

                //draw path
                drawingContext.AddPath(path);
                drawingContext.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Esempio n. 51
0
        public void AddQuadCurveToPoint()
        {
            var matrix = CGAffineTransform.MakeIdentity();

            using (CGPath p1 = new CGPath())
                using (CGPath p2 = new CGPath()) {
                    Assert.IsTrue(p1.IsEmpty, "IsEmpty-1");
                    p1.MoveToPoint(0, 0);
                    p1.AddQuadCurveToPoint(1, 2, 3, 4);
                    p1.CloseSubpath();
                    p2.MoveToPoint(0, 0);
                    p2.AddQuadCurveToPoint(matrix, 1, 2, 3, 4);
                    Assert.IsFalse(p1.IsEmpty, "IsEmpty-2");
                    Assert.That(p1, Is.Not.EqualTo(p2), "CGPathEqualToPath-2");
                    p2.CloseSubpath();
                    Assert.That(p1, Is.EqualTo(p2), "CGPathEqualToPath");
                }
        }
Esempio n. 52
0
        public void DrawBevel(RectangleF rect)
        {
            using (CGContext context = UIGraphics.GetCurrentContext()) {
                context.SetLineWidth(1);
                UIColor.Black.SetFill();
                UIColor.Black.SetStroke();
                var currentPath = new CGPath();

                currentPath.AddLines(new PointF[] {
                    new PointF(10, 20),
                    new PointF(16, 10),
                    new PointF(22, 20)
                });
                currentPath.CloseSubpath();
                context.AddPath(currentPath);
                context.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Esempio n. 53
0
        // http://stackoverflow.com/a/2835659/338
        void AddRoundedRect(CGRect rrect, CGSize corner)
        {
            var rx = corner.Width;

            if (rx * 2 > rrect.Width)
            {
                rx = rrect.Width / 2;
            }
            var ry = corner.Height;

            if (ry * 2 > rrect.Height)
            {
                ry = rrect.Height / 2;
            }
            var path = CGPath.FromRoundedRect(rrect, rx, ry);

            context.AddPath(path);
        }
Esempio n. 54
0
        public override void DrawLine(IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased)
        {
            if (stroke == null || thickness <= 0)
            {
                return;
            }
            gctx.SetAllowsAntialiasing(aliased);
            gctx.SetLineCap(ToLine(lineJoin));

            SetAttributes(null, stroke, thickness);

            var path = new CGPath();

            path.AddLines(points.Select(p => ToPoint(p)).ToArray());

            gctx.AddPath(path);
            gctx.DrawPath(CGPathDrawingMode.Stroke);
        }
Esempio n. 55
0
        public override void Draw(CGRect rect)
        {
            //base.Draw(rect);

            var led = (Led)Element;

            using (var context = UIGraphics.GetCurrentContext()){
                var shadowSize = 3;
                var blur       = shadowSize;
                var radius     = 20;

                context.SetFillColor(led.Color.ToCGColor());
                var bounds = Bounds.Inset(2, 2);
                context.AddPath(CGPath.FromRoundedRect(bounds, radius, radius));
                context.SetShadow(new SizeF(shadowSize, shadowSize), blur);
                context.DrawPath(CGPathDrawingMode.Fill);
            }
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            var startingPoint = new CGPoint(x: rect.GetMinX(), y: rect.GetMaxY() - 10);
            var endingPoint   = new CGPoint(x: rect.GetMaxX(), y: rect.GetMaxY() - 10);

            CGContext context = UIGraphics.GetCurrentContext();

            context.SetLineWidth(1);
            UIColor.Clear.SetFill();
            UIColor.FromRGB(177, 177, 177).SetStroke();
            var currentPath = new CGPath();

            currentPath.AddLines(new CGPoint[] { startingPoint, endingPoint });
            context.AddPath(currentPath);
            context.DrawPath(CGPathDrawingMode.Stroke);
            context.SaveState();
        }
Esempio n. 57
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (var g = UIGraphics.GetCurrentContext()) {
                g.SetFillColor(UIColor.Gray.CGColor);
                g.FillRect(rect);

                g.SetBlendMode(CGBlendMode.Clear);
                UIColor.Clear.SetColor();

                var path = new CGPath();
                path.AddRect(new CGRect(origin, cropSize));

                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.Fill);
            }
        }
Esempio n. 58
0
 public /*interface ChartPainter*/ void DrawCourseFill(List <KChartEntry> list, int seriesIndex, float bottom, SKColor color, Swipe pinchPan)
 {
     if (list.Count > 1)
     {
         canvas.SetFillColor(CG.Color(color));
         var path = new CGPath();
         path.MoveToPoint(CG.Point(pinchPan % new SKPoint(list[0].Ypoint[seriesIndex].X, bottom)));
         path.AddLineToPoint(CG.Point(pinchPan % list[0].Ypoint[seriesIndex]));
         for (int i = 0; i < list.Count; i++)
         {
             path.AddLineToPoint(CG.Point(pinchPan % list[i].Ypoint[seriesIndex]));
         }
         path.AddLineToPoint(CG.Point(pinchPan % new SKPoint(list[list.Count - 1].Ypoint[seriesIndex].X, bottom)));
         path.CloseSubpath();
         canvas.AddPath(path);
         canvas.FillPath();
     }
 }
            public override void Draw(CGRect rect)
            {
                base.Draw(rect);

                using (CGContext g = UIGraphics.GetCurrentContext())
                {
                    g.SetLineWidth(4);
                    UIColor.Blue.SetStroke();

                    var path = new CGPath();

                    var iOSPoints = allPoints.Select(p => new CGPoint(p.X, p.Y)).ToArray();
                    path.AddLines(iOSPoints);

                    g.AddPath(path);
                    g.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
Esempio n. 60
0
        private CGPath BarcodeOverlayPathWithCorners(CGPoint[] corners)
        {
            var path = new CGPath();

            if (corners.Any())
            {
                path.MoveToPoint(CGAffineTransform.MakeIdentity(), corners[0]);

                for (int i = 1; i < corners.Length; i++)
                {
                    path.AddLineToPoint(corners[i]);
                }

                path.CloseSubpath();
            }

            return(path);
        }