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

NSView subview backgrounds


  • Subject: NSView subview backgrounds
  • From: Twisted Theory Software <email@hidden>
  • Date: Mon, 1 Oct 2007 12:42:00 -0500

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.

I found a workaround, to fill the view with a background white before drawing the horizontal gradient paths. Unfortunately, when I add NSButtons with transparent backgrounds as subviews, they appear as white squares in the view. I've noticed that once I resize the window, so that the view redraws, the button appears correctly. However, after it is pressed and released, the white square reappears (the button is just a momentary-light button, so it should return to the initial state).

Adding a [statusView setNeedsDisplay:YES]; after adding the button fixes the problem initially, but a button press apparently doesn't mark the button's rect as dirty, and the white background reappears. Furthermore, if there are many buttons, you can see the buttons' backgrounds change in sequence when they are added and setNeedsDisplay is called. If I call setNeedsDisplay after adding all the buttons, you can see the incorrect background on each one briefly before they update.

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

- (void)drawRect:(NSRect)rect
{
    float steps = rect.size.height;

    [[NSColor whiteColor] set];
    [NSBezierPath fillRect:rect];

// 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];
}


    // draw a black line along the bottom.
    NSBezierPath *path = [NSBezierPath bezierPath];
    [[NSColor blackColor] setStroke];
    [path moveToPoint:NSMakePoint(0,rect.size.height)];
    [path lineToPoint:NSMakePoint(rect.size.width,rect.size.height)];
    [path setLineWidth:1.0];
    [path stroke];

}

Thanks in advance,

Josh
_______________________________________________

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: glenn andreas <email@hidden>
    • Re: NSView subview backgrounds
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: Distributed GUI
  • Next by Date: (no subject)
  • Previous by thread: Re: Best practice for Core Data "ordered" NSArray problem?
  • Next by thread: Re: NSView subview backgrounds
  • Index(es):
    • Date
    • Thread