Re: Problem adding a background NSImageView in a Cocoa View AU?
Re: Problem adding a background NSImageView in a Cocoa View AU?
- Subject: Re: Problem adding a background NSImageView in a Cocoa View AU?
- From: "tahome izwah" <email@hidden>
- Date: Thu, 29 Nov 2007 09:27:29 +0100
I've found a solution to my problem - it is rather clumsy but I wanted
to post it here in case someone else runs into the same issue:
(1) the view hierarchy in a Cocoa view Audio Unit effect doesn't
appear to be respected when the views are drawn. I guess this is a bug
in Leopard, possibly in Interface Builder but I can't be certain.
Maybe someone from Apple should investigate this. Or maybe I am just
entirely brain dead, I don't know :-)
(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):
CGImageRef LoadImageFromBundle(CFStringRef imageName, CFStringRef bundleId)
{
CGImageRef image = NULL;
CFBundleRef bundle = CFBundleGetBundleWithIdentifier( bundleId );
if (bundle == NULL) return NULL;
CFURLRef url = CFBundleCopyResourceURL(bundle, imageName, NULL, NULL);
if (url == NULL) return NULL;
CGDataProviderRef provider = CGDataProviderCreateWithURL(url);
image = CGImageCreateWithPNGDataProvider(provider, NULL, true,
kCGRenderingIntentDefault);
CGDataProviderRelease( provider );
CFRelease( url );
return image;
}
- (void) drawRect: (NSRect) rect
{
NSGraphicsContext *nsctx = [NSGraphicsContext currentContext];
CGContextRef context = (CGContextRef)[nsctx graphicsPort];
CGRect r = NSRectToCGRect([self bounds]);
// this is my image and bundle id, you need to change this
CGImageRef image = LoadImageFromBundle(CFSTR("128.png"),
CFSTR("com.apple.demo.audiounit.WaveformViewDemo"));
if (image != NULL)
{
CGRect dstRect = CGRectMake(0, 0, CGImageGetWidth(image),
CGImageGetHeight(image));
CGContextDrawImage(context, dstRect, image);
CGImageRelease(image);
} else NSLog(@"No image");
}
HTH,
--th
_______________________________________________
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