• 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: NSView subview backgrounds
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSView subview backgrounds


  • Subject: Re: NSView subview backgrounds
  • From: glenn andreas <email@hidden>
  • Date: Mon, 1 Oct 2007 13:17:40 -0500


On Oct 1, 2007, at 12:42 PM, Twisted Theory Software wrote:

Hi,

I have an NSView subclass, which is getting a gradient background, drawn by NSBezierPaths. I found that even though I'm drawing the background using colours with alpha component equal to 1.0, their colour is being effected by the colour of the object underneath it (which is black). I can check that this is true by using the DigitalColor Meter application.

Could anyone suggest how to fix this? I've attached my subclass' drawRect method:

// draw the gradient by horizontal bezier paths
for (int i = 0; i < steps; i++)
{
NSColor *curColour = [NSColor colorByInterpolatingColor:initialColour
withColor:finalColour
basedOnProgress:i
outOfPossibleSteps:steps];
curColour = [curColour colorWithAlphaComponent:1.0];
NSBezierPath *path = [NSBezierPath bezierPath];
[curColour setStroke];
[path moveToPoint:NSMakePoint(0,i)];
[path lineToPoint:NSMakePoint(rect.size.width,i)];
[path setLineWidth:1.0];
[path stroke];
}

Since the line will be centered on the division between pixels, there will be 0.5 of a pixel drawn on each side (i.e., it will end up being blurred with the background).


The quick fix is to do:
[path moveToPoint:NSMakePoint(0,i+0.5)];
[path lineToPoint:NSMakePoint(rect.size.width,i+0.5)];

but the better fix is to use the lower level Quartz support for drawing gradients (which is much more efficient)


Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures, fractals, art



_______________________________________________

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: NSView subview backgrounds
      • From: Twisted Theory Software <email@hidden>
    • Re: NSView subview backgrounds
      • From: "I. Savant" <email@hidden>
References: 
 >NSView subview backgrounds (From: Twisted Theory Software <email@hidden>)

  • Prev by Date: Presenting NSLocalizedFailureReasonErrorKey
  • Next by Date: Re: NSView subview backgrounds
  • Previous by thread: Re: NSView subview backgrounds
  • Next by thread: Re: NSView subview backgrounds
  • Index(es):
    • Date
    • Thread