Re: clearing NSView outside of drawRect:
Re: clearing NSView outside of drawRect:
- Subject: Re: clearing NSView outside of drawRect:
- From: Graham Cox <email@hidden>
- Date: Sat, 13 Sep 2008 10:21:10 +1000
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 (email@hidden)
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:
This email sent to email@hidden