Re: Some questions about the sketch example...
Re: Some questions about the sketch example...
- Subject: Re: Some questions about the sketch example...
- From: Erik Buck <email@hidden>
- Date: Sun, 16 Oct 2005 14:24:22 -0400
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:
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint windowLocation = [theEvent locationInWindow];
NSPoint location = [self convertPoint:windowLocation fromView:nil];
int clicks = [theEvent clickCount];
NSString *message = [NSString stringWithFormat:
@”Left Mouse Down: location (%f, %f), %d click%@, pressure %
0.2f, number %d\n”,
location.x, location.y, clicks, ((clicks > 1) ? @”s” : @””),
[theEvent pressure], [theEvent eventNumber]];
[[NSApp delegate] appendStringToConsole:message];
if (periodicFlag) {
BOOL repeating = YES;
[NSEvent startPeriodicEventsAfterDelay:2.0 withPeriod:0.5];
while (repeating) {
NSEvent *mouseUp = [NSApp
nextEventMatchingMask:NSLeftMouseUpMask
untilDate:nil inMode:NSEventTrackingRunLoopMode
dequeue:NO];
if (mouseUp) {
repeating = NO;
} else {
NSEvent *periodicEvent = [NSApp
nextEventMatchingMask:NSPeriodicMask
untilDate:nil
inMode:NSEventTrackingRunLoopMode
dequeue:YES];
NSString *message = [NSString stringWithFormat:
@”Periodic Event: number %d\n”,
[periodicEvent eventNumber]];
[[NSApp delegate] appendStringToConsole:message];
}
}
[NSEvent stopPeriodicEvents];
}
}
_______________________________________________
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