Home | History | Annotate | Download | only in jglfw
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.backends.jglfw;
     18 
     19 import com.badlogic.gdx.Gdx;
     20 import com.badlogic.gdx.Graphics.DisplayMode;
     21 import com.badlogic.gdx.backends.jglfw.JglfwGraphics.JglfwDisplayMode;
     22 import com.badlogic.gdx.graphics.Color;
     23 import com.badlogic.gdx.utils.Array;
     24 
     25 import java.awt.GraphicsDevice;
     26 import java.awt.GraphicsEnvironment;
     27 
     28 /** @author Nathan Sweet */
     29 public class JglfwApplicationConfiguration {
     30 	/** Title of application window. **/
     31 	public String title = "";
     32 	/** Initial width of the application window. **/
     33 	public int width = 640;
     34 	/** Initial height of the application window. **/
     35 	public int height = 480;
     36 	/** Intial x coordinate of the application window, -1 for center. **/
     37 	public int x = -1;
     38 	/** Intial x coordinate of the application window, -1 for center. **/
     39 	public int y = -1;
     40 	/** True to start in fullscreen. **/
     41 	public boolean fullscreen;
     42 	/** Monitor index to use for fullscreen. **/
     43 	public int fullscreenMonitorIndex = -1;
     44 	/** Number of bits per color channel. **/
     45 	public int r = 8, g = 8, b = 8, a = 8;
     46 	/** Number of bits for the depth buffer. **/
     47 	public int depth = 16;
     48 	/** Number of bits for the stencil buffer. **/
     49 	public int stencil = 0;
     50 	/** Number of samples for MSAA **/
     51 	public int samples = 0;
     52 	/** True to enable vsync. **/
     53 	public boolean vSync = true;
     54 	/** True if the window is resizable. **/
     55 	public boolean resizable = true;
     56 	/** True to call System.exit() when the main loop is complete. **/
     57 	public boolean forceExit = true;
     58 	/** True to have a title and border around the window. **/
     59 	public boolean undecorated;
     60 	/** Causes the main loop to run on the EDT instead of a new thread, for easier interoperability with AWT/Swing. Broken on Linux. **/
     61 	public boolean runOnEDT;
     62 	/** The color to clear the window immediately after creation. **/
     63 	public Color initialBackgroundColor = Color.BLACK;
     64 	/** True to hide the window when it is created. The window must be shown with {@link JglfwGraphics#show()}. **/
     65 	public boolean hidden;
     66 	/** Target framerate when the window is in the foreground. The CPU sleeps as needed. Use 0 to never sleep. **/
     67 	public int foregroundFPS = 60;
     68 	/** Target framerate when the window is in the background. The CPU sleeps as needed. Use 0 to never sleep, -1 to not render. **/
     69 	public int backgroundFPS = 60;
     70 	/** Target framerate when the window is hidden or minimized. The CPU sleeps as needed. Use 0 to never sleep, -1 to not render. **/
     71 	public int hiddenFPS = -1;
     72 	/** Prefrences location on desktop. Default: current directory + ".prefs" */
     73 	public String preferencesLocation = ".prefs/";
     74 
     75 	static public DisplayMode[] getDisplayModes () {
     76 		GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
     77 		java.awt.DisplayMode desktopMode = device.getDisplayMode();
     78 		java.awt.DisplayMode[] displayModes = device.getDisplayModes();
     79 		Array<DisplayMode> modes = new Array();
     80 		outer:
     81 		for (java.awt.DisplayMode mode : displayModes) {
     82 			for (DisplayMode other : modes)
     83 				if (other.width == mode.getWidth() && other.height == mode.getHeight() && other.bitsPerPixel == mode.getBitDepth())
     84 					continue outer; // Duplicate.
     85 			if (mode.getBitDepth() != desktopMode.getBitDepth()) continue;
     86 			modes.add(new JglfwDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth()));
     87 		}
     88 		return modes.toArray(DisplayMode.class);
     89 	}
     90 
     91 	static public DisplayMode getDesktopDisplayMode () {
     92 		java.awt.DisplayMode mode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
     93 		return new JglfwDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth());
     94 	}
     95 }
     96