Inheritance: INativeObject, IDisposable
示例#1
0
		public CTFrame GetFrame (NSRange stringRange, CGPath path, CTFrameAttributes frameAttributes)
		{
			if (path == null)
				throw new ArgumentNullException ("path");
			var frame = CTFramesetterCreateFrame (Handle, stringRange, path.Handle,
					frameAttributes == null ? IntPtr.Zero : frameAttributes.Dictionary.Handle);
			if (frame == IntPtr.Zero)
				return null;
			return new CTFrame (frame, true);
		}
示例#2
0
        internal static CGPath CreateClippingPath(RectangleF rect, float radius)
        {
            var path = new CGPath();
            path.MoveToPoint(rect.GetMinX(), rect.GetMinY());
            path.AddLineToPoint(rect.GetMinX(), rect.GetMaxY() - radius);
            path.AddArcToPoint(rect.GetMinX(), rect.GetMaxY(), rect.GetMinX() + radius, rect.GetMaxY(), radius);
            path.AddLineToPoint(rect.GetMaxX() - radius, rect.GetMaxY());
            path.AddArcToPoint(rect.GetMaxX(), rect.GetMaxY(), rect.GetMaxX(), rect.GetMaxY() - radius, radius);
            path.AddLineToPoint(rect.GetMaxX(), rect.GetMinY());
            path.CloseSubpath();

            return path;
        }
示例#3
0
        public static CGPath ToCGPath(BasicPath path)
        {
            // TODO: We assume for now that only path lines can exist. 
            var linePoints = new List<PointF>();
            foreach (var item in path.Items)
            {
                if (item is BasicPathLine)
                {
                    var line = item as BasicPathLine;
                    linePoints.Add(ToPoint(line.PointA));
                    linePoints.Add(ToPoint(line.PointB));
                }
            }

            var cgPath = new CGPath();
            cgPath.AddLines(linePoints.ToArray());
            return cgPath;
        }
		private void FlyTheShirt(PointF startPoint)
		{
			// Reset starting point of the ImageView
			ivFlyingShirt.Frame = new RectangleF(startPoint.X, startPoint.Y, ivFlyingShirt.Frame.Width, ivFlyingShirt.Frame.Height);

			NSMatrix matrix = (NSMatrix)btnNavigationProducts.ControlView;
			int lastRowIndex = matrix.Rows - 1;
			// Assuming the shopping basket button is always the last in the list...
			var btnFrame = matrix.CellFrameAtRowColumn (lastRowIndex, 0);
			var btnCenter = new PointF (btnFrame.Left + (btnFrame.Width / 2), btnFrame.Top + (btnFrame.Height / 2));
			var btnCenterCompensated = new PointF (btnCenter.X - (ivFlyingShirt.Frame.Width / 2), btnCenter.Y + (ivFlyingShirt.Frame.Height / 2));
			var endPoint = matrix.ConvertPointToView (btnCenterCompensated, matrix.Superview);

			// Create quadratic curve path
			var path = new CGPath ();
			path.MoveToPoint (startPoint);
			// Use the view title label as the control point for the curve
			var controlPoint = lblViewTitle.Superview.ConvertPointToView(new PointF(lblViewTitle.Frame.Left + (lblViewTitle.Frame.Width/3), lblViewTitle.Frame.Bottom), null);
			path.AddQuadCurveToPoint (controlPoint.X, controlPoint.Y, endPoint.X, endPoint.Y);

			// Create animation based on the path and add it to the image view
			var pathAnimation = CAKeyFrameAnimation.GetFromKeyPath ("frameOrigin");
			pathAnimation.Path = path;
			pathAnimation.RepeatCount = 0f;
			pathAnimation.Duration = 0.7f;
			pathAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseInEaseOut);
			pathAnimation.AnimationStarted += delegate {
				// Show the ImageView
				ivFlyingShirt.Hidden = false;
			};
			pathAnimation.AnimationStopped += delegate {
				// Hide the ImageView
				ivFlyingShirt.Hidden = true;
				badgeView.BadgeNumber = WebService.Shared.CurrentOrder.Products.Count;
			};

			ivFlyingShirt.Animations = NSDictionary.FromObjectAndKey (pathAnimation, (NSString)"frameOrigin");

			// Change the frame location via animation
			((NSImageView) ivFlyingShirt.Animator).Frame = new RectangleF(endPoint, ivFlyingShirt.Frame.Size);
		}
