// // SPDrawablePoint.m // SonoDraw // // Created by Brad Larson on 6/23/2008. // // This is a custom subclass of DKDrawableShape for the case in our system // where a single droplet needs to be dispensed #import "SPDrawablePoint.h" @implementation SPDrawablePoint #pragma mark - #pragma mark - as a NSObject + (BOOL) displaysSizeInfoWhenDragging; { return YES; } - (id) init { self = [super init]; if (self != nil) { [self setPathEditingMode:kGCPathCreateModeLineCreate]; mCenter = NSMakePoint(0,0); } return self; } - (id) copyWithZone:(NSZone*) zone { SPDrawablePoint* copy = [super copyWithZone:zone]; if( copy != nil ) { copy->mCenter = mCenter; } return copy; } - (void) calculatePath; { // Draws a spot in terms of a line with the same start and end points NSBezierPath* pointPath = [NSBezierPath bezierPath]; [pointPath moveToPoint:mCenter]; [pointPath lineToPoint:mCenter]; [self setPath:pointPath]; [self setNeedsDisplayInRect:[self bounds]]; } - (void) movePart:(int) pc toPoint:(NSPoint) mp constrainAngle:(BOOL) constrain { switch( pc ) { case kSPDrawablePointCenterPart: [self setCenter:mp]; break; default: break; } } #pragma mark - #pragma mark - as a DKDrawablePath - (void) drawControlPointsOfPath:(NSBezierPath*) path usingKnobs:(DKKnob*) knobs { #pragma unused(path) NSPoint kp; kp = [self pointForPartcode:kSPDrawablePointCenterPart]; [knobs drawKnobAtPoint:kp ofType:kDKBoundingRectKnobType userInfo:nil]; /* kp = [self pointForPartcode:kDKArcPathStartAnglePart]; [knobs drawKnobAtPoint:kp ofType:kDKBoundingRectKnobType angle:mStartAngle userInfo:nil]; kp = [self pointForPartcode:kDKArcPathEndAnglePart]; [knobs drawKnobAtPoint:kp ofType:kDKBoundingRectKnobType angle:mEndAngle userInfo:nil]; kp = [self pointForPartcode:kDKArcPathCentrePointPart]; [knobs drawKnobAtPoint:kp ofType:kDKCentreTargetKnobType userInfo:nil]; kp = [self pointForPartcode:kDKArcPathRotationKnobPart]; [knobs drawKnobAtPoint:kp ofType:kDKRotationKnobType userInfo:nil];*/ } // We override the line drawing method for creating the point just so we can stamp the point at a location - (void) lineCreateLoop:(NSPoint) initialPoint { // creates a single straight line path, with only one segment. There are two ways a user can make a line - click and release, // drag, then click. Or click-drag-release. // NSEvent* theEvent; // NSView* view = [[self layer] currentView]; NSPoint p, ip; p = ip = [self snappedMousePoint:initialPoint withControlFlag:NO]; NSLog(@"Placing point at (%f,%f)", p.x, p.y); [self setCenter:p]; [self setPathEditingMode:kGCPathCreateModeEditExisting]; [self notifyVisualChange]; // NSView* view = [[self layer] currentView]; // [view mouseUp:theEvent]; } #pragma mark - #pragma mark - as a DKDrawableObject - (int) hitSelectedPart:(NSPoint) pt forSnapDetection:(BOOL) snap { float tol = [[[self layer] knobs] controlKnobSize].width; if( snap ) tol *= 2; // int pc; // test for a hit in any of our knobs NSRect kr; NSPoint kp; kr.size = NSMakeSize( tol, tol ); kp = [self pointForPartcode:kSPDrawablePointCenterPart]; kr.origin = kp; kr = NSOffsetRect( kr, tol * -0.5f, tol * -0.5f ); if( NSPointInRect( pt, kr )) return kSPDrawablePointCenterPart; return kGCDrawingEntireObjectPart; } - (NSPoint) pointForPartcode:(int) pc { if (kSPDrawablePointCenterPart) return mCenter; else return NSZeroPoint; } - (NSPoint) location { return mCenter; } - (void) moveToPoint:(NSPoint) p { [self notifyVisualChange]; [self setCenter:p]; } #pragma mark - #pragma mark Accessors - (void) setCenter:(NSPoint)newCenter; { mCenter = newCenter; [self calculatePath]; } @end