summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <alex.merry@cs.ox.ac.uk>2013-02-12 16:08:59 +0000
committerAlex Merry <alex.merry@cs.ox.ac.uk>2013-02-12 16:21:47 +0000
commit0a7223674204a6e8ee311e226b2b5ddef88803a3 (patch)
tree0c93ec903531c5b2eee065ca36e621ecd782610a
parent904fa7d389b98a3ce7735f2979652be43f28ee2a (diff)
Make sure edge bounds include decorations
Fixes rendering of newly-drawn edges in GTK+ version.
-rw-r--r--tikzit/src/common/Edge.m22
-rw-r--r--tikzit/src/common/util.h8
-rw-r--r--tikzit/src/common/util.m18
-rw-r--r--tikzit/src/gtk/Edge+Render.m22
4 files changed, 58 insertions, 12 deletions
diff --git a/tikzit/src/common/Edge.m b/tikzit/src/common/Edge.m
index 4ecb9bf..e90806d 100644
--- a/tikzit/src/common/Edge.m
+++ b/tikzit/src/common/Edge.m
@@ -522,7 +522,27 @@
- (NSRect)boundingRect {
[self updateControls];
- return NSRectAround4Points(src, targ, cp1, cp2);
+ NSRect bound = NSRectAround4Points(head, tail, cp1, cp2);
+ if ([self style] != nil) {
+ switch ([[self style] decorationStyle]) {
+ case ED_Arrow:
+ bound = NSRectWithPoint(bound, [self midTan]);
+ case ED_Tick:
+ bound = NSRectWithPoint(bound, [self leftNormal]);
+ bound = NSRectWithPoint(bound, [self rightNormal]);
+ case ED_None:
+ break;
+ }
+ if ([[self style] headStyle] != AH_None) {
+ bound = NSRectWithPoint(bound, [self leftHeadNormal]);
+ bound = NSRectWithPoint(bound, [self rightHeadNormal]);
+ }
+ if ([[self style] tailStyle] != AH_None) {
+ bound = NSRectWithPoint(bound, [self leftTailNormal]);
+ bound = NSRectWithPoint(bound, [self rightTailNormal]);
+ }
+ }
+ return bound;
}
- (void) adjustWeight:(float)handle_dist withCourseness:(float)wcourseness {
diff --git a/tikzit/src/common/util.h b/tikzit/src/common/util.h
index d868903..1ee4ef5 100644
--- a/tikzit/src/common/util.h
+++ b/tikzit/src/common/util.h
@@ -43,6 +43,14 @@
NSRect NSRectAroundPoints(NSPoint p1, NSPoint p2);
/*!
+ @brief Compute a bounding rectangle for two given points.
+ @param rect the base rectangle
+ @param the point to ensure is included
+ @result A rectangle containing rect and p
+ */
+NSRect NSRectWithPoint(NSRect rect, NSPoint p);
+
+/*!
@brief Compute a bounding rectangle for two given points with a given padding.
@param p1 a point.
@param p2 another point.
diff --git a/tikzit/src/common/util.m b/tikzit/src/common/util.m
index 762516f..2d40cbd 100644
--- a/tikzit/src/common/util.m
+++ b/tikzit/src/common/util.m
@@ -25,6 +25,24 @@ static BOOL fuzzyCompare(float f1, float f2) {
return (ABS(f1 - f2) <= 0.00001f * MIN(ABS(f1), ABS(f2)));
}
+NSRect NSRectWithPoint(NSRect rect, NSPoint p) {
+ CGFloat minX = NSMinX(rect);
+ CGFloat maxX = NSMaxX(rect);
+ CGFloat minY = NSMinY(rect);
+ CGFloat maxY = NSMaxY(rect);
+ if (p.x < minX) {
+ minX = p.x;
+ } else if (p.x > maxX) {
+ maxX = p.x;
+ }
+ if (p.y < minY) {
+ minY = p.y;
+ } else if (p.y > maxY) {
+ maxY = p.y;
+ }
+ return NSMakeRect(minX, minY, maxX - minX, maxY - minY);
+}
+
NSRect NSRectAroundPointsWithPadding(NSPoint p1, NSPoint p2, float padding) {
return NSMakeRect(MIN(p1.x,p2.x)-padding,
MIN(p1.y,p2.y)-padding,
diff --git a/tikzit/src/gtk/Edge+Render.m b/tikzit/src/gtk/Edge+Render.m
index 1f5c41a..3cc2a14 100644
--- a/tikzit/src/gtk/Edge+Render.m
+++ b/tikzit/src/gtk/Edge+Render.m
@@ -30,15 +30,13 @@ static const float cpLineWidth = 1.0;
return cpRadius;
}
-- (float) controlDistanceWithTransformer:(Transformer*)transformer {
- NSPoint c_source = [transformer toScreen:src];
- NSPoint c_target = [transformer toScreen:targ];
- const float dx = (c_target.x - c_source.x);
- const float dy = (c_target.y - c_source.y);
+- (float) controlDistance {
+ const float dx = (targ.x - src.x);
+ const float dy = (targ.y - src.y);
if (dx == 0 && dy == 0) {
- return [transformer scaleToScreen:weight];
+ return weight;
} else {
- return NSDistanceBetweenPoints(c_source, c_target) * weight;
+ return NSDistanceBetweenPoints(src, targ) * weight;
}
}
@@ -237,12 +235,14 @@ static const float cpLineWidth = 1.0;
}
- (NSRect) renderedBoundsWithTransformer:(Transformer*)t whenSelected:(BOOL)selected {
- NSRect bRect = [t rectToScreen:[self boundingRect]];
if (selected) {
- float c_dist = [self controlDistanceWithTransformer:t];
- return NSInsetRect (bRect, -c_dist, -c_dist);
+ float c_dist = [self controlDistance] + cpRadius; // include handle
+ NSRect cp1circ = NSMakeRect (head.x - c_dist, head.y - c_dist, 2*c_dist, 2*c_dist);
+ NSRect cp2circ = NSMakeRect (tail.x - c_dist, tail.y - c_dist, 2*c_dist, 2*c_dist);
+ NSRect rect = NSUnionRect ([self boundingRect], NSUnionRect (cp1circ, cp2circ));
+ return [t rectToScreen:rect];
} else {
- return bRect;
+ return [t rectToScreen:[self boundingRect]];
}
}