示例#5
0
 public static void StrokePath(CGContext context, CGPath path, float pathWidth, CGColor color)
 {
     context.SaveState();
     context.SetLineWidth(pathWidth);
     context.SetStrokeColor(color);
     context.AddPath(path);
     context.StrokePath();
     context.RestoreState();
 }
示例#6
0
		static CTFrame CreateFrame (LayoutInfo li)
		{
			if (string.IsNullOrEmpty (li.Text))
				return null;

			using (CTFramesetter framesetter = new CTFramesetter (CreateAttributedString (li))) {
				CGPath path = new CGPath ();
				bool ellipsize = li.Width.HasValue && li.TextTrimming == TextTrimming.WordElipsis;
				path.AddRect (new RectangleF (0, 0, li.Width.HasValue && !ellipsize ? li.Width.Value : float.MaxValue, li.Height ?? float.MaxValue));

				return framesetter.GetFrame (new NSRange (0, li.Text.Length), path, null);
			}
		}
示例#7
0
		public void AddPath (CGPath path2)
		{
			if (path2 == null)
				throw new ArgumentNullException ("path2");
			CGPathAddPath (handle, IntPtr.Zero, path2.handle);
		}
        internal static void Draw(CGContext ctx, object layout, double x, double y)
        {
            LayoutInfo li = (LayoutInfo)layout;
            if (li.Framesetter == null)
                return;

            CGPath path = new CGPath ();
            path.AddRect (new RectangleF (0, 0, li.Width ?? float.MaxValue, li.Height ?? float.MaxValue));
            CTFrame frame = li.Framesetter.GetFrame (new NSRange (0, li.Text.Length), path, null);

            CTLine ellipsis = null;
            bool ellipsize = li.Width.HasValue && li.TextTrimming == TextTrimming.WordElipsis;
            if (ellipsize)
                ellipsis = new CTLine (CreateAttributedString (li, "..."));

            float lineHeight = layoutManager.DefaultLineHeightForFont (li.Font);

            ctx.SaveState ();
            ctx.TextMatrix = CGAffineTransform.MakeScale (1f, -1f);
            ctx.TranslateCTM ((float)x, (float)y + li.Font.Ascender);
            foreach (var line in frame.GetLines ()) {
                ctx.TextPosition = PointF.Empty;
                if (ellipsize) // we need to create a new CTLine here because the framesetter already truncated the text for the line
                    new CTLine (CreateAttributedString (li, li.Text.Substring (line.StringRange.Location)))
                        .GetTruncatedLine (li.Width.Value, CTLineTruncation.End, ellipsis).Draw (ctx);
                else
                    line.Draw (ctx);
                ctx.TranslateCTM (0, lineHeight);
            }
            ctx.RestoreState ();
        }
        private static float scale = 10000; //or 1 or 10 or 10000 etc for lesser or greater precision.

        #endregion Fields

        #region Constructors

        // An infinite region would cover the entire device region which is the same as
        // not having a clipping region. Note that this is not the same as having an
        // empty region, which when clipping to it has the effect of excluding the entire
        // device region.
        public Region()
        {
            // We set the default region to a very large
            regionObject = infinite;

            var path = RectangleToPath (infinite);
            solution.Add (path);

            regionList.Add (new RegionEntry (RegionType.Infinity, infinite, path));

            regionPath = new CGPath ();
            regionPath.MoveToPoint (infinite.Left, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Bottom);
            regionPath.AddLineToPoint (infinite.Left, infinite.Bottom);

            regionBounds = infinite;
        }
        //        public bool IsInfinite(Graphics g)
        //        {
        //        }
        public void MakeInfinite()
        {
            regionObject = infinite;

            var path = RectangleToPath (infinite);

            // clear out our containers.
            regionList.Clear ();
            solution.Clear ();

            solution.Add (path);
            regionList.Add (new RegionEntry (RegionType.Infinity, infinite, path));

            regionPath = new CGPath ();
            regionPath.MoveToPoint (infinite.Left, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Top);
            regionPath.AddLineToPoint (infinite.Right, infinite.Bottom);
            regionPath.AddLineToPoint (infinite.Left, infinite.Bottom);

            regionBounds = regionPath.BoundingBox;
        }
示例#11
0
		public CGPath (CGPath reference, CGAffineTransform transform)
		{
			if (reference == null)
				throw new ArgumentNullException ("reference");
			handle = CGPathCreateMutableCopyByTransformingPath (reference.Handle, ref transform);
		}
