// Initialize defaults public ArtboardXamarin() { artboardXamarinWidth = 80.000000; artboardXamarinHeight = 80.000000; artboardXamarinFillMode = ArtboardXamarinFillMode.ArtboardXamarinFit; Active = true; }
// // ArtboardXamarin // public void DrawArtboardXamarin(CGRect bounds, ArtboardXamarinFillMode fillMode) { CGContext context; // Get CGContext instance context = UIGraphics.GetCurrentContext(); // Affine Transform baseTransform = CoreGraphics.CGAffineTransform.CGAffineTransformInvert(context.GetUserSpaceToDeviceSpaceTransform()); // Save initial context state context.SaveState(); // Initialize and set new artboard size (scaled) newArtboardSize = GetNewArtboardSize(fillMode, new CGRect(0.0, 0.0, 80.000000, 80.000000), new CGRect(bounds.Left, bounds.Top, bounds.Width, bounds.Height)); context.TranslateCTM(newArtboardSize.X, newArtboardSize.Y); resizedScale = new CGSize(newArtboardSize.Width / 80.000000, newArtboardSize.Height / 80.000000); context.ScaleCTM(resizedScale.Width, resizedScale.Height); // Drawing procedures DrawShapeObjectLogo(context); // Restore initial context state context.RestoreState(); }
// // Resizing logic for ArtboardXamarin // private CGRect GetNewArtboardSize(ArtboardXamarinFillMode fillMode, CGRect sourceRect, CGRect targetRect) { CGSize scales = new CGSize(0, 0); CGSize sizeZero = new CGSize(0, 0); CGRect rectZero = new CGRect(0, 0, 0, 0); if (sourceRect == targetRect || targetRect == rectZero) { return(sourceRect); } else { scales = sizeZero; scales.Width = (nfloat)Math.Abs(targetRect.Width / sourceRect.Width); scales.Height = (nfloat)Math.Abs(targetRect.Height / sourceRect.Height); if (fillMode == ArtboardXamarinFillMode.ArtboardXamarinFit) { scales.Width = (nfloat)Math.Min(scales.Width, scales.Height); scales.Height = (nfloat)scales.Width; } else if (fillMode == ArtboardXamarinFillMode.ArtboardXamarinFill) { scales.Width = (nfloat)Math.Max(scales.Width, scales.Height); scales.Height = scales.Width; } else if (fillMode == ArtboardXamarinFillMode.ArtboardXamarinOriginal) { scales.Width = 1; scales.Height = 1; } if (sourceRect.Width < 0) { sourceRect.X = sourceRect.X + sourceRect.Width; sourceRect.Width = (nfloat)Math.Abs(sourceRect.Width); } if (sourceRect.Height < 0) { sourceRect.Y = sourceRect.Y + sourceRect.Height; sourceRect.Height = (nfloat)Math.Abs(sourceRect.Height); } nfloat newWidth = sourceRect.Width * scales.Width; nfloat newHeight = sourceRect.Height * scales.Height; nfloat newLeft = targetRect.X + (targetRect.Width - newWidth) / 2; nfloat newTop = targetRect.Y + (targetRect.Height - newHeight) / 2; return(new CGRect(newLeft, newTop, newWidth, newHeight)); } }