The following code is supposed to draw a rectangle on the mapWindow NSView. There is another file for my program that uses the NSView window; hence why I want to have a new window. However, the rectangle does not display. Any help would be appreciated.
@interface mapWindow : NSView {@private NSView* theMapWindow;}
- (void)drawRect:(int)pointx: (int)pointy;
@property (assign) IBOutlet NSView* theMapWindow;
@end
@implementation mapWindow
@synthesize theMapWindow;
- (void)mouseDown:(NSEvent *)event
{
NSPoint point = [event locationInWindow];
//NSLog( @"mouseDown location: (%f,%f)", (float) point.x, (float) point.y);
[self drawRect:point.x:point.y];
}
- (void)drawRect:(int)pointx: (int)pointy
{
NSLog(@"Drawing point at (%d, %d)",pointx, pointy);
NSPoint origin = { pointx,pointy };
NSRect rect;
rect.origin = origin;
rect.size.width = 128;
rect.size.height = 128;
NSBezierPath * path;
path = [NSBezierPath bezierPathWithRect:rect];
[path setLineWidth:4];
[[NSColor whiteColor] set];
[path fill];
[[NSColor grayColor] set];
[path stroke];
[theMapWindow setNeedsDisplayInRect:rect];
}
NSView‘sdrawRect:method is called on your behalf; you should use it to your drawing, as described in Drawing View Content.—