Standard controls on top of NSGradients

  • I have a custom NSView subclass that contains an NSGradient. All this class does is draw a grey vertical gradient like iPhoto and iTunes do.

    When I place standard controls on top of one of my custom gradient views, when clicked, they also draw their rects with the same gradient - even though I don't include any code to do that. Do I need to lockFocus or some other aspect of CG on my custom view before I draw my gradient in my view's drawRect: method?

    Thanks,

    Chuck
  • On Apr 5, 2010, at 12:15 PM, Charles Burnstagger wrote:

    > When I place standard controls on top of one of my custom gradient views, when clicked, they also draw their rects with the same gradient - even though I don't include any code to do that. Do I need to lockFocus or some other aspect of CG on my custom view before I draw my gradient in my view's drawRect: method?

    What happens is when those controls redraw, some part of your view is invalidated, so you are asked to draw again. I suspect that when you draw, you are then using the rect parameter passed to -drawRect: to determine the extends of the gradient – which is incorrect.

    The rect parameter passed to -drawRect: is only a hint as to what parts of the view need to be redrawn. You should always do your drawing with respect to your view's bounds.
    --
    David Duncan
    Apple DTS Animation and Printing
  • Thanks.

    Changing to [ self.theGradient drawInRect:self.bounds angle:90.0 ];

    in drawRect:

    did the trick.

    Chuck

    ________________________________
    From: David Duncan <david.duncan...>
    To: Charles Burnstagger <burnstagger...>
    Cc: <cocoa-dev...>
    Sent: Mon, April 5, 2010 12:23:46 PM
    Subject: Re: Standard controls on top of NSGradients

    On Apr 5, 2010, at 12:15 PM, Charles Burnstagger wrote:

    > When I place standard controls on top of one of my custom gradient views, when clicked, they also draw their rects with the same gradient - even though I don't include any code to do that. Do I need to lockFocus or some other aspect of CG on my custom view before I draw my gradient in my view's drawRect: method?

    What happens is when those controls redraw, some part of your view is invalidated, so you are asked to draw again. I suspect that when you draw, you are then using the rect parameter passed to -drawRect: to determine the extends of the gradient – which is incorrect.

    The rect parameter passed to -drawRect: is only a hint as to what parts of the view need to be redrawn. You should always do your drawing with respect to your view's bounds.
    --
    David Duncan
    Apple DTS Animation and Printing
previous month april 2010 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today