Re: Modal event processing
Re: Modal event processing
- Subject: Re: Modal event processing
- From: Fritz Anderson <email@hidden>
- Date: Fri, 06 Jul 2012 15:47:08 -0500
On 6 Jul 2012, at 3:02 PM, Charlie Dickman wrote:
> In my view's drawRect method I use a global state variable that defines the next function to perform. When drawRect gets called I do what is necessary for the current state, set up for the next state, set the value for the next state and then return from drawRect. So the primary driving force is the periodic view update requirement (which is guaranteed by actions invoking [self setNeedsDisplay: YES]).
>
> Within the execution of a particular function I use NSTimers to drive the steps of that function ultimately exiting back to the dispatch stack in drawRect.
>
> So I am at a loss as how to better allow the system to do a better job of servicing menu clicks or keyboard presses.
Taking my cue from "exiting back to the dispatch stack in drawRect" — I don't have the earlier parts of the thread before me, so forgive me if I make the wrong guesses about your intention.
AppKit essentially requires that you use -drawRect: for drawing, and for no other processing at all. Otherwise you're turning your design inside-out ("fighting the framework"). Driving updates to state is the business of your controller layer (maybe the model), not the view layer.
The controller handles an NSTimer firing.
1) It sets properties in the view to configure how it will be drawn next, and calls -setNeedsDisplay:. The view draws. That's it.
OR
2) It updates the model layer. The model informs the controller through a notification or key-value observation that it has changed. The controller updates the view parameters, and calls -setNeedsDisplay:. The view draws. That's it.
OR
3) This is some sort of animation (a throb, for instance) that doesn't represent any model or controller state. Then the view might handle the timer, or use an NSAnimation, to update its own parameters, and call -setNeedsDisplay:. The view draws. That's it. Better: It uses Core Animation to do autonomous changes in rendering.
In all cases, the event mechanism coalesces all the needs-display calls into a periodic call to -drawRect:. In -drawRect:, the view draws itself and does nothing else. The controller and the model do all the processing.
And the event mechanism interleaves user events the whole time.
— F
_______________________________________________
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