mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 15:32:40 -04:00
enabled adaptive anti-aliasing. If the painting becomes to slow it is turned off.
This commit is contained in:
parent
ac0e9cf891
commit
f7c82e4893
@ -87,6 +87,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
private boolean hasChanged = true;
|
private boolean hasChanged = true;
|
||||||
private boolean focusWasLost = false;
|
private boolean focusWasLost = false;
|
||||||
private boolean lockMessageShown = false;
|
private boolean lockMessageShown = false;
|
||||||
|
private boolean antiAlias = true;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -460,20 +461,32 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
|| needsNewBuffer
|
|| needsNewBuffer
|
||||||
|| highLighted.size() != highlightedPaintedSize) {
|
|| highLighted.size() != highlightedPaintedSize) {
|
||||||
|
|
||||||
// long time = System.currentTimeMillis();
|
|
||||||
if (needsNewBuffer)
|
if (needsNewBuffer)
|
||||||
buffer = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(getWidth(), getHeight());
|
buffer = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(getWidth(), getHeight());
|
||||||
|
|
||||||
Graphics2D gr2 = buffer.createGraphics();
|
Graphics2D gr2 = buffer.createGraphics();
|
||||||
|
if (antiAlias) {
|
||||||
|
gr2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
gr2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
gr2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
||||||
|
}
|
||||||
gr2.setColor(Color.WHITE);
|
gr2.setColor(Color.WHITE);
|
||||||
gr2.fillRect(0, 0, getWidth(), getHeight());
|
gr2.fillRect(0, 0, getWidth(), getHeight());
|
||||||
gr2.transform(transform);
|
gr2.transform(transform);
|
||||||
|
|
||||||
GraphicSwing gr = new GraphicSwing(gr2, (int) (2 / transform.getScaleX()));
|
GraphicSwing gr = new GraphicSwing(gr2, (int) (2 / transform.getScaleX()));
|
||||||
|
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
circuit.drawTo(gr, highLighted, modelSync);
|
circuit.drawTo(gr, highLighted, modelSync);
|
||||||
|
time = System.currentTimeMillis() - time;
|
||||||
|
|
||||||
|
if (time > 500) antiAlias = false;
|
||||||
|
if (time < 50) antiAlias = true;
|
||||||
|
|
||||||
|
// System.out.println("repaint: " + Long.toString(time) + "ms");
|
||||||
|
|
||||||
highlightedPaintedSize = highLighted.size();
|
highlightedPaintedSize = highLighted.size();
|
||||||
hasChanged = false;
|
hasChanged = false;
|
||||||
// System.out.println("repaint: " + Long.toString(System.currentTimeMillis() - time) + "ms");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g.drawImage(buffer, 0, 0, null);
|
g.drawImage(buffer, 0, 0, null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user