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