Yep that didi it. Thanks for proving me wrong Quincey. 

Here's a working solution:

// Overlay View

- (void)drawRect:(NSRect)drawRect {
        [NSGraphicsContext saveGraphicsState];
        // Draw all anotations, make sure _annotations is sorted front-to-back
        for (Annotation *a in _annotations) {
                [a draw:drawRect];
        }
        [NSGraphicsContext restoreGraphicsState];
}

// Annotation

- (void)draw:(NSRect)drawRect {
        
        NSRect nodeRect = [_node boundingBox];
        
        if (!NSIntersectsRect(nodeRect, drawRect)) {
                return; // nothing to draw
        }
        
        // Fill the background
        [[self annotationFillColor] set];
        [NSBezierPath fillRect:nodeRect];
        
        // Stroke the border
        [[self annotationStrokeColor] set];
        [NSBezierPath setDefaultLineWidth:2.0];
        [NSBezierPath strokeRect:nodeRect];
        
        // Draw the title
        [[self labelAttributedString] drawAtPoint:[self 
annotationLabelPositionFor:nodeRect]];
        
        // Clip
        NSBezierPath* clipPath = [NSBezierPath bezierPathWithRect:drawRect];
        [clipPath appendBezierPathWithRect:nodeRect];
        [clipPath setWindingRule:NSEvenOddWindingRule];
        [clipPath addClip];
}


> On Jun 9, 2010, at 11:06, Matej Bukovinski wrote:
> 
>> The clipping path approach doesn't really help. It turns out that you can 
>> only intersect the current clipping path (initially the view's bounds) with 
>> a new path and the intersected region is the region where drawing is 
>> visible. This means that when you're drawing a larger rectangle over a 
>> smaller one, you would need to set the clipping path to all areas NOT 
>> covered by the smaller rectangle. This is basically the same problem as 
>> calculating which parts of the larger rectangle to draw and just drawing 
>> there.
> 
> I think you can do it, but it just takes an extra step. For each overlay 
> (front to back):
> 
> 1. Intersect the rect for the current overlay with the "drawRect" (i.e. the 
> rect passed to drawRect:) producing the effective "tintRect".
> 
> 1a. If tintRect is empty, nothing to draw, so skip 2-4.
> 
> 2. Fill the tint rect with the appropriate color.
> 
> 3. Construct a new bezier compound-path object with one path from drawRect 
> (+[NSBezierPath bezierPathWithRect:]), plus a path from the tintRect 
> (-[NSBezierPath appendBezierPathWithRect:]). That essentially "inverts" the 
> tintRect within drawRect. Set the even-odd winding rule on the path, so that 
> you don't have to be concerned about subpath directions (although I believe 
> creating a compound path in the order I described will give correct results 
> with non-zero winding rule, too).
> 
> 4. Intersect this compound path with the current clipping path 
> (-[NSBezierPath addClip]).
> 
> Repeat for each overlay rect.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to