public override void MouseDown(NSEvent evnt) { NSPoint point = evnt.LocationInView(this); int index = this.IndexOfCircleAtPoint(point); if (index >= 0) { this.DragCircleAtIndexWithEvent((uint) index, evnt); } }
public void DragCircleAtIndexWithEvent(uint index, NSEvent evnt) { Circle circle = this.circles.ObjectAtIndex(index).CastTo<Circle>(); circle.Retain(); this.circles.RemoveObjectAtIndex(index); this.circles.AddObject(circle); circle.Release(); this.SetNeedsDisplayInRect(this.BoundsForCircle(circle)); NSEventMask mask = NSEventMask.NSLeftMouseDraggedMask | NSEventMask.NSLeftMouseUpMask; NSPoint start = evnt.LocationInView(this); while (true) { evnt = this.Window.NextEventMatchingMask(mask); if (evnt.Type == NSEventType.NSLeftMouseUp) { break; } this.SetNeedsDisplayInRect(this.BoundsForCircle(circle)); NSPoint center = circle.Center; NSPoint point = evnt.LocationInView(this); center.x += point.x - start.x; center.y += point.y - start.y; circle.Center = center; this.SetNeedsDisplayInRect(this.BoundsForCircle(circle)); start = point; } }