summaryrefslogtreecommitdiff
path: root/tikzit/src/linux/Node+Render.m
diff options
context:
space:
mode:
authorrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-01-17 18:39:31 +0000
committerrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-01-17 18:39:31 +0000
commitf90dd4ffc4b679e61a2a8cf43853b7d3c72c3e83 (patch)
tree15842d8311e621dc2776a77c9740bd72784f13f1 /tikzit/src/linux/Node+Render.m
parent18871fdd7bbfb43eb0971ee358554f321f789eee (diff)
Calculate the head and tail of edges to be just where they contact the node (ie: behave more like tikz).
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@388 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'tikzit/src/linux/Node+Render.m')
-rw-r--r--tikzit/src/linux/Node+Render.m31
1 files changed, 23 insertions, 8 deletions
diff --git a/tikzit/src/linux/Node+Render.m b/tikzit/src/linux/Node+Render.m
index 7450dba..907d818 100644
--- a/tikzit/src/linux/Node+Render.m
+++ b/tikzit/src/linux/Node+Render.m
@@ -27,16 +27,31 @@
@implementation Node (Render)
+- (Shape*) shapeToRender {
+ if (style) {
+ return [Shape shapeForName:[style shapeName]];
+ } else {
+ return [Shape shapeForName:SHAPE_CIRCLE];
+ }
+}
+
- (Transformer*) shapeTransformerForSurface:(id<Surface>)surface {
return [self shapeTransformerFromTransformer:[surface transformer]];
}
-- (NSRect) boundsOnSurface:(id<Surface>)surface {
- return [self boundsUsingShapeTransform:[self shapeTransformerForSurface:surface]];
+- (NSRect) renderBoundsUsingShapeTransform:(Transformer*)shapeTrans {
+ float strokeThickness = style ? [style strokeThickness] : [NodeStyle defaultStrokeThickness];
+ NSRect screenBounds = [shapeTrans rectToScreen:[[self shapeToRender] boundingRect]];
+ screenBounds = NSInsetRect(screenBounds, -strokeThickness, -strokeThickness);
+ return screenBounds;
+}
+
+- (NSRect) renderBoundsForSurface:(id<Surface>)surface {
+ return [self renderBoundsUsingShapeTransform:[self shapeTransformerForSurface:surface]];
}
-- (NSRect) boundsWithLabelOnSurface:(id<Surface>)surface {
- NSRect nodeBounds = [self boundsOnSurface:surface];
+- (NSRect) renderBoundsWithLabelForSurface:(id<Surface>)surface {
+ NSRect nodeBounds = [self renderBoundsForSurface:surface];
NSRect labelRect = NSZeroRect;
if (![label isEqual:@""]) {
id<RenderContext> cr = [surface createRenderContext];
@@ -127,7 +142,7 @@
[context saveState];
- [[self shape] drawPathWithTransform:shapeTrans andContext:context];
+ [[self shapeToRender] drawPathWithTransform:shapeTrans andContext:context];
[context setLineWidth:strokeThickness];
if (!style) {
@@ -145,7 +160,7 @@
alpha = 0.25f;
RColor selectionColor = MakeSolidRColor(0.61f, 0.735f, 1.0f);
- [[self shape] drawPathWithTransform:shapeTrans andContext:context];
+ [[self shapeToRender] drawPathWithTransform:shapeTrans andContext:context];
[context strokePathWithColor:selectionColor andFillWithColor:selectionColor usingAlpha:alpha];
}
@@ -156,7 +171,7 @@
- (BOOL) hitByPoint:(NSPoint)p onSurface:(id<Surface>)surface {
Transformer *shapeTrans = [self shapeTransformerForSurface:surface];
- NSRect screenBounds = [self boundsUsingShapeTransform:shapeTrans];
+ NSRect screenBounds = [self renderBoundsUsingShapeTransform:shapeTrans];
if (!NSPointInRect(p, screenBounds)) {
return NO;
}
@@ -164,7 +179,7 @@
float strokeThickness = style ? [style strokeThickness] : [NodeStyle defaultStrokeThickness];
id<RenderContext> ctx = [surface createRenderContext];
[ctx setLineWidth:strokeThickness];
- [[self shape] drawPathWithTransform:shapeTrans andContext:ctx];
+ [[self shapeToRender] drawPathWithTransform:shapeTrans andContext:ctx];
return [ctx strokeIncludesPoint:p] || [ctx fillIncludesPoint:p];
}