• 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
NSClipView leaves background artifacts when drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSClipView leaves background artifacts when drawing


  • Subject: NSClipView leaves background artifacts when drawing
  • From: Dave Fernandes <email@hidden>
  • Date: Sun, 11 Nov 2007 13:25:04 -0500

Hi All,
I'm having some trouble trying to draw a moving rectangle on a custom view contained inside an NSScrollView. The problem is that while the rectangle draws fine, there is always a 1 pixel border around the newly drawn area that is transparent, showing the NSClipView's background color. The transparent border is always 1 pixel, regardless of my scale set using scaleUnitSquareToSize.


The custom view drawing method, and the method to update the rectangle position are below. The setCursor method is called by an NSTimer callback.

I'm not even sure where to begin searching the archives for this one.

Dave


// Do the drawing.
- (void)drawRect:(NSRect)rect
{
[self lockFocus];
[NSGraphicsContext saveGraphicsState];
NSGraphicsContext* gContext = [NSGraphicsContext currentContext];
[[[self enclosingScrollView] contentView] setBackgroundColor: [NSColor yellowColor]];
[gContext setShouldAntialias:NO];
//[[NSGraphicsContext currentContext] setCompositingOperation:NSCompositeSourceOver];

// Erase the background.
[[NSColor whiteColor] set];
[NSBezierPath fillRect:rect];

// Draw the cursor.
if (drawCursor)
{
[[[NSColor greenColor] colorWithAlphaComponent:0.3] set];
[NSBezierPath fillRect:cursorRect];
}

[NSGraphicsContext restoreGraphicsState];
[self unlockFocus];
}


// Set the current cursor position.
- (void)setCursor:(float)leftEdge width:(float)width
{
	// Flag old cursor rect to be redrawn.
	if (drawCursor)
	{
		[self setNeedsDisplayInRect:cursorRect];
	}

	// Set location of new cursor.
	drawCursor = width > 0.;

	if (drawCursor)
	{
		cursorRect = [self bounds];
		float xSlope = [self bounds].size.width / [sound duration];

		cursorRect.origin.x = leftEdge * xSlope;
		cursorRect.size.width = width * xSlope;

		[self setNeedsDisplayInRect:cursorRect];
	}
}

_______________________________________________

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


  • Prev by Date: Re: Garbage Collection and NSNetService
  • Next by Date: SMS PDU encoding
  • Previous by thread: Re: Crash Reporter for Cocoa Application
  • Next by thread: SMS PDU encoding
  • Index(es):
    • Date
    • Thread