I have been struggling with creating custom cells to go in a matrix. I put up a prior thread, titled nsmatrix, that did a matrix of nstextfieldcells. I got it to work. Now I want to do the same thing, but replace the textfieldcells with custom cells. There is some sample code online. Everyone seems to create a nsimage, and use it to draw the custom cells. Below is the code I have tried for the custom cell.
I suspect the problem is here, where I doubt I have drawn the nsimage properly. All I want is a standard rectangle.
The code for the matrix part is similar to my prior post. I would appreciate any input. Thanks. Adam
Code:
#import "myCell.h"
@implementation myCell
-(id)init
{
if(![super init]) return nil;
return self;
}
- (void)drawInteriorWithFrame:(NSRect)theCellFrame inView:(NSView *)theControlView
{
NSRect anInsetRect = NSInsetRect(theCellFrame,5,5);
NSImage*myImage=[[NSImage alloc]initWithSize:NSMakeSize(150,150)];
[myImage lockFocus];
NSRect myRect=NSMakeRect(0,0,100,100);
[myImage unlockFocus];
NSRect myBox = NSMakeRect(anInsetRect.origin.x,
anInsetRect.origin.y,
anInsetRect.size.width*0.5,
anInsetRect.size.height*0.5);
[myImage drawInRect:myBox fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
@end
I suspect the problem is here, where I doubt I have drawn the nsimage properly. All I want is a standard rectangle.
Code:
[myImage lockFocus];
NSRect myRect=NSMakeRect(0,0,100,100);
[myImage unlockFocus];
The code for the matrix part is similar to my prior post. I would appreciate any input. Thanks. Adam