|
MAC OS X Cocoa NSToolbar 的使用(2) #define START_LOCATION NSMakePoint(10,10)
- (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { sdSide = START_SIDE; sdLocation = START_LOCATION; } return self; }
- (void)mouseDown:(NSEvent *)theEvent { sdLocation = [self convertPoint: [theEvent locationInWindow] fromView: nil]; [self setNeedsDisplay: YES]; }
- (void)drawRect:(NSRect)rect { [[NSColor redColor] set]; [[NSBezierPath bezierPathWithRect: NSMakeRect(sdLocation.x, sdLocation.y, sdSide, sdSide)] fill];
[[NSColor blackColor] set]; [[NSBezierPath bezierPathWithRect: [self bounds]] stroke]; }
- (id)initWithCoder:(NSCoder *)coder { self = [super initWithCoder: coder]; if (self) { [coder decodeValuesOfObjCTypes: "fff", &sdSide, &sdLocation.x, &sdLocation.y]; } return self; }
- (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder: coder]; if (self) { [coder encodeValuesOfObjCTypes: "fff", &sdSide, &sdLocation.x, &sdLocation.y]; } }
@end
|