From 080338f9c9572a7041e5d9d49f6e4392ec703117 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 18 Jul 2012 14:30:53 +0400 Subject: [PATCH] [merge tool] Draw nicely curved divider polygons. --- .../diff/impl/splitter/DividerPolygon.java | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/diff/impl/splitter/DividerPolygon.java b/platform/platform-impl/src/com/intellij/openapi/diff/impl/splitter/DividerPolygon.java index 9ce364f136f4..33db73f3a8eb 100644 --- a/platform/platform-impl/src/com/intellij/openapi/diff/impl/splitter/DividerPolygon.java +++ b/platform/platform-impl/src/com/intellij/openapi/diff/impl/splitter/DividerPolygon.java @@ -22,9 +22,11 @@ import com.intellij.openapi.diff.impl.util.TextDiffType; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.util.Comparing; -import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.GraphicsUtil; import java.awt.*; +import java.awt.geom.CubicCurve2D; +import java.awt.geom.Path2D; import java.util.ArrayList; /** @@ -39,6 +41,8 @@ public class DividerPolygon { private final int myEnd2; private final boolean myApplied; + public static final double CTRL_PROXIMITY_X = 0.3; + public DividerPolygon(int start1, int start2, int end1, int end2, Color color, boolean applied) { myApplied = applied; myStart1 = advance(start1); @@ -53,19 +57,44 @@ public class DividerPolygon { } private void paint(Graphics2D g, int width) { + GraphicsUtil.setupAntialiasing(g); + + if (!myApplied) { + Shape upperCurve = makeCurve(width, myStart1, myStart2, true); + Shape lowerCurve = makeCurve(width, myEnd1, myEnd2, false); + + Path2D path = new Path2D.Double(); + path.append(upperCurve, true); + path.append(lowerCurve, true); g.setColor(myColor); - g.fill(new Polygon(new int[]{0, 0, width, width}, new int[]{myStart1, myEnd1, myEnd2, myStart2}, 4)); + g.fill(path); + g.setColor(DiffUtil.getFramingColor(myColor)); - UIUtil.drawLine(g, 0, myStart1, width, myStart2); - UIUtil.drawLine(g, 0, myEnd1, width, myEnd2); + g.draw(upperCurve); + g.draw(lowerCurve); } else { g.setColor(myColor); - UIUtil.drawLine(g, 0, myStart1 + 1, width, myStart2 + 1); - UIUtil.drawLine(g, 0, myStart1 + 2, width, myStart2 + 2); - UIUtil.drawLine(g, 0, myEnd1 + 1, width, myEnd2 + 1); - UIUtil.drawLine(g, 0, myEnd1, width, myEnd2); + g.draw(makeCurve(width, myStart1 + 1, myStart2 + 1, true)); + g.draw(makeCurve(width, myStart1 + 2, myStart2 + 2, true)); + g.draw(makeCurve(width, myEnd1 + 1, myEnd2 + 1, false)); + g.draw(makeCurve(width, myEnd1 + 2, myEnd2 + 2, false)); + } + } + + private static Shape makeCurve(int width, int y1, int y2, boolean forward) { + if (forward) { + return new CubicCurve2D.Double(0, y1, + width * CTRL_PROXIMITY_X, y1, + width * (1.0 - CTRL_PROXIMITY_X), y2, + width, y2); + } + else { + return new CubicCurve2D.Double(width, y2, + width * (1.0 - CTRL_PROXIMITY_X), y2, + width * CTRL_PROXIMITY_X, y1, + 0, y1); } }