本文整理汇总了C#中CGContext.StrokeRect方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.StrokeRect方法的具体用法?C# CGContext.StrokeRect怎么用?C# CGContext.StrokeRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.StrokeRect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawInContext
public override void DrawInContext (CGContext context)
{
// Drawing with a white stroke color
context.SetRGBStrokeColor (1, 1, 1, 1);
// And 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);
// Add Rect to the current path, then stroke it
context.AddRect (new RectangleF (30, 30, 60, 60));
context.StrokePath ();
// Stroke Rect convenience that is equivalent to above
context.StrokeRect (new RectangleF (30, 120, 60, 60));
// Stroke rect convenience equivalent to the above, plus a call to context.SetLineWidth ().
context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 10);
// Demonstate the stroke is on both sides of the path.
context.SaveState ();
context.SetRGBStrokeColor (1, 0, 0, 1);
context.StrokeRectWithWidth (new RectangleF (30, 210, 60, 60), 2);
context.RestoreState ();
var rects = new RectangleF []
{
new RectangleF (120, 30, 60, 60),
new RectangleF (120, 120, 60, 60),
new RectangleF (120, 210, 60, 60),
};
// Bulk call to add rects to the current path.
context.AddRects (rects);
context.StrokePath ();
// Create filled rectangles via two different paths.
// Add/Fill path
context.AddRect (new RectangleF (210, 30, 60, 60));
context.FillPath ();
// Fill convienience.
context.FillRect (new RectangleF (210, 120, 60, 60));
}
示例2: DrawInContext
public override void DrawInContext (CGContext context)
{
var imageRect = new RectangleF (8, 8, 64, 64);
// Note: The images are actually drawn upside down because Quartz image drawing expects
// the coordinate system to have the origin in the lower-left corner, but a UIView
// puts the origin in the upper-left corner. For the sake of brevity (and because
// it likely would go unnoticed for the image used) this is not addressed here.
// For the demonstration of PDF drawing however, it is addressed, as it would definately
// be noticed, and one method of addressing it is shown there.
// Draw the image in the upper left corner (0,0) with size 64x64
context.DrawImage (imageRect, image);
// Tile the same image across the bottom of the view
// CGContextDrawTiledImage() will fill the entire clipping area with the image, so to avoid
// filling the entire view, we'll clip the view to the rect below. This rect extends
// past the region of the view, but since the view's rectangle has already been applied as a clip
// to our drawing area, it will be intersected with this rect to form the final clipping area
context.ClipToRect(new RectangleF (0, 80, Bounds.Width, Bounds.Height));
// The origin of the image rect works similarly to the phase parameter for SetLineDash and
// SetPatternPhase and specifies where in the coordinate system the "first" image is drawn.
// The size (previously set to 64x64) specifies the size the image is scaled to before being tiled.
imageRect.X = 32;
imageRect.Y = 112;
context.DrawTiledImage (imageRect, image);
// Highlight the "first" image from the DrawTiledImage call.
context.SetRGBFillColor (1, 0, 0, 0.5f);
context.FillRect (imageRect);
// And stroke the clipped area
context.SetLineWidth (3);
context.SetRGBStrokeColor (1, 0, 0, 1);
context.StrokeRect (context.GetClipBoundingBox ());
}
示例3: DrawInContext
public override void DrawInContext (CGContext context)
{
base.DrawInContext (context);
nfloat size = NMath.Min (Bounds.Size.Width, Bounds.Size.Height);
CGAffineTransform transform = AffineTransform;
nfloat xTranslate = 0;
nfloat yTranslate = 0;
if (Bounds.Size.Width < Bounds.Size.Height)
yTranslate = (Bounds.Size.Height - size) / 2f;
else
xTranslate = (Bounds.Size.Width - size) / 2f;
transform.Translate (xTranslate, yTranslate);
nfloat strokeWidth = StrokeFactor * size;
nfloat checkBoxInset = InsetFactor * size;
// Create the outer border for the check box.
nfloat outerDimension = size - 2 * checkBoxInset;
var checkBoxRect = new CGRect(checkBoxInset, checkBoxInset, outerDimension, outerDimension);
checkBoxRect = transform.TransformRect (checkBoxRect);
// Make the desired width of the outer box.
context.SetLineWidth (strokeWidth);
// Set the tint color of the outer box.
context.SetStrokeColor (TintColor);
// Draw the outer box.
context.StrokeRect (checkBoxRect);
// Draw the inner box if it's checked.
if (Checked) {
nfloat markInset = MarkInsetFactor * size;
nfloat markDimension = size - 2 * markInset;
var markRect = new CGRect(markInset, markInset, markDimension, markDimension);
markRect = transform.TransformRect (markRect);
context.SetFillColor (TintColor);
context.FillRect (markRect);
}
}
示例4: DrawRectangle
private void DrawRectangle(CGContext g, PinboardData.RectangleInfo rectInfo)
{
g.SetFillColor(rectInfo.Color);
g.FillRect(rectInfo.Rectangle);
float pw = 0.5f;
CGColor rectBorderColor = new CGColor(0f, rectInfo.Color.Alpha);
g.SetLineWidth(pw);
g.SetStrokeColor(rectBorderColor);
g.SetFillColor(rectInfo.Color);
g.SetLineJoin(CGLineJoin.Miter);
g.BeginPath();
g.StrokeRect(rectInfo.Rectangle);
int margin = 5;
// TODO: Make the font configurable
NSFont font = NSFont.FromFontName("Helvetica", 12f);
NSObject[] objects = new NSObject[] { font, (NSNumber)0 };
NSObject[] keys = new NSObject[] { NSAttributedString.FontAttributeName, NSAttributedString.LigatureAttributeName };
NSDictionary attributes = NSDictionary.FromObjectsAndKeys(objects, keys);
NSAttributedString attrString = new NSAttributedString(rectInfo.Name, attributes);
attrString.DrawString(new RectangleF(rectInfo.X + margin, rectInfo.Y + margin, rectInfo.Width - 2 * margin, rectInfo.Height - 2 * margin));
}
示例5: HatchSphere
/**
* This is fill of hackish stuff.
* Thought this was going to be easier but that just did not work out.
**/
protected void HatchSphere(CGContext context)
{
var hatchSize = getHatchWidth (hatchStyle);
var lineWidth = getLineWidth (hatchStyle);
initializeContext(context, hatchSize, false);
/* draw background in fore ground color*/
drawBackground (context, backColor, hatchSize, hatchSize);
context.SetStrokeColor(foreColor.ToCGColor());
context.SetFillColor(foreColor.ToCGColor());
context.SetLineWidth(1);
context.SetLineCap(CGLineCap.Square);
// Initialize work rectangle
CGRect rect = new CGRect (0,0,1,1);
float quad = hatchSize / 2.0f;
// Left lower quad
rect.Width = quad;
rect.Height = quad;
rect.X = 0;
rect.Y = 0;
context.StrokeRect(rect);
// right upper quad
rect.Width = quad;
rect.Height = quad;
rect.X = quad;
rect.Y = quad;
context.StrokeRect(rect);
// left upper quad
rect.Width = quad;
rect.Height = quad;
rect.X = 0;
rect.Y = quad + 1;
context.FillRect(rect);
// right lower quod
rect.Width = quad;
rect.Height = quad;
rect.X = quad + 1;
rect.Y = 0;
context.FillRect(rect);
// Now we fill in some corner bits with background
// This is a bad hack but now sure what else to do
context.SetFillColor(backColor.ToCGColor());
rect.Height = 1;
rect.Width = 1;
rect.X = 0;
rect.Y = 0;
setPixels (context, rect);
rect.X = 0;
rect.Y = quad;
setPixels(context, rect);
rect.X = 0;
rect.Y = quad;
setPixels(context, rect);
rect.X = quad;
rect.Y = 0;
setPixels(context, rect);
rect.X = quad;
rect.Y = quad;
setPixels(context, rect);
rect.X = quad;
rect.Y = hatchSize;
setPixels(context, rect);
rect.X = hatchSize;
rect.Y = 0;
setPixels(context, rect);
rect.X = hatchSize;
rect.Y = quad;
setPixels(context, rect);
rect.X = hatchSize;
rect.Y = hatchSize;
setPixels(context, rect);
//.........这里部分代码省略.........
示例6: HatchHorizontalBrick
void HatchHorizontalBrick(CGContext context)
{
var hatchWidth = getHatchWidth (hatchStyle);
var hatchHeight = getHatchHeight (hatchStyle);
var lineWidth = getLineWidth (hatchStyle);
initializeContext(context, hatchHeight, false);
/* draw background */
drawBackground (context, backColor, hatchWidth, hatchHeight);
/* draw lines in the foreground color */
context.SetFillColor(foreColor.ToCGColor());
/* draw lines in the foreground color */
context.SetStrokeColor(foreColor.ToCGColor());
context.SetLineWidth(lineWidth);
context.SetLineCap(CGLineCap.Square);
CGRect rect = new CGRect (0,0,1,1);
rect.Y = 3;
rect.Width = hatchWidth;
rect.Height = hatchHeight - 4;
context.StrokeRect(rect);
context.MoveTo(hatchWidth / 2.0f, 0);
context.AddLineToPoint(hatchWidth / 2.0f,3);
context.StrokePath();
}
示例7: DrawRectangle
private 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);
}