NSView
s drawRect:
метод вызывается от вашего имени;Вы должны использовать его для своего чертежа, как описано в Содержимое чертежа .
@interface mapWindow : NSView {
@private
NSView* theMapWindow;
NSPoint drawPoint;
}
// - (void)drawRect:(int)pointx: (int)pointy;
@property (assign) IBOutlet NSView* theMapWindow;
@property (assign) NSPoint drawPoint;
@end
-
@implementation mapWindow
@synthesize theMapWindow, drawPoint;
- (void)mouseDown:(NSEvent *)event
{
NSPoint point = [event locationInWindow];
NSLog(@"[%@ %@] mouseDown location == %@",
NSStringFromClass([self class]),
NSStringFromSelector(_cmd),
NSStringFromPoint(point));
[self setDrawPoint:point];
[self setNeedsDisplay:YES];
//NSLog( @"mouseDown location: (%f,%f)", (float) point.x, (float) point.y);
//[self drawRect:point.x:point.y];
}
- (void)drawRect:(NSRect)frame {
NSLog(@"Drawing point at %@", NSStringFromPoint(drawPoint));
NSRect drawFrame = NSMakeRect(point.x, point.y, 128.0, 128.0);
[NSBezierPath setDefaultLineWidth:4];
[[NSColor whiteColor] set];
[NSBezierPath fillRect:drawFrame];
[[NSColor grayColor] set];
[NSBezierPath strokeRect:drawFrame];
}