Re: NSTableView and NSImageCell
Re: NSTableView and NSImageCell
- Subject: Re: NSTableView and NSImageCell
- From: Stéphane Sudre <email@hidden>
- Date: Mon, 12 Apr 2004 13:56:19 +0200
On lundi, avril 12, 2004, at 09:13 AM, David Dauer wrote:
Hello,
I want to draw a badge over and image that I load into my table. The
strange
thing is, that when I do [NSImageView setImage:myImageWithBadge];
(myimageBithBadge created in awakeFromNib) it displays the image WITH
badge
correctly. In my tableview datasource I use "return myImageWithBadge",
I
only get the image without the overlayed badge image.
The code:
@implementation NSImage (NSImageAdditions)
- (void)applyBadge:(NSImage *)badge withAlpha:(float)alpha
{
NSImage *badgeImage;
badgeImage = [[badge copy] autorelease];
[self lockFocus];
[[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
[badgeImage drawAtPoint:NSMakePoint([self size].width - [badgeImage
size].width,0)
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:alpha];
[self unlockFocus];
}
@end
- (void)awakeFromNib
{
tempImage = [[NSImage imageNamed:@"normalImage"] copy];
[tempImage applyBadge:[NSImage imageNamed:@"badge"]
withAlpha:0.75];
[theImageView setImage:tempImage];
}
Thanks for any suggestion
(coded in Mail.app)
Why don't you do something like this (remove the NSImage category):
+ (NSImage *) badgeImage:(NSImage *) inImage withBadge:(NSImage *)
inBadge withAlpha:(float) inAlpha
{
NSImage * nImage=nil;
if (inImage!=nil && inBadge!=nil)
{
NSRect tFrame;
NSRect tSize;
NSRect tBadgeFrame;
tSize=[inImage size];
nImage=[[NSImage alloc] initWithSize: tSize];
[nImage lockFocus];
tFrame.origin=NSZeroPoint;
tFrame.size=tSize;
[inImage drawAtPoint:NSZeroPoint
fromRect:tFrame
operation:NSCompositeSourceOver
fraction:1.0];
tFrame.origin=NSZeroPoint;
tFrame.size=[inBadge size];
[inBadge drawAtPoint:NSMakePoint(tSize.width - NSWidth(tFrame),0)
fromRect:tFrame
operation:NSCompositeSourceOver
fraction:inAlpha];
[nImage lockFocus];
}
return [nImage autorelease];
}
- (void)awakeFromNib
{
[theImageView setImage:[YourClass badgeImage:[NSImage
imageNamed:@"normalImage"]
withBadge: [NSImage imageNamed:@"badge"]
withAlpha:0.75]];
}
and if you want to have the same picture, retain it.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.