diff options
Diffstat (limited to 'tikzit/src/common/Node.m')
-rw-r--r-- | tikzit/src/common/Node.m | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tikzit/src/common/Node.m b/tikzit/src/common/Node.m index 3421325..8880826 100644 --- a/tikzit/src/common/Node.m +++ b/tikzit/src/common/Node.m @@ -23,6 +23,9 @@ #import "Node.h" +#import "Shape.h" +#import "ShapeNames.h" + @implementation Node @@ -41,6 +44,46 @@ return self; } +- (Shape*) shape { + if (style) { + return [Shape shapeForName:[style shapeName]]; + } else { + return [Shape shapeForName:SHAPE_CIRCLE]; + } +} + +- (Transformer*) shapeTransformerFromTransformer:(Transformer*)t { + // we take a copy to keep the reflection attributes + Transformer *transformer = [[t copy] autorelease]; + NSPoint screenPos = [t toScreen:point]; + [transformer setOrigin:screenPos]; + float scale = [t scale]; + if (style) { + scale *= [style scale]; + } + [transformer setScale:scale]; + return transformer; +} + +- (Transformer*) shapeTransformer { + float scale = 1.0f; + if (style) { + scale = [style scale]; + } + return [Transformer transformerWithOrigin:point andScale:scale]; +} + +- (NSRect) boundsUsingShapeTransform:(Transformer*)shapeTrans { + float strokeThickness = style ? [style strokeThickness] : [NodeStyle defaultStrokeThickness]; + NSRect screenBounds = [shapeTrans rectToScreen:[[self shape] boundingRect]]; + screenBounds = NSInsetRect(screenBounds, -strokeThickness, -strokeThickness); + return screenBounds; +} + +- (NSRect) boundingRect { + return [self boundsUsingShapeTransform:[self shapeTransformer]]; +} + - (BOOL)attachStyleFromTable:(NSArray*)styles { NSString *style_name = [[[data propertyForKey:@"style"] retain] autorelease]; |