本文整理汇总了C#中CGContext.DrawLayer方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.DrawLayer方法的具体用法?C# CGContext.DrawLayer怎么用?C# CGContext.DrawLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.DrawLayer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawFlag
protected void DrawFlag (CGContext context)
{
// declare vars
int i, j;
// general sizes
float flagWidth = imageView.Frame.Width * .8f;
float flagHeight = (float)(flagWidth / 1.9);
PointF flagOrigin = new PointF (imageView.Frame.Width * .1f, imageView.Frame.Height / 3);
// stripe
float stripeHeight = flagHeight / 13;
float stripeSpacing = stripeHeight * 2;
RectangleF stripeRect = new RectangleF (0, 0, flagWidth, stripeHeight);
// star field
float starFieldHeight = 7 * stripeHeight;
float starFieldWidth = flagWidth * (2f / 5f);
RectangleF starField = new RectangleF (flagOrigin.X, flagOrigin.Y + (6 * stripeHeight), starFieldWidth, starFieldHeight);
// stars
float starDiameter = flagHeight * 0.0616f;
float starHorizontalCenterSpacing = (starFieldWidth / 6);
float starHorizontalPadding = (starHorizontalCenterSpacing / 4);
float starVerticalCenterSpacing = (starFieldHeight / 5);
float starVerticalPadding = (starVerticalCenterSpacing / 4);
PointF firstStarOrigin = new PointF (flagOrigin.X + starHorizontalPadding, flagOrigin.Y + flagHeight - starVerticalPadding - (starVerticalCenterSpacing / 2));
PointF secondRowFirstStarOrigin = new PointF (firstStarOrigin.X + (starHorizontalCenterSpacing / 2), firstStarOrigin.Y - (starVerticalCenterSpacing / 2));
// white background + shadow
context.SaveState ();
context.SetShadow (new SizeF (15, -15), 7);
context.SetFillColor (1, 1, 1, 1);
context.FillRect (new RectangleF (flagOrigin.X, flagOrigin.Y, flagWidth, flagHeight));
context.RestoreState ();
// create a stripe layer
using (CGLayer stripeLayer = CGLayer.Create (context, stripeRect.Size)) {
// set red as the fill color
// this works
stripeLayer.Context.SetFillColor (1f, 0f, 0f, 1f);
// but this doesn't ????
//stripeLayer.Context.SetFillColor (new float[] { 1f, 0f, 0f, 1f });
// fill the stripe
stripeLayer.Context.FillRect (stripeRect);
// loop through the stripes and draw the layer
context.SaveState ();
for (i = 0; i < 7; i++) {
Console.WriteLine ("drawing stripe layer");
// draw the layer
context.DrawLayer (stripeLayer, flagOrigin);
// move the origin
context.TranslateCTM (0, stripeSpacing);
}
context.RestoreState ();
}
// draw the star field
//BUGBUG: apple bug - this only works on on-screen CGContext and CGLayer
//context.SetFillColor (new float[] { 0f, 0f, 0.329f, 1.0f });
context.SetFillColor (0f, 0f, 0.329f, 1.0f);
context.FillRect (starField);
// create the star layer
using (CGLayer starLayer = CGLayer.Create (context, starField.Size)) {
// draw the stars
DrawStar (starLayer.Context, starDiameter);
// 6-star rows
// save state so that as we translate (move the origin around,
// it goes back to normal when we restore)
context.SaveState ();
context.TranslateCTM (firstStarOrigin.X, firstStarOrigin.Y);
// loop through each row
for (j = 0; j < 5; j++) {
// each star in the row
for (i = 0; i < 6; i++) {
// draw the star, then move the origin to the right
context.DrawLayer (starLayer, new PointF (0f, 0f));
context.TranslateCTM (starHorizontalCenterSpacing, 0f);
}
// move the row down, and then back left
context.TranslateCTM ( (-i * starHorizontalCenterSpacing), -starVerticalCenterSpacing);
}
context.RestoreState ();
// 5-star rows
context.SaveState ();
context.TranslateCTM (secondRowFirstStarOrigin.X, secondRowFirstStarOrigin.Y);
// loop through each row
for (j = 0; j < 4; j++) {
// each star in the row
for (i = 0; i < 5; i++) {
//.........这里部分代码省略.........
示例2: DrawCoordinateSpace
/// <summary>
/// Draws our coordinate grid
/// </summary>
protected void DrawCoordinateSpace (CGContext context)
{
// declare vars
int remainder;
int textHeight = 20;
#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)
DrawTextAtPoint (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)
DrawCenteredTextAtPoint (context, xPos, 30, xPos.ToString (), textHeight);
}
// increment the position of the next tick
xPos += 20;
}
}
#endregion
// draw our "origin" text
DrawTextAtPoint (context, 20, (20 + (textHeight / 2)), "Origin (0,0)", textHeight);
}