NSView
Revision as of 21:11, 16 February 2005 by Stefan Urbanek (talk | contribs)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
NSView is ...
Code chunks
Dragging objects
Implement the mouseDown: method:
- (void)mouseDown:(NSEvent *)event { NSPoint oldPoint; NSEvent *presentEvent; NSEventType eventType = [event type]; unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask | NSLeftMouseDraggedMask; NSPoint point; float dx,dy; NSPoint location; point = [self convertPoint:[event locationInWindow] fromView:nil]; oldPoint = point; do { while (event && eventType != NSLeftMouseUp) { presentEvent = event; event = [NSApp nextEventMatchingMask: eventMask untilDate: [NSDate distantPast] inMode: NSEventTrackingRunLoopMode dequeue: YES]; eventType = [event type]; } point = [self convertPoint: [presentEvent locationInWindow] fromView: nil]; dx = point.x - oldPoint.x; dy = point.y - oldPoint.y; [self scrollRectToVisible:frame];
Add code here:
// // here move the dragged thing by: dx, dy // ....
Then finish the loop:
[self setNeedsDisplay:YES]; oldPoint = point; if (eventType == NSLeftMouseUp) { break; } event = [NSApp nextEventMatchingMask: eventMask untilDate: nil inMode: NSEventTrackingRunLoopMode dequeue: YES]; eventType = [event type]; } while (eventType != NSLeftMouseUp); [self setNeedsDisplay:YES]; }