From 3efe8f32ee9179be61b3a63ecd9f008202113f23 Mon Sep 17 00:00:00 2001 From: hneemann Date: Fri, 30 Jul 2021 18:02:18 +0200 Subject: [PATCH] adds scaling to VGA window; closes #800 --- .../digital/gui/components/graphics/VGADialog.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/neemann/digital/gui/components/graphics/VGADialog.java b/src/main/java/de/neemann/digital/gui/components/graphics/VGADialog.java index 4a5c6a486..c4f18dca5 100644 --- a/src/main/java/de/neemann/digital/gui/components/graphics/VGADialog.java +++ b/src/main/java/de/neemann/digital/gui/components/graphics/VGADialog.java @@ -54,7 +54,17 @@ public class VGADialog extends JDialog { @Override protected void paintComponent(Graphics g) { - g.drawImage(image, 0, 0, null); + double sx = ((double) getWidth()) / image.getWidth(); + double sy = ((double) getHeight()) / image.getHeight(); + + double s = Math.min(sx, sy); + int w = (int) Math.floor(image.getWidth() * s); + int h = (int) Math.floor(image.getHeight() * s); + + int x = (getWidth() - w) / 2; + int y = (getHeight() - h) / 2; + + g.drawImage(image, x, y, w, h, 0, 0, image.getWidth(), image.getHeight(), null); } } }