Resolution improvements.

- Players can no longer set a container size larger than the screen dimensions.
- If the game resolution is equal to the screen size, the created window will be borderless.
- Added some additional resolutions.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-07-10 20:35:07 -04:00
parent 95f969f62f
commit 842563c6a5
2 changed files with 31 additions and 7 deletions

View File

@ -142,8 +142,7 @@ public class Opsu extends StateBasedGame {
AppGameContainer app = new AppGameContainer(opsu); AppGameContainer app = new AppGameContainer(opsu);
// basic game settings // basic game settings
int[] containerSize = Options.getContainerSize(); Options.setDisplayMode(app);
app.setDisplayMode(containerSize[0], containerSize[1], false);
String[] icons = { "icon16.png", "icon32.png" }; String[] icons = { "icon16.png", "icon32.png" };
app.setIcons(icons); app.setIcons(icons);

View File

@ -34,6 +34,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer; import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
@ -240,8 +241,12 @@ public class Options extends BasicGameState {
{ 1280, 960 }, { 1280, 960 },
{ 1366, 768 }, { 1366, 768 },
{ 1440, 900 }, { 1440, 900 },
{ 1600, 900 },
{ 1680, 1050 }, { 1680, 1050 },
{ 1920, 1080 } { 1920, 1080 },
{ 1920, 1200 },
{ 2560, 1440 },
{ 2560, 1600 }
}; };
/** /**
@ -563,7 +568,11 @@ public class Options extends BasicGameState {
// options (click only) // options (click only)
switch (getClickedOption(y)) { switch (getClickedOption(y)) {
case SCREEN_RESOLUTION: case SCREEN_RESOLUTION:
do {
resolutionIndex = (resolutionIndex + 1) % resolutions.length; resolutionIndex = (resolutionIndex + 1) % resolutions.length;
} while (resolutionIndex != 0 &&
(container.getScreenWidth() < resolutions[resolutionIndex][0] ||
container.getScreenHeight() < resolutions[resolutionIndex][1]));
break; break;
// case FULLSCREEN: // case FULLSCREEN:
// fullscreen = !fullscreen; // fullscreen = !fullscreen;
@ -993,10 +1002,26 @@ public class Options extends BasicGameState {
public static String getScreenshotFormat() { return screenshotFormat[screenshotFormatIndex]; } public static String getScreenshotFormat() { return screenshotFormat[screenshotFormatIndex]; }
/** /**
* Returns the screen resolution. * Sets the container size and makes the window borderless if the container
* @return an array containing the resolution [width, height] * size is identical to the screen resolution.
* <p>
* If the configured resolution is larger than the screen size, the smallest
* available resolution will be used.
* @param app the game container
* @throws SlickException failure to set display mode
*/ */
public static int[] getContainerSize() { return resolutions[resolutionIndex]; } public static void setDisplayMode(AppGameContainer app) throws SlickException {
int screenWidth = app.getScreenWidth();
int screenHeight = app.getScreenHeight();
if (screenWidth < resolutions[resolutionIndex][0] || screenHeight < resolutions[resolutionIndex][1])
resolutionIndex = 0;
int containerWidth = resolutions[resolutionIndex][0];
int containerHeight = resolutions[resolutionIndex][1];
app.setDisplayMode(containerWidth, containerHeight, false);
if (screenWidth == containerWidth && screenHeight == containerHeight)
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
}
// /** // /**
// * Returns whether or not fullscreen mode is enabled. // * Returns whether or not fullscreen mode is enabled.