本文整理汇总了C#中CGContext.RestoreState方法的典型用法代码示例。如果您正苦于以下问题:C# CGContext.RestoreState方法的具体用法?C# CGContext.RestoreState怎么用?C# CGContext.RestoreState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGContext
的用法示例。
在下文中一共展示了CGContext.RestoreState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FillRect
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();
}
示例2: DrawEllipsis
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();
}
示例3: DrawLayer
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 ();
}
示例4: DrawStars
protected void DrawStars (CGContext context)
{
// HACK: Change SetRGBColor to SetFillColor
context.SetFillColor (1f, 0f, 0f, 1f);
// save state so that as we translate (move the origin around,
// it goes back to normal when we restore)
context.SetFillColor (0f, 0f, 0.329f, 1.0f);
context.SaveState ();
context.TranslateCTM (30, 300);
DrawStar (context, 30);
context.RestoreState ();
context.SetFillColor (1f, 0f, 0f, 1f);
context.SaveState ();
context.TranslateCTM (120, 200);
DrawStar (context, 30);
context.RestoreState ();
}
示例5: DrawContentView
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();
}
示例6: DrawLayer
public void DrawLayer(CALayer layer, CGContext context)
{
// fill with white background
context.SetFillColor (1f, 1f, 1f, 1f);
context.FillRect (Bounds);
context.SaveState ();
// flip page so we render it as it's meant to be read
context.TranslateCTM (0f, Bounds.Height);
context.ScaleCTM (1f, -1f);
// scale page at the view-zoom level
context.ScaleCTM (MyScale, MyScale);
context.DrawPDFPage (Page);
context.RestoreState ();
}
示例7: DrawContentView
public void DrawContentView(RectangleF rect, CGContext context, UITableViewElementCell cell)
{
context.SaveState();
var backgroundColor = CellBackgroundColor;
if (backgroundColor != null)
{
if (backgroundColor == UIColor.Clear)
backgroundColor = UIColor.White;
context.SetFillColorWithColor(backgroundColor.ColorWithAlpha(0.4f).CGColor);
context.SetBlendMode(CGBlendMode.Overlay);
context.FillRect(rect);
}
context.RestoreState();
}
示例8: MeasureStringWidth
// TODO: Cannot use NSAttributedString in iOS5, only iOS6+
// public static RectangleF MeasureString(SizeF sizeConstraint, string text, string fontName, float fontSize)
// {
// NSMutableDictionary dict = new NSMutableDictionary();
// dict.Add(NSAttributedString.FontAttributeName, NSFont.FromFontName(fontName, fontSize));
// NSString nsstr = new NSString(text);
// RectangleF rect = nsstr.BoundingRectWithSize(sizeConstraint, NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin, dict);
// return rect;
// }
public static float MeasureStringWidth(CGContext context, string text, string fontName, float fontSize)
{
if (string.IsNullOrEmpty(text))
return 0;
context.SaveState();
PointF pos = context.TextPosition;
context.SelectFont(fontName, fontSize, CGTextEncoding.MacRoman);
context.TextMatrix = CGAffineTransform.MakeScale(1.0f, -1.0f);
//context.TranslateCTM(0, 20);
context.ScaleCTM(1, -1);
context.SetTextDrawingMode(CGTextDrawingMode.Invisible);
context.ShowTextAtPoint(pos.X, pos.Y, text);
PointF pos2 = context.TextPosition;
context.RestoreState();
return pos2.X - pos.X;
}
示例9: DrawLayer
public override void DrawLayer (CALayer layer, CGContext context)
{
// keep a copy since (a) it's a _virtual_ property and (b) it could change between filling and flipping
RectangleF bounds = view.Bounds;
// fill with white background
context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect (bounds);
context.SaveState ();
// flip page so we render it as it's meant to be read
context.TranslateCTM (0.0f, bounds.Height);
context.ScaleCTM (1.0f, -1.0f);
// scale page at the view-zoom level
context.ScaleCTM (view.Scale, view.Scale);
context.DrawPDFPage (view.Page);
context.RestoreState ();
}
示例10: 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));
}
示例11: 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
);
}
}
}
示例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: FillEllipsis
public static void FillEllipsis(CGContext context, RectangleF rect, CGColor color)
{
context.SaveState();
context.SetFillColor(color);
context.FillEllipseInRect(rect);
context.FillPath();
context.RestoreState();
}
示例14: DrawTextInRect
public static SizeF DrawTextInRect(CGContext context, RectangleF rect, string text, string fontName, float fontSize, CGColor fontColor, UILineBreakMode breakMode, UITextAlignment alignment)
{
context.SaveState();
context.SetFillColor(fontColor);
NSString str = new NSString(text);
SizeF size = str.DrawString(rect, UIFont.FromName(fontName, fontSize), breakMode, alignment);
context.RestoreState();
return size;
}
示例15: DrawTextAtPoint
public static SizeF DrawTextAtPoint(CGContext context, PointF pt, string text, string fontName, float fontSize, CGColor fontColor)
{
context.SaveState();
context.SetFillColor(fontColor);
NSString str = new NSString(text);
SizeF size = str.DrawString(pt, UIFont.FromName(fontName, fontSize));
context.RestoreState();
return size;
}