Search in sources :

Example 56 with AffineTransform

use of java.awt.geom.AffineTransform in project intellij-community by JetBrains.

the class EditorGutterComponentImpl method paint.

@Override
public void paint(Graphics g_) {
    ((ApplicationImpl) ApplicationManager.getApplication()).editorPaintStart();
    try {
        Rectangle clip = g_.getClipBounds();
        if (clip.height < 0)
            return;
        Graphics2D g = (Graphics2D) getComponentGraphics(g_);
        AffineTransform old = setMirrorTransformIfNeeded(g, 0, getWidth());
        EditorUIUtil.setupAntialiasing(g);
        Color backgroundColor = getBackground();
        if (myEditor.isDisposed()) {
            g.setColor(myEditor.getDisposedBackground());
            g.fillRect(clip.x, clip.y, clip.width, clip.height);
            return;
        }
        int startVisualLine = myEditor.yToVisibleLine(clip.y);
        int endVisualLine = myEditor.yToVisibleLine(clip.y + clip.height);
        // paint all backgrounds
        int gutterSeparatorX = getWhitespaceSeparatorOffset();
        paintBackground(g, clip, 0, gutterSeparatorX, backgroundColor);
        paintBackground(g, clip, gutterSeparatorX, getFoldingAreaWidth(), myEditor.getBackgroundColor());
        int firstVisibleOffset = myEditor.visualLineStartOffset(startVisualLine);
        int lastVisibleOffset = myEditor.visualLineStartOffset(endVisualLine + 1);
        paintEditorBackgrounds(g, firstVisibleOffset, lastVisibleOffset);
        Object hint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        if (!UIUtil.isJreHiDPI(g))
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        try {
            paintAnnotations(g, startVisualLine, endVisualLine);
            paintLineMarkers(g, firstVisibleOffset, lastVisibleOffset);
            paintFoldingLines(g, clip);
            paintFoldingTree(g, clip, firstVisibleOffset, lastVisibleOffset);
            paintLineNumbers(g, startVisualLine, endVisualLine);
        } finally {
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
        }
        if (old != null)
            g.setTransform(old);
    } finally {
        ((ApplicationImpl) ApplicationManager.getApplication()).editorPaintFinish();
    }
}
Also used : ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) JBColor(com.intellij.ui.JBColor) AffineTransform(java.awt.geom.AffineTransform) RelativePoint(com.intellij.ui.awt.RelativePoint) HintHint(com.intellij.ui.HintHint)

Example 57 with AffineTransform

use of java.awt.geom.AffineTransform in project intellij-community by JetBrains.

the class IconUtil method flip.

@NotNull
public static Icon flip(@NotNull final Icon icon, final boolean horizontal) {
    return new Icon() {

        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D g2d = (Graphics2D) g.create();
            try {
                AffineTransform transform = AffineTransform.getTranslateInstance(horizontal ? x + getIconWidth() : x, horizontal ? y : y + getIconHeight());
                transform.concatenate(AffineTransform.getScaleInstance(horizontal ? -1 : 1, horizontal ? 1 : -1));
                transform.preConcatenate(g2d.getTransform());
                g2d.setTransform(transform);
                icon.paintIcon(c, g2d, 0, 0);
            } finally {
                g2d.dispose();
            }
        }

        @Override
        public int getIconWidth() {
            return icon.getIconWidth();
        }

        @Override
        public int getIconHeight() {
            return icon.getIconHeight();
        }
    };
}
Also used : AffineTransform(java.awt.geom.AffineTransform) RowIcon(com.intellij.ui.RowIcon) LayeredIcon(com.intellij.ui.LayeredIcon) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with AffineTransform

use of java.awt.geom.AffineTransform in project intellij-community by JetBrains.

the class IconUtil method scale.

