diff --git a/core/README.md b/core/README.md index b57bc4b87..13417ab32 100644 --- a/core/README.md +++ b/core/README.md @@ -55,6 +55,8 @@ inside main, will know the screen that's being used for the app - The size() JavaDoc in PApplet is comically old - Does createFont() need to run through PGraphics? - Need to fix sketch placement issues (default size with long setup(), etc) Actually, the default size with long setup() is probably that defaultSize is set false, but the initial render doesn't finish before width/height are set to something useful. +- selectInput(), selectOutput(), selectFolder() now passing 'null' as parent Window. Should just leave them un-anchored, but need to test to make this doesn't break anything else. +- do we need sketchOutputPath() and sketchOutputStream()? #### Removed functions (not final, just notes) param() diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 3bfbd4dd8..78ef298bc 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -30,6 +30,7 @@ import java.awt.Color; import java.awt.Desktop; import java.awt.EventQueue; import java.awt.FileDialog; +import java.awt.Font; // for the Frame object (deprecate?) import java.awt.Frame; import java.awt.GraphicsConfiguration; @@ -54,7 +55,6 @@ import java.util.zip.*; // used by loadImage() functions import javax.imageio.ImageIO; import javax.swing.ImageIcon; - import javax.swing.JFrame; import javax.swing.JFileChooser; import javax.swing.filechooser.FileSystemView; @@ -788,6 +788,16 @@ public class PApplet implements PConstants { } + public String sketchOutputPath() { + return null; + } + + + public OutputStream sketchOutputStream() { + return null; + } + + public void orientation(int which) { // ignore calls to the orientation command } @@ -1336,6 +1346,7 @@ public class PApplet implements PConstants { ////////////////////////////////////////////////////////////// + /* protected void resizeRenderer(int newWidth, int newHeight) { debug("resizeRenderer request for " + newWidth + " " + newHeight); if (width != newWidth || height != newHeight) { @@ -1345,6 +1356,7 @@ public class PApplet implements PConstants { height = newHeight; } } + */ /** @@ -1435,49 +1447,58 @@ public class PApplet implements PConstants { /** * @nowebref */ - public void size(final int w, final int h, - String renderer, String path) { - // Run this from the EDT, just cuz it's AWT stuff (or maybe later Swing) - EventQueue.invokeLater(new Runnable() { - public void run() { - // Set the preferred size so that the layout managers can handle it - setPreferredSize(new Dimension(w, h)); - setSize(w, h); - } - }); - - // ensure that this is an absolute path - if (path != null) path = savePath(path); - - String currentRenderer = g.getClass().getName(); - if (currentRenderer.equals(renderer)) { -// // Avoid infinite loop of throwing exception to reset renderer -// resizeRenderer(w, h); - surface.setSize(w, h); - - } else { // renderer change attempted - // no longer kosher with 3.0a5 - throw new RuntimeException("Y'all need to implement sketchRenderer()"); - /* - // otherwise ok to fall through and create renderer below - // the renderer is changing, so need to create a new object - g = makeGraphics(w, h, renderer, path, true); - this.width = w; - this.height = h; - - // fire resize event to make sure the applet is the proper size -// setSize(iwidth, iheight); - // this is the function that will run if the user does their own - // size() command inside setup, so set defaultSize to false. - defaultSize = false; - - // throw an exception so that setup() is called again - // but with a properly sized render - // this is for opengl, which needs a valid, properly sized - // display before calling anything inside setup(). - throw new RendererChangeException(); - */ + public void size(final int w, final int h, String renderer, String path) { + if (!renderer.equals(sketchRenderer())) { + System.err.println("Because you're not running from the PDE, add this to your code:"); + System.err.println("public String sketchRenderer() {"); + System.err.println(" return " + renderer + ";"); + System.err.println("}"); + throw new RuntimeException("The sketchRenderer() method is not implemented."); } + surface.setSize(w, h); + g.setPath(path); // finally, a path + +// // Run this from the EDT, just cuz it's AWT stuff (or maybe later Swing) +// EventQueue.invokeLater(new Runnable() { +// public void run() { +// // Set the preferred size so that the layout managers can handle it +// setPreferredSize(new Dimension(w, h)); +// setSize(w, h); +// } +// }); +// +// // ensure that this is an absolute path +// if (path != null) path = savePath(path); +// +// String currentRenderer = g.getClass().getName(); +// if (currentRenderer.equals(renderer)) { +//// // Avoid infinite loop of throwing exception to reset renderer +//// resizeRenderer(w, h); +// surface.setSize(w, h); +// +// } else { // renderer change attempted +// // no longer kosher with 3.0a5 +// throw new RuntimeException("Y'all need to implement sketchRenderer()"); +// /* +// // otherwise ok to fall through and create renderer below +// // the renderer is changing, so need to create a new object +// g = makeGraphics(w, h, renderer, path, true); +// this.width = w; +// this.height = h; +// +// // fire resize event to make sure the applet is the proper size +//// setSize(iwidth, iheight); +// // this is the function that will run if the user does their own +// // size() command inside setup, so set defaultSize to false. +// defaultSize = false; +// +// // throw an exception so that setup() is called again +// // but with a properly sized render +// // this is for opengl, which needs a valid, properly sized +// // display before calling anything inside setup(). +// throw new RendererChangeException(); +// */ +// } } @@ -1585,17 +1606,22 @@ public class PApplet implements PConstants { } - /** - * Version of createGraphics() used internally. - */ + public PGraphics makePrimaryGraphics(int wide, int high) { + return makeGraphics(wide, high, sketchRenderer(), null, true); + } + + + /** Version of createGraphics() used internally. */ protected PGraphics makeGraphics(int w, int h, String renderer, String path, boolean primary) { - String openglError = external ? - "Before using OpenGL, first select " + - "Import Library > OpenGL from the Sketch menu." : - "The Java classpath and native library path is not " + // welcome to Java programming! - "properly set for using the OpenGL library."; +// String openglError = external ? +// // This first one should no longer be possible +// "Before using OpenGL, first select " + +// "Import Library > OpenGL from the Sketch menu." : +// // Welcome to Java programming! The training wheels are off. +// "The Java classpath and native library path is not " + +// "properly set for using the OpenGL library."; if (!primary && !g.isGL()) { if (renderer.equals(P2D)) { @@ -1625,26 +1651,30 @@ public class PApplet implements PConstants { String msg = ite.getTargetException().getMessage(); if ((msg != null) && (msg.indexOf("no jogl in java.library.path") != -1)) { - throw new RuntimeException(openglError + - " (The native library is missing.)"); + // Is this true anymore, since the JARs contain the native libs? + throw new RuntimeException("The jogl library folder needs to be " + + "specified with -Djava.library.path=/path/to/jogl"); + } else { ite.getTargetException().printStackTrace(); Throwable target = ite.getTargetException(); - if (platform == MACOSX) target.printStackTrace(System.out); // bug - // neither of these help, or work - //target.printStackTrace(System.err); - //System.err.flush(); - //System.out.println(System.err); // and the object isn't null + if (platform == MACOSX) { + target.printStackTrace(System.out); // OS X bug (still true?) + } throw new RuntimeException(target.getMessage()); } } catch (ClassNotFoundException cnfe) { - if (cnfe.getMessage().indexOf("processing.opengl.PGraphicsOpenGL") != -1) { - throw new RuntimeException(openglError + - " (The library .jar file is missing.)"); - } else { +// if (cnfe.getMessage().indexOf("processing.opengl.PGraphicsOpenGL") != -1) { +// throw new RuntimeException(openglError + +// " (The library .jar file is missing.)"); +// } else { + if (external) { throw new RuntimeException("You need to use \"Import Library\" " + "to add " + renderer + " to your sketch."); + } else { + throw new RuntimeException("The " + renderer + + " renderer is not in the class path."); } } catch (Exception e) { @@ -1663,7 +1693,9 @@ public class PApplet implements PConstants { throw new RuntimeException(msg); } } else { - if (platform == MACOSX) e.printStackTrace(System.out); + if (platform == MACOSX) { + e.printStackTrace(System.out); // OS X bug (still true?) + } throw new RuntimeException(e.getMessage()); } } @@ -1732,7 +1764,8 @@ public class PApplet implements PConstants { long now = System.nanoTime(); if (frameCount == 0) { - surface.checkDisplaySize(); + // 3.0a5 should be no longer needed; handled by PSurface + //surface.checkDisplaySize(); // try { //println("Calling setup()"); @@ -5466,6 +5499,7 @@ public class PApplet implements PConstants { // FILE/FOLDER SELECTION + /* private Frame selectFrame; private Frame selectFrame() { @@ -5488,6 +5522,7 @@ public class PApplet implements PConstants { } return selectFrame; } + */ /** @@ -5531,7 +5566,7 @@ public class PApplet implements PConstants { public void selectInput(String prompt, String callback, File file, Object callbackObject) { - selectInput(prompt, callback, file, callbackObject, selectFrame()); + selectInput(prompt, callback, file, callbackObject, null); //selectFrame()); } @@ -5559,7 +5594,7 @@ public class PApplet implements PConstants { public void selectOutput(String prompt, String callback, File file, Object callbackObject) { - selectOutput(prompt, callback, file, callbackObject, selectFrame()); + selectOutput(prompt, callback, file, callbackObject, null); //selectFrame()); } @@ -5634,7 +5669,7 @@ public class PApplet implements PConstants { public void selectFolder(String prompt, String callback, File file, Object callbackObject) { - selectFolder(prompt, callback, file, callbackObject, selectFrame()); + selectFolder(prompt, callback, file, callbackObject, null); //selectFrame()); } @@ -6081,34 +6116,6 @@ public class PApplet implements PConstants { } } - // Finally, something special for the Internet Explorer users. Turns out - // that we can't get files that are part of the same folder using the - // methods above when using IE, so we have to resort to the old skool - // getDocumentBase() from teh applet dayz. 1996, my brotha. - try { - URL base = getDocumentBase(); - if (base != null) { - URL url = new URL(base, filename); - URLConnection conn = url.openConnection(); - return conn.getInputStream(); -// if (conn instanceof HttpURLConnection) { -// HttpURLConnection httpConnection = (HttpURLConnection) conn; -// // test for 401 result (HTTP only) -// int responseCode = httpConnection.getResponseCode(); -// } - } - } catch (Exception e) { } // IO or NPE or... - - // Now try it with a 'data' subfolder. getting kinda desperate for data... - try { - URL base = getDocumentBase(); - if (base != null) { - URL url = new URL(base, "data/" + filename); - URLConnection conn = url.openConnection(); - return conn.getInputStream(); - } - } catch (Exception e) { } - try { // attempt to load from a local file, used when running as // an application, or as a signed applet @@ -9266,11 +9273,15 @@ public class PApplet implements PConstants { } } - String renderer = applet.sketchRenderer(); - Class rendererClass = - Thread.currentThread().getContextClassLoader().loadClass(renderer); - Method surfaceMethod = rendererClass.getMethod("createSurface"); - PSurface surface = (PSurface) surfaceMethod.invoke(null, new Object[] { }); + try { + String renderer = applet.sketchRenderer(); + Class rendererClass = + Thread.currentThread().getContextClassLoader().loadClass(renderer); + Method surfaceMethod = rendererClass.getMethod("createSurface"); + PSurface surface = (PSurface) surfaceMethod.invoke(null, new Object[] { }); + } catch (Exception e) { + throw new RuntimeException(e); + } // A handful of things that need to be set before init/start. applet.sketchPath = folder; @@ -9319,7 +9330,7 @@ public class PApplet implements PConstants { } surface.placePresent(stopColor); } else { - surface.placeWindow(); + surface.placeWindow(external, location, editorLocation); } // not always running externally when in present mode if (external) { diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 450ba6261..9bde29597 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -60,6 +60,13 @@ public class PGraphicsJava2D extends PGraphics { // boolean useOffscreen = true; // ~40fps boolean useOffscreen = false; + /** + * Java AWT Image object associated with this renderer. For the 1.0 version + * of P2D and P3D, this was be associated with their MemoryImageSource. + * For PGraphicsJava2D, it will be the offscreen drawing buffer. + */ + public Image image; // moved from PGraphics, not sure about this yet + public Graphics2D g2; protected BufferedImage offscreen; @@ -199,22 +206,13 @@ public class PGraphicsJava2D extends PGraphics { g2 = (Graphics2D) image.getGraphics(); } } - } else { + } else { // not the primary surface // Since this buffer's offscreen anyway, no need for the extra offscreen // buffer. However, unlike the primary surface, this feller needs to be // ARGB so that blending ("alpha" compositing) will work properly. image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); g2 = (Graphics2D) image.getGraphics(); } -// if (!useCanvas) { -// defaultComposite = g2.getComposite(); -// } - - // can't un-set this because this may be only a resize - // http://dev.processing.org/bugs/show_bug.cgi?id=463 - //defaultsInited = false; - //checkSettings(); - //reapplySettings = true; } @@ -1694,7 +1692,6 @@ public class PGraphicsJava2D extends PGraphics { } Font font = (Font) textFont.getNative(); - //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(font); return metrics.getAscent(); diff --git a/core/src/processing/core/PSurfaceAWT.java b/core/src/processing/core/PSurfaceAWT.java index a9479ccf4..76d2e3b76 100644 --- a/core/src/processing/core/PSurfaceAWT.java +++ b/core/src/processing/core/PSurfaceAWT.java @@ -44,13 +44,6 @@ public class PSurfaceAWT implements PSurface { boolean useStrategy = false; Canvas canvas; - /** - * Java AWT Image object associated with this renderer. For the 1.0 version - * of P2D and P3D, this was be associated with their MemoryImageSource. - * For PGraphicsJava2D, it will be the offscreen drawing buffer. - */ - public Image image; - PApplet sketch; Thread thread; @@ -390,13 +383,21 @@ public class PSurfaceAWT implements PSurface { sketch.displayWidth = screenRect.width; sketch.displayHeight = screenRect.height; + int sketchWidth = sketch.sketchWidth(); + int sketchHeight = sketch.sketchHeight(); + // Sketch has already requested to be the same as the screen's // width and height, so let's roll with full screen mode. - if (screenRect.width == sketch.sketchWidth() && - screenRect.height == sketch.sketchHeight()) { + if (screenRect.width == sketchWidth && + screenRect.height == sketchHeight) { fullScreen = true; } + if (fullScreen || spanDisplays) { + sketchWidth = screenRect.width; + sketchHeight = screenRect.height; + } + // Using a JFrame fixes a Windows problem with Present mode. This might // be our error, but usually this is the sort of crap we usually get from // OS X. It's time for a turnaround: Redmond is thinking different too! @@ -432,11 +433,17 @@ public class PSurfaceAWT implements PSurface { if (backgroundColor != null) { ((JFrame) frame).getContentPane().setBackground(backgroundColor); } + // this may be the bounds of all screens frame.setBounds(screenRect); frame.setVisible(true); } frame.setLayout(null); - frame.add(applet); + //frame.add(applet); + + // Need to pass back our new sketchWidth/Height here, because it may have + // been overridden by numbers we calculated above if fullScreen and/or + // spanScreens was in use. + sketch.makePrimaryGraphics(sketchWidth, sketchHeight); if (fullScreen) { frame.invalidate(); @@ -603,6 +610,7 @@ public class PSurfaceAWT implements PSurface { } + // needs to resize the frame, which will resize the canvas, and so on... public void setSize(int width, int height) { throw new RuntimeException("implement me, see readme.md"); } @@ -705,7 +713,7 @@ public class PSurfaceAWT implements PSurface { // System.err.println(PApplet.EXTERNAL_QUIT); // System.err.flush(); // important // System.exit(0); - exit(); // don't quit, need to just shut everything down (0133) + sketch.exit(); // don't quit, need to just shut everything down (0133) } }); } @@ -760,17 +768,17 @@ public class PSurfaceAWT implements PSurface { new Rectangle(0, 0, //insets.left, insets.top, windowSize.width - insets.left - insets.right, windowSize.height - insets.top - insets.bottom); - Rectangle oldBounds = getBounds(); + Rectangle oldBounds = canvas.getBounds(); if (!newBounds.equals(oldBounds)) { // the ComponentListener in PApplet will handle calling size() - setBounds(newBounds); + canvas.setBounds(newBounds); // In 0225, calling this via reflection so that we can still // compile in Java 1.6. This is a trap since we really need // to move to 1.7 and cannot support 1.6, but things like text // are still a little wonky on 1.7, especially on OS X. // This gives us a way to at least test against older VMs. - revalidate(); // let the layout manager do its work + canvas.revalidate(); // let the layout manager do its work /* if (revalidateMethod != null) { try { @@ -1213,8 +1221,8 @@ public class PSurfaceAWT implements PSurface { // If the user called the exit() function, the window should close, // rather than the sketch just halting. - if (exitCalled) { - exitActual(); + if (sketch.exitCalled) { + sketch.exitActual(); } } } diff --git a/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java b/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java index 9de7ec65e..7198c0d4f 100644 --- a/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java +++ b/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java @@ -33,7 +33,7 @@ import processing.core.*; /** - * Thin wrapper for the iText PDF library, that handles writing PDF files. + * Thin wrapper for the iText PDF library that handles writing PDF files. * The majority of the work in this library is done by * iText. *