void DrawBorders(CGContext context, nfloat xMin, nfloat xMax, nfloat yMin, nfloat yMax, nfloat fWidth, nfloat fHeight) { if (BorderColorTop != null) { context.SetFillColor(BorderColorTop.CGColor); context.FillRect(new CGRect(xMin, yMin, fWidth, BorderWidth.Top)); } if (BorderColorLeft != null) { context.SetFillColor(BorderColorLeft.CGColor); context.FillRect(new CGRect(xMin, yMin, BorderWidth.Left, fHeight)); } if (BorderColorRight != null) { context.SetFillColor(BorderColorRight.CGColor); context.FillRect(new CGRect(xMax - BorderWidth.Right, yMin, BorderWidth.Right, fHeight)); } if (BorderColorBottom != null) { context.SetFillColor(BorderColorBottom.CGColor); context.FillRect(new CGRect(xMin, yMax - BorderWidth.Bottom, fWidth, BorderWidth.Bottom)); } }
/// <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(); } } } }
public override void Draw(RectangleF bounds, CGContext context, UIView view) { UIColor.White.SetFill (); context.FillRect (bounds); context.DrawLinearGradient ( gradient, new PointF (bounds.Left, bounds.Top), new PointF (bounds.Left, bounds.Bottom), CGGradientDrawingOptions.DrawsAfterEndLocation ); UIColor.DarkGray.SetColor (); view.DrawString ( this.Label, new RectangleF (10, 10, bounds.Width / 2, 10), captionFont, UILineBreakMode.TailTruncation ); UIColor.Black.SetColor (); view.DrawString ( this.Number.ToString (), new RectangleF (bounds.Width / 2, 10, (bounds.Width / 2) - 10, 10), amountFont, UILineBreakMode.TailTruncation, UITextAlignment.Right ); }
public GraphicsContextWrapper(CGContext context, float boundsWidth, float boundsHeight, BasicRectangle dirtyRect) { Context = context; BoundsWidth = boundsWidth; BoundsHeight = boundsHeight; DirtyRect = dirtyRect; }
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(CGRect bounds, CGContext context, UIView view) { if (AutoLoadOnVisible) { LoadMore(); } }
public override void Draw (RectangleF bounds, CGContext context, UIView view) { //UIColor.White.SetFill (); //context.FillRect (bounds); try { UIView searchView = view.ViewWithTag(1); if (searchView == null) { var photoCellView = new PhotoCellView(_images, cellIndex, null); photoCellView.Tag = 1; view.Add(photoCellView); } else { var photoCellView = (PhotoCellView)searchView; photoCellView.Update(_images, cellIndex); photoCellView.DrawBorder(UIColor.Green); } } catch (Exception ex) { Util.LogException("Draw ImagesElement", ex); } }
public override void DrawInContext (CGContext ctx) { UIGraphics.PushContext (ctx); CGRect bounds = this.Bounds; TKFill fill = this.LabelStyle.Fill; TKStroke stroke = new TKStroke (UIColor.Black); TKBalloonShape shape = new TKBalloonShape (TKBalloonShapeArrowPosition.Bottom ,new CGSize(bounds.Size.Width - stroke.Width, bounds.Size.Height - stroke.Width)); CGRect textRect; if (this.IsOutsideBounds == true) { shape.ArrowPosition = TKBalloonShapeArrowPosition.Top; textRect = new CGRect (bounds.Left, bounds.Top - this.LabelStyle.Insets.Top + shape.ArrowSize.Height, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom); } else { textRect = new CGRect (bounds.Left, bounds.Top - this.LabelStyle.Insets.Top, bounds.Size.Width, bounds.Size.Height + this.LabelStyle.Insets.Bottom); } shape.DrawInContext (ctx, new CGPoint (bounds.GetMidX (), bounds.GetMidY ()), new TKDrawing[]{ fill, stroke }); NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle (); paragraphStyle.Alignment = this.LabelStyle.TextAlignment; NSDictionary attributes = new NSDictionary (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (18), UIStringAttributeKey.ForegroundColor, this.LabelStyle.TextColor, UIStringAttributeKey.ParagraphStyle, paragraphStyle); NSString text = new NSString (this.Text); text.WeakDrawString (textRect, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin, attributes, null); UIGraphics.PopContext (); }
public override void Draw(CGRect bounds, CGContext context, UIView view) { var width = 0.5f / UIScreen.MainScreen.Scale; context.BeginPath(); context.SetLineWidth(width); context.SetStrokeColor(UIColor.FromRGB(150, 150, 154).CGColor); var x = bounds.Width / 2f - width; context.MoveTo(x, 0f); context.AddLineToPoint(x, bounds.Height); context.StrokePath(); var row = Value; var half = bounds.Height / 2; var halfText = _font.LineHeight / 2 + 1; row.Image1.Draw(new CGRect(15, half - 8f, 16f, 16f)); if (!string.IsNullOrEmpty(row.Text1)) { UIColor.Gray.SetColor(); new NSString(row.Text1).DrawString(new CGRect(36, half - halfText, bounds.Width / 2 - 40, _font.LineHeight), _font, UILineBreakMode.TailTruncation); } row.Image2.Draw(new CGRect(bounds.Width / 2 + 15, half - 8f, 16f, 16f)); if (!string.IsNullOrEmpty(row.Text2)) { UIColor.Gray.SetColor(); new NSString(row.Text2).DrawString(new CGRect(bounds.Width / 2 + 36, half - halfText, bounds.Width / 2 - 40, _font.LineHeight), _font, UILineBreakMode.TailTruncation); } }
protected void ShowCenteredTextAtPoint (CGContext context, float centerX, float y, string text, int textHeight) { context.SelectFont ("Helvetica-Bold", textHeight, CGTextEncoding.MacRoman); context.SetTextDrawingMode (CGTextDrawingMode.Invisible); context.ShowTextAtPoint (centerX, y, text, text.Length); context.SetTextDrawingMode (CGTextDrawingMode.Fill); context.ShowTextAtPoint (centerX - (context.TextPosition.X - centerX) / 2, y, text, text.Length); }
public override void DrawInContext (CGContext context) { base.DrawInContext (context); context.AddEllipseInRect (Bounds); context.SetFillColor (ClockColor); context.FillPath (); }
public override void Draw(RectangleF bounds, CGContext context, UIView view) { UIColor.DarkGray.SetFill(); context.FillRect(bounds); UIColor.Yellow.SetColor(); view.DrawString(_text, new RectangleF(10, 15, bounds.Width - 20, bounds.Height - 30), UIFont.BoldSystemFontOfSize(14.0f), UILineBreakMode.TailTruncation); }
private static void DrawOutline(CGContext currentContext, IStyle style, CGRect destination) { var vectorStyle = (style as VectorStyle); if (vectorStyle == null) return; if (vectorStyle.Outline == null) return; if (vectorStyle.Outline.Color == null) return; DrawRectangle(currentContext, destination, vectorStyle.Outline.Color); }
public override void DrawInContext(CGContext ctx) { UIGraphics.PushContext(ctx); Draw(Bounds); UIGraphics.PopContext(); }
public static void DrawEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth) { context.SaveState(); context.SetStrokeColor(color); context.SetLineWidth(lineWidth); context.AddEllipseInRect(rect); context.StrokePath(); context.RestoreState(); }
public static void FillRect(CGContext context, RectangleF rect, CGColor color) { context.SaveState(); context.AddRect(rect); context.Clip(); context.SetFillColor(color); context.FillRect(rect); context.RestoreState(); }
public void Draw(CGContext context) { if (DateTime.Now - CreatedTime < delaySpan) return; DrawBackground(context); DrawLines(context); DrawModel(context); }
protected override void DrawGridlines(RectangleF rect, CGContext context) { float maxY = rect.Size.Height; for (float y = CellSize.Height; y < maxY; y += (CellSize.Height + Gridlines.Thickness)) { context.MoveTo(rect.Left, y + 0.5f); context.AddLineToPoint(rect.Right, y + 0.5f); } context.StrokePath(); }
public override void Draw(RectangleF bounds, CGContext context, UIView view) { UIColor.White.SetFill(); context.FillRect(bounds); context.DrawLinearGradient(gradient, new PointF(bounds.Left, bounds.Top), new PointF(bounds.Left, bounds.Bottom), CGGradientDrawingOptions.DrawsAfterEndLocation); UIColor.DarkGray.SetColor(); view.DrawString(Caption, new RectangleF(10, 10, bounds.Width - 20, TextHeight(bounds)), _CaptionFont, UILineBreakMode.WordWrap); }
protected override void DrawGradient(RectangleF rect, CGContext context) { context.DrawLinearGradient(new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor[] { TintColor.CGColor, TintColor.Darken(TintDarkenFactor).CGColor }), new PointF(0.5f, rect.Top), new PointF(0.5f, rect.Bottom), 0); }
public override void DrawMapRect(MKMapRect mapRect, float zoomScale, CGContext context) { if(_polygon != null) DrawPolygon(_polygon,mapRect,zoomScale,context); else foreach(var polygon in _polygons) { DrawPolygon(polygon,mapRect,zoomScale,context); } }
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 Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { base.Selected (dvc, tableView, path); } */ public override void Draw (RectangleF bounds, CGContext context, UIView view) { UIColor.White.SetFill (); context.FillRect (bounds); RectangleF frame = _inviteButton.Frame; frame.X = view.Frame.Width - frame.Width - 10; _inviteButton.Frame = frame; view.Add(_inviteButton); if (userImage != null) { //context.DrawImage(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35), userImage.CGImage); userImage.Draw(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35)); } if (graph.ContainsKey(_User.id)) _User = graph[_User.id]; UIColor.Black.SetColor (); if (_User.name != null) { view.DrawString(_User.name, new RectangleF(50, 5, bounds.Width/2, 10 ), fromFont, UILineBreakMode.TailTruncation); if (userImage == null) { userImage = ImageStore.RequestFullPicture((long)_User.id, (long)_User.id, SizeDB.SizeFacebook, this); userImage = userImage ?? ImageStore.EmptyProfileImage; userImage = UIImageUtils.resizeImage(userImage, new SizeF (35, 35)); userImage = GraphicsII.RemoveSharpEdges(userImage); if (userImage != null) userImage.Draw(new RectangleF((_height - 35)/2, (_height - 35)/2, 35, 35)); } } else { ThreadPool.QueueUserWorkItem(o => { GraphUser gUser = AppDelegateIPhone.AIphone.FacebookServ.GetFriend(_User.id); if (gUser == null) return; lock (lock_graph) { graph[gUser.id] = gUser; } if (gUser.id == _User.id) { _User = gUser; nss.InvokeOnMainThread(()=> view.SetNeedsDisplay()); } }); } }
public override void DrawInContext (CGContext context) { List<TKDrawing> drawables = new List<TKDrawing> (); if (this.Fill != null) { drawables.Add (this.Fill); } if (this.Stroke != null){ drawables.Add (this.Stroke); } Shape.DrawInContext (context, center, drawables.ToArray()); }
protected override void DrawGridlines(RectangleF rect, CGContext context) { float maxX = rect.Size.Width; float cellWidth = CellSize.Width; for (float x = cellWidth; x < maxX; x += (cellWidth + Gridlines.Thickness)) { context.MoveTo(x + 0.5f, rect.Location.Y); context.AddLineToPoint(x + 0.5f, rect.Size.Height); } context.StrokePath(); }
public override void DrawLayer(CALayer layer, CGContext context) { context.SaveState (); context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f); context.FillRect (context.GetClipBoundingBox ()); context.TranslateCTM (0.0f, layer.Bounds.Size.Height); context.ScaleCTM (1.0f, -1.0f); context.ConcatCTM (this.oParentController.currentPDFPage.GetDrawingTransform (CGPDFBox.Crop, layer.Bounds, 0, true)); context.DrawPDFPage (this.oParentController.currentPDFPage); context.RestoreState (); }
/// <summary> /// Initializes a new instance of the <see cref="MonoTouchRenderContext"/> class. /// </summary> /// <param name="context">The context.</param> public MonoTouchRenderContext(CGContext context) { this.gctx = context; // Set rendering quality this.gctx.SetAllowsFontSmoothing(true); this.gctx.SetAllowsFontSubpixelQuantization(true); this.gctx.SetAllowsAntialiasing(true); this.gctx.SetShouldSmoothFonts(true); this.gctx.SetShouldAntialias(true); this.gctx.InterpolationQuality = CGInterpolationQuality.High; }
public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell) { context.SaveState(); float r = 0; float g = 0; float b = 0; var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), new float[] { r, g, b, 0.20f, r, g, b, 0.40f }, new float[] { 0, 1 }); context.DrawLinearGradient(gradient, new PointF(rect.Left, rect.Top), new PointF(rect.Left, rect.Bottom), CGGradientDrawingOptions.DrawsBeforeStartLocation); context.RestoreState(); }
public MonoTouchRenderContext (CGContext context) { gctx = context; //SET RENDERING QUALITY gctx.SetAllowsFontSmoothing(true); gctx.SetAllowsFontSubpixelQuantization(true); gctx.SetAllowsAntialiasing(true); gctx.SetShouldSmoothFonts(true); gctx.SetShouldAntialias(true); gctx.InterpolationQuality = CGInterpolationQuality.High; }
/// <summary> /// Initializes a new instance of the <see cref="CoreGraphicsRenderContext"/> class. /// </summary> /// <param name="context">The context.</param> public CoreGraphicsRenderContext(CGContext context) { this.gctx = context; // Set rendering quality this.gctx.SetAllowsFontSmoothing(true); this.gctx.SetAllowsFontSubpixelQuantization(true); this.gctx.SetAllowsAntialiasing(true); this.gctx.SetShouldSmoothFonts(true); this.gctx.SetShouldAntialias(true); this.gctx.InterpolationQuality = CGInterpolationQuality.High; this.gctx.SetTextDrawingMode(CGTextDrawingMode.Fill); }
UIImage GetImage(UIColor strokeColor, UIColor fillColor, CGSize size, nfloat scale, bool shouldCrop = true, bool keepAspectRatio = true) { if (size.Width == 0 || size.Height == 0 || scale <= 0 || strokeColor == null || fillColor == null) { return(null); } nfloat uncroppedScale; CGRect croppedRectangle = new CGRect(); CGPoint [] cachedPoints; if (shouldCrop && (cachedPoints = Points).Any()) { croppedRectangle = getCroppedRectangle(cachedPoints); croppedRectangle.Width /= scale; croppedRectangle.Height /= scale; if (croppedRectangle.X >= 5) { croppedRectangle.X -= 5; croppedRectangle.Width += 5; } if (croppedRectangle.Y >= 5) { croppedRectangle.Y -= 5; croppedRectangle.Height += 5; } if (croppedRectangle.X + croppedRectangle.Width <= size.Width - 5) { croppedRectangle.Width += 5; } if (croppedRectangle.Y + croppedRectangle.Height <= size.Height - 5) { croppedRectangle.Height += 5; } nfloat scaleX = croppedRectangle.Width / Bounds.Width; nfloat scaleY = croppedRectangle.Height / Bounds.Height; uncroppedScale = 1 / (nfloat)Math.Max(scaleX, scaleY); } else { uncroppedScale = scale; } //Make sure the image is scaled to the screen resolution in case of Retina display. if (keepAspectRatio) { UIGraphics.BeginImageContext(size); } else { UIGraphics.BeginImageContext(new CGSize(croppedRectangle.Width * uncroppedScale, croppedRectangle.Height * uncroppedScale)); } //Create context and set the desired options CGContext context = UIGraphics.GetCurrentContext(); context.SetFillColor(fillColor.CGColor); context.FillRect(new CGRect(0, 0, size.Width, size.Height)); context.SetStrokeColor(strokeColor.CGColor); context.SetLineWidth(StrokeWidth); context.SetLineCap(CGLineCap.Round); context.SetLineJoin(CGLineJoin.Round); context.ScaleCTM(uncroppedScale, uncroppedScale); //Obtain all drawn paths from the array foreach (var bezierPath in paths) { var tempPath = (UIBezierPath)bezierPath.Copy(); if (shouldCrop) { tempPath.ApplyTransform(CGAffineTransform.MakeTranslation(-croppedRectangle.X, -croppedRectangle.Y)); } CGPath path = tempPath.CGPath; context.AddPath(path); tempPath = null; } context.StrokePath(); UIImage image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return(image); }
private void DrawBubble(CGRect frame, CGContext context) { var contourPath = new CGPath(); contourPath.MoveToPoint(this.arrowTip.X, this.arrowTip.Y); switch (this.ArrowPosition) { case ArrowPosition.Bottom: case ArrowPosition.Top: case ArrowPosition.Any: contourPath.AddLineToPoint( new CGPoint(this.arrowTip.X - this.ArrowWidth / 2, this.arrowTip.Y + (this.ArrowPosition == ArrowPosition.Bottom ? -1 : 1) * this.ArrowHeight)); if (this.ArrowPosition == ArrowPosition.Bottom) { this.DrawBubbleBottomShape(frame, contourPath); } else { this.DrawBubbleTopShape(frame, contourPath); } contourPath.AddLineToPoint( new CGPoint(this.arrowTip.X + this.ArrowWidth / 2, this.arrowTip.Y + (this.ArrowPosition == ArrowPosition.Bottom ? -1 : 1) * this.ArrowHeight)); break; case ArrowPosition.Left: case ArrowPosition.Right: contourPath.AddLineToPoint( new CGPoint(this.arrowTip.X + (this.ArrowPosition == ArrowPosition.Right ? -1 : 1) * this.ArrowHeight, this.arrowTip.Y - this.ArrowWidth / 2)); if (this.ArrowPosition == ArrowPosition.Right) { DrawBubbleRightShape(frame, contourPath); } else { DrawBubbleLeftShape(frame, contourPath); } contourPath.AddLineToPoint( new CGPoint(this.arrowTip.X + (this.ArrowPosition == ArrowPosition.Right ? -1 : 1) * this.ArrowHeight, this.arrowTip.Y + this.ArrowWidth / 2)); break; } contourPath.CloseSubpath(); context.AddPath(contourPath); context.Clip(); this.PaintBubble(context); if (BorderWidth > 0f && BorderColor != UIColor.Clear) { this.DrawBorder(contourPath, context); } }
public override void Draw(CGRect rect) { SetNeedsDisplay(); base.Draw(rect); rect.X += _border / 2.0f; rect.Width -= _border; rect.Y += _border / 2.0f; rect.Height -= _border; CGContext cr = UIGraphics.GetCurrentContext(); //cr.SetAllowsAntialiasing(true); float [] cornerRadii = new float[4]; if (_CornerRadii != null) { Array.Copy(_CornerRadii, cornerRadii, 4); } else if (_SkipCorners != null) { for (int i = 0; i < 4; i++) { cornerRadii[i] = _SkipCorners[i]?0f:CornerRadius; } } else { for (int i = 0; i < 4; i++) { cornerRadii[i] = CornerRadius; } } GradientHelper useGradient = _gradient; bool reversed = false; if (!Enabled && _DisabledGradient != null) { useGradient = _DisabledGradient; } else if (Highlighted && Tracking) { if (_HighlightedGradient == null) { reversed = true; } else { _gradient = _HighlightedGradient; } } cr.DrawRoundRect(useGradient.Gradient, rect, cornerRadii, reversed?(float)Math.PI / 2.0f:(float)-Math.PI / 2.0f); if (_border > 0) { if (_SkipCorners == null && _CornerRadii == null) { GraphicUtils.RoundRectPath(cr, rect, _cornerRadius); } else if (_SkipCorners != null) { GraphicUtils.RoundRectPath(cr, rect, _cornerRadius, _SkipCorners); } else if (_CornerRadii != null) { GraphicUtils.RoundRectPath(cr, rect, _CornerRadii); } cr.SetStrokeColor(_borderColor.CGColor.Components); cr.SetLineWidth(_border); cr.StrokePath(); } if (BonusImage != null) { cr.TranslateCTM(0, BonusImage.Size.Height + _BonusImageRect.Y * 2.0f); cr.ScaleCTM(1.0f, -1.0f); cr.DrawImage(_BonusImageRect, _BonusImage.CGImage); } }
protected void ShowTextAtPoint(CGContext context, float x, float y, string text, int textHeight) { context.SelectFont("Helvetica-Bold", textHeight, CGTextEncoding.MacRoman); context.SetTextDrawingMode(CGTextDrawingMode.Fill); context.ShowTextAtPoint(x, y, text, text.Length); }
void DrawGauge(CGContext cg) { }
static void DrawRectangle(CGContext currentContext, CGRect destination, Color outlineColor) { currentContext.SetStrokeColor(outlineColor.R, outlineColor.G, outlineColor.B, outlineColor.A); currentContext.SetLineWidth((nfloat)4f); currentContext.StrokeRect((CGRect)destination); }
public abstract void ClearGradient(CGContext ctx, CGRect bounds);
public abstract void DrawGradient(CGContext ctx, CGRect bounds);
void IGradientProvider.DrawGradient(CGContext ctx, CGRect bounds) => DrawGradient(ctx, bounds);
public override void Draw(CGContext context, IViewPort viewPort) { Render?.DrawAxis(context, viewPort, this); }
public override void DrawInContext(CGContext context) { // The clipping rects we plan to use, which also defines the location and span of each gradient var clips = new RectangleF [] { new RectangleF(10, 30, 60, 90), new RectangleF(90, 30, 60, 90), new RectangleF(170, 30, 60, 90), new RectangleF(250, 30, 60, 90), new RectangleF(30, 140, 120, 120), new RectangleF(170, 140, 120, 120), new RectangleF(30, 280, 120, 120), new RectangleF(170, 280, 120, 120), }; // Linear Gradients PointF start, end; // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state // so that we can revert to the previous larger area. context.SaveState(); context.ClipToRect(clips[0]); // A linear gradient requires only a starting & ending point. // The colors of the gradient are linearly interpolated along the line segment connecting these two points // A gradient location of 0 means that color is expressed fully at the 'start' point // a location of 1 means that color is expressed fully at the 'end' point. // The gradient fills outwards perpendicular to the line segment connectiong start & end points // (which is why we need to clip the context, or the gradient would fill beyond where we want it to). // The gradient options (last) parameter determines what how to fill the clip area that is "before" and "after" // the line segment connecting start & end. start = demoLGStart(clips[0]); end = demoLGEnd(clips[0]); context.DrawLinearGradient(gradient, start, end, 0); context.RestoreState(); // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation context.SaveState(); context.ClipToRect(clips[1]); start = demoLGStart(clips[1]); end = demoLGEnd(clips[1]); context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation); context.RestoreState(); context.SaveState(); context.ClipToRect(clips[2]); start = demoLGStart(clips[2]); end = demoLGEnd(clips[2]); context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation); context.RestoreState(); context.SaveState(); context.ClipToRect(clips[3]); start = demoLGStart(clips[3]); end = demoLGEnd(clips[3]); context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation); context.RestoreState(); // Radial Gradients float startRadius, endRadius; // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state // so that we can revert to the previous larger area. context.SaveState(); context.ClipToRect(clips[4]); // A radial gradient requires a start & end point as well as a start & end radius. // Logically a radial gradient is created by linearly interpolating the center, radius and color of each // circle using the start and end point for the center, start and end radius for the radius, and the color ramp // inherant to the gradient to create a set of stroked circles that fill the area completely. // The gradient options specify if this interpolation continues past the start or end points as it does with // linear gradients. start = end = demoRGCenter(clips[4]); startRadius = demoRGInnerRadius(clips[4]); endRadius = demoRGOuterRadius(clips[4]); context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, 0); context.RestoreState(); // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation context.SaveState(); context.ClipToRect(clips[5]); start = end = demoRGCenter(clips[5]); startRadius = demoRGInnerRadius(clips[5]); endRadius = demoRGOuterRadius(clips[5]); context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation); context.RestoreState(); context.SaveState(); context.ClipToRect(clips[6]); start = end = demoRGCenter(clips[6]); startRadius = demoRGInnerRadius(clips[6]); endRadius = demoRGOuterRadius(clips[6]); context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation); context.RestoreState(); context.SaveState(); context.ClipToRect(clips[7]); start = end = demoRGCenter(clips[7]); startRadius = demoRGInnerRadius(clips[7]); endRadius = demoRGOuterRadius(clips[7]); context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation); context.RestoreState(); // Show the clipping areas context.SetLineWidth(2); context.SetRGBStrokeColor(1, 0, 0, 1); context.AddRects(clips); context.StrokePath(); }
// Uncolored patterns take their color from the given context static void DrawUncolored(CGContext context) { context.FillRect(new RectangleF(0, 0, 8, 8)); context.FillRect(new RectangleF(8, 8, 8, 8)); }
public abstract void Draw(RectangleF bounds, CGContext context, UIView view);
public static CIContext FromContext(CGContext ctx, CIContextOptions options) { NSDictionary dict = options == null ? null : options.ToDictionary(); return(FromContext(ctx, options)); }
/// <summary> /// Draw the contents of the Cell /// </summary> /// <param name="rect">Rect.</param> private void ReDraw(CGRect rect) { foreach (var aView in this.Subviews) { aView.RemoveFromSuperview(); } mContentView = null; CGContext ctx = UIGraphics.GetCurrentContext(); var bkColor = Processor.CellBackgroundColor; switch (Processor.Style) { case CellStyle.Blank: { GridView.Theme.BackgroundColor.ToUIColor().SetFill(); } break; case CellStyle.Cell: { if (bkColor != null) { bkColor.ToUIColor().SetFill(); } else { if (Processor.IsSelected) { GridView.Theme.CellBackgroundHighlight.ToUIColor().SetFill(); } else { var alterColor = (GridView.Theme.CellBackground2 != null) ? GridView.Theme.CellBackground2.ToUIColor() : GridView.Theme.CellBackground.ToUIColor(); var aColor = (Processor.IsOdd) ? GridView.Theme.CellBackground.ToUIColor() : alterColor; aColor.SetFill(); } } } break; case CellStyle.Header: { if (bkColor != null) { bkColor.ToUIColor().SetFill(); } else { GridView.Theme.HeaderBackground.ToUIColor().SetFill(); } } break; } ctx.SetLineWidth(GridView.Theme.CellBorderWidth); GridView.Theme.BorderColor.ToUIColor().SetStroke(); CGPath _path = new CGPath(); var aRect = new CGRect(rect.X, rect.Y, rect.Width - 0, rect.Height - 0); _path.AddRect(aRect); _path.CloseSubpath(); ctx.AddPath(_path); ctx.DrawPath(CGPathDrawingMode.Fill); var topLeftPoint = new CGPoint(0, 0); var topRightPoint = new CGPoint(aRect.Width, 0); var bottomLeftPoint = new CGPoint(0, aRect.Height); var bottomRightPoint = new CGPoint(aRect.Width, aRect.Height); switch (GridView.Theme.CellBorderStyle) { case BorderStyle.Full: { if (Processor.RowIndex != 0 && Processor.Style != CellStyle.Blank) { //draw the upper line ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint }); } if (Processor.Style != CellStyle.Blank && Processor.ColumnIndex != 0) { ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint }); } //ctx.StrokeRect(aRect); } break; case BorderStyle.HorizontalOnly: { if (Processor.RowIndex != 0 && Processor.Style != CellStyle.Blank) { //draw the upper line ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint }); } } break; case BorderStyle.VerticalOnly: { if (Processor.Style != CellStyle.Blank && Processor.ColumnIndex != 0) { ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint }); } } break; } ctx.SetAllowsAntialiasing(true); //do nothing else if the row is blank if (Processor.Style == CellStyle.Blank) { return; } // //get the row index, -1 if it's a header style // var index = (this.Style == CellStyle.Header) ? -1 : this.RowIndex; // // var Value = GridView.GetValue (index, this.ColumnName).Value; if (Processor.Style != CellStyle.Blank && Processor.ValueObject.Value != null) { //update to work with different datatypes //check to see if the formatter is a DSViewFormatter if (Processor.Formatter != null && Processor.Formatter is DSViewFormatter) { var viewFormatter = Processor.Formatter as DSViewFormatter; var aView = viewFormatter.View; if (!(aView is UIView)) { throw new Exception("DSViewFormatter has type that isn't a UIView"); } aView.Value = Processor.ValueObject.Value; var aFrame = rect; if (Processor.Formatter.Size != null) { aFrame.Width = Processor.Formatter.Size.Width; aFrame.Height = Processor.Formatter.Size.Height; } aView.ViewFrame = aFrame.ToDSRectangle(); aView.IsReadOnly = Processor.IsReadOnly; aView.UpdateAction = (obj) => { GridView.Processor.SetValue(Processor.Index, Processor.ColumnName, obj); }; //aView.IsReadOnly = mContentView = (UIView)aView; this.AddSubview(mContentView); } else if (Processor.ValueObject.Value is UIImage || Processor.ValueObject.Value is DSBitmap) { UIImage image = null; if (Processor.ValueObject.Value is UIImage) { image = (UIImage)Processor.ValueObject.Value; } else if (Processor.ValueObject.Value is DSBitmap) { image = ((DSBitmap)Processor.ValueObject.Value).ToUIImage(); } mContentView = new UIImageView(image); var aFrame = mContentView.Frame; if (Processor.Formatter != null) { aFrame.Width = Processor.Formatter.Size.Width; aFrame.Height = Processor.Formatter.Size.Height; //anView.Frame = aFrame; } //try a centralize the image var xPos = (this.Frame.Width / 2) - (aFrame.Size.Width / 2); var yPos = (this.Frame.Height / 2) - (aFrame.Size.Height / 2); aFrame.X = xPos; aFrame.Y = yPos; if (Processor.Formatter != null && Processor.Formatter is DSImageFormatter) { var formta = Processor.Formatter as DSImageFormatter; if (formta.Margin != null) { //apply the margins to the frame var mRect = aFrame.ToDSRectangle(); mRect.ApplyMargin(formta.Margin); aFrame = mRect.ToRectangleF(); } } mContentView.Frame = aFrame.Integral(); this.AddSubview(mContentView); } else if (Processor.ValueObject.Value is Boolean && Processor.Formatter != null && Processor.Formatter is DSBooleanFormatter) { var boolFormatter = Processor.Formatter as DSBooleanFormatter; if (boolFormatter.Style == BooleanFormatterStyle.Text) { UILabel label = new UILabel(rect.Inset(5, 5)); label.BackgroundColor = UIColor.Clear; label.Font = (Processor.Style == CellStyle.Header) ? GridView.Theme.HeaderTextFont.ToUIFont() : GridView.Theme.CellTextFont.ToUIFont(); label.Text = ((bool)Processor.ValueObject.Value) ? boolFormatter.TrueValue.ToString() : boolFormatter.FalseValue.ToString(); if (Processor.Style == CellStyle.Header) { label.TextAlignment = (UITextAlignment)GridView.Theme.HeaderTextAlignment; label.TextColor = GridView.Theme.HeaderTextForeground.ToUIColor(); } else { //check to see if the color has been overridden in the datatable var fgColor = Processor.CellForegroundColor; if (fgColor != null) { label.TextColor = fgColor.ToUIColor(); } else { var alterColor = (GridView.Theme.CellTextForeground2 != null) ? GridView.Theme.CellTextForeground2.ToUIColor() : GridView.Theme.CellTextForeground.ToUIColor(); var aColor = (Processor.IsOdd) ? GridView.Theme.CellTextForeground.ToUIColor() : alterColor; label.TextColor = (Processor.IsSelected) ? GridView.Theme.CellTextHighlight.ToUIColor() : aColor; } label.TextAlignment = (UITextAlignment)boolFormatter.TextAlignment; } mContentView = label; this.AddSubview(mContentView); } else { var bValue = ((bool)Processor.ValueObject.Value) ? boolFormatter.TrueValue : boolFormatter.FalseValue; UIImage image = null; if (bValue != null) { if (bValue is String) { var fileName = bValue as String; if (!String.IsNullOrWhiteSpace(fileName)) { image = new UIImage(fileName); } } else if (bValue is UIImage) { image = (UIImage)bValue; } else if (bValue is DSBitmap) { image = ((DSBitmap)bValue).ToUIImage(); } } if (image != null) { var anView = new UIImageView(image); var aFrame = anView.Frame; if (Processor.Formatter != null) { aFrame.Width = Processor.Formatter.Size.Width; aFrame.Height = Processor.Formatter.Size.Height; } //try a centralize the image var xPos = (this.Frame.Width / 2) - (aFrame.Size.Width / 2); var yPos = (this.Frame.Height / 2) - (aFrame.Size.Height / 2); aFrame.X = xPos; aFrame.Y = yPos; anView.Frame = aFrame.Integral(); mContentView = anView; this.AddSubview(mContentView); } } } else { var label = new UILabel(rect.Inset(5, 5)); label.BackgroundColor = this.BackgroundColor; label.Font = (Processor.Style == CellStyle.Header) ? GridView.Theme.HeaderTextFont.ToUIFont() : GridView.Theme.CellTextFont.ToUIFont(); label.Text = Processor.ValueObject.Value.ToString(); label.LineBreakMode = UILineBreakMode.TailTruncation; var fgColor = Processor.CellForegroundColor; if (Processor.Style == CellStyle.Header) { int numLines = Processor.ValueObject.Value.ToString().Split('\n').Length; label.Lines = (label.Frame.Height >= 13) ? numLines : 1; var textAlignment = GridView.Theme.HeaderTextAlignment; if (Processor.Formatter != null && Processor.Formatter is DSTextFormatter) { textAlignment = ((DSTextFormatter)Processor.Formatter).Alignment; } label.TextAlignment = (UITextAlignment)textAlignment; if (fgColor != null) { label.TextColor = fgColor.ToUIColor(); } else { label.TextColor = GridView.Theme.HeaderTextForeground.ToUIColor(); } } else { //var fgColor = Processor.CellForegroundColor; if (fgColor != null) { label.TextColor = fgColor.ToUIColor(); } else { var alterColor = (GridView.Theme.CellTextForeground2 != null) ? GridView.Theme.CellTextForeground2.ToUIColor() : GridView.Theme.CellTextForeground.ToUIColor(); var aColor = (Processor.IsOdd) ? GridView.Theme.CellTextForeground.ToUIColor() : alterColor; label.TextColor = (Processor.IsSelected) ? GridView.Theme.CellTextHighlight.ToUIColor() : aColor; } var textAlignment = GridView.Theme.CellContentAlignment; if (Processor.Formatter != null && Processor.Formatter is DSTextFormatter) { textAlignment = ((DSTextFormatter)Processor.Formatter).Alignment; } label.TextAlignment = (UITextAlignment)textAlignment; } mContentView = label; this.AddSubview(mContentView); } } //Set the border if (Processor.Style != CellStyle.Blank) { ctx.SetLineWidth(GridView.Theme.BorderWidth); GridView.Theme.BorderColor.ToUIColor().SetStroke(); switch (Processor.PositionType) { case CellPositionType.LeftTop: { ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint }); ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint }); } break; case CellPositionType.LeftMiddle: { ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint }); } break; case CellPositionType.LeftBottom: { ctx.StrokeLineSegments(new CGPoint[] { bottomLeftPoint, bottomRightPoint }); ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, bottomLeftPoint }); } break; case CellPositionType.CenterTop: { ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint }); } break; case CellPositionType.CenterMiddle: { } break; case CellPositionType.CenterBottom: { ctx.StrokeLineSegments(new CGPoint[] { bottomLeftPoint, bottomRightPoint }); } break; case CellPositionType.RightTop: { ctx.StrokeLineSegments(new CGPoint[] { topLeftPoint, topRightPoint }); ctx.StrokeLineSegments(new CGPoint[] { topRightPoint, bottomRightPoint }); } break; case CellPositionType.RightMiddle: { ctx.StrokeLineSegments(new CGPoint[] { topRightPoint, bottomRightPoint }); } break; case CellPositionType.RightBottom: { ctx.StrokeLineSegments(new CGPoint[] { bottomLeftPoint, bottomRightPoint }); ctx.StrokeLineSegments(new CGPoint[] { topRightPoint, bottomRightPoint }); } break; } } if (Processor.Style == CellStyle.Header && Processor.SortStyle != SortIndicatorStyle.None) { //draw the up indicator var anImage = (Processor.SortStyle == SortIndicatorStyle.Ascending) ? GridView.Theme.HeaderSortIndicatorUp : GridView.Theme.HeaderSortIndicatorDown; if (anImage != null) { var aUIImage = anImage.ToUIImage(); //if iOS7 or above set as template image if (iOSHelper.IsiOS7) { aUIImage = aUIImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); } UIImageView aView = new UIImageView(aUIImage); //if iOS7 tint the image with the header text color if (iOSHelper.IsiOS7) { aView.TintColor = GridView.Theme.HeaderTextForeground.ToUIColor(); } var aLeft = this.Bounds.Width - 22; var atop = (this.Bounds.Height / 2) - 5; aView.Frame = new CGRect(aLeft, atop, 16, 8).Integral(); this.AddSubview(aView); } } }
public static CIContext FromContext(CGContext ctx) { return(FromContext(ctx, (CIContextOptions)null)); }
// rect changes depending on if the whole view is being redrawn, or just a section public override void Draw(RectangleF rect) { Console.WriteLine("Draw() Called"); base.Draw(rect); // get a reference to the context using (CGContext context = UIGraphics.GetCurrentContext()) { // declare vars int remainder; int textHeight = 20; // invert the 'y' coordinates on the text context.TextMatrix = CGAffineTransform.MakeScale(1, -1); #region -= vertical ticks =- // create our vertical tick lines using (CGLayer verticalTickLayer = CGLayer.Create(context, new SizeF(20, 3))) { // draw a single tick verticalTickLayer.Context.FillRect(new RectangleF(0, 1, 20, 2)); // draw a vertical tick every 20 pixels float yPos = 20; int numberOfVerticalTicks = (((int)Frame.Height / 20) - 1); for (int i = 0; i < numberOfVerticalTicks; i++) { // draw the layer context.DrawLayer(verticalTickLayer, new PointF(0, yPos)); // starting at 40, draw the coordinate text nearly to the top if (yPos > 40 && i < (numberOfVerticalTicks - 2)) { // draw it every 80 points Math.DivRem((int)yPos, (int)80, out remainder); if (remainder == 0) { ShowTextAtPoint(context, 30, (yPos - (textHeight / 2)), yPos.ToString(), textHeight); } } // increment the position of the next tick yPos += 20; } } #endregion #region -= horizontal ticks =- // create our horizontal tick lines using (CGLayer horizontalTickLayer = CGLayer.Create(context, new SizeF(3, 20))) { horizontalTickLayer.Context.FillRect(new RectangleF(1, 0, 2, 20)); // draw a horizontal tick every 20 pixels float xPos = 20; int numberOfHorizontalTicks = (((int)Frame.Width / 20) - 1); for (int i = 0; i < numberOfHorizontalTicks; i++) { context.DrawLayer(horizontalTickLayer, new PointF(xPos, 0)); // starting at 100, draw the coordinate text nearly to the top if (xPos > 100 && i < (numberOfHorizontalTicks - 1)) { // draw it every 80 points Math.DivRem((int)xPos, (int)80, out remainder); if (remainder == 0) { ShowCenteredTextAtPoint(context, xPos, 40, xPos.ToString(), textHeight); } } // increment the position of the next tick xPos += 20; } } #endregion // draw our "origin" text ShowTextAtPoint(context, 20, (30 + (textHeight / 2)), "Origin (0,0)", textHeight); #region -= points =- // (250,700) context.FillEllipseInRect(new RectangleF(250, 700, 6, 6)); ShowCenteredTextAtPoint(context, 250, 695, "(250,700)", textHeight); // (500,300) context.FillEllipseInRect(new RectangleF(500, 300, 6, 6)); ShowCenteredTextAtPoint(context, 500, 295, "(500,300)", textHeight); #endregion } }
public override void DrawInContext(CGContext ctx) { base.DrawInContext(ctx); ctx.SetFillColor(UIColor.Blue.CGColor); ctx.FillRect(Bounds); }
public void DrawIt(NSObject ob) { CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort; DrawInContext(ctx); }
private void InitWithCGImage(CGImage image, All filter) { int width, height, i; CGContext context = null; IntPtr data; CGColorSpace colorSpace; IntPtr tempData; bool hasAlpha; CGImageAlphaInfo info; CGAffineTransform transform; Size imageSize; SurfaceFormat pixelFormat; bool sizeToFit = false; if (image == null) { throw new ArgumentException(" NSImage is invalid! "); } info = image.AlphaInfo; hasAlpha = ((info == CGImageAlphaInfo.PremultipliedLast) || (info == CGImageAlphaInfo.PremultipliedFirst) || (info == CGImageAlphaInfo.Last) || (info == CGImageAlphaInfo.First) ? true : false); if (image.ColorSpace != null) { if (hasAlpha) { pixelFormat = SurfaceFormat.Rgba32; } else { pixelFormat = SurfaceFormat.Rgb32; } } else { pixelFormat = SurfaceFormat.Alpha8; } imageSize = new Size(image.Width, image.Height); transform = CGAffineTransform.MakeIdentity(); width = imageSize.Width; if ((width != 1) && ((width & (width - 1)) != 0)) { i = 1; while ((sizeToFit ? 2 * i : i) < width) { i *= 2; } width = i; } height = imageSize.Height; if ((height != 1) && ((height & (height - 1)) != 0)) { i = 1; while ((sizeToFit ? 2 * i : i) < height) { i *= 2; } height = i; } // TODO: kMaxTextureSize = 1024 while ((width > 1024) || (height > 1024)) { width /= 2; height /= 2; transform = CGAffineTransform.MakeScale(0.5f, 0.5f); imageSize.Width /= 2; imageSize.Height /= 2; } switch (pixelFormat) { case SurfaceFormat.Rgba32: colorSpace = CGColorSpace.CreateDeviceRGB(); data = Marshal.AllocHGlobal(height * width * 4); context = new CGBitmapContext(data, width, height, 8, 4 * width, colorSpace, CGImageAlphaInfo.PremultipliedLast); colorSpace.Dispose(); break; case SurfaceFormat.Rgb32: colorSpace = CGColorSpace.CreateDeviceRGB(); data = Marshal.AllocHGlobal(height * width * 4); context = new CGBitmapContext(data, width, height, 8, 4 * width, colorSpace, CGImageAlphaInfo.NoneSkipLast); colorSpace.Dispose(); break; case SurfaceFormat.Alpha8: data = Marshal.AllocHGlobal(height * width); context = new CGBitmapContext(data, width, height, 8, width, null, CGImageAlphaInfo.Only); break; default: throw new NotSupportedException("Invalid pixel format"); } context.ClearRect(new RectangleF(0, 0, width, height)); context.TranslateCTM(0, height - imageSize.Height); if (!transform.IsIdentity) { context.ConcatCTM(transform); } context.DrawImage(new RectangleF(0, 0, image.Width, image.Height), image); //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB" if (pixelFormat == SurfaceFormat.Rgb32) { tempData = Marshal.AllocHGlobal(height * width * 2); int d32; short d16; int inPixel32Count = 0, outPixel16Count = 0; for (i = 0; i < width * height; ++i, inPixel32Count += sizeof(int)) { d32 = Marshal.ReadInt32(data, inPixel32Count); short R = (short)((((d32 >> 0) & 0xFF) >> 3) << 11); short G = (short)((((d32 >> 8) & 0xFF) >> 2) << 5); short B = (short)((((d32 >> 16) & 0xFF) >> 3) << 0); d16 = (short)(R | G | B); Marshal.WriteInt16(tempData, outPixel16Count, d16); outPixel16Count += sizeof(short); } Marshal.FreeHGlobal(data); data = tempData; } InitWithData(data, pixelFormat, width, height, imageSize, filter); context.Dispose(); Marshal.FreeHGlobal(data); }
private void PaintBubble(CGContext context) { context.SetFillColor(this.BubbleColor.CGColor); context.FillRect(this.Bounds); }
public override void DrawInContext(CGContext context) { // Drawing with a white stroke color context.SetRGBStrokeColor(1, 1, 1, 1); // Drawing with a blue fill color context.SetRGBFillColor(0, 0, 1, 1); // Draw them with a 2 stroke width so they are a bit more visible. context.SetLineWidth(2); PointF center; // Draw a Star stroked center = new PointF(90, 90); context.MoveTo(center.X, center.Y + 60); for (int i = 1; i < 5; ++i) { float x = (float)(60 * Math.Sin(i * 4 * Math.PI / 5)); float y = (float)(60 * Math.Cos(i * 4 * Math.PI / 5)); context.AddLineToPoint(center.X + x, center.Y + y); } // Closing the path connects the current point to the start of the current path. context.ClosePath(); // And stroke the path context.StrokePath(); // Draw a Star filled center = new PointF(90, 210); context.MoveTo(center.X, center.Y + 60); for (int i = 1; i < 5; ++i) { float x = (float)(60 * Math.Sin(i * 4 * Math.PI / 5)); float y = (float)(60 * Math.Cos(i * 4 * Math.PI / 5)); context.AddLineToPoint(center.X + x, center.Y + y); } // Closing the path connects the current point to the start of the current path. context.ClosePath(); // Use the winding-rule fill mode. context.FillPath(); // Draw a Star filled center = new PointF(90, 330); context.MoveTo(center.X, center.Y + 60); for (int i = 1; i < 5; ++i) { float x = (float)(60 * Math.Sin(i * 4 * Math.PI / 5)); float y = (float)(60 * Math.Cos(i * 4 * Math.PI / 5)); context.AddLineToPoint(center.X + x, center.Y + y); } // Closing the path connects the current point to the start of the current path. context.ClosePath(); // Use the even-odd fill mode. context.EOFillPath(); // Draw a Hexagon stroked center = new PointF(210, 90); context.MoveTo(center.X, center.Y + 60); for (int i = 1; i < 6; ++i) { float x = (float)(60 * Math.Sin(i * 2 * Math.PI / 6)); float y = (float)(60 * Math.Cos(i * 2 * Math.PI / 6)); context.AddLineToPoint(center.X + x, center.Y + y); } // Closing the path connects the current point to the start of the current path. context.ClosePath(); // And stroke the path context.StrokePath(); // Draw a Hexagon stroked & filled center = new PointF(210, 240); context.MoveTo(center.X, center.Y + 60); for (int i = 1; i < 6; ++i) { float x = (float)(60 * Math.Sin(i * 2 * Math.PI / 6)); float y = (float)(60 * Math.Cos(i * 2 * Math.PI / 6)); context.AddLineToPoint(center.X + x, center.Y + y); } // Closing the path connects the current point to the start of the current path. context.ClosePath(); // Use the winding-rule fill mode, and stroke the path after. context.DrawPath(CGPathDrawingMode.FillStroke); }
protected abstract void DrawData(CGContext context);
UIImage GetImage(UIColor strokeColor, UIColor fillColor, CGSize size, nfloat scale, bool shouldCrop = true) { if (size.Width == 0 || size.Height == 0 || scale <= 0 || strokeColor == null || fillColor == null) { return(null); } nfloat uncroppedScale; CGSize uncroppedSize; CGRect croppedRectangle; if (shouldCrop && Points.Count() > 0) { croppedRectangle = getCroppedRectangle(); nfloat scaleX = croppedRectangle.Width / Bounds.Width; nfloat scaleY = croppedRectangle.Height / Bounds.Height; uncroppedScale = 1 / (nfloat)Math.Max(scaleX, scaleY); //uncroppedScale = 1 / getScaleFromSize (croppedRectangle.Size, Bounds); uncroppedSize = getSizeFromScale(uncroppedScale, new CGRect(new CGPoint(0, 0), size)); } else { uncroppedScale = scale; uncroppedSize = size; } //Make sure the image is scaled to the screen resolution in case of Retina display. UIGraphics.BeginImageContext(uncroppedSize); //Create context and set the desired options CGContext context = UIGraphics.GetCurrentContext(); context.SetFillColor(fillColor.CGColor); context.FillRect(new CGRect(0, 0, uncroppedSize.Width, uncroppedSize.Height)); context.SetStrokeColor(strokeColor.CGColor); context.SetLineWidth(StrokeWidth); context.SetLineCap(CGLineCap.Round); context.SetLineJoin(CGLineJoin.Round); context.ScaleCTM(uncroppedScale, uncroppedScale); //Obtain all drawn paths from the array foreach (var bezierPath in paths) { CGPath path = bezierPath.CGPath; context.AddPath(path); } context.StrokePath(); UIImage image = UIGraphics.GetImageFromCurrentImageContext(); if (shouldCrop && Points.Count() > 0) { croppedRectangle = getCroppedRectangle(); CGRect scaledRectangle; scaledRectangle = new CGRect(croppedRectangle.X * uncroppedScale, croppedRectangle.Y * uncroppedScale, size.Width, size.Height); if (scaledRectangle.X >= 5) { scaledRectangle.X -= 5; scaledRectangle.Width += 5; } if (scaledRectangle.Y >= 5) { scaledRectangle.Y -= 5; scaledRectangle.Height += 5; } if (scaledRectangle.X + scaledRectangle.Width <= uncroppedSize.Width - 5) { scaledRectangle.Width += 5; } if (scaledRectangle.Y + scaledRectangle.Height <= uncroppedSize.Height - 5) { scaledRectangle.Height += 5; } CGImage croppedImage = image.CGImage.WithImageInRect(scaledRectangle); image = new UIImage(croppedImage); } return(image); }
/// <summary> /// Rasterizes the triangle specified by the vector / points and their associated colors /// using barycentric coordinates. /// </summary> /// <param name="context"></param> /// <param name="vt1"></param> /// <param name="vt2"></param> /// <param name="vt3"></param> /// <param name="colorV1"></param> /// <param name="colorV2"></param> /// <param name="colorV3"></param> internal void RasterizeTriangle(CGContext context, PointF vt1, PointF vt2, PointF vt3, Color colorV1, Color colorV2, Color colorV3) { // get the bounding box of the triangle int maxX = (int)Math.Max(vt1.X, Math.Max(vt2.X, vt3.X)); int minX = (int)Math.Min(vt1.X, Math.Min(vt2.X, vt3.X)); int maxY = (int)Math.Max(vt1.Y, Math.Max(vt2.Y, vt3.Y)); int minY = (int)Math.Min(vt1.Y, Math.Min(vt2.Y, vt3.Y)); // Barycentric coordinates at minX/minY corner PointF pm = new PointF(minX, minY); var edge32 = new Edge(vt3, vt2, vt1, pm, colorV1); var edge13 = new Edge(vt1, vt3, vt2, pm, colorV2); var edge21 = new Edge(vt2, vt1, vt3, pm, colorV3); int span32 = edge32.EdgeOrigin; int span13 = edge13.EdgeOrigin; int span21 = edge21.EdgeOrigin; edge32Red = colorV1.R; edge32Green = colorV1.G; edge32Blue = colorV1.B; edge32Alpha = colorV1.A; edge13Red = colorV2.R; edge13Green = colorV2.G; edge13Blue = colorV2.B; edge13Alpha = colorV2.A; edge21Red = colorV3.R; edge21Green = colorV3.G; edge21Blue = colorV3.B; edge21Alpha = colorV3.A; int span32XOffset = 0; int span13XOffset = 0; int span21XOffset = 0; bool inside = false; int mask = 0; // Iterate over each pixel of bounding box and check if it's inside // the triangle using the barycentirc approach. for (int y = minY; y <= maxY; y += Edge.StepYSize) { // Barycentric coordinates at start of row span32XOffset = span32; span13XOffset = span13; span21XOffset = span21; inside = false; for (int x = minX; x <= maxX; x += Edge.StepXSize) { mask = span32XOffset | span13XOffset | span21XOffset; // If p is on or inside all edges for any pixels, // render those pixels. if (mask >= 0) { if (!inside) { inside = true; } RenderPixels(context, x, y, edge32, edge13, edge21, span32XOffset, span13XOffset, span21XOffset); } // Step to the right span32XOffset += edge32.StepX; span13XOffset += edge13.StepX; span21XOffset += edge21.StepX; if (mask < 0 && inside) { inside = false; break; } } // Row step span32 += edge32.StepY; span13 += edge13.StepY; span21 += edge21.StepY; } }
public override void Draw(RectangleF rect) { CGContext context = UIGraphics.GetCurrentContext(); element.Draw(rect, context, this); }
public abstract void Draw(CGRect bounds, CGContext context, UIView view);
public CGContextCanvas(CGContext context) { this.context = context; // context.InterpolationQuality = CGInterpolationQuality.High; context.TextMatrix = CGAffineTransform.MakeScale(1, -1); }
public override void ArcNegative(object backend, double xc, double yc, double radius, double angle1, double angle2) { CGContext ctx = ((CGContextBackend)backend).Context; ctx.AddArc((float)xc, (float)yc, (float)radius, (float)(angle1 * degrees), (float)(angle2 * degrees), true); }
public override void DrawInContext(CGContext ctx) { _onDraw(ctx); }