From 27210cadcd8f8942f82500a65c5c80f2e5c91105 Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 31 Oct 2005 06:07:52 +0000 Subject: [PATCH] lots of changes for recordShapes(), defaults(), beginFrame(), drag and drop for adding files to sketches/opening sketches, tool to auto-build sketchbook folder --- app/Editor.java | 128 +++++++++++++++++++++++++------------ app/Runner.java | 3 +- app/Sketch.java | 43 +++++++++---- app/Sketchbook.java | 2 - build/shared/revisions.txt | 36 +++++++++++ core/PApplet.java | 123 +++++++++++++++++++++++++---------- core/PGraphics.java | 90 +++++++++++++++++--------- core/PGraphics2.java | 4 ++ core/PGraphics3.java | 44 +++++++++++++ core/PImage.java | 4 +- core/todo.txt | 61 ++++++++++++------ opengl/PGraphicsGL.java | 71 +++++++++++--------- todo.txt | 59 +++++++++++++---- video/Movie.java | 3 +- 14 files changed, 489 insertions(+), 182 deletions(-) diff --git a/app/Editor.java b/app/Editor.java index 00a81803a..9414cfd15 100644 --- a/app/Editor.java +++ b/app/Editor.java @@ -28,6 +28,8 @@ import processing.app.syntax.*; import processing.app.tools.*; import java.awt.*; +import java.awt.datatransfer.*; +import java.awt.dnd.*; import java.awt.event.*; import java.io.*; import java.lang.reflect.*; @@ -247,62 +249,87 @@ public class Editor extends JFrame }); */ - /* - //System.out.println("adding droptarget"); DropTarget dt = new DropTarget(this, new DropTargetListener() { public void dragEnter(DropTargetDragEvent event) { // debug messages for diagnostics - System.out.println("dragEnter " + event); + //System.out.println("dragEnter " + event); event.acceptDrag(DnDConstants.ACTION_COPY); } - public void dragExit (DropTargetEvent event) { - System.out.println("dragExit " + event); - + public void dragExit(DropTargetEvent event) { + //System.out.println("dragExit " + event); } - public void dragOver (DropTargetDragEvent event) { - System.out.println("dragOver " + event); - //event.acceptDrag(DnDConstants.ACTION_COPY); + public void dragOver(DropTargetDragEvent event) { + //System.out.println("dragOver " + event); + event.acceptDrag(DnDConstants.ACTION_COPY); + } + + public void dropActionChanged(DropTargetDragEvent event) { + //System.out.println("dropActionChanged " + event); } public void drop(DropTargetDropEvent event) { - System.out.println("drop " + event); - - event.acceptDrop(DnDConstants.ACTION_MOVE); + //System.out.println("drop " + event); + event.acceptDrop(DnDConstants.ACTION_COPY); Transferable transferable = event.getTransferable(); DataFlavor flavors[] = transferable.getTransferDataFlavors(); + int successful = 0; + for (int i = 0; i < flavors.length; i++) { try { - System.out.println(flavors[i]); - System.out.println(transferable.getTransferData(flavors[i])); + //System.out.println(flavors[i]); + //System.out.println(transferable.getTransferData(flavors[i])); + java.util.List list = + (java.util.List) transferable.getTransferData(flavors[i]); + for (int j = 0; j < list.size(); j++) { + Object item = list.get(j); + if (item instanceof File) { + File file = (File) item; + + // see if this is a .pde file to be opened + String filename = file.getName(); + if (filename.endsWith(".pde")) { + String name = filename.substring(0, filename.length() - 4); + File parent = file.getParentFile(); + if (name.equals(parent.getName())) { + handleOpenFile(file); + return; + } + } + + if (sketch.addFile(file)) { + successful++; + } + } + } + } catch (Exception e) { e.printStackTrace(); } } - } - public void dropActionChanged(DropTargetDragEvent event) { - System.out.println("dropActionChanged " + event); + if (successful == 0) { + error("No files were added to the sketch."); + + } else if (successful == 1) { + message("One file added to the sketch."); + + } else { + message(successful + " files added to the sketch."); + } } }); - - try { - dt.addDropTargetListener(this); - - } catch (Exception e) { - e.printStackTrace(); - } - */ } /** - * Hack for #@#)$(* Mac OS X. - * This appears to only be required on OS X 10.2, and this code - * isn't even being hit on OS X 10.3 or Windows. + * Hack for #@#)$(* Mac OS X 10.2. + *

+ * This appears to only be required on OS X 10.2, and is not + * even being called on later versions of OS X or Windows. */ public Dimension getMinimumSize() { //System.out.println("getting minimum size"); @@ -485,15 +512,16 @@ public class Editor extends JFrame }); */ - if (!Preferences.getBoolean("export.library")) { - item = newJMenuItem("New", 'N'); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - handleNew(false); - } - }); - menu.add(item); + //if (!Preferences.getBoolean("export.library")) { + item = newJMenuItem("New", 'N'); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleNew(false); + } + }); + menu.add(item); + /* } else { item = newJMenuItem("New Sketch", 'N'); item.addActionListener(new ActionListener() { @@ -511,6 +539,7 @@ public class Editor extends JFrame }); menu.add(item); } + */ menu.add(sketchbook.getOpenMenu()); saveMenuItem = newJMenuItem("Save", 'S'); @@ -673,6 +702,14 @@ public class Editor extends JFrame }); menu.add(item); + item = new JMenuItem("Export Multiple..."); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new ExportMultiple(Editor.this).show(); + } + }); + menu.add(item); + return menu; } @@ -1609,19 +1646,20 @@ public class Editor extends JFrame synchronized public void handleExport() { //String what = sketch.isLibrary() ? "Applet" : "Library"; //message("Exporting " + what + "..."); - message("Exporting applet..."); + //message("Exporting applet..."); try { //boolean success = sketch.isLibrary() ? //sketch.exportLibrary() : sketch.exportApplet(); boolean success = sketch.exportApplet(); if (success) { + File appletFolder = new File(sketch.folder, "applet"); + Base.openFolder(appletFolder); message("Done exporting."); } else { // error message will already be visible } } catch (Exception e) { - message("Error during export."); - e.printStackTrace(); + error(e); } buttons.clear(); } @@ -1724,6 +1762,14 @@ public class Editor extends JFrame // ................................................................... + /** + * Show an error int the status bar. + */ + public void error(String what) { + status.error(what); + } + + public void error(Exception e) { if (e == null) { System.err.println("Editor.error() was passed a null exception."); @@ -1742,7 +1788,7 @@ public class Editor extends JFrame if (mess.indexOf(javaLang) == 0) { mess = mess.substring(javaLang.length()); } - status.error(mess); + error(mess); } e.printStackTrace(); } @@ -1765,7 +1811,7 @@ public class Editor extends JFrame if (mess.indexOf(javaLang) == 0) { mess = mess.substring(javaLang.length()); } - status.error(mess); + error(mess); buttons.clearRun(); } diff --git a/app/Runner.java b/app/Runner.java index 8126bcc90..55f3321cf 100644 --- a/app/Runner.java +++ b/app/Runner.java @@ -227,7 +227,8 @@ public class Runner implements MessageConsumer { window.pack(); // to get a peer, size set later, need for insets applet.leechErr = leechErr; - applet.folder = sketch.folder.getAbsolutePath(); + //applet.folder = sketch.folder.getAbsolutePath(); + applet.path = sketch.folder.getAbsolutePath(); applet.frame = (Frame) window; applet.init(); diff --git a/app/Sketch.java b/app/Sketch.java index e258f0b4d..58c267c79 100644 --- a/app/Sketch.java +++ b/app/Sketch.java @@ -942,10 +942,8 @@ public class Sketch { /** - * Prompt the user for a new file to the sketch. - * This could be .class or .jar files for the code folder, - * .pde or .java files for the project, - * or .dll, .jnilib, or .so files for the code folder + * Prompt the user for a new file to the sketch, then call the + * other addFile() function to actually add it. */ public void addFile() { // make sure the user didn't hide the sketch folder @@ -976,6 +974,26 @@ public class Sketch { // it move instead of copy, they can do it by hand File sourceFile = new File(directory, filename); + // now do the work of adding the file + addFile(sourceFile); + } + + + /** + * Add a file to the sketch. + *

+ * .pde or .java files will be added to the sketch folder.
+ * .jar, .class, .dll, .jnilib, and .so files will all + * be added to the "code" folder.
+ * All other files will be added to the "data" folder. + *

+ * If they don't exist already, the "code" or "data" folder + * will be created. + *

+ * @return true if successful. + */ + public boolean addFile(File sourceFile) { + String filename = sourceFile.getName(); File destFile = null; boolean addingCode = false; @@ -986,7 +1004,7 @@ public class Sketch { filename.toLowerCase().endsWith(".dll") || filename.toLowerCase().endsWith(".jnilib") || filename.toLowerCase().endsWith(".so")) { - //File codeFolder = new File(this.folder, "code"); + if (!codeFolder.exists()) codeFolder.mkdirs(); destFile = new File(codeFolder, filename); @@ -1004,10 +1022,10 @@ public class Sketch { // make sure they aren't the same file if (!addingCode && sourceFile.equals(destFile)) { Base.showWarning("You can't fool me", - "This file has already been copied to the\n" + - "location where you're trying to add it.\n" + - "I ain't not doin nuthin'.", null); - return; + "This file has already been copied to the\n" + + "location where you're trying to add it.\n" + + "I ain't not doin nuthin'.", null); + return false; } // in case the user is "adding" the code in an attempt @@ -1015,10 +1033,11 @@ public class Sketch { if (!sourceFile.equals(destFile)) { try { Base.copyFile(sourceFile, destFile); + } catch (IOException e) { Base.showWarning("Error adding file", - "Could not add '" + filename + - "' to the sketch.", e); + "Could not add '" + filename + "' to the sketch.", e); + return false; } } @@ -1041,6 +1060,7 @@ public class Sketch { setCurrent(newName); editor.header.repaint(); } + return true; } @@ -1843,7 +1863,6 @@ public class Sketch { zos.flush(); zos.close(); - Base.openFolder(appletFolder); return true; } diff --git a/app/Sketchbook.java b/app/Sketchbook.java index ed39b66e1..1144372a8 100644 --- a/app/Sketchbook.java +++ b/app/Sketchbook.java @@ -23,8 +23,6 @@ package processing.app; -//import processing.core.PApplet; - import java.awt.*; import java.awt.event.*; import java.io.*; diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index c6e108183..58ea833c9 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -7,6 +7,42 @@ releases will be super crusty. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . +ABOUT REV 0094 - 30 October 2005 + + +[ additions ] + +- drag and drop! you can now drag and drop a file to the editor + window to add it to the sketch. if you drag and drop a sketch file + (a .pde file whose parent folder is named the same thing), + that sketch will be opened. + http://dev.processing.org/bugs/show_bug.cgi?id=21 + + +[ bug fixes ] + +- stdout.txt and stderr.txt are no longer written to the processing + folder, which will prevent errors for lab users. + http://dev.processing.org/bugs/show_bug.cgi?id=177 + +- console text selection no longer immediately de-selects + http://dev.processing.org/bugs/show_bug.cgi?id=180 + +- removing quotes from QTJAVA path if they exist (this may have fixed + some issues?) + + +[ semi-obscure api tweaks ] + +- in PApplet, "folder" has been renamed to "path" to match savePath(). + +- added dataPath(String filename) to return the full path to the + give filename within the data folder + + +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + ABOUT REV 0093 - 14 October 2005 First release in a while with lots of bug fixes for the video library diff --git a/core/PApplet.java b/core/PApplet.java index e00196148..e4c350bd1 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -153,7 +153,7 @@ public class PApplet extends Applet public String args[]; /** Path to sketch folder */ - public String folder; + public String path; //folder; /** When debugging headaches */ static final boolean THREAD_DEBUG = false; @@ -161,6 +161,12 @@ public class PApplet extends Applet static public final int DEFAULT_WIDTH = 100; static public final int DEFAULT_HEIGHT = 100; + /** + * true if no size() command has been executed. This is used to wait until + * a size has been set before placing in the window and showing it. + */ + protected boolean defaultSize; + /** * Pixel buffer from this applet's PGraphics. *

@@ -365,7 +371,7 @@ public class PApplet extends Applet * Used by PdeEditor to pass in the location where saveFrame() * and all that stuff should write things. */ - static public final String ARGS_SKETCH_FOLDER = "--sketch-folder"; + static public final String ARGS_SKETCH_FOLDER = "--sketch-path"; /** * Message from parent editor (when run as external) to quit. @@ -442,8 +448,10 @@ public class PApplet extends Applet // create a dummy graphics context size(DEFAULT_WIDTH, DEFAULT_HEIGHT); //size(INITIAL_WIDTH, INITIAL_HEIGHT); - width = 0; // use this to flag whether the width/height are valid - height = 0; + //width = 0; // use this to flag whether the width/height are valid + //height = 0; + // need to set width/height otherwise they won't work for static mode apps + defaultSize = true; // this is automatically called in applets // though it's here for applications anyway @@ -748,7 +756,8 @@ public class PApplet extends Applet // time around, g is the proper size and the proper class, so // all that needs to be done is to set the defaults (clear the // background, set default strokeWeight, etc). - g.defaults(); + //g.defaults(); + // this will happen when P3D or OPENGL are used with size() // inside of setup. it's also safe to call defaults() now, // because it's happening inside setup, which is just frame 0, @@ -1096,6 +1105,9 @@ public class PApplet extends Applet if (THREAD_DEBUG) println(Thread.currentThread().getName() + " 1b draw"); + boolean shapeRecorderNull = true; + boolean rawShapeRecorderNull = true; + if (frameCount == 0) { try { //System.out.println("attempting setup"); @@ -1179,6 +1191,13 @@ public class PApplet extends Applet //} //} + // set a flag regarding whether the recorders were non-null + // as of draw().. this will prevent the recorder from being + // reset if recordShape() is called in an event method, such + // as mousePressed() + shapeRecorderNull = (recorder == null); + rawShapeRecorderNull = (g.rawShapeRecorder == null); + // dmouseX/Y is updated only once per frame dmouseX = mouseX; dmouseY = mouseY; @@ -1203,9 +1222,17 @@ public class PApplet extends Applet } g.endFrame(); - if (recorder != null) { - recorder.endFrame(); - recorder = null; + if (!shapeRecorderNull) { + if (recorder != null) { + recorder.endFrame(); + recorder = null; + } + } + if (!rawShapeRecorderNull) { + if (g.rawShapeRecorder != null) { + g.rawShapeRecorder.endFrame(); + g.rawShapeRecorder = null; + } } //} // older end sync @@ -3175,22 +3202,23 @@ public class PApplet extends Applet if (!online) { try { // first see if it's in a data folder - File file = new File(folder + File.separator + "data", filename); + //File file = new File(path + File.separator + "data", filename); + File file = new File(dataPath(filename)); if (!file.exists()) { // next see if it's just in this folder - file = new File(folder, filename); + file = new File(path, filename); } if (file.exists()) { try { - String path = file.getCanonicalPath(); - String filenameActual = new File(path).getName(); + String filePath = file.getCanonicalPath(); + String filenameActual = new File(filePath).getName(); + // make sure there isn't a subfolder prepended to the name + String filenameShort = new File(filename).getName(); // if the actual filename is the same, but capitalized - // differently, warn the user. unfortunately this won't - // work in subdirectories because getName() on a relative - // path will return just the name, while 'filename' may - // contain part of a relative path. - if (filenameActual.equalsIgnoreCase(filename) && - !filenameActual.equals(filename)) { + // differently, warn the user. + //if (filenameActual.equalsIgnoreCase(filenameShort) && + //!filenameActual.equals(filenameShort)) { + if (!filenameActual.equals(filenameShort)) { throw new RuntimeException("This file is named " + filenameActual + " not " + filename + "."); @@ -3215,21 +3243,22 @@ public class PApplet extends Applet if (stream != null) return stream; // hm, check the data subfolder - stream = getClass().getResourceAsStream("data/" + filename); + stream = getClass().getResourceAsStream(dataPath(filename)); if (stream != null) return stream; // attempt to load from a local file, used when running as // an application, or as a signed applet try { // first try to catch any security exceptions try { - File file = new File(folder, filename); + File file = new File(path, filename); stream = new FileInputStream(file); if (stream != null) return stream; } catch (Exception e) { } // ignored try { - stream = new FileInputStream(new File("data", filename)); + //stream = new FileInputStream(new File("data", filename)); + stream = new FileInputStream(dataPath(filename)); if (stream != null) return stream; } catch (IOException e2) { } @@ -3432,16 +3461,27 @@ public class PApplet extends Applet /** * Prepend the path to the sketch folder to the filename or * path that is passed in. Can be used by applets or external - * libraries to save to the sketch folder. Also creates any - * in-between folders so that things save properly. + * libraries to save to the sketch folder. + *

+ * This is different from simply using the "folder" variable + * because it also creates any in-between folders so that + * things save properly. */ public String savePath(String where) { - String filename = folder + File.separator + where; + String filename = path + File.separator + where; createPath(filename); return filename; } + /** + * Return a full path to an item in the data folder. + */ + public String dataPath(String where) { + return path + File.separator + "data" + where; + } + + /** * Creates in-between folders if they don't already exist. */ @@ -5320,7 +5360,7 @@ v PApplet.this.stop(); * * --bgcolor=#xxxxxx background color of the window * - * --sketch-folder location of where to save files from functions + * --sketch-path location of where to save files from functions * like saveStrings() or saveFrame(). defaults to * the folder that the java application was * launched from, which means if this isn't set by @@ -5445,14 +5485,15 @@ v PApplet.this.stop(); // these are needed before init/start applet.frame = frame; - applet.folder = folder; + applet.path = folder; applet.args = PApplet.subset(args, 1); applet.init(); // wait until the applet has figured out its width // hoping that this won't hang if the applet has an exception - while ((applet.width == 0) && !applet.finished) { + //while ((applet.width == 0) && !applet.finished) { + while (applet.defaultSize && !applet.finished) { try { Thread.sleep(5); @@ -5593,12 +5634,23 @@ v PApplet.this.stop(); ////////////////////////////////////////////////////////////// - public void recordFrame(PGraphics recorder) { - recordFrame(recorder, "frame-" + nf(frameCount, 4)); + + public void recordShapes(PGraphics recorder) { + this.recorder = recorder; + recorder.beginFrame(); } - public void recordFrame(PGraphics recorder, String filename) { + //public void recordShapesRaw(PGraphics raw) { + //g.rawShapeRecorder = raw; + //raw.beginFrame(); + //} + + + /* + //recordShapes(recorder, "frame-" + nf(frameCount, 4)); + + public void recordShapes(PGraphics recorder, String filename) { int first = filename.indexOf('#'); int last = filename.lastIndexOf('#'); @@ -5608,15 +5660,16 @@ v PApplet.this.stop(); String suffix = filename.substring(last + 1); filename = prefix + nf(frameCount, count) + suffix; } - recordFrame(recorder, savePath(filename)); + recordShapes(recorder, savePath(filename)); } - public void recordFrame(PGraphics recorder, File file) { + public void recordShapes(PGraphics recorder, File file) { this.recorder = recorder; //recorder.record(frameCount, file); recorder.beginFrame(); //frameCount, file); } + */ ////////////////////////////////////////////////////////////// @@ -6768,4 +6821,10 @@ v PApplet.this.stop(); public final float brightness(int what) { return g.brightness(what); } + + + public void recordShapesRaw(PGraphics rawShapeRecorder) { + if (recorder != null) recorder.recordShapesRaw(rawShapeRecorder); + g.recordShapesRaw(rawShapeRecorder); + } } diff --git a/core/PGraphics.java b/core/PGraphics.java index ea0df8f7e..f7a43d62f 100644 --- a/core/PGraphics.java +++ b/core/PGraphics.java @@ -39,6 +39,12 @@ import java.io.*; */ public class PGraphics extends PImage implements PConstants { + /*** + * Parent applet as passed in by the constructor. If null, then + * no MemoryImageSource will be used or updated, saving memory. + */ + PApplet parent; + /// width minus one (useful for many calculations) public int width1; @@ -48,6 +54,9 @@ public class PGraphics extends PImage implements PConstants { /// width * height (useful for many calculations) public int pixelCount; + /// true if defaults() has been called a first time + boolean defaultsInited; + // ........................................................ // specifics for java memoryimagesource @@ -57,6 +66,11 @@ public class PGraphics extends PImage implements PConstants { // ........................................................ + // used by recordShapesRaw() + public PGraphics rawShapeRecorder; + + // ........................................................ + // needs to happen before background() is called // and resize.. so it's gotta be outside protected boolean hints[] = new boolean[HINT_COUNT]; @@ -453,17 +467,10 @@ public class PGraphics extends PImage implements PConstants { * @param iwidth viewport width * @param iheight viewport height */ - //public PGraphics(int iwidth, int iheight) { - //resize(iwidth, iheight); - - // init color/stroke/fill - // called instead just before setup on first frame - //defaults(); - - // clear geometry for loading later - //circleX = null; // so that bagel knows to init these - //sphereX = null; // diff from cpp b/c mem in cpp is preallocated - //} + public PGraphics(int iwidth, int iheight) { + this(iwidth, iheight, null); + //resize(iwidth, iheight); + } /** @@ -476,12 +483,10 @@ public class PGraphics extends PImage implements PConstants { * @param iheight viewport height */ public PGraphics(int iwidth, int iheight, PApplet applet) { - if (applet != null) applet.addListeners(); - //applet.addMouseListener(applet); - //applet.addMouseMotionListener(applet); - //applet.addKeyListener(applet); - //applet.addFocusListener(applet); - //} + if (applet != null) { + this.parent = applet; + applet.addListeners(); + } resize(iwidth, iheight); } @@ -528,11 +533,13 @@ public class PGraphics extends PImage implements PConstants { for (int i = 0; i < pixelCount; i++) pixels[i] = backgroundColor; //for (int i = 0; i < pixelCount; i++) pixels[i] = 0xffffffff; - cm = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);; - mis = new MemoryImageSource(width, height, pixels, 0, width); - mis.setFullBufferUpdates(true); - mis.setAnimated(true); - image = Toolkit.getDefaultToolkit().createImage(mis); + if (parent != null) { + cm = new DirectColorModel(32, 0x00ff0000, 0x0000ff00, 0x000000ff);; + mis = new MemoryImageSource(width, height, pixels, 0, width); + mis.setFullBufferUpdates(true); + mis.setAnimated(true); + image = Toolkit.getDefaultToolkit().createImage(mis); + } } @@ -543,10 +550,17 @@ public class PGraphics extends PImage implements PConstants { /** - * Initializes engine before drawing a new frame. - * Called by PApplet, no need to call this. + * Prepares the PGraphics for drawing. + *

+ * When creating your own PGraphics, you should call this before + * drawing anything. */ public void beginFrame() { // ignore + // need to call defaults(), but can only be done when it's ok + // to draw (i.e. for opengl, no drawing can be done outside + // beginFrame/endFrame). + if (!defaultsInited) defaults(); + resetMatrix(); // reset model matrix // reset vertices @@ -555,16 +569,19 @@ public class PGraphics extends PImage implements PConstants { /** - * Indicates a completed frame. - * Finishes rendering and swaps the buffer to the screen. - * - * If z-sorting has been turned on, then the triangles will - * all be quicksorted here (to make alpha work more properly) - * and then blit to the screen. + * This will finalize rendering so that it can be shown on-screen. + *

+ * When creating your own PGraphics, you should call this when + * you're finished drawing. */ public void endFrame() { // ignore // moving this back here (post-68) because of macosx thread problem - mis.newPixels(pixels, cm, 0, width); + if (mis != null) { + mis.newPixels(pixels, cm, 0, width); + } + // mark pixels as having been updated, so that they'll work properly + // when this PGraphics is drawn using image(). + updatePixels(); } @@ -607,6 +624,8 @@ public class PGraphics extends PImage implements PConstants { textLeading = 14; textAlign = LEFT; textMode = MODEL; + + defaultsInited = true; } @@ -3475,4 +3494,13 @@ public class PGraphics extends PImage implements PConstants { public void mask(PImage alpha) { // ignore super.mask(alpha); } + + + ////////////////////////////////////////////////////////////// + + + public void recordShapesRaw(PGraphics rawShapeRecorder) { + throw new RuntimeException("recordShapesRaw() not supported " + + "by this renderer."); + } } diff --git a/core/PGraphics2.java b/core/PGraphics2.java index 38df50bc9..c00fd31e6 100644 --- a/core/PGraphics2.java +++ b/core/PGraphics2.java @@ -120,6 +120,10 @@ public class PGraphics2 extends PGraphics { public void endFrame() { // moving this back here (post-68) because of macosx thread problem //mis.newPixels(pixels, cm, 0, width); + + // need to mark pixels as needing an update, without calling + // its own updatePixels, since that's crazy slow + //updatePixels(); } diff --git a/core/PGraphics3.java b/core/PGraphics3.java index b8db26e45..7be8998ee 100644 --- a/core/PGraphics3.java +++ b/core/PGraphics3.java @@ -174,6 +174,11 @@ public class PGraphics3 extends PGraphics { } + public PGraphics3(int iwidth, int iheight) { + this(iwidth, iheight, null); + } + + /** * Constructor for the PGraphics3 object. Use this to ensure that * the defaults get set properly. In a subclass, use this(w, h) @@ -329,6 +334,12 @@ public class PGraphics3 extends PGraphics { } + /** + * See notes in PGraphics. + * If z-sorting has been turned on, then the triangles will + * all be quicksorted here (to make alpha work more properly) + * and then blit to the screen. + */ public void endFrame() { // no need to z order and render // shapes were already rendered in endShape(); @@ -1312,6 +1323,12 @@ public class PGraphics3 extends PGraphics { protected void render_triangles() { //System.out.println("rendering " + triangleCount + " triangles"); + if (rawShapeRecorder != null) { + rawShapeRecorder.colorMode(RGB, 1); + rawShapeRecorder.noStroke(); + rawShapeRecorder.beginShape(TRIANGLES); + } + for (int i = 0; i < triangleCount; i ++) { float a[] = vertices[triangles[i][VERTEX1]]; float b[] = vertices[triangles[i][VERTEX2]]; @@ -1357,10 +1374,24 @@ public class PGraphics3 extends PGraphics { triangle.setIndex(index); triangle.render(); + + if (rawShapeRecorder != null) { + rawShapeRecorder.fill(ar, ag, ab, a[A]); + rawShapeRecorder.vertex(a[X], a[Y]); // a[X] and not a[VX] ? + rawShapeRecorder.fill(br, bg, bb, b[A]); + rawShapeRecorder.vertex(b[X], b[Y]); + rawShapeRecorder.fill(cr, cg, cb, c[A]); + rawShapeRecorder.vertex(c[X], c[Y]); + } + } + + if (rawShapeRecorder != null) { + rawShapeRecorder.endShape(); } } + /* public void triangleCallback(float x1, float y1, float z1, float r1, float g1, float b1, float a1, float u1, float v1, boolean e1, @@ -1380,6 +1411,7 @@ public class PGraphics3 extends PGraphics { float r2, float g2, float b2, float a2, float weight, int cap, int join) { } + */ protected void depth_sort_lines() { @@ -3763,6 +3795,18 @@ public class PGraphics3 extends PGraphics { + ////////////////////////////////////////////////////////////// + + // RAW SHAPE RECORDING + + + public void recordShapesRaw(PGraphics rawShapeRecorder) { + this.rawShapeRecorder = rawShapeRecorder; + rawShapeRecorder.beginFrame(); + } + + + ////////////////////////////////////////////////////////////// // MATH (internal use only) diff --git a/core/PImage.java b/core/PImage.java index 102779c81..0c8ad1695 100644 --- a/core/PImage.java +++ b/core/PImage.java @@ -290,7 +290,9 @@ public class PImage implements PConstants, Cloneable { /** * Mark the pixels in this region as needing an update. *

- * This doesn't take into account + * This is not currently used by any of the renderers, however the api + * is structured this way in the hope of being able to use this to + * speed things up in the future. *

* Note that when using imageMode(CORNERS), * the x2 and y2 positions are non-inclusive. diff --git a/core/todo.txt b/core/todo.txt index d65b80f07..9a201d7e0 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -3,6 +3,44 @@ X fix bug that was causing font sizes not to be set on opengl X http://dev.processing.org/bugs/show_bug.cgi?id=174 X apply fix from toxi to make targa files less picky X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=SoftwareBugs;action=display;num=1127999630 +X "folder" has been renamed to "path" to match savePath(). +X added "dataPath" to return the full path to something in the data folder +X savePath should maybe be appletPath or sketchPath +X because can be used for opening files too +X (i.e. if needing a File object) +X width, height set to zero in static mode +X probably only set when resize() is called, and it's not happening + +_ when using PGraphics, must call beginFrame() and endFrame() +_ also need to be able to turn off MemoryImageSource on endFrame +_ call defaults() in beginFrame() + +o triangleColors are different because they're per-triangle +o as opposed to per-vertex, because it's based on the facet of the tri +X make vertexCount etc properly accessible in PGraphics3 +X so that people can do things like the dxf renderer +X also have a simple way to hook in triangle leeches to PGraphics3 +X this exists, but needs to be documented, or have accessors + +test this +_ "this file is named" errors don't like subdirectories +_ need to strip off past the file separator or something + +_ add texture support to recordShapesRaw (this might be pretty obscure...) + +_ should PGraphics be a base class with implementations and variables? +_ then PGraphics2D and PGraphics3D that subclass it? +_ (or even just PGraphics2 and PGraphics3) +_ also rename PGraphics2 to PGraphicsJava +_ it's goofy to have the naming so different + +_ calling recordFrame() from mousePressed is important +_ dangerous tho because mouse fxn called just before endFrame + +_ tag release 93 (francis thinks it's rev 1666) + +_ text block wrap problem with manual break character (\n) +_ http://dev.processing.org/bugs/show_bug.cgi?id=188 X tweak to only exit from ESC on keyPressed _ probably should just make this a hint() instead @@ -10,10 +48,6 @@ _ probably should just make this a hint() instead _ keypressed ref: repeating keys _ also remove "no drawing inside keypressed" -_ savePath should maybe be appletPath or sketchPath -_ because can be used for opening files too -_ (i.e. if needing a File object) - _ add a e2mouseX and e2mouseY _ so that the prev mouse location is still good on mouseReleased _ http://dev.processing.org/bugs/show_bug.cgi?id=170 @@ -47,14 +81,6 @@ _ use the SW from vertex instead.. why set stroke in triangle vars at all? _ currently truncating to an int inside add_line_no_clip _ need to clean all this crap up -_ how to handle gluTessVertex calls -_ need to re-map through the regular "vertex" command, -_ but that makes things messy because the glu calls make calls to vertex() -_ and i don't want an additional "pathVertex()" function - -_ "this file is named" errors don't like subdirectories -_ need to strip off past the file separator or something - _ stop() not getting called _ http://dev.processing.org/bugs/show_bug.cgi?id=183 _ major problem for libraries @@ -62,13 +88,6 @@ _ and start() is supposedly called by the applet viewer _ http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#start() _ need to track this stuff down a bit -_ triangleColors are different because they're per-triangle -_ as opposed to per-vertex, because it's based on the facet of the tri -_ make vertexCount etc properly accessible in PGraphics3 -_ so that people can do things like the dxf renderer -_ also have a simple way to hook in triangle leeches to PGraphics3 -_ this exists, but needs to be documented, or have accessors - _ recordFrame() and beginFile()/endFile() _ finalize api with more work on multi-page pdf _ how to deal with triangles/lines and triangleCount and lineCount @@ -638,6 +657,10 @@ _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpen _ grabbing sun.cpu.endian throws a security exception with gl applets _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpenGL;action=display;num=1114368123;start=3 _ strokeWeight() doesn't work in opengl or p3d +_ how to handle gluTessVertex calls +_ need to re-map through the regular "vertex" command, +_ but that makes things messy because the glu calls make calls to vertex() +_ and i don't want an additional "pathVertex()" function PGraphicsAI diff --git a/opengl/PGraphicsGL.java b/opengl/PGraphicsGL.java index cfd6909d5..e49d93c82 100644 --- a/opengl/PGraphicsGL.java +++ b/opengl/PGraphicsGL.java @@ -65,9 +65,6 @@ public class PGraphicsGL extends PGraphics3 { public GLU glu; public GLCanvas canvas; - //public Illustrator ai; - public PGraphics shapeListener; - protected float[] projectionFloats; GLUtesselator tobj; @@ -84,8 +81,8 @@ public class PGraphicsGL extends PGraphics3 { /** * Create a new PGraphicsGL at the specified size. *

- * Unlike unlike other PGraphics objects, the PApplet object passed in - * cannot be null for this renderer because OpenGL uses a special canvas + * Unlike other PGraphics objects, the PApplet object passed in cannot + * be null for this renderer because OpenGL uses a special Canvas * object that must be added to a component (the host PApplet, in this case) * that is visible on screen in order to work properly. * @param applet the host applet @@ -430,6 +427,12 @@ public class PGraphicsGL extends PGraphics3 { float cb = min(1, triangleColors[i][2][TRI_DIFFUSE_B] + triangleColors[i][2][TRI_SPECULAR_B]); + if (rawShapeRecorder != null) { + rawShapeRecorder.colorMode(RGB, 1); + rawShapeRecorder.noStroke(); + rawShapeRecorder.beginShape(TRIANGLES); + } + int textureIndex = triangles[i][TEXTURE_INDEX]; if (textureIndex != -1) { //System.out.println("texture drawing"); @@ -563,6 +566,16 @@ public class PGraphicsGL extends PGraphics3 { gl.glDisable(GL.GL_TEXTURE_2D); + if (rawShapeRecorder != null) { + rawShapeRecorder.texture(texture); + rawShapeRecorder.fill(ar, ag, ab, a[A]); + rawShapeRecorder.vertex(a[VX], a[VY], a[U] * uscale, a[V] * vscale); + rawShapeRecorder.fill(br, bg, bb, b[A]); + rawShapeRecorder.vertex(b[VX], b[VY], b[U] * uscale, b[V] * vscale); + rawShapeRecorder.fill(cr, cg, cb, c[A]); + rawShapeRecorder.vertex(c[VX], c[VY], c[U] * uscale, c[V] * vscale); + } + } else { gl.glBegin(GL.GL_TRIANGLES); @@ -582,25 +595,20 @@ public class PGraphicsGL extends PGraphics3 { gl.glNormal3f(c[NX], c[NY], c[NZ]); gl.glVertex3f(c[VX], c[VY], c[VZ]); - if (shapeListener != null) { - shapeListener.colorMode(RGB, 1); - shapeListener.noStroke(); - float alpha = (a[A] + b[A] + c[A]) / 3.0f; - if (alpha > EPSILON) { - shapeListener.fill((ar + br + cr) / 3.0f, - (ag + bg + cg) / 3.0f, - (ab + bb + cb) / 3.0f, - alpha); - shapeListener.beginShape(TRIANGLES); - shapeListener.vertex(a[VX], a[VY]); - shapeListener.vertex(b[VX], b[VY]); - shapeListener.vertex(c[VX], c[VY]); - shapeListener.endShape(); - } + if (rawShapeRecorder != null) { + rawShapeRecorder.fill(ar, ag, ab, a[A]); + rawShapeRecorder.vertex(a[VX], a[VY]); + rawShapeRecorder.fill(br, bg, bb, b[A]); + rawShapeRecorder.vertex(b[VX], b[VY]); + rawShapeRecorder.fill(cr, cg, cb, c[A]); + rawShapeRecorder.vertex(c[VX], c[VY]); } gl.glEnd(); } } + if (rawShapeRecorder != null) { + rawShapeRecorder.endShape(); + } report("out of triangles"); } @@ -621,8 +629,8 @@ public class PGraphicsGL extends PGraphics3 { //report("render_lines 2 " + lines[i][STROKE_WEIGHT]); gl.glBegin(GL.GL_LINE_STRIP); - if (shapeListener != null) { - shapeListener.strokeWeight(sw); + if (rawShapeRecorder != null) { + rawShapeRecorder.strokeWeight(sw); } // always draw a first point @@ -631,12 +639,12 @@ public class PGraphicsGL extends PGraphics3 { gl.glVertex3f(a[VX], a[VY], a[VZ]); //System.out.println("First point: " + a[VX] +", "+ a[VY] +", "+ a[VZ]); - if (shapeListener != null) { + if (rawShapeRecorder != null) { if (a[SA] > EPSILON) { // don't draw if transparent - shapeListener.colorMode(RGB, 1); - shapeListener.stroke(a[SR], a[SG], a[SB], a[SA]); - shapeListener.beginShape(LINE_STRIP); - shapeListener.vertex(a[VX], a[VY]); + rawShapeRecorder.colorMode(RGB, 1); + rawShapeRecorder.beginShape(LINE_STRIP); + rawShapeRecorder.stroke(a[SR], a[SG], a[SB], a[SA]); + rawShapeRecorder.vertex(a[VX], a[VY]); } } @@ -647,13 +655,14 @@ public class PGraphicsGL extends PGraphics3 { gl.glColor4f(b[SR], b[SG], b[SB], b[SA]); gl.glVertex3f(b[VX], b[VY], b[VZ]); - if (shapeListener != null) { - shapeListener.vertex(b[VX], b[VY]); + if (rawShapeRecorder != null) { + rawShapeRecorder.stroke(b[SR], b[SG], b[SB], b[SA]); + rawShapeRecorder.vertex(b[VX], b[VY]); } i++; } - if (shapeListener != null) { - shapeListener.endShape(); + if (rawShapeRecorder != null) { + rawShapeRecorder.endShape(); } gl.glEnd(); } diff --git a/todo.txt b/todo.txt index f76dfa247..32a8a316e 100644 --- a/todo.txt +++ b/todo.txt @@ -10,8 +10,35 @@ X simplest to just not update the console if nothing is waiting in buffer X http://dev.processing.org/bugs/show_bug.cgi?id=180 X problem with using qtjava is probably the quotes.. X remove them because they're matching quotes elsewhere +X drag & drop implementation to add files to sketch +_ http://dev.processing.org/bugs/show_bug.cgi?id=21 +_ test drag and drop on windows +_ also test on linux +X make simple tool for casey to rebuild all the examples at once +X first select a folder, then will open each sketch in turn, and export +X just make it easier to go to the next sketch +X need to rebuild with this release because of 1.3/1.4 issues +_ http://dev.processing.org/bugs/show_bug.cgi?id=117 +o or add tool to hit 'next' to go through examples +o just make it "next file in folder" since examples are all over +o also need to copy examples locally -_ external apps should inherit memory settings from p5 itself +_ file as a bug (already found below) +_ errors during export don't show up properly (no red status bar) + +_ add "reference" and "examples" categories to bugzilla + +the biggies +_ bring back P2D with proper stuff +_ it's something we had and we lost +_ export to application +_ autoformat deleting code +_ use javac? +_ ask japanese students about whether jikes is working ok + +_ make .pde files double-clickable from windows + +o external apps should inherit memory settings from p5 itself _ too confusing to set the memory in two places _ or perhaps, have a setting in the ide for it _ and allow a checkbox for "always run externally" @@ -31,8 +58,26 @@ _ non-processing posts will be deleted (not a java discussion board) _ no duplicate posts - find an area and post to _ explanation of what the areas are _ be sure to look at the reference, especially the extended reference +_ questions like 'how do i do x' are often solved by looking at the api +_ for instance, to get the framerate, use framerate() other faq +_ why strong typing? (link also to language thing on main page) +_ we cannot commit to any sort of timeframe on releases +_ under the hood - basic +_ it's all java +_ don't use awt +_ most things are imported by default +_ under the hood - complex +_ how to get started with coding +_ everything subclasses PApplet +_ if you need a particular name, add it with "extends PApplet" +_ all code from tabs is joined to one sketch +_ if you want it separate, then you have to make .java files +_ in doing so, you'll lose access to 'g' +_ performance +_ video stinks.. java2d stinks.. macs stink +_ note in the 'drawing in 2d' section of faq _ is there a way to do xxx? _ advanced users who are outgrowing the basic reference: _ be sure to check the "complete" reference @@ -60,14 +105,6 @@ _ don't allow subfolders forever inside the sketchbook folder _ once a sketch is found, don't recurse deeper _ same for libraries, cuz this makes a mess _ (do this right after rev 91 release... could break things) -_ make simple tool for casey to rebuild all the examples at once -_ first select a folder, then will open each sketch in turn, and export -_ just make it easier to go to the next sketch -_ need to rebuild with this release because of 1.3/1.4 issues -_ http://dev.processing.org/bugs/show_bug.cgi?id=117 -_ or add tool to hit 'next' to go through examples -_ just make it "next file in folder" since examples are all over -_ also need to copy examples locally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -128,6 +165,7 @@ _ (rather than blocking on each) _ maybe add a loadImages(String files[]) function? + //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// @@ -202,8 +240,6 @@ PDE / Editor _ when running with external editor, hide the editor text area _ http://dev.processing.org/bugs/show_bug.cgi?id=20 -_ drag & drop implementation to add files to sketch -_ http://dev.processing.org/bugs/show_bug.cgi?id=21 _ tab to just indent lines properly, _ rather than having it convert to spaces _ need a smarter handler (rather than the editor listener) @@ -307,6 +343,7 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=59 PDE / Export +_ errors during export don't show up properly (no red status bar) _ write export-to-application _ http://dev.processing.org/bugs/show_bug.cgi?id=60 _ problem with packages.. currently mainClassName is preproc name diff --git a/video/Movie.java b/video/Movie.java index 31d291721..379ebcf75 100644 --- a/video/Movie.java +++ b/video/Movie.java @@ -133,7 +133,8 @@ public class Movie extends PImage try { try { // look inside the sketch folder (if set) - String location = parent.folder + File.separator + "data"; + //String location = parent.path + File.separator + "data"; + String location = parent.dataPath("data"); File file = new File(location, filename); if (file.exists()) { movie = fromDataRef(new DataRef(new QTFile(file)));