public CGColor(CGColorSpace colorspace, CGPattern pattern, float [] components) { if (colorspace == null) { throw new ArgumentNullException("colorspace"); } if (colorspace.handle == IntPtr.Zero) { throw new ObjectDisposedException("colorspace"); } if (pattern == null) { throw new ArgumentNullException("pattern"); } if (components == null) { throw new ArgumentNullException("components"); } handle = CGColorCreateWithPattern(colorspace.handle, pattern.handle, components); if (handle == IntPtr.Zero) { throw new ArgumentException(); } }
public void SetStrokePattern(CGPattern pattern, float [] components) { if (components == null) { throw new ArgumentNullException("components"); } CGContextSetStrokePattern(handle, pattern.handle, components); }
static void DrawCallback(IntPtr voidptr, IntPtr cgcontextptr) { GCHandle gch = GCHandle.FromIntPtr(voidptr); CGPattern container = (CGPattern)gch.Target; CGContext ctx = null; if (cgcontextptr == container.last_cgcontext_ptr) { ctx = container.last_cgcontext.Target as CGContext; } if (ctx == null) { ctx = new CGContext(cgcontextptr); container.last_cgcontext = new WeakReference(ctx); container.last_cgcontext_ptr = cgcontextptr; } container.draw_pattern(ctx); }
void SetupPattern(CGContextBackend gc) { gc.Context.SetPatternPhase (new SizeF (0, 0)); if (gc.CurrentStatus.Pattern is GradientInfo) return; if (gc.CurrentStatus.Pattern is ImagePatternInfo) { var pi = (ImagePatternInfo) gc.CurrentStatus.Pattern; RectangleF bounds = new RectangleF (PointF.Empty, new SizeF (pi.Image.Size.Width, pi.Image.Size.Height)); var t = CGAffineTransform.Multiply (CGAffineTransform.MakeScale (1f, -1f), gc.Context.GetCTM ()); CGPattern pattern; if (pi.Image is CustomImage) { pattern = new CGPattern (bounds, t, bounds.Width, bounds.Height, CGPatternTiling.ConstantSpacing, true, c => { c.TranslateCTM (0, bounds.Height); c.ScaleCTM (1f, -1f); ((CustomImage)pi.Image).DrawInContext (c); }); } else { RectangleF empty = RectangleF.Empty; CGImage cgimg = ((NSImage)pi.Image).AsCGImage (ref empty, null, null); pattern = new CGPattern (bounds, CGAffineTransform.MakeScale (1f, -1f), bounds.Width, bounds.Height, CGPatternTiling.ConstantSpacing, true, c => c.DrawImage (bounds, cgimg)); } CGContext ctx = gc.Context; float[] alpha = new[] { 1.0f }; ctx.SetFillColorSpace (Util.PatternColorSpace); ctx.SetStrokeColorSpace (Util.PatternColorSpace); ctx.SetFillPattern (pattern, alpha); ctx.SetStrokePattern (pattern, alpha); } }
public void SetStrokePattern (CGPattern pattern, float [] components) { if (components == null) throw new ArgumentNullException ("components"); CGContextSetStrokePattern (handle, pattern.handle, components); }
// https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_patterns/dq_patterns.html#//apple_ref/doc/uid/TP30001066-CH206-TPXREF101 internal override void Setup(Graphics graphics, bool fill) { // if this is the same as the last that was set then return if (graphics.LastBrush == this) return; // obtain our width and height so we can set the pattern rectangle float hatch_width = getHatchWidth (hatchStyle); float hatch_height = getHatchHeight (hatchStyle); //choose the pattern to be filled based on the currentPattern selected var patternSpace = CGColorSpace.CreatePattern(null); graphics.context.SetFillColorSpace(patternSpace); patternSpace.Dispose(); // Pattern default work variables var patternRect = new RectangleF(HALF_PIXEL_X,HALF_PIXEL_Y,hatch_width+HALF_PIXEL_X,hatch_height+HALF_PIXEL_Y); var patternTransform = CGAffineTransform.MakeIdentity(); // Since all the patterns were developed with MonoMac on Mac OS the coordinate system is // defaulted to the lower left corner being 0,0 which means for MonoTouch and any view // that is flipped we need to flip it again. Yep should have thought about it to begin with // will look into changing it later if need be. #if MONOMAC if (graphics.isFlipped) patternTransform = new CGAffineTransform(1, 0, 0, -1, 0, hatch_height); #endif #if MONOTOUCH if (!graphics.isFlipped) patternTransform = new CGAffineTransform(1, 0, 0, -1, 0, hatch_height); #endif // DrawPattern callback which will be set depending on hatch style CGPattern.DrawPattern drawPattern; switch (hatchStyle) { case HatchStyle.Horizontal: case HatchStyle.LightHorizontal: case HatchStyle.NarrowHorizontal: case HatchStyle.DarkHorizontal: drawPattern = HatchHorizontal; break; case HatchStyle.Vertical: case HatchStyle.LightVertical: case HatchStyle.NarrowVertical: case HatchStyle.DarkVertical: patternTransform = CGAffineTransform.MakeRotation(90 * (float)Math.PI / 180); drawPattern = HatchHorizontal; break; case HatchStyle.ForwardDiagonal: case HatchStyle.LightDownwardDiagonal: case HatchStyle.DarkDownwardDiagonal: case HatchStyle.WideDownwardDiagonal: // We will flip the x-axis here patternTransform = CGAffineTransform.MakeScale(-1,1); drawPattern = HatchUpwardDiagonal; break; case HatchStyle.BackwardDiagonal: case HatchStyle.LightUpwardDiagonal: case HatchStyle.DarkUpwardDiagonal: case HatchStyle.WideUpwardDiagonal: drawPattern = HatchUpwardDiagonal; break; case HatchStyle.LargeGrid: case HatchStyle.SmallGrid: case HatchStyle.DottedGrid: drawPattern = HatchGrid; break; case HatchStyle.DiagonalCross: drawPattern = HatchDiagonalCross; break; case HatchStyle.Percent05: case HatchStyle.Percent10: case HatchStyle.Percent20: case HatchStyle.Percent25: case HatchStyle.Percent30: case HatchStyle.Percent40: case HatchStyle.Percent50: case HatchStyle.Percent60: case HatchStyle.Percent70: case HatchStyle.Percent75: case HatchStyle.Percent80: case HatchStyle.Percent90: drawPattern = HatchPercentage; break; case HatchStyle.Sphere: drawPattern = HatchSphere; break; case HatchStyle.DashedDownwardDiagonal: patternTransform = CGAffineTransform.MakeScale(-1,1); drawPattern = HatchDashedDiagonal; break; case HatchStyle.DashedUpwardDiagonal: drawPattern = HatchDashedDiagonal; break; case HatchStyle.DashedHorizontal: drawPattern = HatchDashedHorizontal; break; case HatchStyle.DashedVertical: patternTransform = CGAffineTransform.MakeRotation(-90 * (float)Math.PI / 180); drawPattern = HatchDashedHorizontal; break; case HatchStyle.LargeConfetti: case HatchStyle.SmallConfetti: drawPattern = HatchConfetti; break; case HatchStyle.ZigZag: drawPattern = HatchZigZag; break; case HatchStyle.Wave: drawPattern = HatchWave; break; case HatchStyle.HorizontalBrick: drawPattern = HatchHorizontalBrick; break; case HatchStyle.DiagonalBrick: drawPattern = HatchDiagonalBrick; break; // case HatchStyle.Weave: // drawPattern = HatchWeave; // break; case HatchStyle.Trellis: drawPattern = HatchTrellis; break; case HatchStyle.LargeCheckerBoard: case HatchStyle.SmallCheckerBoard: drawPattern = HatchCheckered; break; case HatchStyle.OutlinedDiamond: drawPattern = HatchOutlinedDiamond; break; case HatchStyle.SolidDiamond: drawPattern = HatchSolidDiamond; break; case HatchStyle.DottedDiamond: drawPattern = HatchDottedDiamond; break; case HatchStyle.Divot: drawPattern = HatchDivot; break; case HatchStyle.Shingle: drawPattern = HatchShingle; break; case HatchStyle.Plaid: drawPattern = HatchPlaid; break; default: drawPattern = DrawPolkaDotPattern; break; } //set the pattern as the Current Context’s fill pattern var pattern = new CGPattern(patternRect, patternTransform, hatch_width,hatch_height, CGPatternTiling.NoDistortion, true, drawPattern); //we dont need to set any color, as the pattern cell itself has chosen its own color graphics.context.SetFillPattern(pattern, new float[] { 1 }); graphics.LastBrush = this; // I am setting this to be used for Text coloring in DrawString graphics.lastBrushColor = foreColor; }
void SetPattern () { var t = this.transform; if (viewTransform != null) t.Multiply (viewTransform.Value); ClearPattern(); pattern = new CGPattern(new sd.RectangleF(0, 0, image.Width, image.Height), t, image.Width, image.Height, CGPatternTiling.ConstantSpacing, true, DrawPattern); }
private void ClearPattern() { if (pattern != null) pattern.Dispose(); pattern = null; }
public CGColor(CGColorSpace colorspace, CGPattern pattern, float [] components) { if (colorspace == null) throw new ArgumentNullException ("colorspace"); if (colorspace.handle == IntPtr.Zero) throw new ObjectDisposedException ("colorspace"); if (pattern == null) throw new ArgumentNullException ("pattern"); if (components == null) throw new ArgumentNullException ("components"); handle = CGColorCreateWithPattern (colorspace.handle, pattern.handle, components); if (handle == IntPtr.Zero) throw new ArgumentException (); }
void SetPattern () { sectionSize = new sd.SizeF((EndPoint.X - StartPoint.X) + 1, (EndPoint.Y - StartPoint.Y) + 1); if (Wrap == GradientWrapMode.Reflect) tileSize = new sd.SizeF(sectionSize.Width * 4, sectionSize.Height * 4); else tileSize = new sd.SizeF(sectionSize.Width * 2, sectionSize.Height * 2); var rect = new sd.RectangleF(StartPoint, tileSize); var t = this.transform; if (viewTransform != null) t.Multiply (viewTransform.Value); pattern = new CGPattern(rect, t, rect.Width, rect.Height, CGPatternTiling.ConstantSpacingMinimalDistortion, true, DrawPattern); }
internal override void Setup(Graphics graphics, bool fill) { // if this is the same as the last that was set then return and no changes have been made // then return. if (graphics.LastBrush == this && !changed) return; // obtain our width and height so we can set the pattern rectangle float textureWidth = textureImage.Width; float textureHeight = textureImage.Height; if (wrapMode == WrapMode.TileFlipX || wrapMode == WrapMode.TileFlipY) textureWidth *= 2; if (wrapMode == WrapMode.TileFlipXY) { textureWidth *= 2; textureHeight *= 2; } // this is here for testing only var textureOffset = new PointF(0,-0); //choose the pattern to be filled based on the currentPattern selected var patternSpace = CGColorSpace.CreatePattern(null); graphics.context.SetFillColorSpace(patternSpace); patternSpace.Dispose(); // Pattern default work variables var patternRect = new RectangleF(HALF_PIXEL_X,HALF_PIXEL_Y, textureWidth+HALF_PIXEL_X, textureHeight+HALF_PIXEL_Y); var patternTransform = CGAffineTransform.MakeIdentity(); // We need to take into account the orientation of the graphics object #if MONOMAC if (!graphics.isFlipped) patternTransform = new CGAffineTransform(1, 0, 0, -1, textureOffset.X, textureHeight + textureOffset.Y); #endif #if MONOTOUCH if (graphics.isFlipped) patternTransform = new CGAffineTransform(1, 0, 0, -1, textureOffset.X, textureHeight + textureOffset.Y); #endif patternTransform = CGAffineTransform.Multiply(patternTransform, textureTransform.transform); // DrawPattern callback which will be set depending on hatch style CGPattern.DrawPattern drawPattern; drawPattern = DrawTexture; //set the pattern as the Current Context’s fill pattern var pattern = new CGPattern(patternRect, patternTransform, textureWidth, textureHeight, //textureHeight, CGPatternTiling.NoDistortion, true, drawPattern); //we dont need to set any color, as the pattern cell itself has chosen its own color graphics.context.SetFillPattern(pattern, new float[] { 1 }); changed = false; graphics.LastBrush = this; // I am setting this to be used for Text coloring in DrawString //graphics.lastBrushColor = foreColor; }
void SetPattern() { var t = CGAffineTransform.Multiply(transform, viewTransform); ClearPattern(); pattern = new CGPattern(new sd.RectangleF(0, 0, image.Width, image.Height), t, image.Width, image.Height, CGPatternTiling.NoDistortion, true, DrawPattern); }
void SetPattern() { sectionSize = new sd.SizeF((EndPoint.X - StartPoint.X) + 1, (EndPoint.Y - StartPoint.Y) + 1); if (Wrap == GradientWrapMode.Reflect) tileSize = new sd.SizeF(sectionSize.Width * 4, sectionSize.Height * 4); else tileSize = new sd.SizeF(sectionSize.Width * 2, sectionSize.Height * 2); var rect = new sd.RectangleF(StartPoint, tileSize); var t = CGAffineTransform.Multiply(transform, viewTransform); pattern = new CGPattern(rect, t, rect.Width, rect.Height, CGPatternTiling.NoDistortion, true, DrawPattern); }