Re: Need more NSLeftMouseDragged events
Re: Need more NSLeftMouseDragged events
- Subject: Re: Need more NSLeftMouseDragged events
- From: Sailor Quasar <email@hidden>
- Date: Mon, 12 Jan 2004 06:43:31 -0500
- Resent-date: Mon, 12 Jan 2004 07:51:39 -0500
- Resent-from: Sailor Quasar <email@hidden>
- Resent-message-id: <email@hidden t>
- Resent-to: email@hidden
On Monday, January 12, 2004, at 05:45 AM, M. Uli Kusterer 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.
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.
Given the points I tend to get with the drawing I do now, this would
present roughly the same effect as using a line tool rather than a
pencil tool. I don't think the event loop is a major bottleneck, though.
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.
That much I already do, at least, and this machine has Quartz Extreme,
so there's not much bottleneck as far as that's concerned.
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.
Mainly because I need QuickDraw operations to handle the extra backing
stores I need for this implementation. I've yet to find a CopyBits()
equivelant in CoreGraphics.
I've done some experimentation; switching to a tracking loop that only
handles the mouse events (plus a periodic stream to flush the drawing)
makes things a LOT better, as does writing to my backing store buffer
directly rather than using SetCPixel() wrapped by Get/SetGWorld() (gee,
what a surprise =). Adding a Bresenham to this should make it
sufficient, now I just have to dig up an implementation of it :).
-- Sailor Quasar, guardian of Leraz's memory
"A face of stone may hide a soul with the deepest Love of all"
Email: email@hidden
-- Sailor Quasar, just another player in The World
"Come with me in the twilight of the summer night for awhile"
Email: email@hidden
_______________________________________________
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.