RE: Dragging Around A NSScrollView
RE: Dragging Around A NSScrollView
- Subject: RE: Dragging Around A NSScrollView
- From: "Eric Huffman" <email@hidden>
- Date: Sun, 28 Mar 2004 15:52:59 -0600
I have a situation where I use an approach similar to that below.
However, I was wondering if anyone could describe the pros and cons of
using the "mouse-tracking-loop-within mouseDown:" vs. the
"save-state-for mouseDown: and mouseDragged:" approaches. Not being a
cocoa expert, I am never exactly sure which approach to take. The later
approach gives the app kit control over handling the various events,
timers, etc..., that occur during the drag and that seems generally like
a "good thing".
- Eric
>
> For the latter, in mouseDown: save the visible bounds ([self
>
> visibleBounds]) and the event location (locationInWindow). Then in
>
> mouseDragged: you create a new rectangle from the visible bounds,
>
> offsetting it with the distance between the location from mouseDown:
>
> and the current location -- then send [self
>
> scrollRectToVisible:newRect] to make the scrollbars move.
>
>
Jim sent me some code to handle the dragging and the cursor pretty
>
easily. The scrolling part was pretty darn simple:
>
>
>
- (void)mouseDragged:(NSEvent *)theEvent
>
{
>
[self scrollPoint:
>
NSMakePoint(startOrigin.x - ([theEvent locationInWindow].x -
>
startPt.x),
>
startOrigin.y - ([theEvent locationInWindow].y -
>
startPt.y))];
>
}
>
>
Thanks for the help.
>
>
>
>
Seth Willits
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.