The Shape of Everything
A website mostly about Mac stuff, written by Gus Mueller
» Acorn
» Twitter
» Maybe Pizza?
» Code
» Archive
November 30, 2009

I'll leave the implementation up to the reader, but I thought I'd share a little NSView subclass fun:

@interface TSAwesomeView : NSView {
- (void) addCursorRect:(NSRect)r cursor:(NSCursor*)c block:(void(^)(void))aBlock;
- (BOOL) executeCursorRectForPoint:(NSPoint)p;

And it's used like so:

[canvas addCursorRect:r
               cursor:[NSCursor moveKnobCursor]
    // your fancy code here

And finally, in the mouseDown: of our view subclass:

NSPoint pt = [self convertPoint:[theEvent locationInWindow] fromView:nil];
if ([self executeCursorRectForPoint:pt]) {

This way we can bypass looking through our model again, and finding what rect our point falls in, and then figure out what action to do based on that. The Acorn 2.2 betas have been using this for the shape handles, and it's been working pretty well. Just remember to do a little cleanup in - (void) discardCursorRects;