From 3e7d54902fbf075543488330a31897e9e964482e Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 26 Oct 2014 12:12:01 +0100 Subject: [PATCH] Add GraphicsSettings to retrieve refresh rate (and more). --- src/de/teamteamteam/spacescooter/Main.java | 5 ++- .../utilities/GraphicsSettings.java | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/de/teamteamteam/spacescooter/utilities/GraphicsSettings.java diff --git a/src/de/teamteamteam/spacescooter/Main.java b/src/de/teamteamteam/spacescooter/Main.java index dfa775e..0e76b93 100644 --- a/src/de/teamteamteam/spacescooter/Main.java +++ b/src/de/teamteamteam/spacescooter/Main.java @@ -8,6 +8,7 @@ import de.teamteamteam.spacescooter.entities.TestEntity; import de.teamteamteam.spacescooter.gui.GameFrame; import de.teamteamteam.spacescooter.threads.PaintThread; import de.teamteamteam.spacescooter.threads.UpdateThread; +import de.teamteamteam.spacescooter.utilities.GraphicsSettings; /** * Nothing but a class containing the main method. @@ -21,6 +22,8 @@ public class Main { * @param args Command line arguments. */ public static void main(String[] args) { + GraphicsSettings gs = new GraphicsSettings(); //Get settings + final GameFrame gf = new GameFrame(); //Whatever. @@ -38,7 +41,7 @@ public class Main { //Initialize GameThread PaintThread paintThread = new PaintThread(gf); - paintThread.setHz(60); //This may be set depending on the system graphic settings. + paintThread.setHz(gs.getRefreshRate()); //This may be set depending on the system graphic settings. paintThread.start(); //Initialize UpdateThread diff --git a/src/de/teamteamteam/spacescooter/utilities/GraphicsSettings.java b/src/de/teamteamteam/spacescooter/utilities/GraphicsSettings.java new file mode 100644 index 0000000..f16e3d7 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/utilities/GraphicsSettings.java @@ -0,0 +1,41 @@ +package de.teamteamteam.spacescooter.utilities; + +import java.awt.DisplayMode; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; + +public class GraphicsSettings { + + private int height; + private int width; + private int refreshRate; + private int bitDepth; + + public GraphicsSettings() { + this.retrieveSettings(); + } + + public int getRefreshRate() { + return this.refreshRate; + } + + public void retrieveSettings() { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + + for(int i=0; i < gs.length; i++) { + DisplayMode dm = gs[i].getDisplayMode(); + this.refreshRate = dm.getRefreshRate(); + if(this.refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) { + System.err.println("[!]Display Mode " + i + ": Unknown refresh rate!"); + this.refreshRate = 60; //sane default value. :/ + } + this.bitDepth = dm.getBitDepth(); + this.height = dm.getHeight(); + this.width = dm.getWidth(); + + System.out.println("Display Mode " + i + ": " + this.width + "x" + this.height+ "@" + this.refreshRate + "Hz, " + this.bitDepth + " bit"); + } + } + +}