[FEATURE] Add optional (default off) dynamic scaling.

This commit is contained in:
Jan Philipp Timme 2015-01-30 11:52:38 +01:00
parent af4c22c0fd
commit bd9afc1f10
2 changed files with 13 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferStrategy; import java.awt.image.BufferStrategy;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -62,7 +63,7 @@ public class GameFrame extends JFrame {
public void init() { public void init() {
this.setTitle(GameConfig.windowTitle); this.setTitle(GameConfig.windowTitle);
this.setSize(GameConfig.windowWidth, GameConfig.windowHeight); this.setSize(GameConfig.windowWidth, GameConfig.windowHeight);
this.setResizable(false); this.setResizable(GameConfig.dynamicSize);
this.setUndecorated(false); this.setUndecorated(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE); 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 //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. //up our coordinates. The new origin shall be the first usable pixel in the top left corner.
bufferedGraphics.translate(this.insetLeft, this.insetTop); 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. this.superScreen.doPaint(bufferedGraphics); //Trigger the actual paint routines.
} catch (Exception e) { } catch (Exception e) {
System.err.println("Exception in GameFrame.draw() gefangen:"); System.err.println("Exception in GameFrame.draw() gefangen:");

View File

@ -82,6 +82,11 @@ public final class GameConfig {
* The first level the game will start with. * The first level the game will start with.
*/ */
public static final String firstLevel = "levels/test.level"; 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. * Private constructor, this class will never be instantiated.