| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,7 @@ | |||
| 40 | 40 | import java.awt.image.BufferedImage; | |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | + | ||
| 43 | 44 | // used by loadImage() functions | |
| 44 | 45 | import javax.imageio.ImageIO; | |
| 45 | 46 | // allows us to remove our own MediaTracker code | |
@@ -256,7 +257,7 @@ public class PApplet implements PConstants { | |||
| 256 | 257 | * true if no size() command has been executed. This is used to wait until | |
| 257 | 258 | * a size has been set before placing in the window and showing it. | |
| 258 | 259 | */ | |
| 259 | - public boolean defaultSize; | ||
| 260 | + // public boolean defaultSize; | ||
| 260 | 261 | ||
| 261 | 262 | // /** Storage for the current renderer size to avoid re-allocation. */ | |
| 262 | 263 | // Dimension currentSize = new Dimension(); | |
@@ -507,7 +508,7 @@ public class PApplet implements PConstants { | |||
| 507 | 508 | * across platforms and input methods. | |
| 508 | 509 | */ | |
| 509 | 510 | @Deprecated | |
| 510 | - public boolean firstMouse; | ||
| 511 | + public boolean firstMouse = true; | ||
| 511 | 512 | ||
| 512 | 513 | /** | |
| 513 | 514 | * ( begin auto-generated from mouseButton.xml ) | |
@@ -706,10 +707,10 @@ public class PApplet implements PConstants { | |||
| 706 | 707 | */ | |
| 707 | 708 | public float frameRate = 10; | |
| 708 | 709 | ||
| 709 | - protected boolean looping; | ||
| 710 | + protected boolean looping = true; | ||
| 710 | 711 | ||
| 711 | 712 | /** flag set to true when a redraw is asked for by the user */ | |
| 712 | - protected boolean redraw; | ||
| 713 | + protected boolean redraw = true; | ||
| 713 | 714 | ||
| 714 | 715 | /** | |
| 715 | 716 | * ( begin auto-generated from frameCount.xml ) | |
@@ -828,55 +829,55 @@ public class PApplet implements PConstants { | |||
| 828 | 829 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |
| 829 | 830 | ||
| 830 | 831 | ||
| 831 | - /** | ||
| 832 | - * Applet initialization. This can do GUI work because the components have | ||
| 833 | - * not been 'realized' yet: things aren't visible, displayed, etc. | ||
| 834 | - */ | ||
| 835 | - public void init() { | ||
| 836 | - // println("init() called " + Integer.toHexString(hashCode())); | ||
| 837 | - // using a local version here since the class variable is deprecated | ||
| 838 | - // Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); | ||
| 839 | - // screenWidth = screen.width; | ||
| 840 | - // screenHeight = screen.height; | ||
| 841 | - | ||
| 842 | - defaultSize = true; | ||
| 843 | - finished = false; // just for clarity | ||
| 844 | - | ||
| 845 | - // this will be cleared by draw() if it is not overridden | ||
| 846 | - looping = true; | ||
| 847 | - redraw = true; // draw this guy at least once | ||
| 848 | - firstMouse = true; | ||
| 849 | - | ||
| 850 | - // calculated dynamically on first call | ||
| 851 | - // // Removed in 2.1.2, brought back for 2.1.3. Usually sketchPath is set | ||
| 852 | - // // inside runSketch(), but if this sketch takes care of calls to init() | ||
| 853 | - // // when PApplet.main() is not used (i.e. it's in a Java application). | ||
| 854 | - // // THe path needs to be set here so that loadXxxx() functions work. | ||
| 855 | - // if (sketchPath == null) { | ||
| 856 | - // sketchPath = calcSketchPath(); | ||
| 857 | - // } | ||
| 858 | - | ||
| 859 | - // set during Surface.initFrame() | ||
| 860 | - // // Figure out the available display width and height. | ||
| 861 | - // // No major problem if this fails, we have to try again anyway in | ||
| 862 | - // // handleDraw() on the first (== 0) frame. | ||
| 863 | - // checkDisplaySize(); | ||
| 864 | - | ||
| 865 | - // // Set the default size, until the user specifies otherwise | ||
| 866 | - // int w = sketchWidth(); | ||
| 867 | - // int h = sketchHeight(); | ||
| 868 | - // defaultSize = (w == DEFAULT_WIDTH) && (h == DEFAULT_HEIGHT); | ||
| 832 | + // /** | ||
| 833 | + // * Applet initialization. This can do GUI work because the components have | ||
| 834 | + // * not been 'realized' yet: things aren't visible, displayed, etc. | ||
| 835 | + // */ | ||
| 836 | + // public void init() { | ||
| 837 | + //// println("init() called " + Integer.toHexString(hashCode())); | ||
| 838 | + // // using a local version here since the class variable is deprecated | ||
| 839 | + //// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); | ||
| 840 | + //// screenWidth = screen.width; | ||
| 841 | + //// screenHeight = screen.height; | ||
| 869 | 842 | // | |
| 870 | - // g = makeGraphics(w, h, sketchRenderer(), null, true); | ||
| 871 | - // // Fire component resize event | ||
| 872 | - // setSize(w, h); | ||
| 873 | - // setPreferredSize(new Dimension(w, h)); | ||
| 843 | + // defaultSize = true; | ||
| 844 | + // finished = false; // just for clarity | ||
| 874 | 845 | // | |
| 875 | - // width = g.width; | ||
| 876 | - // height = g.height; | ||
| 877 | - | ||
| 878 | - surface.startThread(); | ||
| 879 | - } | ||
| 846 | + // // this will be cleared by draw() if it is not overridden | ||
| 847 | + // looping = true; | ||
| 848 | + // redraw = true; // draw this guy at least once | ||
| 849 | + // firstMouse = true; | ||
| 850 | + // | ||
| 851 | + // // calculated dynamically on first call | ||
| 852 | + //// // Removed in 2.1.2, brought back for 2.1.3. Usually sketchPath is set | ||
| 853 | + //// // inside runSketch(), but if this sketch takes care of calls to init() | ||
| 854 | + //// // when PApplet.main() is not used (i.e. it's in a Java application). | ||
| 855 | + //// // THe path needs to be set here so that loadXxxx() functions work. | ||
| 856 | + //// if (sketchPath == null) { | ||
| 857 | + //// sketchPath = calcSketchPath(); | ||
| 858 | + //// } | ||
| 859 | + // | ||
| 860 | + // // set during Surface.initFrame() | ||
| 861 | + //// // Figure out the available display width and height. | ||
| 862 | + //// // No major problem if this fails, we have to try again anyway in | ||
| 863 | + //// // handleDraw() on the first (== 0) frame. | ||
| 864 | + //// checkDisplaySize(); | ||
| 865 | + // | ||
| 866 | + //// // Set the default size, until the user specifies otherwise | ||
| 867 | + //// int w = sketchWidth(); | ||
| 868 | + //// int h = sketchHeight(); | ||
| 869 | + //// defaultSize = (w == DEFAULT_WIDTH) && (h == DEFAULT_HEIGHT); | ||
| 870 | + //// | ||
| 871 | + //// g = makeGraphics(w, h, sketchRenderer(), null, true); | ||
| 872 | + //// // Fire component resize event | ||
| 873 | + //// setSize(w, h); | ||
| 874 | + //// setPreferredSize(new Dimension(w, h)); | ||
| 875 | + //// | ||
| 876 | + //// width = g.width; | ||
| 877 | + //// height = g.height; | ||
| 878 | + // | ||
| 879 | + // surface.startThread(); | ||
| 880 | + // } | ||
| 880 | 881 | ||
| 881 | 882 | ||
| 882 | 883 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |
@@ -2368,7 +2369,7 @@ public void handleDraw() { | |||
| 2368 | 2369 | // // Give up, instead set the new renderer and re-attempt setup() | |
| 2369 | 2370 | // return; | |
| 2370 | 2371 | // } | |
| 2371 | - defaultSize = false; | ||
| 2372 | + // defaultSize = false; | ||
| 2372 | 2373 | ||
| 2373 | 2374 | } else { // frameCount > 0, meaning an actual draw() | |
| 2374 | 2375 | // update the current frameRate | |
@@ -10119,7 +10120,7 @@ static public void runSketch(final String[] args, | |||
| 10119 | 10120 | sketch.windowColor = windowColor; | |
| 10120 | 10121 | } | |
| 10121 | 10122 | ||
| 10122 | - PSurface surface = sketch.initSurface(); | ||
| 10123 | + final PSurface surface = sketch.initSurface(); | ||
| 10123 | 10124 | // sketch.initSurface(windowColor, displayIndex, fullScreen, spanDisplays); | |
| 10124 | 10125 | ||
| 10125 | 10126 | /* | |
@@ -10146,16 +10147,25 @@ static public void runSketch(final String[] args, | |||
| 10146 | 10147 | surface.placeWindow(location, editorLocation); | |
| 10147 | 10148 | } | |
| 10148 | 10149 | ||
| 10150 | + // EventQueue.invokeLater(new Runnable() { | ||
| 10151 | + // public void run() { | ||
| 10152 | + | ||
| 10149 | 10153 | // Helps avoid this code being duplicated 2x per surface class. | |
| 10150 | 10154 | // Andres is testing to make sure this doesn't cause trouble. | |
| 10151 | 10155 | if (sketch.getGraphics().displayable()) { | |
| 10152 | 10156 | surface.setVisible(true); | |
| 10153 | 10157 | } | |
| 10154 | 10158 | ||
| 10155 | 10159 | // not always running externally when in present mode | |
| 10156 | - if (external) { | ||
| 10160 | + if (sketch.external) { | ||
| 10157 | 10161 | surface.setupExternalMessages(); | |
| 10158 | 10162 | } | |
| 10163 | + | ||
| 10164 | + //sketch.init(); | ||
| 10165 | + surface.startThread(); | ||
| 10166 | + | ||
| 10167 | + // } | ||
| 10168 | + // }); | ||
| 10159 | 10169 | } | |
| 10160 | 10170 | ||
| 10161 | 10171 | ||
@@ -10220,7 +10230,7 @@ private void deprecationWarning(String method) { | |||
| 10220 | 10230 | surface.initOffscreen(this); // for PDF/PSurfaceNone and friends | |
| 10221 | 10231 | } | |
| 10222 | 10232 | ||
| 10223 | - init(); | ||
| 10233 | + // init(); | ||
| 10224 | 10234 | return surface; | |
| 10225 | 10235 | } | |
| 10226 | 10236 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,6 +160,7 @@ public class SmoothCanvas extends Canvas { | |||
| 160 | 160 | private Dimension newSize = new Dimension(0, 0); | |
| 161 | 161 | ||
| 162 | 162 | ||
| 163 | + // Turns out getParent() returns a JPanel on a JFrame. Yech. | ||
| 163 | 164 | public Frame getFrame() { | |
| 164 | 165 | return frame; | |
| 165 | 166 | } | |
@@ -197,7 +198,11 @@ public void validate() { | |||
| 197 | 198 | // System.out.println("validate() render old=" + oldSize + " -> new=" + newSize); | |
| 198 | 199 | oldSize = newSize; | |
| 199 | 200 | sketch.setSize(newSize.width, newSize.height); | |
| 201 | + // try { | ||
| 200 | 202 | render(); | |
| 203 | + // } catch (IllegalStateException ise) { | ||
| 204 | + // System.out.println(ise.getMessage()); | ||
| 205 | + // } | ||
| 201 | 206 | } | |
| 202 | 207 | } | |
| 203 | 208 | ||
@@ -248,103 +253,35 @@ public void addNotify() { | |||
| 248 | 253 | ||
| 249 | 254 | ||
| 250 | 255 | synchronized protected void render() { | |
| 251 | - // System.out.println("render() top"); | ||
| 252 | - | ||
| 253 | - /* | ||
| 254 | - if (!EventQueue.isDispatchThread()) { | ||
| 255 | - //throw new IllegalStateException("render() called outside the EDT"); | ||
| 256 | - //System.err.println("render() called outside the EDT"); | ||
| 257 | - new Exception("render() called outside the EDT").printStackTrace(); | ||
| 256 | + if (canvas.isDisplayable() && | ||
| 257 | + graphics.image != null) { | ||
| 258 | + if (canvas.getBufferStrategy() == null) { | ||
| 259 | + canvas.createBufferStrategy(2); | ||
| 258 | 260 | } | |
| 259 | - */ | ||
| 260 | - // if (canvas == null) { | ||
| 261 | - // removeListeners(this); | ||
| 262 | - // canvas = new Canvas(); | ||
| 263 | - // add(canvas); | ||
| 264 | - // setIgnoreRepaint(true); | ||
| 265 | - // canvas.setIgnoreRepaint(true); | ||
| 266 | - // addListeners(canvas); | ||
| 267 | - //// add(canvas, BorderLayout.CENTER); | ||
| 268 | - //// doLayout(); | ||
| 269 | - // } | ||
| 270 | - | ||
| 271 | - // not sure why this was here, can't be good | ||
| 272 | - //canvas.setBounds(0, 0, sketch.width, sketch.height); | ||
| 273 | - | ||
| 274 | - if (!canvas.isDisplayable()) { | ||
| 275 | - // System.out.println("no peer.. holding"); | ||
| 276 | - return; | ||
| 277 | - } | ||
| 278 | - | ||
| 279 | - if (graphics.image == null) { | ||
| 280 | - if (PApplet.DEBUG) { | ||
| 281 | - new Exception("image is null, returning").printStackTrace(System.out); | ||
| 261 | + BufferStrategy strategy = canvas.getBufferStrategy(); | ||
| 262 | + if (strategy != null) { | ||
| 263 | + // Render single frame | ||
| 264 | + // try { | ||
| 265 | + do { | ||
| 266 | + // The following loop ensures that the contents of the drawing buffer | ||
| 267 | + // are consistent in case the underlying surface was recreated | ||
| 268 | + do { | ||
| 269 | + Graphics2D draw = (Graphics2D) strategy.getDrawGraphics(); | ||
| 270 | + // draw to width/height, since this may be a 2x image | ||
| 271 | + draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null); | ||
| 272 | + draw.dispose(); | ||
| 273 | + } while (strategy.contentsRestored()); | ||
| 274 | + | ||
| 275 | + // Display the buffer | ||
| 276 | + strategy.show(); | ||
| 277 | + | ||
| 278 | + // Repeat the rendering if the drawing buffer was lost | ||
| 279 | + } while (strategy.contentsLost()); | ||
| 282 | 280 | } | |
| 283 | - return; | ||
| 284 | 281 | } | |
| 285 | - | ||
| 286 | - Canvas c = canvas; | ||
| 287 | - // Frame c = frame; | ||
| 288 | - // System.out.println("render(), canvas bounds are " + canvas.getBounds()); | ||
| 289 | - if (c.getBufferStrategy() == null) { // whole block [121222] | ||
| 290 | - // System.out.println("creating a strategy"); | ||
| 291 | - c.createBufferStrategy(2); | ||
| 292 | - } | ||
| 293 | - BufferStrategy strategy = c.getBufferStrategy(); | ||
| 294 | - // System.out.println(strategy); | ||
| 295 | - if (strategy == null) { | ||
| 296 | - return; | ||
| 297 | - } | ||
| 298 | - // Render single frame | ||
| 299 | - do { | ||
| 300 | - // The following loop ensures that the contents of the drawing buffer | ||
| 301 | - // are consistent in case the underlying surface was recreated | ||
| 302 | - do { | ||
| 303 | - Graphics2D draw = (Graphics2D) strategy.getDrawGraphics(); | ||
| 304 | - //draw.drawImage(pg.image, 0, 0, sketch.width, sketch.height, null); | ||
| 305 | - //System.out.println("render() drawing image"); | ||
| 306 | - /* | ||
| 307 | - while (sketch.insideDraw) { | ||
| 308 | - System.out.println("render() yielding because inside draw"); | ||
| 309 | - //Thread.yield(); | ||
| 310 | - try { | ||
| 311 | - Thread.sleep(1); | ||
| 312 | - } catch (InterruptedException e) { } | ||
| 313 | - } | ||
| 314 | - */ | ||
| 315 | - | ||
| 316 | - // this wasn't any faster than setting the image size while drawing | ||
| 317 | - // if (graphics.pixelFactor == 2) { | ||
| 318 | - // draw.scale(0.5, 0.5); | ||
| 319 | - // } | ||
| 320 | - | ||
| 321 | - // draw to width/height, since this may be a 2x image | ||
| 322 | - draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null); | ||
| 323 | - // draw.drawImage(graphics.image, 0, 0, null); | ||
| 324 | - draw.dispose(); | ||
| 325 | - | ||
| 326 | - // Repeat the rendering if the drawing buffer contents | ||
| 327 | - // were restored | ||
| 328 | - // System.out.println("restored " + strategy.contentsRestored()); | ||
| 329 | - } while (strategy.contentsRestored()); | ||
| 330 | - | ||
| 331 | - // Display the buffer | ||
| 332 | - // System.out.println("showing"); | ||
| 333 | - strategy.show(); | ||
| 334 | - | ||
| 335 | - // Repeat the rendering if the drawing buffer was lost | ||
| 336 | - // System.out.println("lost " + strategy.contentsLost()); | ||
| 337 | - // System.out.println(); | ||
| 338 | - } while (strategy.contentsLost()); | ||
| 339 | - // System.out.println("render() bottom"); | ||
| 340 | 282 | } | |
| 341 | 283 | ||
| 342 | 284 | ||
| 343 | - // Object offscreenLock = new Object(); | ||
| 344 | - // BufferedImage offscreen; | ||
| 345 | - // BufferedImage onscreen; | ||
| 346 | - | ||
| 347 | - | ||
| 348 | 285 | /* | |
| 349 | 286 | protected void blit() { | |
| 350 | 287 | // Other folks that call render() (i.e. paint()) are already on the EDT. | |
@@ -762,8 +699,10 @@ private void setFullFrame() { | |||
| 762 | 699 | //frame.setExtendedState(Frame.MAXIMIZED_BOTH); | |
| 763 | 700 | ||
| 764 | 701 | // https://github.com/processing/processing/pull/3162 | |
| 765 | - frame.dispose(); // release native resources, allows setUndecorated() | ||
| 702 | + //frame.dispose(); // release native resources, allows setUndecorated() | ||
| 703 | + frame.removeNotify(); | ||
| 766 | 704 | frame.setUndecorated(true); | |
| 705 | + frame.addNotify(); | ||
| 767 | 706 | ||
| 768 | 707 | // this may be the bounds of all screens | |
| 769 | 708 | frame.setBounds(screenRect); | |
@@ -1479,7 +1418,6 @@ public Thread createThread() { | |||
| 1479 | 1418 | @Override | |
| 1480 | 1419 | public void callDraw() { | |
| 1481 | 1420 | sketch.handleDraw(); | |
| 1482 | - //blit(); | ||
| 1483 | 1421 | render(); | |
| 1484 | 1422 | } | |
| 1485 | 1423 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments