import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.util.ui.GraphicsUtil;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import javax.swing.border.Border;
import javax.swing.tree.TreeCellRenderer;
import java.awt.*;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.PathIterator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
}
// 2. Waved effect
if (attributes.isWaved()) {
- GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
- Stroke oldStroke = g.getStroke();
- try {
- g.setStroke(new BasicStroke(.7F));
- if (attributes.getWaveColor() != null) {
- g.setColor(attributes.getWaveColor());
- }
- final int wavedAt = textBaseline + 1;
- GeneralPath wavePath = new GeneralPath(PathIterator.WIND_EVEN_ODD);
- wavePath.moveTo(offset, wavedAt);
- for (int x = offset; x <= offset + fragmentWidth; x += 4) {
- wavePath.lineTo(x + 2, wavedAt + 2);
- wavePath.lineTo(x + 4, wavedAt);
- }
- g.draw(wavePath);
- } finally {
- config.restore();
- g.setStroke(oldStroke);
+ if (attributes.getWaveColor() != null) {
+ g.setColor(attributes.getWaveColor());
}
+ UIUtil.drawWave(g, new Rectangle(offset, textBaseline + 1, fragmentWidth, Math.max(2, metrics.getDescent())));
}
// 3. Underline
if (attributes.isUnderline()) {
else {
endVisLine = offsetToVisualLine(myDocument.getLineEndOffset(Math.min(myDocument.getLineCount() - 1, endLine)));
}
- int height = endVisLine * getLineHeight() - yStartLine + getLineHeight() + WAVE_HEIGHT;
+ int height = endVisLine * getLineHeight() - yStartLine + getLineHeight() + 2;
myEditorComponent.repaintEditorComponent(visibleArea.x, yStartLine, visibleArea.x + visibleArea.width, height);
myGutterComponent.repaint(0, yStartLine, myGutterComponent.getWidth(), height);
int y = visibleLineToY(visibleStartLine) + getAscent() + 1;
g.setColor(attributes.getEffectColor());
if (attributes.getEffectType() == EffectType.WAVE_UNDERSCORE) {
- drawWave(g, end.x, end.x + charWidth - 1, y);
+ UIUtil.drawWave((Graphics2D)g, new Rectangle(end.x, y, end.x + charWidth - 1, 2));
}
else if (attributes.getEffectType() == EffectType.BOLD_DOTTED_LINE) {
final int dottedAt = SystemInfo.isMac ? y - 1 : y;
}
else if (effectType == EffectType.WAVE_UNDERSCORE) {
g.setColor(effectColor);
- drawWave(g, xStart, xEnd, y + 1);
+ UIUtil.drawWave((Graphics2D)g, new Rectangle(xStart, y+1, xEnd - xStart, getDescent() - 1));
g.setColor(savedColor);
}
else if (effectType == EffectType.BOLD_DOTTED_LINE) {
}
}
- private static final int WAVE_HEIGHT = 2;
- private static final int WAVE_SEGMENT_LENGTH = 4;
-
- private static void drawWave(Graphics g, int xStart, int xEnd, int y) {
- int startSegment = xStart / WAVE_SEGMENT_LENGTH;
- int endSegment = xEnd / WAVE_SEGMENT_LENGTH;
- for (int i = startSegment; i < endSegment; i++) {
- drawWaveSegment(g, WAVE_SEGMENT_LENGTH * i, y);
- }
-
- int x = WAVE_SEGMENT_LENGTH * endSegment;
- UIUtil.drawLine(g, x, y + WAVE_HEIGHT, x + WAVE_SEGMENT_LENGTH / 2, y);
- }
-
- private static void drawWaveSegment(Graphics g, int x, int y) {
- UIUtil.drawLine(g, x, y + WAVE_HEIGHT, x + WAVE_SEGMENT_LENGTH / 2, y);
- UIUtil.drawLine(g, x + WAVE_SEGMENT_LENGTH / 2, y, x + WAVE_SEGMENT_LENGTH, y + WAVE_HEIGHT);
- }
-
private int getTextSegmentWidth(@NotNull CharSequence text,
int start,
int end,
import com.intellij.icons.AllIcons;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.FontRenderContext;
+import java.awt.geom.GeneralPath;
import java.awt.im.InputContext;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
}
}
+ public static void drawWave(Graphics2D g, Rectangle rectangle) {
+ GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
+ Stroke oldStroke = g.getStroke();
+ try {
+ g.setStroke(new BasicStroke(0.7F));
+ double cycle = 4;
+ final double wavedAt = rectangle.y + (double)rectangle.height /2 - .5;
+ GeneralPath wavePath = new GeneralPath();
+ wavePath.moveTo(rectangle.x, wavedAt - Math.cos(rectangle.x * 2 * Math.PI / cycle));
+ for (int x = rectangle.x + 1; x <= rectangle.x + rectangle.width; x++) {
+ wavePath.lineTo(x, wavedAt - Math.cos(x * 2 * Math.PI / cycle) );
+ }
+ g.draw(wavePath);
+ }
+ finally {
+ config.restore();
+ g.setStroke(oldStroke);
+ }
+ }
+
@NotNull
public static String[] splitText(String text, FontMetrics fontMetrics, int widthLimit, char separator) {
ArrayList<String> lines = new ArrayList<String>();