Properly handle non-fullscreen DisplayModes

This commit is contained in:
Elias Naur 2008-10-02 08:10:47 +00:00
parent a7accb99a0
commit 95a13203a1
1 changed files with 26 additions and 41 deletions

View File

@ -211,10 +211,8 @@ public final class Display {
* @return The desktop display mode
*/
public static DisplayMode getDesktopDisplayMode() {
synchronized (GlobalLock.lock) {
return initial_mode;
}
}
/**
* Return the current display mode, as set by setDisplayMode().
@ -222,10 +220,8 @@ public final class Display {
* @return The current display mode
*/
public static DisplayMode getDisplayMode() {
synchronized ( GlobalLock.lock ) {
return current_mode;
}
}
/**
* Set the current display mode. If no OpenGL context has been created, the given mode will apply to
@ -242,14 +238,15 @@ public final class Display {
synchronized (GlobalLock.lock) {
if (mode == null)
throw new NullPointerException("mode must be non-null");
boolean was_fullscreen = isFullscreen();
current_mode = mode;
if (isCreated()) {
destroyWindow();
// If mode is not fullscreen capable, make sure we are in windowed mode
if ( !mode.isFullscreen() )
resetFullscreen();
try {
if ( fullscreen )
if (was_fullscreen && !isFullscreen())
display_impl.resetDisplayMode();
else if (isFullscreen())
switchDisplayMode();
createWindow();
makeCurrentAndSetSwapInterval();
@ -264,11 +261,11 @@ public final class Display {
}
private static DisplayMode getEffectiveMode() {
return !fullscreen && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode;
return !isFullscreen() && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode;
}
private static int getWindowX() {
if ( !fullscreen && parent == null ) {
if (!isFullscreen() && parent == null) {
// if no display location set, center window
if (x == -1) {
return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
@ -281,7 +278,7 @@ public final class Display {
}
private static int getWindowY() {
if ( !fullscreen && parent == null ) {
if (!isFullscreen() && parent == null) {
// if no display location set, center window
if ( y == -1 ) {
return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
@ -301,14 +298,14 @@ public final class Display {
if ( window_created ) {
return;
}
Canvas tmp_parent = fullscreen ? null : parent;
Canvas tmp_parent = isFullscreen() ? null : parent;
if ( tmp_parent != null && !tmp_parent.isDisplayable() ) // Only a best effort check, since the parent can turn undisplayable hereafter
throw new LWJGLException("Parent.isDisplayable() must be true");
if ( tmp_parent != null ) {
tmp_parent.addComponentListener(component_listener);
}
DisplayMode mode = getEffectiveMode();
display_impl.createWindow(mode, fullscreen, tmp_parent, getWindowX(), getWindowY());
display_impl.createWindow(mode, isFullscreen(), tmp_parent, getWindowX(), getWindowY());
window_created = true;
setTitle(title);
@ -444,15 +441,6 @@ public final class Display {
}
}
private static void resetFullscreen() {
synchronized ( GlobalLock.lock ) {
if ( Display.fullscreen ) {
Display.fullscreen = false;
display_impl.resetDisplayMode();
}
}
}
/** Return the last parent set with setParent(). */
public static Canvas getParent() {
synchronized ( GlobalLock.lock ) {
@ -478,7 +466,7 @@ public final class Display {
return;
destroyWindow();
try {
if ( fullscreen ) {
if (isFullscreen()) {
switchDisplayMode();
} else {
display_impl.resetDisplayMode();
@ -509,13 +497,14 @@ public final class Display {
*/
public static void setFullscreen(boolean fullscreen) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
if ( Display.fullscreen != fullscreen ) {
boolean was_fullscreen = isFullscreen();
Display.fullscreen = fullscreen;
if (was_fullscreen != isFullscreen()) {
if (!isCreated())
return;
destroyWindow();
try {
if ( fullscreen ) {
if (isFullscreen()) {
switchDisplayMode();
} else {
display_impl.resetDisplayMode();
@ -535,7 +524,7 @@ public final class Display {
/** @return whether the Display is in fullscreen mode */
public static boolean isFullscreen() {
synchronized (GlobalLock.lock) {
return fullscreen;
return fullscreen && current_mode.isFullscreen();
}
}
@ -819,7 +808,7 @@ public final class Display {
throw new NullPointerException("pixel_format cannot be null");
removeShutdownHook();
registerShutdownHook();
if ( fullscreen )
if (isFullscreen())
switchDisplayMode();
try {
peer_info = display_impl.createPeerInfo(pixel_format);
@ -996,16 +985,12 @@ public final class Display {
*/
public static void setLocation(int new_x, int new_y) {
synchronized ( GlobalLock.lock ) {
if ( fullscreen ) {
return;
}
// cache position
x = new_x;
y = new_y;
// offset if already created
if ( isCreated() ) {
if (isCreated() && !isFullscreen()) {
reshape();
}
}