Пример #1
0
        public override void MouseDragged(NSEvent theEvent)
        {
            base.MouseDragged(theEvent);
            CGPoint down = mMouseDownEvent.LocationInWindow;
            CGPoint drag = theEvent.LocationInWindow;
            // Calculate the distance between this dragging position and the mouse down position
            double distance = Math.Sqrt(Math.Pow(down.X - drag.X, 2) + Math.Pow(down.Y - drag.Y, 2));

            // Don't do too often
            if (distance < 3)
            {
                return;
            }

            // And not if there is no string to drag
            if (mLetter.Length == 0)
            {
                return;
            }

            // Get the size of the string
            CGSize size = mLetter.StringSize(mTextAttributes);

            // Create the image that will be dragged
            NSImage anImage = new NSImage(size);

            // Create a rect in which you will draw the letter
            // in the image
            CGRect imageBounds = CGRect.Empty;

            imageBounds.Location = new CGPoint(0.0f, 0.0f);
            imageBounds.Size     = size;

            // Draw the letter on the image
            anImage.LockFocus();
            DrawStringCenteredInRectangle(mLetter, imageBounds);
            anImage.UnlockFocus();

            // Get the location of the mouse down event
            CGPoint p = this.ConvertPointFromView(down, null);

            // Drag from the center of theimage
            p = new CGPoint(p.X - size.Width / 2, p.Y - size.Height / 2);

            // Get the pasteboard
            NSPasteboard pb = NSPasteboard.FromName(NSPasteboard.NSDragPasteboardName);

            // Put the string and the pdf image in the pasteboard
            WriteToPasteBoard(pb);

            // Start the drag - deprecated, should use BeginDraggingSession, but need to wait for new Xam.Mac. Bug filed. #26941
            this.DragImage(anImage, p, CGSize.Empty, mMouseDownEvent, pb, this, true);
        }
Пример #2
0
        public void DragStart(TransferDataSource data, DragDropAction dragAction, object image, double xhot, double yhot)
        {
            var lo = RootWidget.ConvertPointToBase(new PointF(Widget.Bounds.X, Widget.Bounds.Y));

            lo = RootWidget.Window.ConvertBaseToScreen(lo);
            var ml = NSEvent.CurrentMouseLocation;
            var pb = NSPasteboard.FromName(NSPasteboard.NSDragPasteboardName);

            if (pb == null)
            {
                throw new InvalidOperationException("Could not get pasteboard");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            InitPasteboard(pb, data);
            var img = (NSImage)image;
            var pos = new PointF(ml.X - lo.X - (float)xhot, lo.Y - ml.Y - (float)yhot + img.Size.Height);

            Widget.DragImage(img, pos, new SizeF(0, 0), NSApplication.SharedApplication.CurrentEvent, pb, Widget, true);
        }
Пример #3
0
        public void DragStart(DragStartData sdata)
        {
            var lo = Widget.ConvertPointToBase(new PointF(Widget.Bounds.X, Widget.Bounds.Y));

            lo = Widget.Window.ConvertBaseToScreen(lo);
            var ml = NSEvent.CurrentMouseLocation;
            var pb = NSPasteboard.FromName(NSPasteboard.NSDragPasteboardName);

            if (pb == null)
            {
                throw new InvalidOperationException("Could not get pasteboard");
            }
            if (sdata.Data == null)
            {
                throw new ArgumentNullException("data");
            }
            InitPasteboard(pb, sdata.Data);
            var img = (NSImage)sdata.ImageBackend;
            var pos = new PointF(ml.X - lo.X - (float)sdata.HotX, lo.Y - ml.Y - (float)sdata.HotY + img.Size.Height);

            Widget.DragImage(img, pos, new SizeF(0, 0), NSApplication.SharedApplication.CurrentEvent, pb, Widget, true);
        }