| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ee49fb8 commit d55e9b7
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,11 @@ | |||
| 3 | 3 | import java.awt.Canvas; | |
| 4 | 4 | import java.awt.Color; | |
| 5 | 5 | 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; | ||
| 6 | 11 | ||
| 7 | 12 | import org.lwjgl.LWJGLException; | |
| 8 | 13 | import org.lwjgl.input.Keyboard; | |
@@ -21,16 +26,20 @@ | |||
| 21 | 26 | import processing.opengl.PGraphicsOpenGL; | |
| 22 | 27 | ||
| 23 | 28 | public class PSurfaceLWJGL implements PSurface { | |
| 29 | + GraphicsDevice displayDevice; | ||
| 24 | 30 | PApplet sketch; | |
| 25 | 31 | PGraphics graphics; | |
| 26 | 32 | ||
| 27 | 33 | int sketchWidth; | |
| 28 | 34 | int sketchHeight; | |
| 29 | 35 | ||
| 30 | 36 | Frame frame; | |
| 37 | + // Note that x and y may not be zero, depending on the display configuration | ||
| 38 | + Rectangle screenRect; | ||
| 31 | 39 | ||
| 32 | 40 | PLWJGL pgl; | |
| 33 | 41 | ||
| 42 | + boolean fullScreenRequested; | ||
| 34 | 43 | // ........................................................ | |
| 35 | 44 | ||
| 36 | 45 | // Event handling | |
@@ -66,12 +75,99 @@ public Frame initFrame(PApplet sketch, Color backgroundColor, | |||
| 66 | 75 | int deviceIndex, boolean fullScreen, boolean spanDisplays) { | |
| 67 | 76 | this.sketch = sketch; | |
| 68 | 77 | ||
| 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(); | ||
| 71 | 154 | ||
| 72 | 155 | frame = new DummyFrame(); | |
| 73 | 156 | return frame; | |
| 74 | 157 | } | |
| 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 | + } | ||
| 75 | 171 | ||
| 76 | 172 | @Override | |
| 77 | 173 | public void setTitle(String title) { | |
@@ -118,7 +214,7 @@ public void startThread() { | |||
| 118 | 214 | thread = new AnimationThread(); | |
| 119 | 215 | thread.start(); | |
| 120 | 216 | } else { | |
| 121 | - throw new IllegalStateException("Thread already started in PSurfaceAWT"); | ||
| 217 | + throw new IllegalStateException("Thread already started in PSurfaceLWJGL"); | ||
| 122 | 218 | } | |
| 123 | 219 | } | |
| 124 | 220 | ||
@@ -244,15 +340,20 @@ public AnimationThread() { | |||
| 244 | 340 | @Override | |
| 245 | 341 | public void run() { // not good to make this synchronized, locks things up | |
| 246 | 342 | 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 | + | ||
| 252 | 349 | Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); | |
| 350 | + System.err.println(sketchWidth + " " + sketchHeight); | ||
| 351 | + if (fullScreenRequested) { | ||
| 352 | + Display.setFullscreen(true); | ||
| 353 | + } | ||
| 253 | 354 | ||
| 254 | 355 | // Display.setDisplayMode(Display.getDesktopDisplayMode()); | |
| 255 | - // Display.setFullscreen(true); | ||
| 356 | + // | ||
| 256 | 357 | // Display.create(); | |
| 257 | 358 | ||
| 258 | 359 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments