On 13 Sep 2008, at 1:29 am, Chinh Nguyen wrote:

My selection is several pixels behind my mouse as I'm dragging it when I use setNeedsDisplay:


This suggests you're handling the drag loop incorrectly. There's no reason this should be the case when using setNeedDisplay: - if you organise your code right, it will work fine, and no extra tricks like using your own tracking loop are needed.

Maybe you could show your code?

Normally, for dragging a selection rect I use the following basic approach:

1. On mouse down, make a note of the initial point in an ivar. This is the "anchor". 2. On mouse dragged, form a rect from two corner points, being the current mouse and the previously recorded anchor. Save this in an ivar. Invalidate that rect with setNeedsDisplayInRect:. 3. On drawRect:, use the rect calculated in (2) to draw the selection highlight as you wish. If you are using the rect to select objects, you can also pass it to other methods that find which objects it touches or encloses.

The above should keep up with the mouse with no noticeable lag. If your "detect selected objects" method is very slow it may stutter somewhat, but that's a different area for optimisation - the fundamental approach to dragging the box doesn't need to change.


hth,


Graham
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to