From 9c8989701400d4a7fdc5e57dcb46b927de5a8508 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Fri, 8 Jul 2016 13:40:49 +0300 Subject: [PATCH] IDEA-97406 support LINE_UNDERSCORE as well as WAVE_UNDERSCORE --- .../src/com/intellij/ui/EffectPainter.java | 21 +++++++++++++++++++ .../intellij/ui/SimpleColoredComponent.java | 3 +-- .../openapi/editor/impl/EditorImpl.java | 5 ++--- .../editor/impl/view/EditorPainter.java | 2 +- .../util/resources/misc/registry.properties | 4 ++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/EffectPainter.java b/platform/platform-api/src/com/intellij/ui/EffectPainter.java index d954390700c3..8df85aa43c10 100644 --- a/platform/platform-api/src/com/intellij/ui/EffectPainter.java +++ b/platform/platform-api/src/com/intellij/ui/EffectPainter.java @@ -26,6 +26,27 @@ import java.awt.geom.*; * @author Sergey.Malenkov */ public enum EffectPainter implements RegionPainter { + /** + * @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 */ diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index 4897f413f98e..a99c1a9b0817 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -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()) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java index 99b3439ba71c..b48b34ab9e4e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java @@ -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) { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java index d22724fc0624..12a31baa617e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java @@ -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)); diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 34fa2644cf99..0f6d3bff37d2 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -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