FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

more frame handling · kybr/processing@d55e9b7 · GitHub

Repository navigation

Commit d55e9b7

Browse files
committed
more frame handling
1 parent ee49fb8 commit d55e9b7

1 file changed

Lines changed: 110 additions & 9 deletions

File tree

‎java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java‎

Lines changed: 110 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import java.awt.Canvas;
44
import java.awt.Color;
55
import java.awt.Frame;
6+
import java.awt.GraphicsConfiguration;
7+
import java.awt.GraphicsDevice;
8+
import java.awt.GraphicsEnvironment;
9+
import java.awt.Rectangle;
10+
import java.awt.geom.Rectangle2D;
611

712
import org.lwjgl.LWJGLException;
813
import org.lwjgl.input.Keyboard;
@@ -21,16 +26,20 @@
2126
import processing.opengl.PGraphicsOpenGL;
2227

2328
public class PSurfaceLWJGL implements PSurface {
29+
GraphicsDevice displayDevice;
2430
PApplet sketch;
2531
PGraphics graphics;
2632

2733
int sketchWidth;
2834
int sketchHeight;
2935

3036
Frame frame;
37+
// Note that x and y may not be zero, depending on the display configuration
38+
Rectangle screenRect;
3139

3240
PLWJGL pgl;
3341

42+
boolean fullScreenRequested;
3443
// ........................................................
3544

3645
// Event handling
@@ -66,12 +75,99 @@ public Frame initFrame(PApplet sketch, Color backgroundColor,
6675
int deviceIndex, boolean fullScreen, boolean spanDisplays) {
6776
this.sketch = sketch;
6877

69-
sketchWidth = sketch.width = sketch.sketchWidth();
70-
sketchHeight = sketch.height = sketch.sketchHeight();
78+
GraphicsEnvironment environment =
79+
GraphicsEnvironment.getLocalGraphicsEnvironment();
80+
81+
DisplayMode desktopMode = Display.getDesktopDisplayMode();
82+
PApplet.println("DESKTOP MODES");
83+
PApplet.println(desktopMode);
84+
PApplet.println("ALL MODES");
85+
try {
86+
DisplayMode[] allModes = Display.getAvailableDisplayModes();
87+
for (DisplayMode mode: allModes) {
88+
PApplet.println(mode);
89+
}
90+
} catch (LWJGLException e) {
91+
// TODO Auto-generated catch block
92+
e.printStackTrace();
93+
}
94+
95+
96+
97+
98+
if (deviceIndex >= 0) { // if -1, use the default device
99+
GraphicsDevice[] devices = environment.getScreenDevices();
100+
if (deviceIndex < devices.length) {
101+
displayDevice = devices[deviceIndex];
102+
} else {
103+
System.err.format("Display %d does not exist, " +
104+
"using the default display instead.", deviceIndex);
105+
for (int i = 0; i < devices.length; i++) {
106+
System.err.format("Display %d is %s\n", i, devices[i]);
107+
}
108+
}
109+
}
110+
if (displayDevice == null) {
111+
displayDevice = environment.getDefaultScreenDevice();
112+
}
113+
114+
// Need to save the window bounds at full screen,
115+
// because pack() will cause the bounds to go to zero.
116+
// http://dev.processing.org/bugs/show_bug.cgi?id=923
117+
screenRect = spanDisplays ? getDisplaySpan() :
118+
displayDevice.getDefaultConfiguration().getBounds();
119+
120+
// Set the displayWidth/Height variables inside PApplet, so that they're
121+
// usable and can even be returned by the sketchWidth()/Height() methods.
122+
sketch.displayWidth = screenRect.width;
123+
sketch.displayHeight = screenRect.height;
124+
125+
sketchWidth = sketch.sketchWidth();
126+
sketchHeight = sketch.sketchHeight();
127+
128+
// Sketch has already requested to be the same as the screen's
129+
// width and height, so let's roll with full screen mode.
130+
if (screenRect.width == sketchWidth &&
131+
screenRect.height == sketchHeight) {
132+
fullScreen = true;
133+
}
134+
135+
if (fullScreen || spanDisplays) {
136+
sketchWidth = screenRect.width;
137+
sketchHeight = screenRect.height;
138+
}
139+
140+
if (fullScreen) {
141+
// Called here because the graphics device is needed before we can
142+
// determine whether the sketch wants size(displayWidth, displayHeight),
143+
// and getting the graphics device will be PSurface-specific.
144+
// PApplet.hideMenuBar();
145+
146+
// Useful hidden switches:
147+
// http://wiki.lwjgl.org/index.php?title=LWJGL_Hidden_Switches
148+
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
149+
fullScreenRequested = true;
150+
}
151+
152+
// sketchWidth = sketch.width = sketch.sketchWidth();
153+
// sketchHeight = sketch.height = sketch.sketchHeight();
71154

72155
frame = new DummyFrame();
73156
return frame;
74157
}
158+
159+
// get the bounds for all displays
160+
static Rectangle getDisplaySpan() {
161+
Rectangle bounds = new Rectangle();
162+
GraphicsEnvironment environment =
163+
GraphicsEnvironment.getLocalGraphicsEnvironment();
164+
for (GraphicsDevice device : environment.getScreenDevices()) {
165+
for (GraphicsConfiguration config : device.getConfigurations()) {
166+
Rectangle2D.union(bounds, config.getBounds(), bounds);
167+
}
168+
}
169+
return bounds;
170+
}
75171

76172
@Override
77173
public void setTitle(String title) {
@@ -118,7 +214,7 @@ public void startThread() {
118214
thread = new AnimationThread();
119215
thread.start();
120216
} else {
121-
throw new IllegalStateException("Thread already started in PSurfaceAWT");
217+
throw new IllegalStateException("Thread already started in PSurfaceLWJGL");
122218
}
123219
}
124220

@@ -244,15 +340,20 @@ public AnimationThread() {
244340
@Override
245341
public void run() { // not good to make this synchronized, locks things up
246342
try {
247-
DisplayMode[] modes = Display.getAvailableDisplayModes();
248-
for (DisplayMode mode: modes) {
249-
System.err.println(mode.toString());
250-
}
251-
343+
// DisplayMode[] modes = Display.getAvailableDisplayModes();
344+
// for (DisplayMode mode: modes) {
345+
// System.err.println(mode.toString());
346+
// }
347+
348+
252349
Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight));
350+
System.err.println(sketchWidth + " " + sketchHeight);
351+
if (fullScreenRequested) {
352+
Display.setFullscreen(true);
353+
}
253354

254355
// Display.setDisplayMode(Display.getDesktopDisplayMode());
255-
// Display.setFullscreen(true);
356+
//
256357
// Display.create();
257358

258359

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL