Re: Some questions about the sketch example...
Re: Some questions about the sketch example...
- Subject: Re: Some questions about the sketch example...
- From: Greg Titus <email@hidden>
- Date: Sun, 16 Oct 2005 12:44:37 -0700
On Oct 16, 2005, at 11:24 AM, Erik Buck wrote:
The Sketch.app example is a descendant of the Draw.app example
which used this hijacking the event loop techniques.
Hijacking the event loop is quite common in Cocoa applications in
part because NeXT and later Apple included examples and
documentation that hijack the event loop. In the past, NeXT
justified the behavior as a performance improvement.
Apple still recommends it: http://developer.apple.com/documentation/
Cocoa/Conceptual/BasicEventHandling/Tasks/HandlingMouseEvents.html
I have never (even on 25MHz systems) seen a noticeable performance
problem with using -mouseDragged: and -mouseUp:. I personally
strongly recommend NOT hijacking the event loop the way Apple
recommends. However, even "Cocoa Programming" includes an example
of this technique in Chapter 15:
I would not recommend doing this for performance.
I _would_ recommend doing this in some cases for code clarity. For
instance, if you have a Sketch-like view where a mouse down/drag/up
may be causing the movement of a graphic, or the resizing of a
graphic, or the creation of a new graphic, or a rotation of a
graphic, et cetera, depending upon tool selection or where you clicked.
If you use -mouseDown:/-mouseMoved:/-mouseUp: then you end up with a
lot of temporary state in instance variables and giant switch
statements to do different things on -mouseMoved:/-mouseUp: based on
the current action.
If you manually pull events out of the event loop, then you have
similar -mouseDown: code for determining what action is being taken,
but then you end up calling a -handleGraphicMove:/-
handleGraphicResize:/etc method that has its own event loop that
handles all the needed state locally to the method as you are
wiggling the mouse around.
The result is fewer variables "global" to the view class, and the
code for each type of activity is all in one place instead of being
split into multiple methods with switch cases.
- Greg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden