From 093e7a12524a3ddedd833df6c284025f1d0a4a8c Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Thu, 22 Aug 2013 17:19:40 +0100 Subject: Unset default "center" anchor when applying a style Edges almost always want to be anchored to the "center" of an unstyled (style=none) node, as otherwise edges won't join up. However, this anchor should be discarded if a style is then set on the node, otherwise arrowheads tend to disappear. --- tikzit/src/common/Edge.m | 35 +++++++++++++++++++++++++++++++++++ tikzit/src/common/Graph.m | 8 ++------ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'tikzit/src/common') diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m index 7b538b5..ea20d2a 100644 --- a/tikzit/src/common/Edge.m +++ b/tikzit/src/common/Edge.m @@ -325,6 +325,12 @@ [source removeObserver:self forKeyPath:@"style"]; + if ([s style] == nil) { + [self setSourceAnchor:@"center"]; + } else if ([sourceAnchor isEqual:@"center"]) { + [self setSourceAnchor:@""]; + } + [source release]; source = [s retain]; @@ -336,6 +342,7 @@ [source addObserver:self forKeyPath:@"style" options:NSKeyValueObservingOptionNew + | NSKeyValueObservingOptionOld context:NULL]; dirty = YES; @@ -348,6 +355,12 @@ [target removeObserver:self forKeyPath:@"style"]; + if ([t style] == nil) { + [self setTargetAnchor:@"center"]; + } else if ([targetAnchor isEqual:@"center"]) { + [self setTargetAnchor:@""]; + } + [target release]; target = [t retain]; @@ -359,6 +372,7 @@ [target addObserver:self forKeyPath:@"style" options:NSKeyValueObservingOptionNew + | NSKeyValueObservingOptionOld context:NULL]; dirty = YES; @@ -371,6 +385,27 @@ context:(void *)context { + if ([keyPath isEqual:@"style"]) { + id oldStyle = [change objectForKey:NSKeyValueChangeOldKey]; + id newStyle = [change objectForKey:NSKeyValueChangeNewKey]; + id none = [NSNull null]; + if (object == source) { + if (oldStyle != none && newStyle == none) { + [self setSourceAnchor:@"center"]; + } else if (oldStyle == none && newStyle != none && + [sourceAnchor isEqual:@"center"]) { + [self setSourceAnchor:@""]; + } + } + if (object == target) { + if (oldStyle != none && newStyle == none) { + [self setTargetAnchor:@"center"]; + } else if (oldStyle == none && newStyle != none && + [targetAnchor isEqual:@"center"]) { + [self setTargetAnchor:@""]; + } + } + } dirty = YES; } diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m index 2a01bae..33a81f6 100644 --- a/tikzit/src/common/Graph.m +++ b/tikzit/src/common/Graph.m @@ -736,17 +736,13 @@ NSString *srcAnchor; NSString *tgtAnchor; - if ([[e source] style] == nil) { - srcAnchor = @".center"; - } else if ([[e sourceAnchor] isEqual:@""]) { + if ([[e sourceAnchor] isEqual:@""]) { srcAnchor = @""; } else { srcAnchor = [NSString stringWithFormat:@".%@", [e sourceAnchor]]; } - if ([[e target] style] == nil) { - tgtAnchor = @".center"; - } else if ([[e targetAnchor] isEqual:@""]) { + if ([[e targetAnchor] isEqual:@""]) { tgtAnchor = @""; } else { tgtAnchor = [NSString stringWithFormat:@".%@", [e targetAnchor]]; -- cgit v1.2.3