public override void Draw(CoreGraphics.CGRect rect) { base.Draw(rect); using (CGContext g = UIGraphics.GetCurrentContext()) { if ((xLocations != null) && (yLocations != null)) { CGPath currentPath = new CGPath(); for (int i = 0; i < xLocations.Length; i++) { currentPath.AddLines(new CGPoint[] { new CGPoint(xLocations[i], 0), new CGPoint(xLocations[i], Frame.Height) }); } for (int i = 0; i < yLocations.Length; i++) { currentPath.AddLines(new CGPoint[] { new CGPoint(0, yLocations[i]), new CGPoint(Frame.Width, yLocations[i]) }); } g.SetLineWidth(1); g.AddPath(currentPath); g.SetStrokeColor(UIColor.FromRGB(0, 0, 0).CGColor); g.DrawPath(CGPathDrawingMode.Stroke); } } }
private void DrawForwardRightBackwardLeft() { //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 brPoints = new CGPoint[] { new CGPoint(x3, y2), new CGPoint(x2, y2), new CGPoint(x2, y3) }; var blPoints = new CGPoint[] { new CGPoint(x1, y3), new CGPoint(x1, y2), new CGPoint(x0, y2) }; var tlPoints = new CGPoint[] { new CGPoint(x0, y1), new CGPoint(x1, y1), new CGPoint(x1, y0) }; body.AddLines(trPoints.Union(brPoints).Union(blPoints).Union(tlPoints).ToArray()); body.CloseSubpath(); outline.AddLines(trPoints); outline.AddLines(brPoints); outline.AddLines(blPoints); outline.AddLines(tlPoints); g.AddPath(body); g.DrawPath(CGPathDrawingMode.Fill); g.AddPath(outline); g.DrawPath(CGPathDrawingMode.Stroke); } }
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); }
private void DrawNet(CGContext drawingContext) { // set line parameter for drawing drawingContext.SetLineWidth(1); // set color parameters for drawing UIColor.Clear.SetFill(); source.GetColorForNet().SetStroke(); for (int j = 1; j < numberOfNetSteps + 2; j++) { var radius = (j * (maxGraphWidth / (numberOfNetSteps + 1))) / 2; // calculate points for polygon current net step var points = new List <CGPoint>(); for (int i = 0; i < numberOfDataPoints + 1; 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); points.Add(new CGPoint(x, y)); } // generate path to draw net step var path = new CGPath(); path.AddLines(points.ToArray()); //draw path drawingContext.AddPath(path); drawingContext.DrawPath(CGPathDrawingMode.Stroke); } }
public override void Draw(CGRect rect) { base.Draw(rect); using (CGContext g = UIGraphics.GetCurrentContext()) { //set up drawing attributes g.SetLineWidth(10); UIColor.Blue.SetFill(); UIColor.Red.SetStroke(); //create geometry var path = new CGPath(); path.AddLines( new CGPoint[] { new CGPoint(100, 200), new CGPoint(160, 100), new CGPoint(220, 200) }); path.CloseSubpath(); //add geometry to graphics context and draw it g.AddPath(path); g.DrawPath(CGPathDrawingMode.FillStroke); } }
/// <summary> /// Loads the scroll indicator. /// </summary> void LoadScrollIndicator() { scroll = new CALayer(); var image = UIImage.FromBundle("VIEWPORT/SCROLL BAR-130x688"); scroll.Bounds = new CGRect(0, 0, image.CGImage.Width / image.CurrentScale, image.CGImage.Height / image.CurrentScale); scroll.Position = new CGPoint(ScopeBounds.Width / 2 + ScopeBounds.Left, ScopeBounds.Height + ScopeBounds.Top); scroll.Contents = image.CGImage; Layer.AddSublayer(scroll); scrollBar = new CAShapeLayer(); var path = new CGPath(); var data = new CGPoint[2]; data [0].X = 0 + ScopeBounds.Left + 2; data [1].X = 100; data [0].Y = ScopeBounds.Height + ScopeBounds.Top; data [1].Y = ScopeBounds.Height + ScopeBounds.Top; path.AddLines(data); scrollBar.LineWidth = 2f; scrollBar.StrokeColor = new CGColor(72f / 255f, 72f / 255f, 72f / 255f); scrollBar.FillColor = new CGColor(0, 0, 0, 0); scrollBar.Path = path; Layer.AddSublayer(scrollBar); }
public override void Draw(CGRect rect) { base.Draw(rect); using (var ctxt = UIGraphics.GetCurrentContext()) { ctxt.SetStrokeColor(StrokeColor); using (var path = new CGPath()) { var imageSize = this.Bounds.Size; lock (quadrilaterals) { var scaled = quadrilaterals.Select(q => q.Select(pt => pt.Scaled(imageSize))); foreach (var q in scaled) { path.AddLines(q.ToArray()); path.CloseSubpath(); } } ctxt.AddPath(path); ctxt.StrokePath(); // Draw text } ctxt.SaveState(); ctxt.ScaleCTM(1, -1); ctxt.SetFillColor(UIColor.Red.CGColor); ctxt.SetTextDrawingMode(CGTextDrawingMode.Fill); ctxt.SelectFont("Helvetica", 32, CGTextEncoding.MacRoman); //Draw the text at given coords. ctxt.ShowTextAtPoint(25, -25, Message); ctxt.RestoreState(); } }
public override void Draw(CGRect rect) { base.Draw(rect); var context = UIGraphics.GetCurrentContext(); context.SetLineWidth(4); UIColor.Red.SetFill(); UIColor.Blue.SetStroke(); var path = new CGPath(); var p1 = new CGPoint(100, 200); var p2 = new CGPoint(160, 100); var p3 = new CGPoint(220, 200); path.AddLines(new CGPoint[] { p1, p2, p3 }); /**path.AddLines(new PointF[]{ * new PointF(100,200), * new PointF(160,100), * new PointF(220,200)}); */ path.CloseSubpath(); context.AddPath(path); context.DrawPath(CGPathDrawingMode.FillStroke); }
void addDescription() { //Text of the description nfloat deltax = 55; var descriptionpath = new CGPath(); descriptionpath.AddLines(new CGPoint[] { new CGPoint(0, 280), new CGPoint(260, 280), new CGPoint(260 + deltax, 0), new CGPoint(deltax, 0) }); descriptionpath.CloseSubpath(); nfloat descriptionHeight = 280; CGRect frame = new CGRect(60, 256, 310, 280); //eview2.Bounds var descriptionview = new UIFormatedText() { Frame = frame, Text = _descriptionText, Foreground = UIColor.Black, FontSize = 28, FontName = "HelveticaNeue-Light", TextHeight = descriptionHeight, TextAligment = CoreText.CTTextAlignment.Left, Path = descriptionpath }; descriptionview.Transform = CGAffineTransformMakeSkew(-1 * skew, descriptionHeight); descriptionview.BackgroundColor = UIColor.Clear; Add(descriptionview); }
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); }
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); }
public UIImage GetDrawlineImage() { CGRect pageRect; if (IsPdfBackground == true) { pageRect = PDFpageRect; } else { pageRect = imageBackgroundRect; } UIGraphics.BeginImageContext(pageRect.Size); CGContext context = UIGraphics.GetCurrentContext(); context.SetLineWidth(2); path.AddLines(pointlist.ToArray()); UIColor.Red.SetStroke(); context.AddPath(path); context.DrawPath(CGPathDrawingMode.Stroke); context.SaveState(); UIImage thm = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return(thm); }
public override void Draw(CGRect rect) { base.Draw(rect); var context = UIGraphics.GetCurrentContext(); context.SetLineWidth(2); UIColor.Black.SetStroke(); UIColor.Clear.SetFill(); var topPath = new CGPath(); var bottomPath = new CGPath(); topPath.AddLines(new CGPoint[] { new CGPoint((rect.Width / 2) - 10, 11), new CGPoint(rect.Width / 2, 3), new CGPoint((rect.Width / 2) + 10, 11) }); bottomPath.AddLines(new CGPoint[] { new CGPoint((rect.Width / 2) - 10, 16), new CGPoint(rect.Width / 2, 8), new CGPoint((rect.Width / 2) + 10, 16) }); context.AddPath(topPath); context.AddPath(bottomPath); context.DrawPath(CGPathDrawingMode.FillStroke); }
/// <summary> /// Draws a polygon. The polygon can have stroke and/or fill. /// </summary> /// <param name="points">The points.</param> /// <param name="fill">The fill color.</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 DrawPolygon(IList <ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { this.SetAlias(aliased); var convertedPoints = (aliased ? points.Select(p => p.ConvertAliased()) : points.Select(p => p.Convert())).ToArray(); if (fill.IsVisible()) { this.SetFill(fill); using (var path = new CGPath()) { path.AddLines(convertedPoints); path.CloseSubpath(); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Fill); } if (stroke.IsVisible() && thickness > 0) { this.SetStroke(stroke, thickness, dashArray, lineJoin); using (var path = new CGPath()) { path.AddLines(convertedPoints); path.CloseSubpath(); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Stroke); } }
void CreateAnimationGroup() { PointF fromPt = _sublayer.Position; _sublayer.Position = new PointF(200, 300); CGPath path = new CGPath(); path.AddLines(new PointF[] { fromPt, new PointF(250, 225), new PointF(100, 250), new PointF(200, 300) }); CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position"); animPosition.Path = path; _sublayer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1); CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform"); animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D(CATransform3D.MakeRotation(0, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI / 2f, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1)) }; CAAnimationGroup spinningMonkeyGroup = CAAnimationGroup.CreateAnimation(); spinningMonkeyGroup.Duration = 2; spinningMonkeyGroup.Animations = new CAAnimation[] { animPosition, animRotate }; _sublayer.AddAnimation(spinningMonkeyGroup, null); }
public override void Draw(CGRect rect) { base.Draw(rect); using (CGContext g = UIGraphics.GetCurrentContext()) { // calc points float height = (float)rect.Height / 2; float centerX = (float)rect.Width / 2; CGPoint p1 = new CGPoint(centerX - height / 2, height / 2 + height); CGPoint p2 = new CGPoint(centerX, height / 2); CGPoint p3 = new CGPoint(centerX + height / 2, height / 2 + height); //set up drawing attributes g.SetLineWidth(10); UIColor.Blue.SetFill(); UIColor.Red.SetStroke(); //create geometry var path = new CGPath(); path.AddLines(new CGPoint[] { p1, p2, p3 }); path.CloseSubpath(); //add geometry to graphics context and draw it g.AddPath(path); g.DrawPath(CGPathDrawingMode.FillStroke); } }
public override void DrawPolygon(IList <ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { // gctx.SetAllowsAntialiasing(aliased); if (fill != null) { ToColor(fill).SetFill(); var path = new CGPath(); path.AddLines(points.Select(p => ToPoint(p)).ToArray()); path.CloseSubpath(); gctx.AddPath(path); gctx.DrawPath(CGPathDrawingMode.Fill); } if (stroke != null && thickness > 0) { SetAttributes(null, stroke, thickness); gctx.SetLineCap(ToLine(lineJoin)); var path = new CGPath(); path.AddLines(points.Select(p => ToPoint(p)).ToArray()); path.CloseSubpath(); gctx.AddPath(path); gctx.DrawPath(CGPathDrawingMode.Stroke); } }
public override void Draw(CGRect rect) { base.Draw(rect); var gctx = UIGraphics.GetCurrentContext(); gctx.SetFillColor(UIColor.Purple.CGColor); gctx.FillRect(rect); gctx.SetBlendMode(CGBlendMode.Clear); UIColor.Clear.SetColor(); 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); }
public static void DrawLines(CGContext context, IEnumerable <CGPoint> points, LineStyle lineStyle) { if ((points?.Count() ?? 0) < 2) { return; } context.SetLineWidth(lineStyle.LineWidth); lineStyle.Color.SetStroke(); var path = new CGPath(); context.SetLineCap(lineStyle.LineCap); path.AddLines(new CGPoint[] { points.ElementAt(0), points.ElementAt(1) }); for (int i = 2; i < points.Count(); i++) { path.AddLineToPoint(points.ElementAt(i)); } context.AddPath(path); context.DrawPath(CGPathDrawingMode.Stroke); }
public override void DrawMapRect(MKMapRect mapRect, float zoomScale, CGContext context) { UIGraphics.PushContext(context); context.SetLineWidth(4000); UIColor.Blue.SetFill(); CGPath path = new CGPath(); RectangleF r = this.RectForMapRect(_overlay.BoundingMapRect()); PointF _origin = r.Location; path.AddLines(new PointF[] { _origin, new PointF(_origin.X + 35000, _origin.Y + 80000), new PointF(_origin.X - 50000, _origin.Y + 30000), new PointF(_origin.X + 50000, _origin.Y + 30000), new PointF(_origin.X - 35000, _origin.Y + 80000) }); context.AddPath(path); context.DrawPath(CGPathDrawingMode.Fill); UIGraphics.PopContext(); }
public override void Draw(CoreGraphics.CGRect rect) { base.Draw(rect); using (CGContext g = UIGraphics.GetCurrentContext()) { if (points != null) { CGPath currentPath = new CGPath(); currentPath.AddLines(points); g.AddPath(currentPath); g.SetLineWidth(2); if (invertColors) { g.SetStrokeColor(UIColor.FromRGB(255, 255, 255).CGColor); } else { g.SetStrokeColor(UIColor.FromRGB(0, 0, 0).CGColor); } g.AddLineToPoint(rect.Right, rect.Bottom); g.AddLineToPoint(rect.Left, rect.Bottom); g.ClosePath(); if (displayPoints) { g.SetAlpha(.7f); g.SetFillColor(UIColor.FromRGB(100, 100, 100).CGColor); } else if (invertColors) { g.SetFillColor(UIColor.FromRGB(255, 255, 255).CGColor); } else { g.SetFillColor(UIColor.FromRGB(0, 0, 0).CGColor); } g.DrawPath(CGPathDrawingMode.FillStroke); g.SetAlpha(1f); if (displayPoints) { nfloat smallRadius = Frame.Width * .01f; nfloat bigRadius = Frame.Width * .03f; foreach (CGPoint point in points) { g.SetFillColor(UIColor.FromRGB(0, 0, 0).CGColor); g.SetAlpha(.3f); g.AddArc(point.X, point.Y, bigRadius, 0.0f, (float)Math.PI * 2.0f, true); g.FillPath(); g.SetAlpha(1f); g.AddArc(point.X, point.Y, smallRadius, 0.0f, (float)Math.PI * 2.0f, true); g.FillPath(); } } } } }
void CreateKeyframeAnimation() { // animate the position PointF fromPt = _sublayer.Position; _sublayer.Position = new PointF(200, 300); CGPath path = new CGPath(); path.AddLines(new PointF[] { fromPt, new PointF(250, 225), new PointF(100, 250), new PointF(200, 300) }); CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position"); animPosition.Path = path; animPosition.Duration = 2; _sublayer.AddAnimation(animPosition, "position"); // animate the layer transform _sublayer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1); CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform"); animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D(CATransform3D.MakeRotation(0, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI / 2f, 0, 0, 1)), NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1)) }; /* see bug comment below * animRotate.Values = new NSObject[] { * NSNumber.FromFloat (0f), * NSNumber.FromFloat ((float)Math.PI / 2f), * NSNumber.FromFloat ((float)Math.PI) }; */ //BUG: MonoTouch does not have this class method bound as of MonoTouch Versino 3.1.3 //animRotate.ValueFunction = CAValueFunction.FunctionWithName(CAValueFunction.RotateZ); animRotate.Duration = 2; _sublayer.AddAnimation(animRotate, "transform"); }
public void UpdatePoints(CGPoint[] points) { var path = new CGPath(); path.AddLines(points); ShapeLayer.UpdateShape(path); }
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 ViewDidAppear(bool animated) { base.ViewDidAppear(animated); // get the initial value to start the animation from CGPoint 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 CGPoint(200, 300); // create a path for the animation to follow CGPath path = new CGPath(); path.AddLines(new CGPoint[] { fromPt, new CGPoint(50, 300), new CGPoint(200, 50), new CGPoint(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"); }
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); }
public static void DrawOnDemandAvailabilityStatus(CGContext context, OnDemandScreening screening, nfloat side, bool selected) { // Establish some base dimensions. const int maxDaysInRuler = 5; const int margin = 2; nfloat w = side - 2 * margin; nfloat h = side - 2 * margin; nfloat x = margin; nfloat y = margin; var windowSeconds = (screening.WindowEndTime - screening.WindowStartTime).TotalSeconds; var passedSeconds = (screening.StartTime - screening.WindowStartTime).TotalSeconds; nfloat wPassed = w * (nfloat)passedSeconds / (nfloat)windowSeconds; nfloat wLeft = w - wPassed; // Initlialize core graphics settings. context.SetStrokeColor(ClickPadTextColor(selected).CGColor); context.SetLineWidth(1); // Draw the passed time part of the progres bar. using (var passedPath = new CGPath()) { context.SetFillColor(ClickPadTextColor(selected).CGColor); passedPath.AddRect(new CGRect(x, y + h * 1 / 16, wPassed, h * 2 / 16)); passedPath.CloseSubpath(); context.AddPath(passedPath); } context.DrawPath(CGPathDrawingMode.FillStroke); // Draw the left time part of the progress bar. using (var leftPath = new CGPath()) { context.SetFillColor((selected ? ClickPadBackgroundColor(selected) : NSColor.White).CGColor); leftPath.AddRect(new CGRect(x + wPassed, y + h * 1 / 16, wLeft, h * 2 / 16)); leftPath.CloseSubpath(); context.AddPath(leftPath); } context.DrawPath(CGPathDrawingMode.FillStroke); // Draw verticle needle lines to indicate availability days. var daySeconds = ViewController.DaySpan.TotalSeconds; nfloat days = (nfloat)windowSeconds / (nfloat)daySeconds; nfloat wPeriod = w / days; if (days <= maxDaysInRuler) { using (var needlePath = new CGPath()) { for (int i = 1; i < days; i++) { needlePath.AddLines(new CGPoint[] { new CGPoint(i * wPeriod, y + h * 1 / 16), new CGPoint(i * wPeriod, y + h * 3 / 16) }); } context.AddPath(needlePath); } } context.DrawPath(CGPathDrawingMode.FillStroke); }
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 Draw(CGRect rect) { base.Draw(rect); using (CGContext g = UIGraphics.GetCurrentContext()) { g.SetLineWidth(5); UIColor.White.SetFill(); UIColor.White.SetStroke(); var path = new CGPath(); var point1 = new CGPoint(0f, Frame.Height); var point2 = new CGPoint((Frame.Width / 2f), 0f); var point3 = new CGPoint(Frame.Width, Frame.Height); path.AddLines(new CGPoint[] { point1, point2, point3 }); path.CloseSubpath(); CAShapeLayer mask = new CAShapeLayer(); mask.Frame = this.Frame; mask.Path = path; this.Layer.Mask = mask; g.AddPath(path); g.DrawPath(CGPathDrawingMode.FillStroke); } }
public static void DrawSoldOutSymbol(CGContext g, bool selected, CGRect rect) { var path = new CGPath(); nfloat margin = rect.Width * 3 / 16; nfloat side = (nfloat)Math.Min((double)rect.Height, (double)rect.Width) - 2 * margin; g.SetLineWidth(2); SoldOutColor(selected).SetStroke(); var diagonalLeftTopToRightBottom = new CGPath(); diagonalLeftTopToRightBottom.AddLines(new CGPoint[] { new CGPoint(margin, margin + side), new CGPoint(margin + side, margin) }); diagonalLeftTopToRightBottom.CloseSubpath(); g.AddPath(diagonalLeftTopToRightBottom); var diagonalLeftBottomToRightTop = new CGPath(); diagonalLeftBottomToRightTop.AddLines(new CGPoint[] { new CGPoint(margin, margin), new CGPoint(margin + side, margin + side) }); diagonalLeftBottomToRightTop.CloseSubpath(); g.AddPath(diagonalLeftBottomToRightTop); g.DrawPath(CGPathDrawingMode.Stroke); }
public override void Draw(CGRect rect) { base.Draw(rect); if (!initialPoint.IsEmpty) { //get graphics context using (CGContext g = UIGraphics.GetCurrentContext()){ //set up drawing attributes g.SetLineWidth(2); UIColor.Red.SetStroke(); //add lines to the touch points if (path.IsEmpty) { path.AddLines(new CGPoint[] { initialPoint, latestPoint }); } else { path.AddLineToPoint(latestPoint); } //use a dashed line g.SetLineDash(0, new nfloat[] { 5, 2 }); //add geometry to graphics context and draw it g.AddPath(path); g.DrawPath(CGPathDrawingMode.Stroke); } } }
public void setPoints(CGPoint[] points) { pathSet = true; path.AddLines(points); pointsList = points; //SetNeedsDisplay(); }
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"); }
private void DrawLabels() { var radius = (maxGraphWidth / 2) + source.GetLabelDistance(); 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) }); var rayLabel = new UILabel(); rayLabel.Text = source.GetNameForRay(i); rayLabel.TextAlignment = UITextAlignment.Center; rayLabel.SizeToFit(); rayLabel.Center = new CGPoint(x, y); rayLabel.BackgroundColor = source.GetLabelBackgroundColor(); rayLabel.TextColor = source.GetColorForNet(); AddSubview(rayLabel); } }
void DrawLine(CGPoint pt1, CGPoint pt2, UIColor color) { UIGraphics.BeginImageContext(Frame.Size); using (var g = UIGraphics.GetCurrentContext()) { Layer.RenderInContext(g); var path = new CGPath(); path.AddLines(new CGPoint[] { pt1, pt2 }); g.SetLineWidth(3); color.SetStroke(); g.AddPath(path); g.DrawPath(CGPathDrawingMode.Stroke); Image = UIGraphics.GetImageFromCurrentImageContext(); } UIGraphics.EndImageContext(); LineDrawn?.Invoke(this, EventArgs.Empty); }
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); }
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); } }
public override void Draw (CGRect rect) { base.Draw (rect); //get graphics context using (CGContext g = UIGraphics.GetCurrentContext ()) { //set up drawing attributes g.SetLineWidth (10); UIColor.Blue.SetFill (); UIColor.Red.SetStroke (); //create geometry var path = new CGPath (); path.AddLines (new CGPoint[]{ new CGPoint (100, 200), new CGPoint (160, 100), new CGPoint (220, 200)}); path.CloseSubpath (); //use a dashed line g.SetLineDash (0, new nfloat[]{10, 4}); //add geometry to graphics context and draw it g.AddPath (path); g.DrawPath (CGPathDrawingMode.FillStroke); // add the path back to the graphics context so that it is the current path g.AddPath (path); // set the current path to be the clipping path g.Clip (); // the color space determines how Core Graphics interprets color information using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) { CGGradient gradient = new CGGradient (rgb, new CGColor[] { UIColor.Blue.CGColor, UIColor.Yellow.CGColor }); // draw a linear gradient g.DrawLinearGradient ( gradient, new CGPoint (path.BoundingBox.Left, path.BoundingBox.Top), new CGPoint (path.BoundingBox.Right, path.BoundingBox.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation); } } }
public override void DrawMapRect (MKMapRect mapRect, float zoomScale, CGContext context) { UIGraphics.PushContext(context); context.SetLineWidth (4000); UIColor.Blue.SetFill(); CGPath path = new CGPath (); RectangleF r = this.RectForMapRect(_overlay.BoundingMapRect()); PointF _origin = r.Location; path.AddLines (new PointF[] { _origin, new PointF (_origin.X + 35000, _origin.Y + 80000), new PointF (_origin.X - 50000, _origin.Y + 30000), new PointF (_origin.X + 50000, _origin.Y + 30000), new PointF (_origin.X - 35000, _origin.Y + 80000) }); context.AddPath (path); context.DrawPath (CGPathDrawingMode.Fill); UIGraphics.PopContext(); }
public override void DrawLayer (CALayer layer, CGContext context) { context.SetLineWidth (4); var path = new CGPath (); path.AddLines(new PointF[]{new PointF(0,0), new PointF(100,100), new PointF(100,0)}); path.CloseSubpath (); context.AddPath (path); context.DrawPath (CGPathDrawingMode.Stroke); }
public override void Draw(CGRect rect) { base.Draw (rect); using (CGContext g = UIGraphics.GetCurrentContext ()) { if (!isCroppedImageDisplayed) { g.ClearRect (Frame); g.SetLineWidth (10); UIColor.Blue.SetFill (); UIColor.Red.SetStroke (); var path = new CGPath (); path.AddLines (_markers.Select (x => x.Location).ToArray ()); path.CloseSubpath (); g.AddPath (path); g.DrawPath (CGPathDrawingMode.FillStroke); } else { g.ClearRect (Frame); var markers = _markers; foreach (var marker in markers) { marker.RemoveFromSuperview (); } } } }
void CreateKeyframeAnimation () { // animate the position PointF fromPt = _sublayer.Position; _sublayer.Position = new PointF (200, 300); CGPath path = new CGPath (); path.AddLines (new PointF[] { fromPt, new PointF (250, 225), new PointF (100, 250), new PointF (200, 300) }); CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("position"); animPosition.Path = path; animPosition.Duration = 2; _sublayer.AddAnimation (animPosition, "position"); // animate the layer transform _sublayer.Transform = CATransform3D.MakeRotation ((float)Math.PI, 0, 0, 1); CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("transform"); animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D (CATransform3D.MakeRotation (0, 0, 0, 1)), NSNumber.FromCATransform3D (CATransform3D.MakeRotation ((float)Math.PI / 2f, 0, 0, 1)), NSNumber.FromCATransform3D (CATransform3D.MakeRotation ((float)Math.PI, 0, 0, 1)) }; /* see bug comment below animRotate.Values = new NSObject[] { NSNumber.FromFloat (0f), NSNumber.FromFloat ((float)Math.PI / 2f), NSNumber.FromFloat ((float)Math.PI) }; */ //BUG: MonoTouch does not have this class method bound as of MonoTouch Versino 3.1.3 //animRotate.ValueFunction = CAValueFunction.FunctionWithName(CAValueFunction.RotateZ); animRotate.Duration = 2; _sublayer.AddAnimation (animRotate, "transform"); }
public override void TouchesMoved(NSSet touches, UIEvent evt) { // base.TouchesMoved(touches, evt); if (!TrapState.Shared.HasActiveSnapshotImage) return; touchesDidMove = true; var touch = touches.AnyObject as UITouch; var point = touch.LocationInView(bufferImageView); var difX = point.X - pathStart.X; var difY = point.Y - pathStart.Y; var path = new UIBezierPath (); switch (Tool) { case Annotate.Tool.Callout: case Annotate.Tool.Color: return; case Annotate.Tool.Marker: counter++; markerPoints[counter] = point; if (counter == 4) { // move the endpoint to the middle of the line joining the second control point // of the first Bezier segment and the first control point of the second Bezier segment markerPoints[3] = new CGPoint ((markerPoints[2].X + markerPoints[4].X) / 2, (markerPoints[2].Y + markerPoints[4].Y) / 2); path = new UIBezierPath (); path.MoveTo(markerPoints[0]); path.AddCurveToPoint(markerPoints[3], markerPoints[1], markerPoints[2]); path.LineWidth = bzPath.LineWidth; // add to cached path to draw and add to undo stack bzPath.AppendPath(path); // replace points and get ready to handle the next segment markerPoints[0] = markerPoints[3]; markerPoints[1] = markerPoints[4]; counter = 1; } path.Stroke(); bufferImageView.Image = UIGraphics.GetImageFromCurrentImageContext(); break; case Annotate.Tool.Arrow: var total = Math.Sqrt(Math.Pow(difX, 2) + Math.Pow(difX, 2)); var tailL = (nfloat)(total * 0.7); var tailW = bzPath.LineWidth / 2; var headW = (nfloat)((total * 0.2) / 2); arrowPoints[0] = new CGPoint (0, tailW); arrowPoints[1] = new CGPoint (tailL, tailW); arrowPoints[2] = new CGPoint (tailL, headW); arrowPoints[3] = new CGPoint ((nfloat)total, 0); arrowPoints[4] = new CGPoint (tailL, -headW); arrowPoints[5] = new CGPoint (tailL, -tailW); arrowPoints[6] = new CGPoint (0, -tailW); nfloat cosine = (nfloat)(difX / total), sine = (nfloat)(difY / total); var transform = new CGAffineTransform (cosine, sine, -sine, cosine, pathStart.X, pathStart.Y); var cgPath = new CGPath (); cgPath.AddLines(transform, arrowPoints, 7); cgPath.CloseSubpath(); path = UIBezierPath.FromPath(cgPath); path.LineWidth = bzPath.LineWidth; // cache path to draw and add to undo stack later bzPath = path; UIGraphics.BeginImageContextWithOptions(bufferRect.Size, false, 0); strokeColor.SetFill(); path.Fill(); strokeColor.SetStroke(); path.Stroke(); bufferImageView.Image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); break; case Annotate.Tool.Circle: case Annotate.Tool.Square: var origin = new CGPoint ((nfloat)Math.Min(pathStart.X, point.X), (nfloat)Math.Min(pathStart.Y, point.Y)); var size = new CGSize ((nfloat)Math.Abs(difX), (nfloat)Math.Abs(difY)); var rect = new CGRect (origin, size); path = Tool == Annotate.Tool.Circle ? UIBezierPath.FromOval(rect) : UIBezierPath.FromRect(rect); path.LineWidth = bzPath.LineWidth; // cache path to draw and add to undo stack later bzPath = path; UIGraphics.BeginImageContextWithOptions(bufferRect.Size, false, 0); strokeColor.SetStroke(); path.Stroke(); bufferImageView.Image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); break; } }
public override void Draw (CGRect rect) { foreach (var line in Lines) { line.Color.SetStroke (); line.Path.Stroke (); } var context = UIGraphics.GetCurrentContext (); context.SetLineWidth(1); UIColor.Gray.SetStroke (); var path = new CGPath (); path.AddLines(new CGPoint[]{ new CGPoint(rect.Size.Width/2,0), new CGPoint(rect.Size.Width/2,rect.Size.Height), }); path.AddLines(new CGPoint[]{ new CGPoint(0,rect.Size.Height/2), new CGPoint(rect.Size.Width,rect.Size.Height/2), }); path.CloseSubpath(); context.AddPath(path); context.DrawPath(CGPathDrawingMode.FillStroke); }
public override void Draw (RectangleF rect) { float x = 105; float y = 105; float r = 100; float twopi = (2f * (float)Math.PI) * -1f; CGContext ctx = UIGraphics.GetCurrentContext (); //base circle UIColor.FromRGB (137, 136, 133).SetColor (); ctx.AddArc (x, y, r + 3, 0, twopi, true); ctx.FillPath (); //border circle UIColor.FromRGB (231, 231, 231).SetColor (); ctx.AddArc (x, y, r, 0, twopi, true); ctx.FillPath (); //Center circle UIColor.White.SetColor (); ctx.AddArc (x, y, r / 1.2f, 0, twopi, true); ctx.FillPath (); UIColor.Black.SetFill (); //Slow SizeF stringSize = StringSize ("Fast", font10); DrawString ("Fast", new PointF (105 - r + 7, 105 + r / 2 - 28), stringSize.Width, font10, UILineBreakMode.TailTruncation); //fast stringSize = StringSize ("Slow", font10); DrawString ("Slow", new PointF (105 + r - 25, 105 - r / 2 + 20), stringSize.Width, font10, UILineBreakMode.TailTruncation); //pubnub UIColor.Red.SetFill (); stringSize = StringSize ("PubNub", font18b); DrawString ("PubNub", new PointF ((r * 2 - stringSize.Width) / 2 + 5, y - r / 2f), stringSize.Width, font18b, UILineBreakMode.TailTruncation); //needle //double percentFromMaxValue = max / 100.0d; max =1000; double percentFromMaxValue = max / 100.0d; if (lag > max) { lag = max; } //angle double invertLag = ((max - min)/2 - lag) *2 + lag; //Debug.WriteLine("lag: "+ lag.ToString() + " invlag:" + invLag.ToString()); double angle = 360 - Math.Round((double)invertLag / percentFromMaxValue* (90 / 100.0f)) * Math.PI / 180.0; //double angle2 = 360 - Math.Round((double)lag / percentFromMaxValue* (90 / 100.0f)) * Math.PI / 180.0;; //Debug.WriteLine("lagangle: "+ angle.ToString() + " invLagangle" + angle2.ToString()); //double angle = WrapValue(lag, max); float distance = 80; PointF p = new PointF(distance * (float)Math.Cos(angle), distance * (float)Math.Sin(angle)); UIColor.Brown.SetStroke (); CGPath path1 = new CGPath (); ctx.SetLineWidth(3); PointF newPoint = new PointF (105 - p.X, 105 - p.Y); PointF[] linePoints = new PointF[] { newPoint, new PointF (105, 105) }; path1.AddLines (linePoints); path1.CloseSubpath (); ctx.AddPath (path1); ctx.DrawPath (CGPathDrawingMode.FillStroke); //caliberate UIColor.Brown.SetColor (); double theta = 0.0; for (int i = 0; i < 360; i++) { float bx4= (float)(x - 4 + (r -10) * (Math.Cos(theta * Math.PI / 180))); float by4= (float)(y - 15 + (r - 10) * (Math.Sin(theta * Math.PI / 180))); if((theta > 160) && (theta <350)) { UIColor.Black.SetColor (); DrawString (".", new PointF (bx4,by4), StringSize(".", font18b).Width, font18b, UILineBreakMode.TailTruncation); } else if (((theta >= 0) && (theta <40)) || ((theta >= 350) && (theta <= 360))) { //redline UIColor.Red.SetColor (); DrawString (".", new PointF (bx4,by4), StringSize(".", font18b).Width, font18b, UILineBreakMode.TailTruncation); } theta += 10.0; } //small circle UIColor.FromRGB (220, 214, 194).SetColor (); //ctx.AddArc (x, y+y*.33f, r/1.5f, 0, twopi, true ); ctx.AddArc (x, y + r / 2f, r / 2f, 0, twopi, true); ctx.FillPath (); //speed in small circle UIColor.Black.SetFill (); stringSize = StringSize (Convert.ToInt32(lag).ToString(), font18b); DrawString (Convert.ToInt32(lag).ToString(), new PointF ((r * 2 - stringSize.Width) / 2 + 4, y + r / 2f - 15), stringSize.Width, font18b, UILineBreakMode.TailTruncation); //ms UIColor.Black.SetFill (); stringSize = StringSize ("MS", font18b); DrawString ("MS", new PointF ((r - stringSize.Width) / 2 + 55, y + r / 2f + 10), stringSize.Width, font18b, UILineBreakMode.TailTruncation); }
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); }
public override void Draw (CGRect rect) { base.Draw (rect); //get graphics context using (CGContext g = UIGraphics.GetCurrentContext ()) { //set up drawing attributes g.SetLineWidth (10); UIColor.Blue.SetFill (); UIColor.Red.SetStroke (); //create geometry var path = new CGPath (); path.AddLines (new CGPoint[]{ new CGPoint (100, 200), new CGPoint (160, 100), new CGPoint (220, 200)}); path.CloseSubpath (); //use a dashed line g.SetLineDash (0, new nfloat[] { 10, 4 * (nfloat)Math.PI }); //add geometry to graphics context and draw it g.AddPath (path); g.DrawPath (CGPathDrawingMode.FillStroke); // add the path back to the graphics context so that it is the current path g.AddPath (path); // set the current path to be the clipping path g.Clip (); // the color space determines how Core Graphics interprets color information using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) { CGGradient gradient = new CGGradient (rgb, new CGColor[] { UIColor.Blue.CGColor, UIColor.Yellow.CGColor }); // draw a linear gradient g.DrawLinearGradient ( gradient, new CGPoint (path.BoundingBox.Left, path.BoundingBox.Top), new CGPoint (path.BoundingBox.Right, path.BoundingBox.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation); } UIGraphics.BeginImageContext (new CGSize (200.0f, 200.0f)); } // UITableViewCell cellView as new; // var anyView; // // UIGraphics.BeginImageContext (cellView.Frame.Size); // // //render the view's layer in the current context // anyView.Layer.RenderInContext (UIGraphics.GetCurrentContext ()); // // //get a UIImage from the context // UIImage anyViewImage = UIGraphics.GetImageFromCurrentImageContext (); // UIGraphics.EndImageContext (); }
private void DrawLine(int x, int y, int x2, int y2) { var path = new CGPath(); path.AddLines(new CGPoint[] { new CGPoint(x, y), new CGPoint(x2, y2) }); path.CloseSubpath(); _context.AddPath(path); _context.DrawPath(CGPathDrawingMode.Stroke); }
public override void Draw (CGRect rect) { base.Draw (rect); _highTemps = null; _lowTemps = null; _hourlyTemps = null; if (Forecasts.Count == 0 || Hourly.Count == 0) return; graphRect = new CGRect (rect.X + padding, rect.Y + padding, rect.Width - (padding * 2), rect.Height - (padding * 2)); var days = Hourly.GroupBy (h => h.FCTTIME.mday).Select (g => g.First ().FCTTIME.weekday_name_abbrev).ToList (); var dayCount = hourly ? days.Count : Forecasts.Count; var xAxisScale = (graphRect.Width + padding / 2) / dayCount; inset = xAxisScale / 2; var highest = (nfloat)(hourly ? HourlyTemps.Max () : HighTemps.Max ()); var lowest = (nfloat)(hourly ? HourlyTemps.Min () : LowTemps.Min ()); scaleHigh = NMath.Round (highest, MidpointRounding.AwayFromZero); scaleLow = lowest < 0 ? NMath.Round (lowest, MidpointRounding.AwayFromZero) : NMath.Round (lowest); var rangePadding = Settings.UomTemperature.IsImperial () ? scalePadding : (scalePadding / 2); scaleHigh += rangePadding; scaleLow -= rangePadding; scaleRange = scaleHigh - scaleLow; var scaleIncrement = scaleRange / dividerCount; scaleX = (graphRect.Width - inset) / (hourly ? HourlyTemps.Count : Forecasts.Count); scaleY = graphRect.Height / dividerCount; nfloat x, y; using (CGContext ctx = UIGraphics.GetCurrentContext ()) { // Draw x and y axis using (UIColor color = UIColor.White) { color.SetStroke (); ctx.SetLineWidth (1); using (CGPath p = new CGPath ()) { p.MoveToPoint (graphRect.GetMinX (), graphRect.GetMaxY ()); p.AddLines (new [] { new CGPoint (graphRect.GetMinX (), graphRect.GetMinY ()), new CGPoint (graphRect.GetMinX (), graphRect.GetMaxY ()), new CGPoint (graphRect.GetMaxX (), graphRect.GetMaxY ()) }); ctx.AddPath (p); ctx.DrawPath (CGPathDrawingMode.Stroke); } } // Draw horizontal gridlines using (UIColor color = UIColor.Black.ColorWithAlpha (0.08f)) { for (int i = 1; i < dividerCount; i += 2) { y = (i + 1) * scaleY; color.SetFill (); ctx.FillRect (new CGRect (graphRect.GetMinX (), graphRect.GetMaxY () - y, graphRect.Width, scaleY)); ctx.StrokePath (); } } drawLines (); // Draw y-axis labels nfloat yStep = scaleLow; ctx.SaveState (); ctx.TranslateCTM (0, rect.Height); ctx.ScaleCTM (1, -1); for (int i = 0; i <= dividerCount; i++) { y = padding + (i * scaleY); var step = NMath.Round (yStep).ToString (); drawLabel (ctx, rect, y, padding - 6, UITextAlignment.Right, step, false, true); yStep += scaleIncrement; } // Draw x-axis labels for (int i = 0; i < dayCount; i++) { x = padding + (i * xAxisScale); drawLabel (ctx, rect, padding - 6, x, UITextAlignment.Left, hourly ? days [i] : Forecasts [i]?.date?.weekday_short, false); } ctx.RestoreState (); } }
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); } }
public override void Draw (CGRect rect) { DirectionArrow dv = (DirectionArrow)Element; var bounds = Bounds; float width; float height; width = height = (float)Math.Min(Bounds.Width, Bounds.Height); float centerX = width / 2.0f; float centerY = height / 2.0f; float size = (width * 0.8f) / 2.0f; float sizeSmall = size * 0.6f; // Draw background circle using (var context = UIGraphics.GetCurrentContext ()) { context.SetFillColor (dv.CircleColor.ToCGColor ()); context.SetStrokeColor (dv.CircleColor.ToCGColor ()); context.SetLineWidth (0.0f); // Draw circle using (CGPath path = new CGPath ()) { // Set colors and line widhts context.SetLineWidth (0.0f); context.SetStrokeColor (dv.CircleColor.ToCGColor ()); context.SetFillColor (dv.CircleColor.ToCGColor ()); // Draw circle path.AddArc (centerX, centerY, centerX, 0.0f, (float)Math.PI * 2.0f, true); path.CloseSubpath (); // Draw path context.AddPath (path); context.DrawPath (CGPathDrawingMode.FillStroke); } } // Check, if we inside of the zone if (double.IsPositiveInfinity(dv.Direction)) { // Draw circle, because we are here using (var context = UIGraphics.GetCurrentContext ()) { context.SetFillColor (dv.ArrowColor.ToCGColor ()); context.SetStrokeColor (dv.ArrowColor.ToCGColor ()); context.SetLineWidth (5.0f); // Draw circle using (CGPath path = new CGPath ()) { // Draw circle path.AddArc (centerX, centerY, centerX * 0.3f, 0.0f, (float)Math.PI * 2.0f, true); path.CloseSubpath (); // Draw path context.AddPath (path); context.DrawPath (CGPathDrawingMode.FillStroke); } } return; } // Check, if the direction is invalid if (double.IsNegativeInfinity(dv.Direction)) { // Draw cross, because direction is invalid using (var context = UIGraphics.GetCurrentContext()) { context.SetFillColor(dv.ArrowColor.ToCGColor()); context.SetStrokeColor(dv.ArrowColor.ToCGColor()); context.SetLineWidth(0.1875f * width); context.SetLineCap(CGLineCap.Round); // Draw circle using (CGPath path = new CGPath ()) { // Draw cross var points = new List<CGPoint>(2); points.Add(new CGPoint(centerX - centerX * 0.4f, centerY - centerY * 0.4f)); points.Add(new CGPoint(centerX + centerX * 0.4f, centerY + centerY * 0.4f)); path.AddLines(points.ToArray()); path.CloseSubpath (); context.AddPath (path); points = new List<CGPoint>(2); points.Add(new CGPoint(centerX - centerX * 0.4f, centerY + centerY * 0.4f)); points.Add(new CGPoint(centerX + centerX * 0.4f, centerY - centerY * 0.4f)); path.AddLines(points.ToArray()); path.CloseSubpath (); context.AddPath (path); context.SetLineCap(CGLineCap.Round); context.DrawPath(CGPathDrawingMode.Stroke); } } return; } // We have a direction, so draw an arrow var direction = 180.0 - dv.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; CGPoint p1 = new CGPoint((float) (centerX + size * Math.Sin (rad1)), (float) (centerY + size * Math.Cos (rad1))); CGPoint p2 = new CGPoint((float) (centerX + size * Math.Sin (rad2)), (float) (centerY + size * Math.Cos (rad2))); CGPoint p3 = new CGPoint((float) (centerX + size * Math.Sin (rad3)), (float) (centerY + size * Math.Cos (rad3))); CGPoint p4 = new CGPoint((float) (centerX + sizeSmall * Math.Sin (rad4)), (float) (centerY + sizeSmall * Math.Cos (rad4))); using (var context = UIGraphics.GetCurrentContext ()) { // Draw first half of arrow using (CGPath path = new CGPath ()) { context.SetLineWidth (0.5f); context.SetStrokeColor (dv.ArrowColor.ToCGColor ()); //1f, 0, 0, 1); context.SetFillColor (dv.ArrowColor.ToCGColor ()); path.AddLines (new CGPoint[] { p1, p2, p4 }); path.CloseSubpath (); context.AddPath (path); context.DrawPath (CGPathDrawingMode.FillStroke); } // Draw second half of arrow using (CGPath path = new CGPath()) { context.SetStrokeColor (dv.ArrowColor.ToCGColor ()); context.SetFillColor (dv.ArrowColor.ToCGColor ()); // was 0.5f path.AddLines (new CGPoint[] { p1, p3, p4 }); path.CloseSubpath (); context.AddPath (path); context.DrawPath (CGPathDrawingMode.FillStroke); } } }
void CreateAnimationGroup () { PointF fromPt = _sublayer.Position; _sublayer.Position = new PointF (200, 300); CGPath path = new CGPath (); path.AddLines (new PointF[] { fromPt, new PointF (250, 225), new PointF (100, 250), new PointF (200, 300) }); CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("position"); animPosition.Path = path; _sublayer.Transform = CATransform3D.MakeRotation ((float)Math.PI, 0, 0, 1); CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath ("transform"); animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D (CATransform3D.MakeRotation (0, 0, 0, 1)), NSNumber.FromCATransform3D (CATransform3D.MakeRotation ((float)Math.PI / 2f, 0, 0, 1)), NSNumber.FromCATransform3D (CATransform3D.MakeRotation ((float)Math.PI, 0, 0, 1)) }; CAAnimationGroup spinningMonkeyGroup = CAAnimationGroup.CreateAnimation (); spinningMonkeyGroup.Duration = 2; spinningMonkeyGroup.Animations = new CAAnimation[] { animPosition, animRotate }; _sublayer.AddAnimation (spinningMonkeyGroup, null); }
// image processing method void worker() { // turn screen image into gray-scale raw bitmap byte-stream using (var screenImage = CGImage.ScreenImage) using(var rectImage = screenImage.WithImageInRect(Frame)) _buffer.Draw(rectImage); // process the image to remove our drawing - WARNING the edge pixels of the image are not processed if (null != _drawnImage) { unsafe { var bufPtr = _buffer.BaseAddress; var drawnPtr = _drawnImage.BaseAddress; var height = _buffer.Height; var width = _buffer.Width; // if we draw to this pixel replace it with the average of the surrounding pixels for (int y = 1; y < height-1; y++) { var scan0 = width * (y -1); var scan1 = width * y; var scan2 = width * (y +1); for (int x = 1; x < width-1; x++) { ++scan0; ++scan1; ++scan2; if (drawnPtr[scan1] != 0) { var val = (bufPtr[scan0] + bufPtr[scan2] + bufPtr[scan1 -1] + bufPtr[scan1 + 1]) / 4; bufPtr[scan1] = (Byte)val; } } } } } /* trial 1, marshaling, ~0.5fps if (null != _drawnImage) { for (int y = 1; y < _buffer.Height; y++) { for (int x = 1; x < _buffer.Width; x++) { // if we draw to this pixel replace it with the average of the surrounding pixels if (_drawnImage.ReadPixel(x, y) != 0) { var val = (byte)(((int)_buffer.ReadPixel(x, y - 1) + (int) _buffer.ReadPixel(x, y + 1) + (int)_buffer.ReadPixel(x - 1, y) + (int)_buffer.ReadPixel(x + 1, y)) / 4); _buffer.WritePixel(x, y, val); } } } } */ var path = new CGPath(); int lastX = -1000, lastY = -1000; unsafe { var bufPtr = _buffer.BaseAddress; var height = _buffer.Height; var width = _buffer.Width; for (int y = 0; y < height - 1; y++) { var scan0 = width * y; var scan1 = width * (y + 1); for (int x = 0; x < width - 1; x++) { int edge = (Math.Abs(bufPtr[scan0] - bufPtr[scan0 + 1]) + Math.Abs(bufPtr[scan0] - bufPtr[scan1])) / 2; if (edge > 10) { int dist = (int)(Math.Pow(x - lastX, 2) + Math.Pow(y - lastY, 2)); if (dist > 50) { lastX = x; lastY = y; } else if (dist > 10) { path.AddLines(new PointF[] { new PointF(lastX, lastY), new PointF(x, y) }); lastX = x; lastY = y; } } ++scan0; ++scan1; } } } /* trial 1, marshaling, ~0.5fps for (int y = 0; y < _buffer.Height - 1; y++) { for (int x = 0; x < _buffer.Width - 1; x++) { int edge = (Math.Abs(_buffer.ReadPixel(x, y) - _buffer.ReadPixel(x + 1, y)) + Math.Abs(_buffer.ReadPixel(x, y) - _buffer.ReadPixel(x, y + 1))) / 2; if (edge > 20) { int dist = (int)(Math.Pow(x - lastX, 2) + Math.Pow(y - lastY, 2)); if (dist > 50) { lastX = x; lastY = y; } else if (dist > 10) { path.AddLines(new PointF[] { new PointF(lastX, lastY), new PointF(x, y) }); lastX = x; lastY = y; } } } }*/ _path = path; SetNeedsDisplay(); }
public override void Draw(RectangleF rect) { base.Draw (rect); // Red underline using (CGContext context = UIGraphics.GetCurrentContext ()) { context.SetLineWidth(1); UIColor.Red.SetStroke (); //create geometry CGPath path = new CGPath (); path.AddLines(new PointF[]{ new PointF(5, rect.Height -5), new PointF(rect.Width-5, rect.Height -5)}); path.CloseSubpath(); //add geometry to graphics context and draw it context.AddPath(path); context.DrawPath(CGPathDrawingMode.FillStroke); }; }
private void DrawRightForwardBackward() { //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 bPoints = new CGPoint[] { new CGPoint (x3, y2), new CGPoint (x2, y2), new CGPoint (x2, y3) }; var tlPoints = new CGPoint[] { new CGPoint (x1, y3), new CGPoint (x1, y0), }; body.AddLines (trPoints.Union(bPoints).Union(tlPoints).ToArray()); body.CloseSubpath (); outline.AddLines (trPoints); outline.AddLines (bPoints); outline.AddLines (tlPoints); g.AddPath(body); g.DrawPath(CGPathDrawingMode.Fill); g.AddPath(outline); g.DrawPath(CGPathDrawingMode.Stroke); } }
public override void DrawPolygon (IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { // gctx.SetAllowsAntialiasing(aliased); if (fill != null) { ToColor(fill).SetFill(); var path = new CGPath (); path.AddLines(points.Select(p => ToPoint(p)).ToArray()); path.CloseSubpath(); gctx.AddPath(path); gctx.DrawPath (CGPathDrawingMode.Fill); } if (stroke != null && thickness > 0) { SetAttributes (null, stroke, thickness); gctx.SetLineCap(ToLine(lineJoin)); var path = new CGPath (); path.AddLines(points.Select(p => ToPoint(p)).ToArray()); path.CloseSubpath(); gctx.AddPath(path); gctx.DrawPath (CGPathDrawingMode.Stroke); } }
private void DrawRight() { //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 x1 = this.Frame.Width; var x2 = this.Frame.Width / 2f; var y1 = this.Frame.Height * GUTTER; var y2 = this.Frame.Height - y1; var points = new CGPoint[] { new CGPoint (x1, y1), new CGPoint (x2, y1), new CGPoint (x2, y2), new CGPoint (x1, y2), }; body.AddLines (points); body.CloseSubpath (); outline.AddLines (points); g.AddPath(body); g.DrawPath(CGPathDrawingMode.Fill); g.AddPath(outline); g.DrawPath(CGPathDrawingMode.Stroke); } }
private UIImage drawArrow (double direction) { // direction = 180.0 - direction; 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) (32 + 32 * Math.Sin (rad1)), (float) (32 + 32 * Math.Cos (rad1))); PointF p2 = new PointF((float) (32 + 32 * Math.Sin (rad2)), (float) (32 + 32 * Math.Cos (rad2))); PointF p3 = new PointF((float) (32 + 32 * Math.Sin (rad3)), (float) (32 + 32 * Math.Cos (rad3))); PointF p4 = new PointF((float) (32 + 20 * Math.Sin (rad4)), (float) (32 + 20 * Math.Cos (rad4))); 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 (); }
/// <summary> /// Draws a polygon. The polygon can have stroke and/or fill. /// </summary> /// <param name="points">The points.</param> /// <param name="fill">The fill color.</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 DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased) { this.SetAlias(aliased); var convertedPoints = (aliased ? points.Select(p => p.ConvertAliased()) : points.Select(p => p.Convert())).ToArray(); if (fill.IsVisible()) { this.SetFill(fill); using (var path = new CGPath()) { path.AddLines(convertedPoints); path.CloseSubpath(); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Fill); } if (stroke.IsVisible() && thickness > 0) { this.SetStroke(stroke, thickness, dashArray, lineJoin); using (var path = new CGPath()) { path.AddLines(convertedPoints); path.CloseSubpath(); this.gctx.AddPath(path); } this.gctx.DrawPath(CGPathDrawingMode.Stroke); } }