Re: problem getting CALayer to draw an image

2018-04-05 Thread James Walker
Sorry about the mysterious blank posts.  Let's see if I can do it with 
plain text rather than HTML.



On 4/5/2018 11:05 AM, David Duncan wrote:
>> On Apr 5, 2018, at 10:53 AM, James Walker  
wrote:

>>
>> I have a generic NSView that contains some subviews, and I'd like to 
add a background image.  I tried code like this:

>>
>> NSImage* backgroundImage = [NSImage imageNamed: @"blueprint 
controls.png"];

>> CALayer* holderLayer = [CALayer layer];
>> _throttleHolder.layer = holderLayer;
>> _throttleHolder.wantsLayer = YES;
>> holderLayer.zPosition = 4.0f;
>> holderLayer.contents = backgroundImage;
>> holderLayer.hidden = NO;
>> holderLayer.bounds = NSRectToCGRect( _throttleHolder.bounds );
>> [holderLayer setNeedsDisplay];
> You don’t need to call -setNeedsDisplay here, and it may be what is 
destroying your content (when a layer displays, its stores the result of 
drawing in contents – you don’t want that since you are setting the 
contents directly).


Thank you (and also thanks to Rob Petrovec).  I think my first try 
didn't have that line, but when it didn't work, I started making 
desperate changes.  In my first attempt, I tried using the layer that 
the view already owned by virtue of being marked layer-backed in the 
nib, rather than adding my own layer.


For the record, I get correct results with just this:

NSImage* backgroundImage = [NSImage imageNamed: @"blueprint controls.png"];
_throttleHolder.layer = [CALayer layer];
_throttleHolder.layer.contents = backgroundImage;

___

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

This email sent to arch...@mail-archive.com


Re: problem getting CALayer to draw an image (repost)

2018-04-05 Thread James Walker

___

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

This email sent to arch...@mail-archive.com


Re: problem getting CALayer to draw an image

2018-04-05 Thread James Walker

___

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

This email sent to arch...@mail-archive.com


Re: problem getting CALayer to draw an image

2018-04-05 Thread James Walker

___

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

This email sent to arch...@mail-archive.com


Re: problem getting CALayer to draw an image

2018-04-05 Thread David Duncan

> On Apr 5, 2018, at 10:53 AM, James Walker  wrote:
> 
> I have a generic NSView that contains some subviews, and I'd like to add a 
> background image.  I tried code like this:
> 
> NSImage* backgroundImage = [NSImage imageNamed: @"blueprint controls.png"];
> CALayer* holderLayer = [CALayer layer];
> _throttleHolder.layer = holderLayer;
> _throttleHolder.wantsLayer = YES;
> holderLayer.zPosition = 4.0f;
> holderLayer.contents = backgroundImage;
> holderLayer.hidden = NO;
> holderLayer.bounds = NSRectToCGRect( _throttleHolder.bounds );
> [holderLayer setNeedsDisplay];

You don’t need to call -setNeedsDisplay here, and it may be what is destroying 
your content (when a layer displays, its stores the result of drawing in 
contents – you don’t want that since you are setting the contents directly).

Overall however, I think AppKit has an NSView method (something like 
updateLayer I think) that you want to override to do this. The layer’s geometry 
should already be set by AppKit and you should not modify it if I recall 
correctly. Geometry includes things such as center/bounds/frame and hidden.

> 
> But no background image shows up.  On the other hand, if I add the line
> 
> holderLayer.backgroundColor = CGColorGetConstantColor( kCGColorWhite );
> 
> then I get a white background, so apparently the layer is there and capable 
> of drawing.  And yes, I have made sure that backgroundImage is not nil.
> 
> At this point, it probably would have been quicker to just go ahead and 
> subclass NSView, but I'm curious about what dumb mistake I'm making.
> ___
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan

___

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

This email sent to arch...@mail-archive.com


Re: problem getting CALayer to draw an image

2018-04-05 Thread Rob Petrovec
If you take out the setNeedsDisplay it draws ok.

—Rob


> On Apr 5, 2018, at 11:53 AM, James Walker  wrote:
> 
> I have a generic NSView that contains some subviews, and I'd like to add a 
> background image.  I tried code like this:
> 
> NSImage* backgroundImage = [NSImage imageNamed: @"blueprint controls.png"];
> CALayer* holderLayer = [CALayer layer];
> _throttleHolder.layer = holderLayer;
> _throttleHolder.wantsLayer = YES;
> holderLayer.zPosition = 4.0f;
> holderLayer.contents = backgroundImage;
> holderLayer.hidden = NO;
> holderLayer.bounds = NSRectToCGRect( _throttleHolder.bounds );
> [holderLayer setNeedsDisplay];
> 
> But no background image shows up.  On the other hand, if I add the line
> 
> holderLayer.backgroundColor = CGColorGetConstantColor( kCGColorWhite );
> 
> then I get a white background, so apparently the layer is there and capable 
> of drawing.  And yes, I have made sure that backgroundImage is not nil.
> 
> At this point, it probably would have been quicker to just go ahead and 
> subclass NSView, but I'm curious about what dumb mistake I'm making.
> ___
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/petrock%40mac.com
> 
> This email sent to petr...@mac.com

___

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

This email sent to arch...@mail-archive.com


problem getting CALayer to draw an image

2018-04-05 Thread James Walker
I have a generic NSView that contains some subviews, and I'd like to add 
a background image.  I tried code like this:


NSImage* backgroundImage = [NSImage imageNamed: @"blueprint controls.png"];
CALayer* holderLayer = [CALayer layer];
_throttleHolder.layer = holderLayer;
_throttleHolder.wantsLayer = YES;
holderLayer.zPosition = 4.0f;
holderLayer.contents = backgroundImage;
holderLayer.hidden = NO;
holderLayer.bounds = NSRectToCGRect( _throttleHolder.bounds );
[holderLayer setNeedsDisplay];

But no background image shows up.  On the other hand, if I add the line

holderLayer.backgroundColor = CGColorGetConstantColor( kCGColorWhite );

then I get a white background, so apparently the layer is there and 
capable of drawing.  And yes, I have made sure that backgroundImage is 
not nil.


At this point, it probably would have been quicker to just go ahead and 
subclass NSView, but I'm curious about what dumb mistake I'm making.

___

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

This email sent to arch...@mail-archive.com