I am having trouble drawing to a view more than once. I want the following program to fill my view with white and then draw a black path from a given point (coordinates (100,100)) to the coordinates of a mouseDown event.
I have set up a custom view in IB that uses my class BADraw which is as follows:
BADraw.h:
BADraw.m:
IB information:
I dragged a custom view from the IB palette into my window and set it to use BADraw.
Output:
The output is a white rectangle filling the window. No paths appear when I click.
I'm obviously missing something basic here, but I don't know what. What do I need to do?
I have set up a custom view in IB that uses my class BADraw which is as follows:
BADraw.h:
Code:
#import <Cocoa/Cocoa.h>
@interface BADraw : NSView {}
@end
BADraw.m:
Code:
#import "BADraw.h"
@implementation BADraw
-(void)mouseDown:(NSEvent*)event{
NSPoint p;
p.x = 100;
p.y = 100;
NSBezierPath* path = [[NSBezierPath alloc] init];
[path moveToPoint:p];
[path setLineWidth:1.0];
[[NSColor blackColor] set];
[path lineToPoint:[event locationInWindow]];
[path stroke];
//I tried using the following methods to get the path to display:
[self lockFocus];
[self setNeedsDisplay:YES];
[self display];
[self unlockFocus];
[path release];
}
-(void)drawRect:(NSRect)rect{
[[NSColor whiteColor] set];
[NSBezierPath fillRect:[self bounds]];
}
@end
IB information:
I dragged a custom view from the IB palette into my window and set it to use BADraw.
Output:
The output is a white rectangle filling the window. No paths appear when I click.
I'm obviously missing something basic here, but I don't know what. What do I need to do?