|
From: <eli...@us...> - 2008-04-07 19:21:47
|
Revision: 2987
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2987&view=rev
Author: elias_naur
Date: 2008-04-07 12:21:40 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
Let the Display resize itself to match its parent, if non null
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java
trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-04-07 18:44:46 UTC (rev 2986)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2008-04-07 19:21:40 UTC (rev 2987)
@@ -50,6 +50,9 @@
import java.util.Arrays;
import java.util.HashSet;
import java.awt.Canvas;
+import java.awt.event.ComponentListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
@@ -111,6 +114,16 @@
private static boolean window_created = false;
+ private static boolean parent_resized;
+
+ private static ComponentListener component_listener = new ComponentAdapter() {
+ public final void componentResized(ComponentEvent e) {
+ synchronized (GlobalLock.lock) {
+ parent_resized = true;
+ }
+ }
+ };
+
static {
Sys.initialize();
display_impl = createDisplayImplementation();
@@ -238,6 +251,36 @@
}
}
+ private static DisplayMode getEffectiveMode() {
+ return !fullscreen && parent != null ? new DisplayMode(parent.getWidth(), parent.getHeight()) : current_mode;
+ }
+
+ private static int getWindowX() {
+ if (!fullscreen && parent == null) {
+ // if no display location set, center window
+ if (x == -1) {
+ return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
+ } else {
+ return x;
+ }
+ } else {
+ return 0;
+ }
+ }
+
+ private static int getWindowY() {
+ if (!fullscreen && parent == null) {
+ // if no display location set, center window
+ if (y == -1) {
+ return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
+ } else {
+ return y;
+ }
+ } else {
+ return 0;
+ }
+ }
+
/**
* Create the native window peer from the given mode and fullscreen flag.
* A native context must exist, and it will be attached to the window.
@@ -246,25 +289,14 @@
if (window_created) {
return;
}
- int window_x;
- int window_y;
- if (!fullscreen && parent == null) {
- // if no display location set, center window
- if (x == -1 && y == -1) {
- window_x = Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
- window_y = Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
- } else {
- window_x = x;
- window_y = y;
- }
- } else {
- window_x = 0;
- window_y = 0;
- }
Canvas tmp_parent = fullscreen ? 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");
- display_impl.createWindow(current_mode, fullscreen, tmp_parent, window_x, window_y);
+ if (tmp_parent != null) {
+ tmp_parent.addComponentListener(component_listener);
+ }
+ DisplayMode mode = getEffectiveMode();
+ display_impl.createWindow(mode, fullscreen, tmp_parent, getWindowX(), getWindowY());
window_created = true;
setTitle(title);
@@ -282,6 +314,9 @@
if (!window_created) {
return;
}
+ if (parent != null) {
+ parent.removeComponentListener(component_listener);
+ }
try {
if (context != null && context.isCurrent()) {
Context.releaseCurrentContext();
@@ -676,6 +711,10 @@
}
pollDevices();
+ if (parent_resized) {
+ reshape();
+ parent_resized = false;
+ }
}
}
@@ -985,11 +1024,16 @@
// offset if already created
if(isCreated()) {
- display_impl.reshape(x, y, current_mode.getWidth(), current_mode.getHeight());
+ reshape();
}
}
}
+ private static void reshape() {
+ DisplayMode mode = getEffectiveMode();
+ display_impl.reshape(getWindowX(), getWindowY(), mode.getWidth(), mode.getHeight());
+ }
+
/**
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
* "Radeon9700". If the adapter cannot be determined, this function returns null.
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 18:44:46 UTC (rev 2986)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/awt/DisplayParentTest.java 2008-04-07 19:21:40 UTC (rev 2987)
@@ -83,13 +83,7 @@
int current_width = 0;
while (isVisible()) {
angle += 1.0f;
- if (getWidth() != current_width || getHeight() != current_height) {
- current_width = getWidth();
- current_height = getHeight();
- Display.setDisplayMode(new DisplayMode(getWidth(), getHeight()));
- GL11.glViewport(0, 0, current_width, current_height);
- }
- GL11.glViewport(0, 0, getWidth(), getHeight());
+ GL11.glViewport(0, 0, display_parent.getWidth(), display_parent.getHeight());
GL11.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL11.glMatrixMode(GL11.GL_PROJECTION);
Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2008-04-07 18:44:46 UTC (rev 2986)
+++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2008-04-07 19:21:40 UTC (rev 2987)
@@ -240,6 +240,7 @@
Display *disp = (Display *)(intptr_t)display;
Window window = (Window)window_ptr;
XMoveWindow(disp, window, x, y);
+ XResizeWindow(disp, window, width, height);
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_getRootWindow(JNIEnv *env, jclass clazz, jlong display, jint screen) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|