Re: Need more NSLeftMouseDragged events
Re: Need more NSLeftMouseDragged events
- Subject: Re: Need more NSLeftMouseDragged events
- From: "M. Uli Kusterer" <email@hidden>
- Date: Mon, 12 Jan 2004 11:45:21 +0100
At 5:06 Uhr -0500 12.01.2004, Sailor Quasar wrote:
I'm implementing a "pencil" tool for a painting surface using a
subclass of NSQuickDrawView. I respond to NSLeftMouseDragged by
setting a pixel for the current event, which is the simple way.
Unfortunately, this tends to result in a bunch of single pixels on
my surface, rather than a connected series, since the faster the
mouse moves, the less drag events I get per area of screen.
Hi Sailor!
what I did in my app was to use a Bresenham line drawing algorithm
to draw more brush blotches between the two mouse positions I got.
If you want continuous drawing, I'd definitely suggest you do the
same.
This will of course only slightly alleviate your problem, as on
slower Macs, you will sort of get a polygon instead of a smooth line.
If that is the problem for what you're doing, a loop that fetches the
events using the appropriate NSApplication methods would definitely
be a practicable idea, though in my case it wasn't really necessary.
However, THE NUMBER ONE SLOWDOWN I've found on MacOS X, is drawing
too much. Drawing is one of the slowest operations on OS X (at least
pre-Quartz-Extreme), and if you keep redrawing the entire view when
the user draws a short line in it, that will definitely lead to a
slowdown. Use setNeedsRedrawInRect: or whatever the method is called
to only redraw the part that's actually changed.
Finally, I'm wondering why you're using an NSQuickdrawView. Just use
an NSImage to do you drawing in, and create your own custom view that
draws it, performs hit-testing etc. (NSImageView on various occasions
redraws the entire image where you wouldn't want it to happen, so
don't subclass that). You'll get the nice smooth Quartz drawing for
free.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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.