Re: Problem adding a background NSImageView in a Cocoa View
Re: Problem adding a background NSImageView in a Cocoa View
- Subject: Re: Problem adding a background NSImageView in a Cocoa View
- From: Jorge Castellanos <email@hidden>
- Date: Thu, 29 Nov 2007 18:39:13 -0500
It appears that it has a WaveformViewDemoView as its main view, and
everything else is a
subview of this.
Yes, you could do thatt without writing custom code. In other words,
just set an NSImage view to cover all the background and then add all
other controls as subviews. The problem with this solution is that
managing and maintaining controls in IB becomes a bit tricky.
(2) you can still set a backdrop image if you override drawRect in
your topmost Cocoa view that contains all the sub views (in my example
this is drawRect in WaveformViewDemoView). I guess this is what Jorge
was getting at. I am using the following code (which isn't clean
because in a real app you wouldn't load the image everytime you need
to redraw but you get the idea):
Two comments:
a) An easier way of doing it is getting rid of the background custom
view in IB, and just set the "CustomView" of your window to be of the
class of your view that draws custom code. You can do this from IB.
Just select the window, switch to "outline view" and set the class of
the custom view to be of type "myBackgroundDrawerView".
This way is transparent and simple.
b) The code you wrote below works, but there is an easier and shorter
way to do it using Cocoa. In drawRect stick the following code:
// Load the image.
NSImage *anImage = [NSImage imageNamed:@"imageName"];
// Find the point at which to draw it.
NSPoint backgroundCenter;
backgroundCenter.x = [self bounds].size.width * 0.5;
backgroundCenter.y = [self bounds].size.height * 0.5;
NSPoint drawPoint = backgroundCenter;
drawPoint.x -= [anImage size].width * 0.5;
drawPoint.y -= [anImage size].height * 0.5;
// Draw it.
[anImage drawAtPoint:drawPoint fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
Hope this helps!
jorge castellanos
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden