adds scaling to VGA window; closes #800

This commit is contained in:
hneemann 2021-07-30 18:17:49 +02:00
parent 3efe8f32ee
commit ff48fa0ac8

View File

@ -54,17 +54,21 @@ public class VGADialog extends JDialog {
@Override @Override
protected void paintComponent(Graphics g) { protected void paintComponent(Graphics g) {
double sx = ((double) getWidth()) / image.getWidth(); if (getWidth() == image.getWidth() && getHeight() == image.getHeight()) {
double sy = ((double) getHeight()) / image.getHeight(); g.drawImage(image, 0, 0, null);
} else {
double sx = ((double) getWidth()) / image.getWidth();
double sy = ((double) getHeight()) / image.getHeight();
double s = Math.min(sx, sy); double s = Math.min(sx, sy);
int w = (int) Math.floor(image.getWidth() * s); int w = (int) Math.floor(image.getWidth() * s);
int h = (int) Math.floor(image.getHeight() * s); int h = (int) Math.floor(image.getHeight() * s);
int x = (getWidth() - w) / 2; int x = (getWidth() - w) / 2;
int y = (getHeight() - h) / 2; int y = (getHeight() - h) / 2;
g.drawImage(image, x, y, w, h, 0, 0, image.getWidth(), image.getHeight(), null); g.drawImage(image, x, y, w, h, 0, 0, image.getWidth(), image.getHeight(), null);
}
} }
} }
} }