I am trying to make a simple Cocoa program. I have a little black box (a subclass of NSView drawing an NSRect on screen) following my mouse around. That part I have working. What I need for it to do is: when I click the mouse I want to leave a "copy" of that black box behind.
I have been trying to get this to work for over five hours now and I have tried everything under the sun. I am sure that the solution is simple, my guess is that I am missing a grasping of the fundamental concepts.
Here is what I have (a "stay" is supposed to be the copy that stays behind):
@property NSMutableArray *stays;
...
- (void) makeStay {
if (!_stays)
_stays = [[NSMutableArray alloc]init];
NSValue *newStay = [NSValue valueWithRect:self.frame];
[_stays addObject:newStay];
}
...
-(void)drawRect:(NSRect)rect {
[[NSColor blackColor] set];
NSRectFill([self bounds]);
for (int x = 0; x < _stays.count; x++) {
NSRectFill([_stays[x] rectValue]);
}
}
Any help on how to understand the fundamentals of NSView so that this would work would be appreciated!