|
From: <eli...@us...> - 2008-04-07 10:18:13
|
Revision: 2973
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2973&view=rev
Author: elias_naur
Date: 2008-04-07 03:18:09 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
Windows: Implemented Display.setParent support
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java
trunk/LWJGL/src/native/windows/context.c
trunk/LWJGL/src/native/windows/context.h
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2008-04-07 09:23:27 UTC (rev 2972)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2008-04-07 10:18:09 UTC (rev 2973)
@@ -71,6 +71,8 @@
private final static int WM_QUIT = 0x0012;
private final static int WM_SYSCOMMAND = 0x0112;
private final static int WM_PAINT = 0x000F;
+ private final static int WM_KILLFOCUS = 8;
+ private final static int WM_SETFOCUS = 7;
private final static int SC_SIZE = 0xF000;
private final static int SC_MOVE = 0xF010;
@@ -118,6 +120,7 @@
private static boolean cursor_clipped;
private WindowsDisplayPeerInfo peer_info;
private Object current_cursor;
+ private Canvas parent;
private WindowsKeyboard keyboard;
private WindowsMouse mouse;
@@ -140,21 +143,41 @@
current_display = this;
}
- public void createWindow(DisplayMode mode, boolean fullscreen, Canvas container, int x, int y) throws LWJGLException {
+ public void createWindow(DisplayMode mode, boolean fullscreen, Canvas parent, int x, int y) throws LWJGLException {
close_requested = false;
is_dirty = false;
isFullscreen = fullscreen;
isMinimized = false;
isFocused = false;
did_maximize = false;
- nCreateWindow(mode, fullscreen, x, y);
+ this.parent = parent;
+ long parent_hwnd = parent != null ? getHwnd(parent) : 0;
+ boolean isUndecorated = isUndecorated();
+ nCreateWindow(mode, fullscreen, x, y, isUndecorated, parent_hwnd);
peer_info.initDC();
showWindow(getHwnd(), SW_SHOWDEFAULT);
- setForegroundWindow(getHwnd());
- setFocus(getHwnd());
+ if (parent == null) {
+ setForegroundWindow(getHwnd());
+ setFocus(getHwnd());
+ }
}
- private native void nCreateWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
+ private native void nCreateWindow(DisplayMode mode, boolean fullscreen, int x, int y, boolean undecorated, long parent_hwnd) throws LWJGLException;
+ private static boolean isUndecorated() {
+ return Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated");
+ }
+
+ private static long getHwnd(Canvas parent) throws LWJGLException {
+ AWTCanvasImplementation awt_impl = AWTGLCanvas.createImplementation();
+ WindowsPeerInfo parent_peer_info = (WindowsPeerInfo)awt_impl.createPeerInfo(parent, null);
+ ByteBuffer parent_peer_info_handle = parent_peer_info.lockAndGetHandle();
+ try {
+ return parent_peer_info.getHwnd();
+ } finally {
+ parent_peer_info.unlock();
+ }
+ }
+
public void destroyWindow() {
nDestroyWindow();
resetCursorClipping();
@@ -213,7 +236,6 @@
return;
}
inAppActivate = true;
- isFocused = active;
if (active) {
if (isFullscreen) {
restoreDisplayMode();
@@ -350,6 +372,9 @@
public void update() {
nUpdate();
+ if (parent != null && parent.isFocusOwner()) {
+ setFocus(getHwnd());
+ }
if (did_maximize) {
did_maximize = false;
/**
@@ -369,9 +394,9 @@
public void reshape(int x, int y, int width, int height) {
if (!isFullscreen)
- nReshape(getHwnd(), x, y, width, height);
+ nReshape(getHwnd(), x, y, width, height, isUndecorated(), parent != null);
}
- private static native void nReshape(long hwnd, int x, int y, int width, int height);
+ private static native void nReshape(long hwnd, int x, int y, int width, int height, boolean undecorated, boolean child);
public native DisplayMode[] getAvailableDisplayModes() throws LWJGLException;
/* Mouse */
@@ -682,6 +707,12 @@
break;
}
return defWindowProc(hwnd, msg, wParam, lParam);
+ case WM_KILLFOCUS:
+ isFocused = false;
+ return 0;
+ case WM_SETFOCUS:
+ isFocused = true;
+ return 0;
case WM_MOUSEMOVE:
int xPos = (int)(short)(lParam & 0xFFFF);
int yPos = transformY(getHwnd(), (int)(short)((lParam >> 16) & 0xFFFF));
Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java 2008-04-07 09:23:27 UTC (rev 2972)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java 2008-04-07 10:18:09 UTC (rev 2973)
@@ -65,11 +65,12 @@
final Canvas display_parent = new Canvas();
display_parent.setFocusable(true);
add(display_parent);
- addWindowListener(new WindowAdapter() {
+/* addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
+ Display.destroy();
dispose();
}
- });
+ });*/
setResizable(true);
setVisible(true);
Display.setParent(display_parent);
@@ -102,7 +103,9 @@
while(Keyboard.next()) {
// closing on ESCAPE
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) {
+ Display.destroy();
dispose();
+ break;
}
if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
Modified: trunk/LWJGL/src/native/windows/context.c
===================================================================
--- trunk/LWJGL/src/native/windows/context.c 2008-04-07 09:23:27 UTC (rev 2972)
+++ trunk/LWJGL/src/native/windows/context.c 2008-04-07 10:18:09 UTC (rev 2973)
@@ -112,7 +112,7 @@
}
}
-void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, bool fullscreen, bool undecorated) {
+void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, bool fullscreen, bool undecorated, bool child_window) {
DWORD exstyle, windowflags;
if (fullscreen) {
exstyle = WS_EX_APPWINDOW;
@@ -120,6 +120,9 @@
} else if (undecorated) {
exstyle = WS_EX_APPWINDOW;
windowflags = WS_POPUP;
+ } else if (child_window) {
+ exstyle = 0;
+ windowflags = WS_CHILDWINDOW;
} else {
exstyle = WS_EX_APPWINDOW;
windowflags = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
@@ -136,13 +139,13 @@
*
* Returns true for success, or false for failure
*/
-HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated)
+HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated, HWND parent)
{
RECT clientSize;
DWORD exstyle, windowflags;
HWND new_hwnd;
- getWindowFlags(&windowflags, &exstyle, fullscreen, undecorated);
+ getWindowFlags(&windowflags, &exstyle, fullscreen, undecorated, parent != NULL);
// If we're not a fullscreen window, adjust the height to account for the
// height of the title bar (unless undecorated)
@@ -164,8 +167,8 @@
"",
windowflags,
x, y, clientSize.right - clientSize.left, clientSize.bottom - clientSize.top,
+ parent,
NULL,
- NULL,
dll_handle,
NULL);
@@ -462,5 +465,5 @@
HWND createDummyWindow(int origin_x, int origin_y) {
if (!registerDummyWindow())
return NULL;
- return createWindow(_CONTEXT_PRIVATE_CLASS_NAME, origin_x, origin_y, 1, 1, false, false);
+ return createWindow(_CONTEXT_PRIVATE_CLASS_NAME, origin_x, origin_y, 1, 1, false, false, NULL);
}
Modified: trunk/LWJGL/src/native/windows/context.h
===================================================================
--- trunk/LWJGL/src/native/windows/context.h 2008-04-07 09:23:27 UTC (rev 2972)
+++ trunk/LWJGL/src/native/windows/context.h 2008-04-07 10:18:09 UTC (rev 2973)
@@ -80,7 +80,7 @@
/**
* Return appropriate window and extended style flags from the given fullscreen and undecorated property
*/
-extern void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, bool fullscreen, bool undecorated);
+extern void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, bool fullscreen, bool undecorated, bool child_window);
/*
* Create a window with the specified position, size, and
@@ -89,7 +89,7 @@
*
* Returns true for success, or false for failure
*/
-extern HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated);
+extern HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated, HWND parent);
extern int findPixelFormatOnDC(JNIEnv *env, HDC hdc, int origin_x, int origin_y, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer, bool floating_point);
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2008-04-07 09:23:27 UTC (rev 2972)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2008-04-07 10:18:09 UTC (rev 2973)
@@ -178,13 +178,12 @@
return getAvailableDisplayModes(env);
}
-JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateWindow(JNIEnv *env, jobject self, jobject mode, jboolean fullscreen, jint x, jint y) {
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateWindow(JNIEnv *env, jobject self, jobject mode, jboolean fullscreen, jint x, jint y, jboolean undecorated, jlong parent_hwnd) {
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
jfieldID fid_width = (*env)->GetFieldID(env, cls_displayMode, "width", "I");
jfieldID fid_height = (*env)->GetFieldID(env, cls_displayMode, "height", "I");
int width = (*env)->GetIntField(env, mode, fid_width);
int height = (*env)->GetIntField(env, mode, fid_height);
- bool isUndecorated; // Whether we're undecorated or not
static bool oneShotInitialised = false;
if (!oneShotInitialised) {
if (!registerWindow(lwjglWindowProc, WINDOWCLASSNAME)) {
@@ -194,8 +193,7 @@
oneShotInitialised = true;
}
- isUndecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
- display_hwnd = createWindow(WINDOWCLASSNAME, x, y, width, height, fullscreen, isUndecorated);
+ display_hwnd = createWindow(WINDOWCLASSNAME, x, y, width, height, fullscreen, undecorated, (HWND)parent_hwnd);
if (display_hwnd == NULL) {
throwException(env, "Failed to create the window.");
return;
@@ -320,12 +318,12 @@
return result;
}
-JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nReshape(JNIEnv *env, jclass unused, jlong hwnd_ptr, jint x, jint y, jint width, jint height) {
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nReshape(JNIEnv *env, jclass unused, jlong hwnd_ptr, jint x, jint y, jint width, jint height, jboolean undecorated, jboolean child) {
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
DWORD exstyle, windowflags;
RECT clientSize;
- getWindowFlags(&windowflags, &exstyle, false, getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated"));
+ getWindowFlags(&windowflags, &exstyle, false, undecorated, child);
// If we're not a fullscreen window, adjust the height to account for the
// height of the title bar:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|