From bd9afc1f105c9f47509e02b5621f6a56d2c22773 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 30 Jan 2015 11:52:38 +0100 Subject: [PATCH] [FEATURE] Add optional (default off) dynamic scaling. --- src/de/teamteamteam/spacescooter/GameFrame.java | 9 ++++++++- src/de/teamteamteam/spacescooter/brain/GameConfig.java | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/de/teamteamteam/spacescooter/GameFrame.java b/src/de/teamteamteam/spacescooter/GameFrame.java index bf4f8f2..10a624b 100644 --- a/src/de/teamteamteam/spacescooter/GameFrame.java +++ b/src/de/teamteamteam/spacescooter/GameFrame.java @@ -5,6 +5,7 @@ import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Toolkit; +import java.awt.geom.AffineTransform; import java.awt.image.BufferStrategy; import javax.swing.JFrame; @@ -62,7 +63,7 @@ public class GameFrame extends JFrame { public void init() { this.setTitle(GameConfig.windowTitle); this.setSize(GameConfig.windowWidth, GameConfig.windowHeight); - this.setResizable(false); + this.setResizable(GameConfig.dynamicSize); this.setUndecorated(false); this.setDefaultCloseOperation(EXIT_ON_CLOSE); @@ -138,6 +139,12 @@ public class GameFrame extends JFrame { //Apply translation since different platforms use different window decorations that mess //up our coordinates. The new origin shall be the first usable pixel in the top left corner. bufferedGraphics.translate(this.insetLeft, this.insetTop); + //Optional code to perform upscaling. + if(GameConfig.dynamicSize) { + AffineTransform af = new AffineTransform(); + af.scale((this.getWidth() - this.getInsets().left) / (GameConfig.windowWidth*1.0), (this.getHeight() - this.getInsets().top) / (GameConfig.windowHeight*1.0)); + bufferedGraphics.setTransform(af); + } this.superScreen.doPaint(bufferedGraphics); //Trigger the actual paint routines. } catch (Exception e) { System.err.println("Exception in GameFrame.draw() gefangen:"); diff --git a/src/de/teamteamteam/spacescooter/brain/GameConfig.java b/src/de/teamteamteam/spacescooter/brain/GameConfig.java index 64abe31..1cc7f7f 100644 --- a/src/de/teamteamteam/spacescooter/brain/GameConfig.java +++ b/src/de/teamteamteam/spacescooter/brain/GameConfig.java @@ -82,6 +82,11 @@ public final class GameConfig { * The first level the game will start with. */ public static final String firstLevel = "levels/test.level"; + + /** + * Whether or not the window is resizable and scales dynamically. + */ + public static final boolean dynamicSize = false; /** * Private constructor, this class will never be instantiated.