#import #import @interface View : NSView { } @end @implementation View - (BOOL)isFlipped { return NO; } - (void) drawRect: (NSRect) rect { int i; [[NSColor blackColor] set]; PSsetlinewidth(1); for (i=0; i<250; i+=50) { PSmoveto(i,0); PSlineto(i,250); PSmoveto(0,i); PSlineto(250,i); } PSstroke(); } @end @interface FlippedView : View { } @end @implementation FlippedView - (BOOL)isFlipped { return YES; } @end @interface ArrowView : View { } @end @implementation ArrowView - (void)drawRect: (NSRect) r { [super drawRect:r]; [[NSColor blueColor] set]; PSsetlinewidth(3); PSmoveto(100, 00); PSlineto(120, 40); PSstroke(); [[NSColor redColor] set]; PSmoveto(120, 40); PSlineto(100, 30); PSstroke(); [[NSColor brownColor] set]; PSmoveto(100, 30); PSlineto(130, 00); PSstroke(); } @end @interface FlippedArrowView : ArrowView { } @end @implementation FlippedArrowView - (BOOL)isFlipped { return YES; } @end @interface matrixController : NSObject { NSWindow *win; NSView *v[6]; } @end @implementation matrixController - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSRect wf = {{100, 100}, {800, 550}}; NSRect bf = {{50, 50}, {200, 200}}; unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; int i, j; //NSLog(@"Starting the application\n"); win = [[NSWindow alloc] initWithContentRect:wf styleMask:style backing:NSBackingStoreRetained defer:NO]; //NSLog(@"Making the matrix\n"); v[0] = [[ArrowView alloc] initWithFrame: bf]; bf.origin.x += 250; v[1] = [[View alloc] initWithFrame: bf]; bf.origin.x += 250; v[2] = [[FlippedView alloc] initWithFrame: bf]; bf.origin.x -= 500; bf.origin.y += 250; v[3] = [[FlippedArrowView alloc] initWithFrame: bf]; bf.origin.x += 250; v[4] = [[View alloc] initWithFrame: bf]; bf.origin.x += 250; v[5] = [[FlippedView alloc] initWithFrame: bf]; [v[0] allocateGState]; [v[3] allocateGState]; for (i=0; i<6; i++) [[win contentView] addSubview: v[i]]; [win setTitle:@"NSMatrix Test"]; [win orderFront:nil]; [self performSelector:@selector(desenha:) withObject:self afterDelay:1.2]; } - (void)desenha:(id)x { [v[0] lockFocus]; [v[0] unlockFocus]; [v[0] lockFocus]; [[NSColor yellowColor] set]; PSsetlinewidth(1); PSmoveto(100, 100); PSlineto(120, 140); PSstroke(); [v[1] lockFocus]; [[NSColor yellowColor] set]; PSsetlinewidth(1); PSmoveto(120, 100); PSlineto(120, 140); PSstroke(); [[NSColor redColor] set]; PSmoveto(120, 140); PSlineto(100, 130); PSstroke(); [[NSColor brownColor] set]; PSmoveto(100, 130); PSlineto(130, 100); PSstroke(); NSCopyBits([v[0] gState], NSMakeRect(110, 10, 50, 50), NSMakePoint(50, 60)); [v[1] unlockFocus]; [v[2] lockFocus]; NSCopyBits([v[0] gState], NSMakeRect(110, 10, 50, 50), NSMakePoint(50, 60)); [v[2] unlockFocus]; [v[0] unlockFocus]; [v[3] lockFocus]; [v[4] lockFocus]; NSCopyBits([v[3] gState], NSMakeRect(110, 10, 50, 50), NSMakePoint(50, 60)); [v[4] unlockFocus]; [v[5] lockFocus]; NSCopyBits([v[3] gState], NSMakeRect(110, 10, 50, 50), NSMakePoint(50, 60)); [v[5] unlockFocus]; [v[3] unlockFocus]; [win flushWindow]; NSLog(@"%p %p %p %p %p %p", [v[0] gState], [v[1] gState], [v[2] gState], [v[3] gState], [v[4] gState], [v[5] gState]); } @end int main(int argc, char **argv, char** env) { id pool = [[NSAutoreleasePool alloc] init]; NSApplication *theApp; theApp = [NSApplication sharedApplication]; [theApp setDelegate: ([[matrixController alloc] init])]; [theApp run]; [pool release]; return 0; }