summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2013-08-25 20:34:38 +0100
committerAlex Merry <dev@randomguy3.me.uk>2013-08-25 20:34:38 +0100
commite707060efcf1cb751b7f1a0e26051bc6b93b123f (patch)
tree0a1c53e72f502f0c07be446b6795e3fe86963777
parent778d71f996a91273da7fa4625d0c66ceacb4cd63 (diff)
Recalculate edge properties when shapes are refreshed
Shape sizes can change (if you're actively editing a shape), which can mean that some edge properties need to be recalculated. We do this at the graph, rather than edge, level to avoid the overhead of installing a notification for every single edge.
-rw-r--r--tikzit/src/common/Edge.h5
-rw-r--r--tikzit/src/common/Edge.m4
-rw-r--r--tikzit/src/common/Graph.m20
3 files changed, 29 insertions, 0 deletions
diff --git a/tikzit/src/common/Edge.h b/tikzit/src/common/Edge.h
index 64da138..accf38c 100644
--- a/tikzit/src/common/Edge.h
+++ b/tikzit/src/common/Edge.h
@@ -274,6 +274,11 @@ typedef enum {
- (id)initWithSource:(Node*)s andTarget:(Node*)t;
/*!
+ @brief Force the recalculation of the derived properties.
+ */
+- (void)recalculateProperties;
+
+/*!
@brief Recompute the control points and midpoint.
*/
- (void)updateControls;
diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m
index ea20d2a..ba80aef 100644
--- a/tikzit/src/common/Edge.m
+++ b/tikzit/src/common/Edge.m
@@ -127,6 +127,10 @@
return NSMakePoint (pt.x + dx, pt.y + dy);
}
+- (void)recalculateProperties {
+ dirty = YES;
+}
+
- (void)updateControls {
// check for external modification to the node locations
if (src.x != [source point].x || src.y != [source point].y ||
diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m
index 33a81f6..258ece4 100644
--- a/tikzit/src/common/Graph.m
+++ b/tikzit/src/common/Graph.m
@@ -23,6 +23,11 @@
#import "Graph.h"
#import "TikzGraphAssembler.h"
+#import "Shape.h"
+
+@interface Graph (Private)
+- (void) shapeDictionaryReplaced:(NSNotification*)notification;
+@end
@implementation Graph
@@ -36,6 +41,11 @@
edges = [[NSMutableArray alloc] initWithCapacity:10];
inEdges = nil;
outEdges = nil;
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(shapeDictionaryReplaced:)
+ name:@"ShapeDictionaryReplaced"
+ object:[Shape class]];
}
return self;
}
@@ -56,6 +66,8 @@
}
- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
[graphLock lock];
[inEdges release];
[outEdges release];
@@ -837,4 +849,12 @@
@end
+@implementation Graph (Private)
+- (void) shapeDictionaryReplaced:(NSNotification*)notification {
+ for (Edge *e in edges) {
+ [e recalculateProperties];
+ }
+}
+@end
+
// vi:ft=objc:ts=4:noet:sts=4:sw=4