Compositing an image on a NSButtonCell subclass ?
Compositing an image on a NSButtonCell subclass ?
- Subject: Compositing an image on a NSButtonCell subclass ?
- From: Eric Morand <email@hidden>
- Date: Mon, 1 Aug 2005 13:09:24 +0200
Hi list !
I've a custom NSButton subclass (and its belonging custom
NSButtonCell subclass) and am trying to composite an image on the
drawWithFrame method of the cell.
The problem is that it is not working and I don't know what I am
doing wrong.
Here is my code :
#import <AppKit/AppKit.h>
@interface MainWindowTopMenuButton : NSButton
{
}
@end
#import "MainWindowTopMenuButton.h"
@implementation MainWindowTopMenuButton
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
NSArchiver * anArchiver = [[NSArchiver alloc]
initForWritingWithMutableData:[NSMutableData dataWithCapacity: 256]];
[anArchiver encodeClassName:@"NSButtonCell"
intoClassName:@"MainWindowTopMenuButtonCell"];
[anArchiver encodeRootObject:[self cell]];
[self setCell:[NSUnarchiver unarchiveObjectWithData:[anArchiver
archiverData]]];
return self;
}
@end
#import <AppKit/AppKit.h>
@interface MainWindowTopMenuButtonCell : NSButtonCell
{
}
@end
#import "MainWindowTopMenuButtonCell.h"
@implementation MainWindowTopMenuButtonCell
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSLog (@"drawWithFrame"); // OK !
NSImage * anImage = [NSImage imageNamed:@"HeaderButtonCell"];
[anImage compositeToPoint:cellFrame.origin
operation:NSCompositeSourceOver];
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
@end
Pretty straightforward, no ? Well, for some reason, the image doesn't
draw.
To instantiate such button, I put a button in IB, change its custom
class to MainWindowTopMenuButton and...that's all ! The drawWithFrame
method is called, I've checked this with the NSLog command. And the
image exists, of course (it doesn't work with other images anyway).
I'm pretty sure there is an obvious thing I am not doing correctly.
But for some reason, I just can't put my finger on it...
Thanks,
Eric.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden