0
我已经让我认为是一个图像编辑器的完美开始。无论你点击什么,它都会绘制一个正方形。我的问题是,当你点击不同的地方,或拖动鼠标,它只是移动广场(而不是绘制另一个)。我怎样才能在自定义视图中绘制,而无需将其当前内容拖到任何地方?如何将自定义视图放入NSImageWell中?
这里是我的代码:
头(.h)
NSBezierPath *thePath;
NSColor *theColor;
NSTimer *updateTimer;
NSPoint *mousePoint;
int testInt = 1;
int x = 0;
int y = 0;
@interface test : NSView {
IBOutlet NSView *myView;
IBOutlet NSButton *button;
}
@property (readwrite) NSPoint mousePoint;
@end
.m文件(不管它是叫)
@implementation test
@synthesize mousePoint;
- (void) mouseDown:(NSEvent*)someEvent {
mousePoint = [someEvent locationInWindow];
NSLog(@"Location: x= %f, y = %f", (float)mousePoint.x, (float)mousePoint.y);
x = mousePoint.x;
y = mousePoint.y;
[button setHidden:TRUE];
[button setHidden:FALSE];
[self setNeedsDisplay:YES];
}
- (void) mouseDragged:(NSEvent *)someEvent {
mousePoint = [someEvent locationInWindow];
NSLog(@"Location: x= %f, y = %f", (float)mousePoint.x, (float)mousePoint.y);
x = mousePoint.x;
y = mousePoint.y;
[button setHidden:TRUE];
[button setHidden:FALSE];
[self setNeedsDisplay:YES];
}
- (void) drawRect:(NSRect)rect; {
thePath = [NSBezierPath bezierPathWithRect:NSMakeRect(x, y, 10, 10)];
theColor = [NSColor blackColor];
[theColor set];
[thePath fill];
}
@end
为什么不这项工作?
非常感谢。这听起来像它会工作 – Justin 2011-04-14 17:42:54
它完美的工作!非常感谢! – Justin 2011-04-15 13:48:58