respect display location

This commit is contained in:
Brian Matzon 2004-12-27 21:38:50 +00:00
parent b032d56cea
commit abb1a97b3b
1 changed files with 12 additions and 7 deletions

View File

@ -69,13 +69,13 @@ public final class Display {
private static long timeNow, timeThen; private static long timeNow, timeThen;
/** X coordinate of the window */ /** X coordinate of the window */
private static int x; private static int x = -1;
/** /**
* Y coordinate of the window. Y in window coordinates is from the top of the display down, * Y coordinate of the window. Y in window coordinates is from the top of the display down,
* unlike GL, where it is typically at the bottom of the display. * unlike GL, where it is typically at the bottom of the display.
*/ */
private static int y; private static int y = -1;
/** Title of the window (never null) */ /** Title of the window (never null) */
private static String title = "Game"; private static String title = "Game";
@ -201,8 +201,12 @@ public final class Display {
* A native context must exist, and it will be attached to the window. * A native context must exist, and it will be attached to the window.
*/ */
private static void createWindow() throws LWJGLException { private static void createWindow() throws LWJGLException {
x = Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2); // if no display location set, center window
y = Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2); if(x == -1 && y == -1) {
setLocation(Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2),
Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2));
}
display_impl.createWindow(current_mode, fullscreen, (fullscreen) ? 0 : x, (fullscreen) ? 0 : y); display_impl.createWindow(current_mode, fullscreen, (fullscreen) ? 0 : x, (fullscreen) ? 0 : y);
setTitle(title); setTitle(title);
initControls(); initControls();
@ -610,6 +614,7 @@ public final class Display {
display_impl.destroyContext(); display_impl.destroyContext();
GLContext.unloadOpenGLLibrary(); GLContext.unloadOpenGLLibrary();
context = null; context = null;
x = y = -1;
try { try {
GLContext.useContext(null); GLContext.useContext(null);
} catch (LWJGLException e) { } catch (LWJGLException e) {
@ -657,7 +662,9 @@ public final class Display {
* The window is clamped to remain entirely on the screen. If you attempt * The window is clamped to remain entirely on the screen. If you attempt
* to position the window such that it would extend off the screen, the window * to position the window such that it would extend off the screen, the window
* is simply placed as close to the edge as possible. * is simply placed as close to the edge as possible.
* @param x , y The new window location * <br><b>note</b>If no location has been specified (or x == y == -1) the window will be centered
* @param x The new window location on the x axis
* @param y The new window location on the y axis
*/ */
public static void setLocation(int x, int y) { public static void setLocation(int x, int y) {
if (fullscreen) { if (fullscreen) {
@ -666,8 +673,6 @@ public final class Display {
// offset if already created // offset if already created
if(isCreated()) { if(isCreated()) {
x = Math.max(0, Math.min(initial_mode.getWidth() - current_mode.getWidth(), x));
y = Math.max(0, Math.min(initial_mode.getHeight() - current_mode.getHeight(), y));
display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight()); display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight());
} }