示例#12
0
        static CTFrame CreateFrame(LayoutInfo li)
        {
            if (string.IsNullOrEmpty (li.Text))
                return null;

            using (CTFramesetter framesetter = new CTFramesetter (CreateAttributedString (li))) {
                CGPath path = new CGPath ();
                path.AddRect (new RectangleF (0, 0, li.Width ?? float.MaxValue, li.Height ?? float.MaxValue));

                return framesetter.GetFrame (new NSRange (0, li.Text.Length), path, null);
            }
        }
        public override void DrawRect(System.Drawing.RectangleF dirtyRect)
        {
            base.DrawRect(dirtyRect);

            if(!IsPlaying)
                return;           

            // Save context state
            CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort;
            context.SaveState();

            // Calculate size
            float size = (Bounds.Width > Bounds.Height) ? Bounds.Height : Bounds.Width;
            float circleRadius = (size - 4) / 2;
            RectangleF rect = new RectangleF(padding / 2, padding / 2, size - padding, size - padding);

            CGColor color1 = GlobalTheme.PanelBackgroundColor1;
            CGColor color2 = GlobalTheme.PanelBackgroundColor2;
            CGGradient gradientBackground;
            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();            
            float[] locationListBackground = new float[] { 1.0f, 0.0f };
            List<float> colorListBackground = new List<float>();
            colorListBackground.AddRange(color1.Components);
            colorListBackground.AddRange(color2.Components);
            gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);

            // Create path
            CGPath path = new CGPath();
            float x = Bounds.Width / 2;
            float y = Bounds.Height / 2;
            path.AddArc(x, y, circleRadius, 0, 2 * (float)Math.PI, false);
            path.AddArc(x, y, circleRadius / 3, 0, 2 * (float)Math.PI, false);
            context.AddPath(path);

            // Draw outline
            context.SetLineWidth(1.5f);
            context.SetStrokeColor(GlobalTheme.PanelBorderColor);
            context.StrokePath();

            // Clip path and draw gradient inside
            context.AddPath(path);
            context.EOClip();
            context.DrawLinearGradient(gradientBackground, new PointF(0, 0), new PointF(0, Bounds.Height), CGGradientDrawingOptions.DrawsAfterEndLocation);

            context.RestoreState();
        }
示例#14
0
        private void DrawWindowBackgroundGradient(RectangleF drawingRect, CGPath clippingPath)
        {
            var window = (AppStoreWindow)Window;
            clippingPath.ApplyClippingPathInCurrentContext();
            if (window.IsTextured())
            {
                // If this is a textured window, we can draw the real background gradient and noise pattern
                var contentBorderThickness = window.TitleBarHeight;
                if (window.IsFullScreen())
                {
                    contentBorderThickness -= window.MinimumTitleBarHeight();
                }
                window.SetAutorecalculatesContentBorderThickness(false, NSRectEdge.MaxYEdge);
                window.SetContentBorderThickness(contentBorderThickness, NSRectEdge.MaxYEdge);
                NSGraphicsExtensions.DrawWindowBackground(drawingRect);
            }
            else
            {
                // Not textured, we have to fake the background gradient and noise pattern
                var drawsAsMainWindow = window.DrawsAsMainWindow();
                var startColor = drawsAsMainWindow ? window.TitleBarStartColor : window.InactiveTitleBarStartColor;
                var endColor = drawsAsMainWindow ? window.TitleBarEndColor : window.InactiveTitleBarEndColor;

                if (startColor == default(NSColor))
                    startColor = AppStoreWindow.DefaultTitleBarStartColor(drawsAsMainWindow);
                if (endColor == default(NSColor))
                    endColor = AppStoreWindow.DefaultTitleBarEndColor(drawsAsMainWindow);

                var context = NSGraphicsContext.CurrentContext.GraphicsPort;
                var gradient = DrawingHelper.CreateGraidentWithColors(startColor, endColor);
                context.DrawLinearGradient(gradient, new PointF(drawingRect.GetMidX(), drawingRect.GetMinY()), new PointF(drawingRect.GetMidX(), drawingRect.GetMaxY()), 0);

                if (drawsAsMainWindow)
                {
                    var noiseRect = new RectangleF(1.0f, 1.0f, drawingRect.Width, drawingRect.Height);

                    if (window.ShowBaselineSeparator)
                    {
                        var separatorHeight = BaselineSeparatorFrame.Height;
                        noiseRect.Y -= separatorHeight;
                        noiseRect.Height += separatorHeight;
                    }

                    NSGraphicsContext.CurrentContext.SaveGraphicsState();
                    var noiseClippingPath = DrawingHelper.CreateClippingPath(noiseRect, CORNER_CLIP_RADIUS);
                    context.AddPath(noiseClippingPath);
                    context.Clip();
                    DrawNoise(0.1f);
                    NSGraphicsContext.CurrentContext.RestoreGraphicsState();
                }
            }
            if (window.ShowBaselineSeparator)
            {
                DrawBaselineSeparator(BaselineSeparatorFrame);
            }
        }
        public Region(GraphicsPath path)
        {
            var clonePath = (GraphicsPath)path.Clone();
            regionObject = clonePath;
            regionPath = new CGPath ();

            PlotPath (clonePath);

            clonePath.Flatten ();
            var flatPath = PointFArrayToIntArray (clonePath.PathPoints, scale);
            solution.Add (flatPath);
            regionList.Add (new RegionEntry (RegionType.Path, clonePath, flatPath));
            regionBounds = regionPath.BoundingBox;
        }
