• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Erasing drawn content
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Erasing drawn content


  • Subject: Re: Erasing drawn content
  • From: Matej Bukovinski <email@hidden>
  • Date: Wed, 9 Jun 2010 22:00:57 +0200

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 (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

  • Follow-Ups:
    • Re: Erasing drawn content
      • From: Quincey Morris <email@hidden>
References: 
 >Re: Erasing drawn content (From: "Paul Sanders" <email@hidden>)
 >Re: Erasing drawn content (From: Matej Bukovinski <email@hidden>)
 >Re: Erasing drawn content (From: Quincey Morris <email@hidden>)

  • Prev by Date: Problem opening large files into NSDocument
  • Next by Date: Question about scaling text within a subView
  • Previous by thread: Re: Erasing drawn content
  • Next by thread: Re: Erasing drawn content
  • Index(es):
    • Date
    • Thread