Search in sources :

Example 1 with VisualLinesIterator

use of com.intellij.openapi.editor.impl.view.VisualLinesIterator in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method doPaintLineNumbers.

private void doPaintLineNumbers(Graphics2D g, int startVisualLine, int endVisualLine, int offset, @NotNull TIntFunction convertor) {
    int lastLine = myEditor.logicalToVisualPosition(new LogicalPosition(endLineNumber(), 0)).line;
    endVisualLine = Math.min(endVisualLine, lastLine);
    if (startVisualLine > endVisualLine) {
        return;
    }
    Color color = myEditor.getColorsScheme().getColor(EditorColors.LINE_NUMBERS_COLOR);
    g.setColor(color != null ? color : JBColor.blue);
    Font font = getFontForLineNumbers();
    g.setFont(font);
    AffineTransform old = setMirrorTransformIfNeeded(g, getLineNumberAreaOffset(), getLineNumberAreaWidth());
    try {
        VisualLinesIterator visLinesIterator = new VisualLinesIterator(myEditor, startVisualLine);
        while (!visLinesIterator.atEnd() && visLinesIterator.getVisualLine() <= endVisualLine) {
            LogicalPosition logicalPosition = myEditor.visualToLogicalPosition(new VisualPosition(visLinesIterator.getVisualLine(), 0));
            if (EditorUtil.getSoftWrapCountAfterLineStart(myEditor, logicalPosition) <= 0) {
                int logLine = convertor.execute(visLinesIterator.getStartLogicalLine());
                if (logLine >= 0) {
                    int startY = visLinesIterator.getY();
                    if (myEditor.isInDistractionFreeMode()) {
                        Color fgColor = myTextFgColors.get(visLinesIterator.getVisualLine());
                        g.setColor(fgColor != null ? fgColor : color != null ? color : JBColor.blue);
                    }
                    String s = String.valueOf(logLine + 1);
                    int textOffset = isMirrored() ? offset - getLineNumberAreaWidth() - 1 : offset - g.getFontMetrics().stringWidth(s);
                    g.drawString(s, textOffset, startY + myEditor.getAscent());
                }
            }
            visLinesIterator.advance();
        }
    } finally {
        if (old != null)
            g.setTransform(old);
    }
}
Also used : JBColor(com.intellij.ui.JBColor) VisualLinesIterator(com.intellij.openapi.editor.impl.view.VisualLinesIterator) AffineTransform(java.awt.geom.AffineTransform) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 2 with VisualLinesIterator

use of com.intellij.openapi.editor.impl.view.VisualLinesIterator in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method paintAnnotations.

private void paintAnnotations(Graphics2D g, int startVisualLine, int endVisualLine) {
    int x = getAnnotationsAreaOffset();
    int w = getAnnotationsAreaWidthEx();
    if (w == 0)
        return;
    AffineTransform old = setMirrorTransformIfNeeded(g, x, w);
    try {
        Color color = myEditor.getColorsScheme().getColor(EditorColors.ANNOTATIONS_COLOR);
        g.setColor(color != null ? color : JBColor.blue);
        g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN));
        for (int i = 0; i < myTextAnnotationGutters.size(); i++) {
            TextAnnotationGutterProvider gutterProvider = myTextAnnotationGutters.get(i);
            int lineHeight = myEditor.getLineHeight();
            int lastLine = myEditor.logicalToVisualPosition(new LogicalPosition(endLineNumber(), 0)).line;
            endVisualLine = Math.min(endVisualLine, lastLine);
            if (startVisualLine > endVisualLine) {
                break;
            }
            int annotationSize = myTextAnnotationGutterSizes.get(i);
            VisualLinesIterator visLinesIterator = new VisualLinesIterator(myEditor, startVisualLine);
            while (!visLinesIterator.atEnd() && visLinesIterator.getVisualLine() <= endVisualLine) {
                int logLine = visLinesIterator.getStartLogicalLine();
                int y = visLinesIterator.getY();
                String s = gutterProvider.getLineText(logLine, myEditor);
                final EditorFontType style = gutterProvider.getStyle(logLine, myEditor);
                final Color bg = gutterProvider.getBgColor(logLine, myEditor);
                if (bg != null) {
                    g.setColor(bg);
                    g.fillRect(x, y, annotationSize, lineHeight);
                }
                g.setColor(myEditor.getColorsScheme().getColor(gutterProvider.getColor(logLine, myEditor)));
                g.setFont(myEditor.getColorsScheme().getFont(style));
                if (!StringUtil.isEmpty(s)) {
                    // we leave half of the gap before the text
                    g.drawString(s, GAP_BETWEEN_ANNOTATIONS / 2 + x, y + myEditor.getAscent());
                }
                visLinesIterator.advance();
            }
            if (startVisualLine == 0 && endVisualLine == 0) {
                //allow paining gutters for empty documents
                String s = gutterProvider.getLineText(0, myEditor);
                final EditorFontType style = gutterProvider.getStyle(0, myEditor);
                final Color bg = gutterProvider.getBgColor(0, myEditor);
                if (bg != null) {
                    g.setColor(bg);
                    g.fillRect(x, 0, annotationSize, lineHeight);
                }
                g.setColor(myEditor.getColorsScheme().getColor(gutterProvider.getColor(0, myEditor)));
                g.setFont(myEditor.getColorsScheme().getFont(style));
                if (!StringUtil.isEmpty(s)) {
                    g.drawString(s, GAP_BETWEEN_ANNOTATIONS / 2 + x, myEditor.getAscent());
                }
            }
            x += annotationSize;
        }
    } finally {
        if (old != null)
            g.setTransform(old);
    }
}
Also used : JBColor(com.intellij.ui.JBColor) VisualLinesIterator(com.intellij.openapi.editor.impl.view.VisualLinesIterator) AffineTransform(java.awt.geom.AffineTransform) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Aggregations

VisualLinesIterator (com.intellij.openapi.editor.impl.view.VisualLinesIterator)2 HintHint (com.intellij.ui.HintHint)2 JBColor (com.intellij.ui.JBColor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 AffineTransform (java.awt.geom.AffineTransform)2 EditorFontType (com.intellij.openapi.editor.colors.EditorFontType)1