Loading Mac OS X hack through reflection
This commit is contained in:
parent
38c18eb35c
commit
c3f840346c
|
@ -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();
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -8,6 +8,7 @@ NATIVE = \
|
|||
org_lwjgl_Sys.cpp \
|
||||
# org_lwjgl_input_Controller.cpp \
|
||||
org_lwjgl_input_Keyboard.cpp \
|
||||
org_lwjgl_opengl_MacOSX.cpp \
|
||||
# org_lwjgl_input_Mouse.cpp \
|
||||
# org_lwjgl_input_Cursor.cpp \
|
||||
org_lwjgl_opengl_Window.cpp
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Include file to access public window features
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifndef _LWJGL_WINDOW_H_INCLUDED_
|
||||
#define _LWJGL_WINDOW_H_INCLUDED_
|
||||
|
||||
#include <jni.h>
|
||||
extern void setQuitRequested(void);
|
||||
|
||||
#endif /* _LWJGL_WINDOW_H_INCLUDED_ */
|
|
@ -33,7 +33,7 @@
|
|||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Linux keyboard handling.
|
||||
* Mac OS X keyboard handling.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include "Window.h"
|
||||
#include "org_lwjgl_opengl_MacOSX.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSX_setQuitRequested(JNIEnv *, jclass) {
|
||||
setQuitRequested();
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_lwjgl_opengl_MacOSX */
|
||||
|
||||
#ifndef _Included_org_lwjgl_opengl_MacOSX
|
||||
#define _Included_org_lwjgl_opengl_MacOSX
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_MacOSX
|
||||
* Method: setQuitRequested
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSX_setQuitRequested
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -62,8 +62,12 @@ static void setWindowTitle(JNIEnv *env, jstring title_obj) {
|
|||
env->ReleaseStringUTFChars(title_obj, title);
|
||||
}
|
||||
|
||||
static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
|
||||
void setQuitRequested(void) {
|
||||
close_requested = true;
|
||||
}
|
||||
|
||||
static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
|
||||
setQuitRequested();
|
||||
return noErr;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
|
||||
#include <JavaVM/jni.h>
|
||||
|
||||
void throwException(JNIEnv* env, const char* msg);
|
||||
extern void throwException(JNIEnv* env, const char* msg);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue