示例#1
0
        public override void MouseDown(NSEvent theEvent)
        {
            Element.Points.CollectionChanged -= OnPointsCollectionChanged;
            Element.Points.Clear();
            currentPath.RemoveAllPoints();

            previousPoint = theEvent.LocationInWindow;
            currentPath.MoveTo(previousPoint);

            InvokeOnMainThread(Layer !.SetNeedsDisplay);
            Element.Points.CollectionChanged += OnPointsCollectionChanged;
        }
示例#2
0
        public static XIR.Image RemoteRepresentation(this NSLineJoinStyle obj)
        {
            // Customize the line cap style for the new object.
            var aPath       = new NSBezierPath();
            var lineWidth   = 10;
            var sampleWidth = 50;

            // First we draw the presentation line
            aPath.LineWidth = lineWidth;
            aPath.MoveTo(new CGPoint(lineWidth, lineWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth / 2, sampleWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth, lineWidth));

            switch ((NSLineJoinStyle)obj)
            {
            case NSLineJoinStyle.Bevel:
                aPath.LineJoinStyle = NSLineJoinStyle.Bevel;
                break;

            case NSLineJoinStyle.Miter:
                aPath.LineJoinStyle = NSLineJoinStyle.Miter;
                break;

            case NSLineJoinStyle.Round:
                aPath.LineJoinStyle = NSLineJoinStyle.Round;
                break;
            }

            // let's make sure we leave a little room for the line width drawing as well by adding the lineWidth as well
            var width  = aPath.ControlPointBounds.Right + lineWidth;
            var height = aPath.ControlPointBounds.Bottom + lineWidth;

            var nsimage = new NSImage(new CGSize(width, height));

            nsimage.LockFocus();

            brush.Set();
            aPath.Stroke();

            // Second, we draw the inset line to demonstrate the bounds
            aPath.RemoveAllPoints();
            aPath.LineWidth = 2;
            aPath.MoveTo(new CGPoint(lineWidth, lineWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth / 2, sampleWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth, lineWidth));

            pen.Set();
            aPath.Stroke();

            nsimage.UnlockFocus();
            return(nsimage.RemoteRepresentation());
        }
        public override void MouseDown(NSEvent theEvent)
        {
            Element.Lines.CollectionChanged -= OnLinesCollectionChanged;
            if (!Element.MultiLineMode)
            {
                Element.Lines.Clear();
                currentPath.RemoveAllPoints();
            }

            previousPoint = theEvent.LocationInWindow;
            currentPath.MoveTo(previousPoint);
            currentLine = new Line
            {
                Points = new ObservableCollection <Point>
                {
                    new (previousPoint.X, previousPoint.Y)
                }
            };

            UpdateDisplay();
            Element.Lines.CollectionChanged += OnLinesCollectionChanged;
        }
示例#4
0
        public override void MouseDown(NSEvent theEvent)
        {
            Element.Lines.CollectionChanged -= OnLinesCollectionChanged;
            if (!Element.MultiLineMode)
            {
                Element.Lines.Clear();
                currentPath.RemoveAllPoints();
            }

            previousPoint = theEvent.LocationInWindow;
            currentPath.MoveTo(previousPoint);
            currentLine = new Line()
            {
                Points = new ObservableCollection <Point>()
                {
                    new Point(previousPoint.X, previousPoint.Y)
                }
            };

            InvokeOnMainThread(Layer !.SetNeedsDisplay);
            Element.Lines.CollectionChanged += OnLinesCollectionChanged;
        }
示例#5
0
        public override void DrawRect(CoreGraphics.CGRect dirtyRect)
        {
            mPath.RemoveAllPoints();
            CGRect bounds = this.Bounds;

            // Fill view with green
            NSColor.Green.Set();
            NSBezierPath.FillRect(bounds);
            NSColor.White.Set();
            foreach (Oval oval in Ovals)
            {
                mPath.AppendPathWithOvalInRect(oval.Rect);
            }
            mPath.Stroke();
        }
示例#6
0
        ObservableCollection <Point> SmoothedPathWithGranularity(ObservableCollection <Point> currentPoints,
                                                                 int granularity,
                                                                 ref NSBezierPath smoothedPath)
        {
            // not enough points to smooth effectively, so return the original path and points.
            if (currentPoints.Count < granularity + 2)
            {
                return(new ObservableCollection <Point>(currentPoints));
            }

            // create a new bezier path to hold the smoothed path.
            smoothedPath.RemoveAllPoints();
            var smoothedPoints = new ObservableCollection <Point>();

            // duplicate the first and last points as control points.
            currentPoints.Insert(0, currentPoints[0]);
            currentPoints.Add(currentPoints[^ 1]);
示例#7
0
        public static XIR.Image RemoteRepresentation(this NSLineCapStyle obj)
        {
            // Customize the line cap style for the new object.
            var aPath       = new NSBezierPath();
            var lineWidth   = 16;
            var sampleWidth = 100;

            // First we draw the presentation line
            aPath.LineWidth = lineWidth;
            aPath.MoveTo(new CGPoint(lineWidth, lineWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth, lineWidth));

            switch ((NSLineCapStyle)obj)
            {
            case NSLineCapStyle.Square:
                aPath.LineCapStyle = NSLineCapStyle.Square;
                break;

            case NSLineCapStyle.Butt:
                aPath.LineCapStyle = NSLineCapStyle.Butt;
                break;

            case NSLineCapStyle.Round:
                aPath.LineCapStyle = NSLineCapStyle.Round;
                break;
            }

            // let's make sure we leave a little room for the line width drawing as well by adding the lineWidth as well
            var width  = aPath.ControlPointBounds.Right + lineWidth;
            var height = aPath.ControlPointBounds.Bottom + lineWidth;

            var nsimage = new NSImage(new CGSize(width, height));

            nsimage.LockFocus();

            // We need to offset the image a little so it will not be cut off
            var transform = new NSAffineTransform();

            transform.Translate(aPath.LineWidth / 2, aPath.LineWidth / 2);
            aPath.TransformUsingAffineTransform(transform);

            brush.Set();
            aPath.Stroke();

            // Second, we draw the inset line to demonstrate the bounds
            aPath.RemoveAllPoints();
            lineWidth      += lineWidth / 2;
            aPath.LineWidth = 2;
            aPath.MoveTo(new CGPoint(lineWidth, lineWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth, lineWidth));

            pen.Set();
            aPath.Stroke();

            // Third, we draw the inset line endings which are two circles
            aPath.RemoveAllPoints();
            var circleWidth = 2;

            aPath.LineWidth    = circleWidth;
            aPath.LineCapStyle = NSLineCapStyle.Butt;
            aPath.AppendPathWithOvalInRect(new CGRect(lineWidth - (int)(circleWidth / 2), lineWidth - (int)(circleWidth / 2), circleWidth, circleWidth));
            aPath.AppendPathWithOvalInRect(new CGRect(lineWidth + sampleWidth - (int)(circleWidth / 2), lineWidth - (int)(circleWidth / 2), circleWidth, circleWidth));

            pen.Set();
            aPath.Stroke();
            nsimage.UnlockFocus();
            return(nsimage.RemoteRepresentation());
        }