mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-24 04:42:51 -04:00
adds scaling to VGA window; closes #800
This commit is contained in:
parent
3efe8f32ee
commit
ff48fa0ac8
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user