本文整理汇总了C#中CGContext.AddPath方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.AddPath方法的具体用法?C# CGContext.AddPath怎么用?C# CGContext.AddPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.AddPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawMapRect
/// <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();
}
}
}
}
示例2: DrawPolyline
public void DrawPolyline(MKPolyline polygon,MKMapRect mapRect, float zoomScale, CGContext context)
{
CGPath path = this.polyPath (polygon,mapRect,zoomScale,context);
if (path != null)
{
this.ApplyFillProperties (context, zoomScale);
context.BeginPath ();
context.AddPath (path);
context.DrawPath (CGPathDrawingMode.Stroke);
this.ApplyStrokeProperties (context, zoomScale);
context.BeginPath ();
context.AddPath (path);
context.StrokePath ();
}
}
示例3: CreateShape
public override void CreateShape(CGPath path, CGContext gctx)
{
path.AddRect (new RectangleF (_origin, new SizeF (100, 100)));
gctx.AddPath (path);
gctx.DrawPath (CGPathDrawingMode.FillStroke);
}
示例4: DrawGraph
public void DrawGraph(CGContext g,nfloat x0,nfloat y0)
{
g.SetLineWidth (_lineWidth);
// Draw background circle
CGPath path = new CGPath ();
_backColor.SetStroke ();
path.AddArc (x0, y0, _radius, 0, 2.0f * (float)Math.PI, true);
g.AddPath (path);
g.DrawPath (CGPathDrawingMode.Stroke);
// Draw overlay circle
var pathStatus = new CGPath ();
_frontColor.SetStroke ();
pathStatus.AddArc(x0, y0, _radius, 0, _degrees * (float)Math.PI, false);
g.AddPath (pathStatus);
g.DrawPath (CGPathDrawingMode.Stroke);
}
示例5: CreateShape
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);
}
示例6: DrawInContext
public override void DrawInContext(CGContext ctx)
{
base.DrawInContext (ctx);
// clip
var cornerRadius = Bounds.Height * Slider.Curvaceousness / 2.0f;
UIBezierPath switchOutline = UIBezierPath.FromRoundedRect( (CGRect)Bounds, (nfloat)cornerRadius);
ctx.AddPath (switchOutline.CGPath);
ctx.Clip ();
// 1) fill the track
ctx.SetFillColor (Slider.TrackColor.CGColor);
ctx.AddPath(switchOutline.CGPath);
ctx.FillPath ();
// 2) fill the highlighed range
ctx.SetFillColor(Slider.TrackHighlightColor.CGColor);
var lower = Slider.positionForValue (Slider.LowValue);
var higher = Slider.positionForValue(Slider.HighValue);
ctx.FillRect((CGRect)new CGRect(lower, 0, higher - lower, Bounds.Height));
// 3) add a highlight over the track
CGRect highlight = new CGRect(cornerRadius/2, Bounds.Height/2,
Bounds.Width - cornerRadius, Bounds.Height/2);
UIBezierPath highlightPath = UIBezierPath.FromRoundedRect ((CGRect)highlight, (nfloat)highlight.Height * Slider.Curvaceousness / 2.0f);
ctx.AddPath(highlightPath.CGPath);
ctx.SetFillColor( UIColor.FromWhiteAlpha((nfloat)1.0f, (nfloat)0.4f).CGColor);
ctx.FillPath ();
// 4) inner shadow
ctx.SetShadow( new CGSize(0f, 2.0f), 3.0f, UIColor.Gray.CGColor);
ctx.AddPath (switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Gray.CGColor);
ctx.StrokePath ();
// 5) outline the track
ctx.AddPath( switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Black.CGColor);
ctx.SetLineWidth ((nfloat)0.5f);
ctx.StrokePath ();
}
示例7: DrawInContext
public override void DrawInContext(CGContext ctx)
{
base.DrawInContext (ctx);
// clip
var cornerRadius = Bounds.Height / 2.0f;
UIBezierPath switchOutline = UIBezierPath.FromRoundedRect( (CGRect)Bounds, (nfloat)cornerRadius);
ctx.AddPath (switchOutline.CGPath);
ctx.Clip ();
// 1) fill the track
ctx.SetFillColor (UIColor.Green.CGColor);
ctx.AddPath(switchOutline.CGPath);
ctx.FillPath ();
// 2) fill the highlighed range //Skipped for demo
// 3) add a highlight over the track
CGRect highlight = new CGRect(cornerRadius/2, Bounds.Height/2,
Bounds.Width - cornerRadius, Bounds.Height/2);
UIBezierPath highlightPath = UIBezierPath.FromRoundedRect ((CGRect)highlight, (nfloat)highlight.Height / 2.0f);
ctx.AddPath(highlightPath.CGPath);
ctx.SetFillColor( UIColor.FromWhiteAlpha((nfloat)1.0f, (nfloat)0.4f).CGColor);
ctx.FillPath ();
// 4) inner shadow
ctx.SetShadow( new CGSize(0f, 2.0f), 3.0f, UIColor.Gray.CGColor);
ctx.AddPath (switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Gray.CGColor);
ctx.StrokePath ();
// 5) outline the track
ctx.AddPath( switchOutline.CGPath);
ctx.SetStrokeColor(UIColor.Black.CGColor);
ctx.SetLineWidth ((nfloat)0.5f);
ctx.StrokePath ();
//
// ctx.SetFillColor (UIColor.Blue.CGColor);
// ctx.FillRect (Bounds);
}
示例8: DrawMapRect
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();
}
示例9: DrawBorder
private void DrawBorder(CGContext context, CGPath path)
{
var separatorColor = Element.Theme.SeparatorColor ?? TableView.SeparatorColor;
context.SetLineWidth(1);
context.SetStrokeColor(separatorColor.CGColor);
context.SetShadowWithColor(new SizeF(0,0), 0f, UIColor.Clear.CGColor);
context.AddPath(path);
context.DrawPath(CGPathDrawingMode.Stroke);
return;
}
示例10: Draw
public override void Draw(RectangleF bounds, CGContext context, UIView view)
{
var leftMargin = LeftRightPadding;
// Superview is the container, its superview the uitableviewcell
var uiTableViewCell = view.Superview.Superview as UITableViewCell;
bool highlighted = uiTableViewCell != null && uiTableViewCell.Highlighted & IsTappedAssigned;
var timeColor = highlighted ? UIColor.White : UIColor.Gray;
var textColor = highlighted ? UIColor.White : UIColor.FromRGB(41, 41, 41);
var nameColor = highlighted ? UIColor.White : UIColor.FromRGB(0, 64, 128);
if (Image != null)
{
var imageRect = new RectangleF(LeftRightPadding, TopBottomPadding, 32f, 32f);
UIColor.White.SetColor ();
context.SaveState ();
//context.TranslateCTM (imageRect.X, imageRect.Y);
context.SetLineWidth (1);
// On device, the shadow is painted in the opposite direction!
context.SetShadowWithColor (new SizeF (0, 0), 3, UIColor.DarkGray.CGColor);
context.AddPath (UIBezierPath.FromRect(imageRect).CGPath);
context.FillPath ();
context.RestoreState ();
Image.Draw(imageRect);
leftMargin += LeftRightPadding + imageRect.Width + 3f;
}
var contentWidth = bounds.Width - LeftRightPadding - leftMargin;
var daysAgo = Time.ToDaysAgo();
timeColor.SetColor();
var daysWidth = daysAgo.MonoStringLength(DateFont);
RectangleF timeRect;
timeRect = Image != null ? new RectangleF(leftMargin, TopBottomPadding + UserFont.LineHeight, daysWidth, DateFont.LineHeight) :
new RectangleF(bounds.Width - LeftRightPadding - daysWidth, TopBottomPadding + 1f, daysWidth, DateFont.LineHeight);
view.DrawString(daysAgo, timeRect, DateFont, UILineBreakMode.TailTruncation);
nameColor.SetColor();
view.DrawString(Name,
new RectangleF(leftMargin, TopBottomPadding, contentWidth, UserFont.LineHeight),
UserFont, UILineBreakMode.TailTruncation
);
if (!string.IsNullOrEmpty(String))
{
UIColor.Black.SetColor();
var top = TopBottomPadding + UserFont.LineHeight + 3f;
if (Image != null)
top += DateFont.LineHeight;
textColor.SetColor();
if (Image == null)
{
view.DrawString(String,
new RectangleF(LeftRightPadding, top, bounds.Width - LeftRightPadding * 2, bounds.Height - TopBottomPadding - top),
DescFont, UILineBreakMode.TailTruncation
);
}
else
{
view.DrawString(String,
new RectangleF(leftMargin, top, contentWidth, bounds.Height - TopBottomPadding - top),
DescFont, UILineBreakMode.TailTruncation
);
}
}
}
示例11: DrawRect
//.........这里部分代码省略.........
g.SetFillColor(strokeColor);
List<Arc> innerArcs = new List<Arc>();
if (cornerRadius.TopLeft != 0)
{
innerArcs.Add(this.DrawArc(g, cornerRadius.TopLeft, center, borderThickness.LeftF(), borderThickness.TopF(), 180f, 270f));
}
else
{
innerArcs.Add(new Arc() { Center = center });
}
g.BeginPath();
g.SetLineWidth(borderThickness.TopF());
g.MoveTo((nfloat)cornerRadius.TopLeft, borderThickness.TopF() / 2);
g.AddLineToPoint(rect.Right - (nfloat)cornerRadius.TopRight - borderThickness.RightF() / 2, borderThickness.TopF() / 2);
g.StrokePath();
center = new CGPoint(rect.Right - cornerRadius.TopRight - borderThickness.Right / 2, rect.Top + cornerRadius.TopRight + borderThickness.Top / 2);
if (cornerRadius.TopRight != 0)
{
innerArcs.Add(this.DrawArc(g, cornerRadius.TopRight, center, borderThickness.TopF(), borderThickness.RightF(), -90f, 0f));
}
else
{
innerArcs.Add(new Arc { Center = center });
}
g.BeginPath();
g.SetLineWidth(borderThickness.RightF());
g.MoveTo(rect.Right - borderThickness.RightF() / 2, (nfloat)cornerRadius.TopRight);
g.AddLineToPoint(rect.Right - borderThickness.RightF() / 2, rect.Height - (nfloat)cornerRadius.BottomRight);
g.StrokePath();
center = new CGPoint(rect.Right - cornerRadius.BottomRight - borderThickness.Right / 2, rect.Bottom - cornerRadius.BottomRight - borderThickness.Bottom / 2);
if (cornerRadius.BottomRight != 0)
{
innerArcs.Add(this.DrawArc(g, cornerRadius.BottomRight, center, borderThickness.RightF(), borderThickness.BottomF(), 0f, 90f));
}
else
{
innerArcs.Add(new Arc() { Center = center });
}
g.BeginPath();
g.SetLineWidth(borderThickness.BottomF());
g.MoveTo(rect.Right - (nfloat)cornerRadius.BottomRight, rect.Bottom - borderThickness.BottomF() / 2);
g.AddLineToPoint(rect.Left + (nfloat)cornerRadius.BottomLeft, rect.Bottom - borderThickness.BottomF() / 2);
g.StrokePath();
center = new CGPoint((rect.Left + cornerRadius.BottomLeft + borderThickness.Left / 2), (rect.Bottom - cornerRadius.BottomLeft - borderThickness.Bottom / 2));
if (cornerRadius.BottomLeft != 0)
{
innerArcs.Add(this.DrawArc(g, cornerRadius.BottomLeft, center, borderThickness.BottomF(), borderThickness.LeftF(), 90f, 180f));
}
else
{
innerArcs.Add(new Arc() { Center = center });
}
g.SetLineWidth((nfloat)borderThickness.Left);
g.MoveTo(rect.Left + borderThickness.LeftF() / 2, rect.Bottom - (nfloat)cornerRadius.BottomLeft);
g.AddLineToPoint(rect.Left + borderThickness.LeftF() / 2, rect.Top + (nfloat)cornerRadius.TopLeft);
g.StrokePath();
if (fill != null)
{
var fillColor = fill.ToUIColor(rect.Size).CGColor;
g.SetFillColor(fillColor);
g.SetLineWidth(0);
using (CGPath path = new CGPath())
{
path.AddArc(
innerArcs[0].Center.X,
innerArcs[0].Center.Y,
innerArcs[0].Radius,
innerArcs[0].EndingAngle,
innerArcs[0].StartingAngle,
false);
path.AddArc(
innerArcs[1].Center.X,
innerArcs[1].Center.Y,
innerArcs[1].Radius,
innerArcs[1].EndingAngle,
innerArcs[1].StartingAngle,
false);
path.AddArc(
innerArcs[2].Center.X,
innerArcs[2].Center.Y,
innerArcs[2].Radius,
innerArcs[2].EndingAngle,
innerArcs[2].StartingAngle,
false);
path.AddArc(
innerArcs[3].Center.X,
innerArcs[3].Center.Y,
innerArcs[3].Radius,
innerArcs[3].EndingAngle,
innerArcs[3].StartingAngle,
false);
g.AddPath(path);
g.DrawPath(CGPathDrawingMode.Fill);
}
}
}
示例12: DrawAddPhotoButton
void DrawAddPhotoButton(CGContext ctx)
{
UIColor background = pressed ? HighlightedButtonColor : NormalButtonColor;
RectangleF bounds = PhotoRect;
float alpha = 1.0f;
ctx.SaveState ();
ctx.AddPath (PhotoBorder);
ctx.Clip ();
using (var cs = CGColorSpace.CreateDeviceRGB ()) {
var bottomCenter = new PointF (bounds.GetMidX (), bounds.GetMaxY ());
var topCenter = new PointF (bounds.GetMidX (), bounds.Y);
float[] gradColors;
CGPath container;
gradColors = new [] { 0.23f, 0.23f, 0.23f, alpha, 0.67f, 0.67f, 0.67f, alpha };
using (var gradient = new CGGradient (cs, gradColors, new [] { 0.0f, 1.0f })) {
ctx.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
}
var bg = bounds.Inset (1.0f, 1.0f);
container = GraphicsUtil.MakeRoundedRectPath (bg, 13.5f);
ctx.AddPath (container);
ctx.Clip ();
background.SetFill ();
ctx.FillRect (bg);
gradColors = new [] {
0.0f, 0.0f, 0.0f, 0.75f,
0.0f, 0.0f, 0.0f, 0.65f,
0.0f, 0.0f, 0.0f, 0.35f,
0.0f, 0.0f, 0.0f, 0.05f
};
using (var gradient = new CGGradient (cs, gradColors, new float [] { 0.0f, 0.1f, 0.4f, 1.0f })) {
ctx.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
}
}
//ctx.AddPath (PhotoBorder);
//ctx.SetStrokeColor (0.5f, 0.5f, 0.5f, 1.0f);
//ctx.SetLineWidth (0.5f);
//ctx.StrokePath ();
ctx.RestoreState ();
}
示例13: DrawLayer
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);
}
示例14: DrawLinearGradient
private void DrawLinearGradient(CGContext context, RectangleF rect, CGColor startColor, CGColor endColor)
{
CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
float [] locations = { 0.0f, 1.0f };
CGColor [] colors = new CGColor[] { startColor, endColor };
CGGradient gradient = new CGGradient (colorSpace, colors, locations);
PointF startPoint = new PointF (rect.GetMidX (), rect.GetMinY ());
PointF endPoint = new PointF (rect.GetMidX (), rect.GetMaxY ());
context.SaveState ();
context.AddPath (UIBezierPath.FromRoundedRect (rect, 10).CGPath);
context.Clip ();
context.DrawLinearGradient (gradient, startPoint, endPoint, 0);
context.RestoreState ();
}
示例15: DrawInContext
public override void DrawInContext(CGContext ctx)
{
base.DrawInContext (ctx);
var knobFrame = CGRect.Inflate(Bounds, -2.0f, -2.0f);
UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height / 2.0f);
// 1) fill - with a subtle shadow
ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor);
ctx.SetFillColor( UIColor.White.CGColor);
ctx.AddPath( knobPath.CGPath);
ctx.FillPath ();
// 2) outline
ctx.SetStrokeColor(UIColor.Gray.CGColor);
ctx.SetLineWidth((nfloat)0.5f);
ctx.AddPath(knobPath.CGPath);
ctx.StrokePath ();
// 3) inner gradient
var rect = CGRect.Inflate(knobFrame, -2.0f, -2.0f);
var clipPath = UIBezierPath.FromRoundedRect ((CGRect)rect, (nfloat)rect.Height / 2.0f);
CGGradient myGradient;
CGColorSpace myColorspace;
nfloat[] locations = { 0.0f, 1.0f };
nfloat[] components = { 0.0f, 0.0f, 0.0f , 0.15f, // Start color
0.0f, 0.0f, 0.0f, 0.05f }; // End color
myColorspace = CGColorSpace.CreateDeviceRGB (); // CGColorSpaceCreateDeviceRGB();
myGradient = new CGGradient( myColorspace, components, locations);
CGPoint startPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMinY());
CGPoint endPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMaxY());
ctx.SaveState ();
ctx.AddPath( clipPath.CGPath);
ctx.Clip ();
ctx.DrawLinearGradient( (CGGradient)myGradient, (CGPoint)startPoint, (CGPoint)endPoint, (CGGradientDrawingOptions)0);
myGradient.Dispose ();
myColorspace.Dispose();
ctx.RestoreState();
// 4) highlight
if (Highlighted)
{
// fill
ctx.SetFillColor(UIColor.FromWhiteAlpha((nfloat)0.0f, (nfloat)0.1f).CGColor);
ctx.AddPath( knobPath.CGPath);
ctx.FillPath();
}
//
// if (Highlighted)
// ctx.SetFillColor (UIColor.Yellow.CGColor);
// else
// ctx.SetFillColor (UIColor.Red.CGColor);
//
// ctx.FillRect (Bounds);
}