示例#16
0
		public void Transform (IMatrix matrix)
		{
			if (transform == null)
				transform = matrix;
			else
				transform.Prepend (matrix);
			var path = new CGPath ();
			path.AddPath (matrix.ToCG (), Control);
			Control = path;
		}
        public void MakeEmpty()
        {
            regionObject = RectangleF.Empty;

            var path = RectangleToPath (RectangleF.Empty);

            // clear out our containers.
            regionList.Clear ();
            solution.Clear ();

            solution.Add (path);
            regionList.Add (new RegionEntry (RegionType.Empty, RectangleF.Empty, path));

            regionPath = new CGPath ();

            regionBounds = Rectangle.Empty;
        }
示例#18
0
		public GraphicsPathHandler ()
		{
			Control = new CGPath ();
		}
        void PathsToInternalPath(Paths paths)
        {
            regionPath = new CGPath ();

            foreach (var poly in solution)
            {
                regionPath.MoveToPoint(IntPointToPointF(poly[0]));

                for (var p =1; p < poly.Count; p++)
                {
                    regionPath.AddLineToPoint (IntPointToPointF (poly [p]));
                }
            }
        }
示例#20
0
		public GraphicsPathHandler(CGPath path)
		{
			Control = path;
		}
示例#21
0
 public void AddPath(CGPath path)
 {
     CGContextAddPath(handle, path.handle);
 }
        /// <summary>
        /// Draws a polygon. The polygon can have stroke and/or fill.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        /// <param name="dashArray">The dash array.</param>
        /// <param name="lineJoin">The line join type.</param>
        /// <param name="aliased">If set to <c>true</c> the shape will be aliased.</param>
        public override void DrawPolygon(IList<ScreenPoint> points, OxyColor fill, OxyColor stroke, double thickness, double[] dashArray, LineJoin lineJoin, bool aliased)
        {
            this.SetAlias (aliased);
            var convertedPoints = (aliased ? points.Select (p => p.ConvertAliased ()) : points.Select (p => p.Convert ())).ToArray ();
            if (fill.IsVisible ()) {
                this.SetFill (fill);
                using (var path = new CGPath ()) {
                    path.AddLines (convertedPoints);
                    path.CloseSubpath ();
                    this.gctx.AddPath (path);
                }

                this.gctx.DrawPath (CGPathDrawingMode.Fill);
            }

            if (stroke.IsVisible () && thickness > 0) {
                this.SetStroke (stroke, thickness, dashArray, lineJoin);

                using (var path = new CGPath ()) {
                    path.AddLines (convertedPoints);
                    path.CloseSubpath ();
                    this.gctx.AddPath (path);
                }

                this.gctx.DrawPath (CGPathDrawingMode.Stroke);
            }
        }
示例#23
0
		public void AddPath (CGAffineTransform t, CGPath path2)
		{
			if (path2 == null)
				throw new ArgumentNullException ("path2");
			CGPathAddPath (handle, ref t, path2.handle);
		}
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="stroke">The stroke color.</param>
        /// <param name="thickness">The stroke thickness.</param>
        public override void DrawRectangle(OxyRect rect, OxyColor fill, OxyColor stroke, double thickness)
        {
            this.SetAlias (true);
            var convertedRect = rect.ConvertAliased ();

            if (fill.IsVisible ()) {
                this.SetFill (fill);
                using (var path = new CGPath ()) {
                    path.AddRect (convertedRect);
                    this.gctx.AddPath (path);
                }

                this.gctx.DrawPath (CGPathDrawingMode.Fill);
            }

            if (stroke.IsVisible () && thickness > 0) {
                this.SetStroke (stroke, thickness);

                using (var path = new CGPath ()) {
                    path.AddRect (convertedRect);
                    this.gctx.AddPath (path);
                }

                this.gctx.DrawPath (CGPathDrawingMode.Stroke);
            }
        }
