Re: Mouse Coalescing
Re: Mouse Coalescing
- Subject: Re: Mouse Coalescing
- From: Ian was here <email@hidden>
- Date: Thu, 23 Oct 2008 15:37:59 -0700 (PDT)
That seems to work well. I set a counter that decrements every time the mouseDragged: method is called. When the counter reaches zero, it draws the bezier path (as well as all the other objects in the view). Thanks.
--- On Sun, 10/19/08, Michael Ash <email@hidden> wrote:
> From: Michael Ash <email@hidden>
> Subject: Re: Mouse Coalescing
> To: "Cocoa Developers" <email@hidden>
> Date: Sunday, October 19, 2008, 7:54 PM
> 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
_______________________________________________
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