本文整理汇总了C#中CGPath类的典型用法代码示例。如果您正苦于以下问题:C# CGPath类的具体用法?C# CGPath怎么用?C# CGPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CGPath类属于命名空间,在下文中一共展示了CGPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePieSegment
private UIImage CreatePieSegment(CGSize size, nfloat endAngle)
{
// Add the arc
var arc = new CGPath();
arc.MoveToPoint(size.Width / 2.0f, size.Height / 2.0f);
arc.AddLineToPoint(size.Width / 2.0f, 0);
arc.AddArc(size.Width / 2.0f, size.Height / 2.0f, size.Width / 2.0f, _startAngle, endAngle, false);
arc.AddLineToPoint(size.Width / 2.0f, size.Height / 2.0f);
// Stroke the arc
UIGraphics.BeginImageContextWithOptions(size, false, 0);
var context = UIGraphics.GetCurrentContext();
context.AddPath(arc);
context.SetFillColor(UIColor.FromRGBA(0f, 0f, 0f, 1f).CGColor);
context.FillPath();
// Get the mask image
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
}
示例2: Draw
public override void Draw(RectangleF rect)
{
var element = Element as CircleView;
if (element == null) {
throw new InvalidOperationException ("Element must be a Circle View type");
}
//get graphics context
using(CGContext context = UIGraphics.GetCurrentContext ()){
context.SetFillColor(element.FillColor.ToCGColor());
context.SetStrokeColor(element.StrokeColor.ToCGColor());
context.SetLineWidth(element.StrokeThickness);
if (element.StrokeDash > 1.0f) {
context.SetLineDash (
0,
new float[] { element.StrokeDash, element.StrokeDash });
}
//create geometry
var path = new CGPath ();
path.AddEllipseInRect (rect);
path.CloseSubpath();
//add geometry to graphics context and draw it
context.AddPath(path);
context.DrawPath(CGPathDrawingMode.FillStroke);
}
}
示例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: Draw
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);
}
示例5: Draw
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);
}
}
示例6: DrawView
public DrawView (RectangleF frame) : base (frame)
{
DrawPath = new CGPath ();
CurrentLineColor = UIColor.Black;
PenWidth = 5.0f;
Lines = new List<VESLine> ();
}
示例7: Draw
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);
}
示例8: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
animationPath = new CGPath ();
backgroundImage = new UIImageView (View.Frame);
View.AddSubview (backgroundImage);
CreatePath ();
btnContents.TouchUpInside += (sender, e) => {
if(ContentsButtonClicked != null)
ContentsButtonClicked(sender, e);
};
btnAnimate.TouchUpInside += (s, e) => {
// create a keyframe animation
var keyFrameAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath ("position");
keyFrameAnimation.Path = animationPath;
keyFrameAnimation.Duration = 3;
keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseInEaseOut);
imgToAnimate.Layer.AddAnimation (keyFrameAnimation, "MoveImage");
imgToAnimate.Layer.Position = new PointF (700f, 900f);
};
}
示例9: Draw
public override void Draw(System.Drawing.RectangleF rect)
{
//Get the current context
CGContext ctxt = UIGraphics.GetCurrentContext();
ctxt.ClearRect(rect);
//Set up the stroke and fill characteristics
ctxt.SetLineWidth(3.0f);
float[] gray = { 0.5f, 0.5f, 0.5f, 1.0f};
ctxt.SetStrokeColor(gray);
float[] red = { 0.75f, 0.25f, 0.25f, 1.0f};
ctxt.SetFillColor(red);
//Draw a line between the two location points
ctxt.MoveTo(Loc1.X, Loc1.Y);
ctxt.AddLineToPoint(Loc2.X, Loc2.Y);
ctxt.StrokePath();
var p1Box = new RectangleF(Loc1.X, Loc1.Y, 0.0f, 0.0f);
var p2Box = new RectangleF(Loc2.X, Loc2.Y, 0.0f, 0.0f);
var offset = -8.0f;
foreach(var r in new RectangleF[] {p1Box, p2Box})
{
using(var path = new CGPath())
{
var cpath = new CGPath();
r.Inflate (new SizeF (offset, offset));
cpath.AddElipseInRect(r);
ctxt.AddPath(cpath);
ctxt.FillPath();
}
}
}
示例10: DrawEllipse
/// <summary>
/// Draws an ellipse.
/// </summary>
/// <param name="rect">The rectangle.</param>
/// <param name="fill">The fill color.</param>
/// <param name="stroke">The stroke color.</param>
/// <param name="thickness">The thickness.</param>
public override void DrawEllipse(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
{
this.SetAlias(false);
var convertedRectangle = rect.Convert();
if (fill.IsVisible())
{
this.SetFill(fill);
using (var path = new CGPath())
{
path.AddEllipseInRect(convertedRectangle);
this.gctx.AddPath(path);
}
this.gctx.DrawPath(CGPathDrawingMode.Fill);
}
if (stroke.IsVisible() && thickness > 0)
{
this.SetStroke(stroke, thickness);
using (var path = new CGPath())
{
path.AddEllipseInRect(convertedRectangle);
this.gctx.AddPath(path);
}
this.gctx.DrawPath(CGPathDrawingMode.Stroke);
}
}
示例11: ViewDidAppear
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");
}
示例12: 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();
}
}
}
}
示例13: Clear
// clear the canvas
public void Clear()
{
drawPath.Dispose ();
drawPath = new CGPath ();
fingerDraw = false;
SetNeedsDisplay ();
}
示例14: Draw
public override void Draw(CGRect rect)
{
//get graphics context
using (CGContext g = UIGraphics.GetCurrentContext())
{
//set up drawing attributes
UIColor.Black.SetFill();
//create geometry
_overlay = new CGPath();
_overlay.AddRect(new RectangleF(0f, 0f, _width, _height));
if(_isRound)
_overlay.AddEllipseInRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height));
else
_overlay.AddRect(new RectangleF((float)_rect.X, (float)_rect.Y, (float)_rect.Width, (float)_rect.Height));
g.SetStrokeColor(UIColor.Clear.CGColor);
g.SetAlpha(0.6f);
//add geometry to graphics context and draw it
g.AddPath(_overlay);
g.DrawPath(CGPathDrawingMode.EOFillStroke);
}
}
示例15: ShipSprite
public ShipSprite(PointF initialPosition)
: base(NSBundle.MainBundle.PathForResource ("spaceship", "png"))
{
CGPath boundingPath = new CGPath ();
boundingPath.MoveToPoint (-12f, -38f);
boundingPath.AddLineToPoint (12f, -38f);
boundingPath.AddLineToPoint (9f, 18f);
boundingPath.AddLineToPoint (2f, 38f);
boundingPath.AddLineToPoint (-2f, 38f);
boundingPath.AddLineToPoint (-9f, 18f);
boundingPath.AddLineToPoint (-12f, -38f);
#if false
// Debug overlay
SKShapeNode shipOverlayShape = new SKShapeNode () {
Path = boundingPath,
StrokeColor = UIColor.Clear,
FillColor = UIColor.FromRGBA (0f, 1f, 0f, 0.5f)
};
ship.AddChild (shipOverlayShape);
#endif
var body = SKPhysicsBody.BodyWithPolygonFromPath (boundingPath);
body.CategoryBitMask = Category.Ship;
body.CollisionBitMask = Category.Ship | Category.Asteroid | Category.Planet | Category.Edge;
body.ContactTestBitMask = body.CollisionBitMask;
body.LinearDamping = 0;
body.AngularDamping = 0.5f;
PhysicsBody = body;
Position = initialPosition;
}