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();
}
}
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();
}
};
}
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;
}
};
}
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;
}
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);
}
Aggregations