IDEA-97406 support LINE_UNDERSCORE as well as WAVE_UNDERSCORE

This commit is contained in:
Sergey Malenkov
2016-07-08 13:45:04 +03:00
parent d48f1c0b09
commit 9c89897014
5 changed files with 29 additions and 6 deletions
@@ -26,6 +26,27 @@ import java.awt.geom.*;
* @author Sergey.Malenkov
*/
public enum EffectPainter implements RegionPainter<Paint> {
/**
* @see com.intellij.openapi.editor.markup.EffectType#LINE_UNDERSCORE
*/
LINE_UNDERSCORE {
@Override
public void paint(Graphics2D g, int x, int y, int width, int height, Paint paint) {
// we assume here that Y is a baseline of a text
if (!Registry.is("ide.text.effect.line.new")) {
g.setPaint(paint);
g.drawLine(x, y + 1, x + width, y + 1);
}
else if (paint != null && width > 0 && height > 0) {
g.setPaint(paint);
int h = height < 4 ? 2 : height >> 1;
double pos = Registry.doubleValue("ide.text.effect.line.new.pos");
y += (int)((double)height - h * pos);
g.setPaint(paint);
g.drawLine(x, y, x + width, y);
}
}
},
/**
* @see com.intellij.openapi.editor.markup.EffectType#WAVE_UNDERSCORE
*/
@@ -837,8 +837,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible, Co
}
// 3. Underline
if (attributes.isUnderline()) {
final int underlineAt = textBaseline + 1;
UIUtil.drawLine(g, offset, underlineAt, offset + fragmentWidth, underlineAt);
EffectPainter.LINE_UNDERSCORE.paint(g, offset, textBaseline, fragmentWidth, metrics.getDescent(), g.getColor());
}
// 4. Bold Dotted Line
if (attributes.isBoldDottedLine()) {
@@ -2428,7 +2428,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
drawBoldLineUnderScore(g, end.x, y - 1, charWidth - 1);
}
else if (attributes.getEffectType() != EffectType.BOXED) {
UIUtil.drawLine(g, end.x, y, end.x + charWidth - 1, y);
EffectPainter.LINE_UNDERSCORE.paint((Graphics2D)g, end.x, y - 1, charWidth - 1, getDescent(), attributes.getEffectColor());
}
}
}
@@ -3546,8 +3546,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
}
if (effectType == EffectType.LINE_UNDERSCORE) {
g.setColor(effectColor);
UIUtil.drawLine(g, xStart, y + 1, xEnd, y + 1);
EffectPainter.LINE_UNDERSCORE.paint((Graphics2D)g, xStart, y, xEnd - xStart, getDescent(), effectColor);
g.setColor(savedColor);
}
else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
@@ -429,7 +429,7 @@ class EditorPainter implements TextDrawingCallback {
int xEnd = (int)xTo;
g.setColor(effectColor);
if (effectType == EffectType.LINE_UNDERSCORE) {
UIUtil.drawLine(g, xStart, y + 1, xEnd, y + 1);
EffectPainter.LINE_UNDERSCORE.paint(g, xStart, y, xEnd - xStart, myView.getDescent(), effectColor);
}
else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
int height = JBUI.scale(Registry.intValue("editor.bold.underline.height", 2));
@@ -761,6 +761,10 @@ cidr.xcode.derived.data.override.description=Ignore Xcode DerivedData location s
editor.rainbow.identifiers=false
editor.rainbow.identifiers.description=Rainbow identifiers in editor
ide.text.effect.line.new=false
ide.text.effect.line.new.description=Enables new line painter for text
ide.text.effect.line.new.pos=0.5
ide.text.effect.line.new.pos.description=Changes a line position
ide.text.effect.wave.new=false
ide.text.effect.wave.new.description=Enables new wave painter for text
ide.text.effect.wave.new.scale=false