Re: Mouse Coalescing
Re: Mouse Coalescing
- Subject: Re: Mouse Coalescing
- From: "Michael Ash" <email@hidden>
- Date: Sun, 19 Oct 2008 22:54:49 -0400
On Sun, Oct 19, 2008 at 9:06 PM, Ian was here <email@hidden> wrote:
> I have a drawing application that uses a pen tool to do free style drawing. I am using Quartz in OS X 10.4 (NSBezierPath). The initial problem I had was not getting enough points between event cycles if the user moved the mouse too quickly. I turned off mouse coalescing with a call to SetMouseCoalescingEnabled( false, NULL ). This gave me beautiful drawing. Only problem is that it's slow and takes a while to catch up after the mouse up event.
>
> This is kind of an off the wall question, but is there another way to do this? I feel my only other option may be to use OPenGL, where the drawing would happen much faster.
As you hint, the problem is not mouse coalescing but performance.
OpenGL won't help with this, because your drawing performance is going
to be tied to the refresh rate of your monitor anyway.
So how do you fix it? Make your event handler run faster. But how can
you do that if you can't make drawing go faster? Easy: decouple mouse
event handling from drawing.
You'll want to disable coalescing as you have done. But then in the
event handler, you do *not* want to redraw every time you get a mouse
moved event. Doing so guarantees that once the rate of mouse-moved
events exceeds your monitor's refresh rate (or your ability to draw,
if it happens to be worse) then lag will develop.
Instead, do what I'd call "display coalescing". Don't redraw with
every event. Instead, have a drawing flag. When you get a mouse event
and the flag isn't set, set it and then post a custom event to the
event queue. Then when you receive that custom event, redraw. This
will essentially coalesce all the mouse moved events that were
received while drawing so that you stay up to date with them. You will
have to ensure that the non-drawing parts of your code always run
faster than mouse events come in, but that should be trivial if you're
just adding points to some sort of data structure.
Mike
_______________________________________________
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