@NotNull
public static Icon scale(@NotNull final Icon source, double _scale) {
    final int hiDPIscale;
    if (source instanceof ImageIcon) {
        Image image = ((ImageIcon) source).getImage();
        hiDPIscale = RetinaImage.isAppleHiDPIScaledImage(image) || image instanceof JBHiDPIScaledImage ? 2 : 1;
    } else {
        hiDPIscale = 1;
    }
    final double scale = Math.min(32, Math.max(.1, _scale));
    return new Icon() {

        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Graphics2D g2d = (Graphics2D) g.create();
            try {
                g2d.translate(x, y);
                AffineTransform transform = AffineTransform.getScaleInstance(scale, scale);
                transform.preConcatenate(g2d.getTransform());
                g2d.setTransform(transform);
                g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                source.paintIcon(c, g2d, 0, 0);
            } finally {
                g2d.dispose();
            }
        }

        @Override
        public int getIconWidth() {
            return (int) (source.getIconWidth() * scale) / hiDPIscale;
        }

        @Override
        public int getIconHeight() {
            return (int) (source.getIconHeight() * scale) / hiDPIscale;
        }
    };
}
Also used : AffineTransform(java.awt.geom.AffineTransform) RowIcon(com.intellij.ui.RowIcon) LayeredIcon(com.intellij.ui.LayeredIcon) BufferedImage(java.awt.image.BufferedImage) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with AffineTransform

use of java.awt.geom.AffineTransform in project intellij-community by JetBrains.

the class PaintersHelper method computeOffsets.

@NotNull
int[] computeOffsets(Graphics gg, @NotNull JComponent component) {
    if (myPainters.isEmpty())
        return ArrayUtil.EMPTY_INT_ARRAY;
    int i = 0;
    int[] offsets = new int[2 + myPainters.size() * 2];
    // store current graphics transform
    Graphics2D g = (Graphics2D) gg;
    AffineTransform tx = g.getTransform();
    // graphics tx offsets include graphics scale
    offsets[i++] = (int) tx.getTranslateX();
    offsets[i++] = (int) tx.getTranslateY();
    // calculate relative offsets for painters
    Rectangle r = null;
    Component prev = null;
    for (Painter painter : myPainters) {
        if (!painter.needsRepaint())
            continue;
        Component cur = myPainter2Component.get(painter);
        if (cur != prev || r == null) {
            Container curParent = cur.getParent();
            if (curParent == null)
                continue;
            r = SwingUtilities.convertRectangle(curParent, cur.getBounds(), component);
            prev = cur;
        }
        // component offsets don't include graphics scale, so compensate
        offsets[i++] = (int) (r.x * tx.getScaleX());
        offsets[i++] = (int) (r.y * tx.getScaleY());
    }
    return offsets;
}
Also used : Painter(com.intellij.openapi.ui.Painter) AbstractPainter(com.intellij.openapi.ui.AbstractPainter) AffineTransform(java.awt.geom.AffineTransform) NotNull(org.jetbrains.annotations.NotNull)

Example 60 with AffineTransform

use of java.awt.geom.AffineTransform in project intellij-community by JetBrains.

the class PaintersHelper method runAllPainters.

void runAllPainters(Graphics gg, int[] offsets) {
    if (myPainters.isEmpty())
        return;
    Graphics2D g = (Graphics2D) gg;
    AffineTransform orig = g.getTransform();
    int i = 0;
    // restore transform at the time of computeOffset()
    AffineTransform t = new AffineTransform();
    t.translate(offsets[i++], offsets[i++]);
    for (Painter painter : myPainters) {
        if (!painter.needsRepaint())
            continue;
        Component cur = myPainter2Component.get(painter);
        g.setTransform(t);
        g.translate(offsets[i++], offsets[i++]);
        // paint in the orig graphics scale (note, the offsets are pre-scaled)
        g.scale(orig.getScaleX(), orig.getScaleY());
        painter.paint(cur, g);
    }
    g.setTransform(orig);
}
Also used : Painter(com.intellij.openapi.ui.Painter) AbstractPainter(com.intellij.openapi.ui.AbstractPainter) AffineTransform(java.awt.geom.AffineTransform)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)370 BufferedImage (java.awt.image.BufferedImage)60 Graphics2D (java.awt.Graphics2D)54 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)40 Point2D (java.awt.geom.Point2D)28 Shape (java.awt.Shape)24 Font (java.awt.Font)23 Paint (java.awt.Paint)23 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 ArrayList (java.util.ArrayList)18 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 Rectangle (java.awt.Rectangle)16 PathIterator (java.awt.geom.PathIterator)16 Color (java.awt.Color)15 Point (java.awt.Point)15 FontRenderContext (java.awt.font.FontRenderContext)15 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 AffineTransformOp (java.awt.image.AffineTransformOp)13