• 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: Unwanted artifacts when using controls in NSView subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unwanted artifacts when using controls in NSView subclass


  • Subject: Re: Unwanted artifacts when using controls in NSView subclass
  • From: email@hidden
  • Date: Tue, 04 Apr 2006 12:54:22 +0000

Thanks Paul.

It kind of suprises me that using [self bounds] really makes a difference.

Can you (or anyone else) explain or point to references that would explain why?

- Paul Heal

 -------------- Original message ----------------------
From: Paul Lynch <email@hidden>
> What happens if you use [self bounds] instead of rect in your first
> line?
>
> The Cocoa code sure seems a lot neater, doesn't it?
>
> Paul
>
> On 3 Apr 2006, at 21:45, email@hidden wrote:
>
> > Hi all,
> >
> > I'm playing with subclassing NSView to allow for some colored
> > backgrounds and borders around sections of my window. I'm
> > overriding the drawRect just as in most examples.
> >
> > However, I have a problem that if I place a button in my custom
> > view, then click the button in my running application my stroke and
> > fill color encompass the button afterwards.
> >
> > Here's the snippet I use to override my drawRect...
> >
> > - (void)drawRect:(NSRect)rect {
> > 	rect = NSInsetRect(rect,2.0,2.0);
> >        NSColor *bgColor = [NSColor colorWithDeviceRed:.5 green:0.5
> > blue:0.5 alpha:0.5];
> > 	NSColor *strokeColor = [NSColor colorWithDeviceRed:0.0 green:0.0
> > blue:0.0 alpha:1.0];
> > 	CGRect cgRect = CGRectMake
> > (rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
> > 	CGContextRef context = [[NSGraphicsContext currentContext]
> > graphicsPort];
> > 	CGContextSaveGState(context);
> >
> > 	CGContextSetFillColorWithColor(context,[bgColor
> > convertToCGColorRef]); //convertToCGColorRef is contained within a
> > category for NSColor.
> > 	CGContextSetStrokeColorWithColor(context,[strokeColor
> > convertToCGColorRef]);
> > 	CGContextSetLineWidth(context,2.0);
> > 	CGContextFillRect(context,cgRect);
> > 	CGContextStrokeRect(context,cgRect);
> >
> > 	CGContextRestoreGState(context);
> >
> > }
> >
> > I've also tried the Cocoa drawing way, without going to Quartz
> > engine directly...
> >
> > - (void)drawRect:(NSRect)rect {
> > 	rect = NSInsetRect(rect,2.0,2.0);
> >        NSColor *bgColor = [NSColor colorWithDeviceRed:.5 green:0.5
> > blue:0.5 alpha:0.5];
> > 	NSColor *strokeColor = [NSColor colorWithDeviceRed:0.0 green:0.0
> > blue:0.0 alpha:1.0];
> > 	NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect];
> > 	[path setLineWidth:2.0];
> > 	[bgColor setFill];
> > 	[strokeColor setStroke];
> > 	[path fill];
> > 	[path stroke];
> >
> > }
> >
> > Thanks in advance for any assistance.
> >
> > - Paul
> >  _______________________________________________
> > 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
> >
>


 _______________________________________________
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

  • Follow-Ups:
    • Re: Unwanted artifacts when using controls in NSView subclass
      • From: Paul Lynch <email@hidden>
  • Prev by Date: Robustness of CoreData against malicious documents?
  • Next by Date: Why does this code not create a colored dot?
  • Previous by thread: Re: Unwanted artifacts when using controls in NSView subclass
  • Next by thread: Re: Unwanted artifacts when using controls in NSView subclass
  • Index(es):
    • Date
    • Thread