Drawing in view on mouse click
Drawing in view on mouse click
- Subject: Drawing in view on mouse click
- From: geek <email@hidden>
- Date: Sun, 28 Jul 2002 16:09:43 -0400
Hello World.
Well, here's my question: I have an view which contain the board for a
simple board game and I want to print an image into the view everytime
a click is performed inside the view bounds. So far I have done this:
- (void)mouseDown:(NSEvent *)theEvent {
NSPoint loc = [self convertPoint:[theEvent locationInWindow]
fromView:[[self window] contentView]];
xCoord = loc.x
yCoord = loc.y;
[self setNeedsDisplay:YES];
}
- (float)getXPos {
return xCoord;
}
- (float)getYPos {
return yCoord;
}
-(void)drawRect:(NSRect)rect {
int i;
NSImage *pion = [[NSImage alloc]initByReferencingFile:@"xRed.png"];
[...] (code to display the board grid.
[pion compositeToPoint:NSMakePoint([self getXPos], [self getYPos])
operation:NSCompositeCopy];
[self setNeedsDisplay:YES];
}
People on IRC have pointed me to the compositeToPoint: thing and at
this time, nothing is working. The image isn't displaying on clicks.
Any suggestion to ad to this code?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.