Search in sources :

Example 1 with Painter

use of com.intellij.openapi.ui.Painter 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 2 with Painter

use of com.intellij.openapi.ui.Painter 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)

Example 3 with Painter

use of com.intellij.openapi.ui.Painter in project intellij-community by JetBrains.

the class PaintersHelper method clear.

public void clear() {
    for (Painter painter : myPainters) {
        painter.removeListener(this);
    }
    myPainters.clear();
    myPainter2Component.clear();
}
Also used : Painter(com.intellij.openapi.ui.Painter) AbstractPainter(com.intellij.openapi.ui.AbstractPainter)

Aggregations

AbstractPainter (com.intellij.openapi.ui.AbstractPainter)3 Painter (com.intellij.openapi.ui.Painter)3 AffineTransform (java.awt.geom.AffineTransform)2 NotNull (org.jetbrains.annotations.NotNull)1