示例#25
0
		public CGPath (CGPath basePath)
		{
			if (basePath == null)
				throw new ArgumentNullException ("basePath");
			handle = CGPathCreateMutableCopy (basePath.handle);
		}
示例#26
0
		public void AddPath (CGPath path)
		{
			CGContextAddPath (handle, path.handle);
		}
示例#27
0
 public static void DrawLine(CGContext context, PointF[] points, float lineWidth, CGColor color)
 {
     context.SaveState();
     var path = new CGPath();
     path.AddLines(points);
     context.AddPath(path);
     context.SetLineWidth(lineWidth);
     context.SetStrokeColor(color);
     context.StrokePath();
     context.RestoreState();
 }
        public Region(RectangleF rect)
        {
            regionObject = rect;
            var path = RectangleToPath (rect);
            solution.Add (path);
            regionList.Add (new RegionEntry (RegionType.Rectangle, rect, path));
            regionPath = new CGPath ();
            regionPath.MoveToPoint (rect.Left, rect.Top);
            regionPath.AddLineToPoint (rect.Right, rect.Top);
            regionPath.AddLineToPoint (rect.Right, rect.Bottom);
            regionPath.AddLineToPoint (rect.Left, rect.Bottom);

            regionBounds = rect;
        }
示例#29
0
 public static void EOFillPath(CGContext context, CGPath path, CGColor color)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddPath(path);
     context.EOFillPath();
     context.RestoreState();
 }
示例#30
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            float padding = 4;
            CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort;

            if (RoundedRadius == 0)
            {
                if (!Enabled)
                    CoreGraphicsHelper.FillRect(context, Bounds, DisabledBackgroundColor);
                else if (_isMouseDown)
                    CoreGraphicsHelper.FillRect(context, Bounds, BackgroundMouseDownColor);
                else if (_isMouseOver)
                    CoreGraphicsHelper.FillRect(context, Bounds, BackgroundMouseOverColor);
                else
                    CoreGraphicsHelper.FillRect(context, Bounds, BackgroundColor);

                CoreGraphicsHelper.DrawRect(context, Bounds, BorderColor, 2);
            } 
            else
            {
                var roundedPath = NSBezierPath.FromRoundedRect(Bounds, RoundedRadius, RoundedRadius);
                NSColor nsColor = null;
                if(!Enabled)
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(DisabledBackgroundColor));
                else if (_isMouseDown)
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundMouseDownColor));
                else if (_isMouseOver)
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundMouseOverColor));
                else
                    nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundColor));
                nsColor.SetFill();
                roundedPath.Fill();
            }

            //CoreGraphicsHelper.DrawRect(context, Bounds, BorderColor, 2);
            RectangleF rectTextSize = CoreGraphicsHelper.MeasureString(Bounds.Size, Title, "Roboto", 11);
            RectangleF rectText;
            if (Image != null)
            {
                float xImage = ((Bounds.Width - rectTextSize.Width - (padding * 2) - Image.Size.Width) / 2);
                RectangleF rectImage = new RectangleF(xImage, (Bounds.Height - Image.Size.Height) / 2, Image.Size.Width, Image.Size.Height);
                Image.DrawInRect(rectImage, new RectangleF(0, 0, Image.Size.Width, Image.Size.Height), NSCompositingOperation.SourceOver, 1.0f);

                float xText = xImage + padding + Image.Size.Width + padding;
                rectText = new RectangleF(xText, (Bounds.Height - rectTextSize.Height) / 2, rectTextSize.Width, rectTextSize.Height);
            } 
            else
            {
                rectText = new RectangleF(padding * 2, ((Bounds.Height - rectTextSize.Height) / 2) - 2, rectTextSize.Width, rectTextSize.Height);
            }

            CoreGraphicsHelper.DrawText(rectText, 0, 0, Title, "Roboto", 11, NSColor.White);

            var triangleColor = new CGColor(0.8f, 0.8f, 0.8f);
            float trianglePadding = 8;
            float triangleWidth = 8;
            var path = new CGPath();
            path.MoveToPoint(new PointF(Bounds.Width - trianglePadding, trianglePadding));
            path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding - (triangleWidth / 2), Bounds.Height - trianglePadding));
            path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding - triangleWidth, trianglePadding));
            path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding, trianglePadding));

            CoreGraphicsHelper.StrokePath(context, path, 1, triangleColor);
            if(_isMouseOver)
                CoreGraphicsHelper.FillPath(context, path, triangleColor);
        }