Search in sources :

Example 51 with AffineTransform

use of java.awt.geom.AffineTransform in project android_frameworks_base by AOSPA.

the class Region_Delegate method translate.

@LayoutlibDelegate
static /*package*/
void translate(Region thisRegion, int dx, int dy, Region dst) {
    Region_Delegate regionDelegate = sManager.getDelegate(thisRegion.mNativeRegion);
    if (regionDelegate == null) {
        return;
    }
    Region_Delegate targetRegionDelegate = sManager.getDelegate(dst.mNativeRegion);
    if (targetRegionDelegate == null) {
        return;
    }
    if (regionDelegate.mArea.isEmpty()) {
        targetRegionDelegate.mArea = new Area();
    } else {
        targetRegionDelegate.mArea = new Area(regionDelegate.mArea);
        AffineTransform mtx = new AffineTransform();
        mtx.translate(dx, dy);
        targetRegionDelegate.mArea.transform(mtx);
    }
}
Also used : Area(java.awt.geom.Area) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 52 with AffineTransform

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

the class ScalableIconComponent method paintComponent.

protected void paintComponent(Graphics g) {
    final Icon icon = myIsSelected ? mySelectedIcon : myIcon;
    if (icon != null) {
        final Graphics2D g2 = (Graphics2D) g;
        g2.setBackground(getBackground());
        final AffineTransform savedTransform = g2.getTransform();
        g2.scale(((double) getWidth()) / icon.getIconWidth(), ((double) getHeight()) / icon.getIconHeight());
        icon.paintIcon(this, g2, 0, 0);
        g2.setTransform(savedTransform);
    }
    super.paintComponent(g);
}
Also used : AffineTransform(java.awt.geom.AffineTransform)

Example 53 with AffineTransform

use of java.awt.geom.AffineTransform 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 54 with AffineTransform

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

the class EditorGutterComponentImpl method setMirrorTransformIfNeeded.

@Nullable
private AffineTransform setMirrorTransformIfNeeded(Graphics2D g, int offset, int width) {
    if (isMirrored()) {
        AffineTransform old = g.getTransform();
        AffineTransform transform = new AffineTransform(old);
        //transform.translate(getWidth(), 0); // revert mirroring transform
        //transform.scale(-1, 1); // revert mirroring transform
        //transform.translate(getWidth() - offset - width, 0); // move range start to the X==0
        //transform.translate(-offset, 0);
        transform.scale(-1, 1);
        transform.translate(-offset * 2 - width, 0);
        g.setTransform(transform);
        return old;
    } else {
        return null;
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) Nullable(org.jetbrains.annotations.Nullable)

Example 55 with AffineTransform

use of java.awt.geom.AffineTransform 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

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