NSSlider responding to superview's drawRect

2008-06-10 Thread Jonathan Dann

Hi All,

This is something that I haven't seen before. I have a custom view  
that inherits from NSView directly and just draws a gradient  
background. In IB I've placed an NSSlider on the view which works  
fine. The problem comes when drawRect in my custom view is invoked, I  
draw the gradient and a 1px line at the top of the view, but the line  
also gets draw just above the NSSlider! logging shows the following


1) resize window - drawRect is called and the line above the slider  
disappears
2) move slider - drawRect is called from my gradient view but with the  
frame of the slider. The line then appears.


Is this a known issue with NSSlider and a custom view or have I missed  
an idiosyncracy of NSControls.


Thanks in adavnce,

Jonathan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSSlider responding to superview's drawRect

2008-06-10 Thread Andy Lee
Check the code that draws the 1-pixel line.  It should be calculating  
coordinates of the line based on the view's bounds rectangle, not the  
rectangle that is passed to drawRect:.


--Andy

On Jun 10, 2008, at 11:51 AM, Jonathan Dann wrote:


Hi All,

This is something that I haven't seen before. I have a custom view  
that inherits from NSView directly and just draws a gradient  
background. In IB I've placed an NSSlider on the view which works  
fine. The problem comes when drawRect in my custom view is invoked,  
I draw the gradient and a 1px line at the top of the view, but the  
line also gets draw just above the NSSlider! logging shows the  
following


1) resize window - drawRect is called and the line above the slider  
disappears
2) move slider - drawRect is called from my gradient view but with  
the frame of the slider. The line then appears.


Is this a known issue with NSSlider and a custom view or have I  
missed an idiosyncracy of NSControls.


Thanks in adavnce,

Jonathan

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSSlider responding to superview's drawRect

2008-06-10 Thread Ken Ferry

You're probably filling your gradient into the rect passed in drawRect.

That rectangle just represents the dirty part of your view. If you had  
a solid color to draw, you could just fill the rect, but with a  
gradient you will get your gradient, top to bottom, within this  
possibly small rect within your view.


Try drawing the gradient into [self bounds] instead.  This describes  
the location of the entire view in its own coordinate system.


-Ken

On Jun 10, 2008, at 8:51 AM, Jonathan Dann <[EMAIL PROTECTED]> wrote:


Hi All,

This is something that I haven't seen before. I have a custom view  
that inherits from NSView directly and just draws a gradient  
background. In IB I've placed an NSSlider on the view which works  
fine. The problem comes when drawRect in my custom view is invoked,  
I draw the gradient and a 1px line at the top of the view, but the  
line also gets draw just above the NSSlider! logging shows the  
following


1) resize window - drawRect is called and the line above the slider  
disappears
2) move slider - drawRect is called from my gradient view but with  
the frame of the slider. The line then appears.


Is this a known issue with NSSlider and a custom view or have I  
missed an idiosyncracy of NSControls.


Thanks in adavnce,

Jonathan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com

This email sent to [EMAIL PROTECTED]

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSSlider responding to superview's drawRect

2008-06-10 Thread Jonathan Dann


On 10 Jun 2008, at 17:05, Ken Ferry wrote:

You're probably filling your gradient into the rect passed in  
drawRect.


That rectangle just represents the dirty part of your view. If you  
had a solid color to draw, you could just fill the rect, but with a  
gradient you will get your gradient, top to bottom, within this  
possibly small rect within your view.


Try drawing the gradient into [self bounds] instead.  This describes  
the location of the entire view in its own coordinate system.



On 10 Jun 2008, at 17:03, Andy Lee wrote:
Check the code that draws the 1-pixel line.  It should be  
calculating coordinates of the line based on the view's bounds  
rectangle, not the rectangle that is passed to drawRect:.


--Andy


Thanks to you both, you're absolutely correct!  Works like a charm now.

I'd like to be able to change the fill of my view depending on whether  
the application is active or not.  The only problem is -drawRect isn't  
called when the application becomes inactive, is there a notification  
I can register for?  In all my NSControl subclassing -drawRect is  
called on both become active and deactivating.


Thanks again for your help, that subtlety has never come to light  
until now.


Jonathan

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: NSSlider responding to superview's drawRect

2008-06-10 Thread Michael Watson
This is normally what I have to do as well, but is there a more  
optimized way to achieve the goal of drawing only the rect that needs  
redrawing?



--
m-s

On 10 Jun, 2008, at 12:05, Ken Ferry wrote:

You're probably filling your gradient into the rect passed in  
drawRect.


That rectangle just represents the dirty part of your view. If you  
had a solid color to draw, you could just fill the rect, but with a  
gradient you will get your gradient, top to bottom, within this  
possibly small rect within your view.


Try drawing the gradient into [self bounds] instead.  This describes  
the location of the entire view in its own coordinate system.


-Ken

On Jun 10, 2008, at 8:51 AM, Jonathan Dann <[EMAIL PROTECTED]> wrote:


Hi All,

This is something that I haven't seen before. I have a custom view  
that inherits from NSView directly and just draws a gradient  
background. In IB I've placed an NSSlider on the view which works  
fine. The problem comes when drawRect in my custom view is invoked,  
I draw the gradient and a 1px line at the top of the view, but the  
line also gets draw just above the NSSlider! logging shows the  
following


1) resize window - drawRect is called and the line above the slider  
disappears
2) move slider - drawRect is called from my gradient view but with  
the frame of the slider. The line then appears.


Is this a known issue with NSSlider and a custom view or have I  
missed an idiosyncracy of NSControls.


Thanks in adavnce,

Jonathan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/kenferry%40gmail.com

This email sent to [EMAIL PROTECTED]

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/mikey-san 
%40bungie.org


This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: NSSlider responding to superview's drawRect

2008-06-10 Thread Graham Cox
I don't think it's worth attempting. I *think* that gradients are  
cached in some way so trying to recalculate the gradient to span the  
update rect correctly is: a) going to need a fair bit of work to  
calculate and b) not allow caching to work efficiently. In any case,  
pixels that are clipped out shouldn't be being drawn anyway, so the  
performance gain is likely to be miniscule.


G.

On 11 Jun 2008, at 7:22 am, Michael Watson wrote:

This is normally what I have to do as well, but is there a more  
optimized way to achieve the goal of drawing only the rect that  
needs redrawing?



--
m-s

On 10 Jun, 2008, at 12:05, Ken Ferry wrote:

You're probably filling your gradient into the rect passed in  
drawRect.


That rectangle just represents the dirty part of your view. If you  
had a solid color to draw, you could just fill the rect, but with a  
gradient you will get your gradient, top to bottom, within this  
possibly small rect within your view.


Try drawing the gradient into [self bounds] instead.  This  
describes the location of the entire view in its own coordinate  
system.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]