#include #include #include #include @interface Foo : NSObject +(void) draw; @end @implementation Foo +(void) draw { printf("%@ asked to draw\n",self); } @end void dump_reps(NSImage *img) { NSArray *reps=[img representations]; int i; for (i=0;i<[reps count];i++) { printf("rep %2i: %@\n",i,[reps objectAtIndex: i]); } printf("total: %3i representations\n",[reps count]); } int main(int argc, char **argv) { NSAutoreleasePool *arp=[NSAutoreleasePool new]; NSImage *i; NSCustomImageRep *customRep; [NSApplication sharedApplication]; i=[[NSImage alloc] init]; [i setSize: NSMakeSize(64,64)]; printf("\n* clean NSImage\n"); dump_reps(i); customRep=[[NSCustomImageRep alloc] initWithDrawSelector: @selector(draw) delegate: [Foo self]]; [i addRepresentation: customRep]; printf("\n* with custom image rep\n"); dump_reps(i); { NSImage *dummy=[[NSImage alloc] init]; [dummy setSize: NSMakeSize(64,64)]; [dummy lockFocus]; [i compositeToPoint: NSMakePoint(0,0) operation: NSCompositeSourceOver]; [dummy unlockFocus]; [dummy release]; } printf("\n* after drawing\n"); dump_reps(i); [arp release]; return 0; }