Loading Mac OS X hack through reflection

This commit is contained in:
Elias Naur 2003-10-01 09:33:22 +00:00
parent 38c18eb35c
commit c3f840346c
9 changed files with 190 additions and 18 deletions

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2002 Lightweight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
/**
* $Id$
*
* Mac OS X specific hacks
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
class MacOSX {
public static void initMacOSX() {
java.awt.Toolkit.getDefaultToolkit();
new com.apple.eawt.Application().addApplicationListener(new com.apple.eawt.ApplicationAdapter() {
public void handleQuit(com.apple.eawt.ApplicationEvent e) {
e.setHandled(false);
setQuitRequested();
}
});
}
private static native void setQuitRequested();
}

View file

@ -25,6 +25,7 @@ import org.lwjgl.Display;
import org.lwjgl.Sys;
import java.util.HashSet;
import java.lang.reflect.Method;
public final class Window {
@ -53,19 +54,19 @@ public final class Window {
* I have posted a bug report to apple regarding the behaviour.
*
*/
if (Display.getPlatform() == Display.PLATFORM_AGL) {
java.awt.Toolkit.getDefaultToolkit();
new com.apple.eawt.Application().addApplicationListener(new com.apple.eawt.ApplicationAdapter() {
public void handleQuit(com.apple.eawt.ApplicationEvent e) {
e.setHandled(false);
apple_quit = true;
}
});
}
if (Display.getPlatform() == Display.PLATFORM_AGL)
initMacOSX();
}
/** Special quit boolean set from the apple version */
private static boolean apple_quit;
private static void initMacOSX() {
try {
Class mac_class = Class.forName("org.lwjgl.opengl.MacOSX");
Method init_method = mac_class.getMethod("initMacOSX", null);
init_method.invoke(null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
/** Whether the window is currently created, ie. has a native peer */
private static boolean created;
@ -185,9 +186,7 @@ public final class Window {
*/
public static boolean isCloseRequested() {
assert isCreated() : "Cannot determine state of uncreated window";
boolean result = nIsCloseRequested() || apple_quit;
apple_quit = false;
return result;
return nIsCloseRequested();
}
private static native boolean nIsCloseRequested();
@ -342,7 +341,6 @@ public final class Window {
throws Exception;
private static void createWindow() throws Exception {
apple_quit = false;
HashSet extensions = new HashSet();
nCreate(title, x, y, width, height, fullscreen, color, alpha, depth, stencil, extensions);
GLCaps.determineAvailableExtensions(extensions);