1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Syncing with Processing 1.0.7 (5692); needs testing.

Also, the Sketchbook and Examples menus are currently disabled on the Mac to work-around a bug in Apple's implementation of Java.  I think this bug may have been solved, so I should try re-enabling the menus and see what happens (on 10.4 and 10.5 and 10.6).  Also, I may still need to update the jre / jdk on Linux.
This commit is contained in:
David A. Mellis
2009-09-24 03:16:00 +00:00
parent 240607a4a6
commit 3dc7fc0781
29 changed files with 1413 additions and 959 deletions

View File

@ -3,13 +3,12 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2004-08 Ben Fry and Casey Reas
Copyright (c) 2004-09 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
License as published by the Free Software Foundation, version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -606,13 +605,13 @@ public class PApplet extends Applet
// though it's here for applications anyway
start();
}
public int getSketchWidth() {
return DEFAULT_WIDTH;
}
public int getSketchHeight() {
return DEFAULT_HEIGHT;
}
@ -621,8 +620,8 @@ public class PApplet extends Applet
public String getSketchRenderer() {
return JAVA2D;
}
/**
* Called by the browser or applet viewer to inform this applet that it
* should start its execution. It is called after the init method and
@ -825,7 +824,7 @@ public class PApplet extends Applet
meth.add(o, method);
} catch (NoSuchMethodException nsme) {
die("There is no " + name + "() method in the class " +
die("There is no public " + name + "() method in the class " +
o.getClass().getName());
} catch (Exception e) {
@ -842,7 +841,7 @@ public class PApplet extends Applet
meth.add(o, method);
} catch (NoSuchMethodException nsme) {
die("There is no " + name + "() method in the class " +
die("There is no public " + name + "() method in the class " +
o.getClass().getName());
} catch (Exception e) {
@ -1391,6 +1390,9 @@ public class PApplet extends Applet
//System.out.println("handleDraw() " + frameCount);
g.beginDraw();
if (recorder != null) {
recorder.beginDraw();
}
long now = System.nanoTime();
@ -1442,6 +1444,9 @@ public class PApplet extends Applet
}
g.endDraw();
if (recorder != null) {
recorder.endDraw();
}
frameRateLastNanos = now;
frameCount++;
@ -2233,6 +2238,76 @@ public class PApplet extends Applet
}
//////////////////////////////////////////////////////////////
public void method(String name) {
// final Object o = this;
// final Class<?> c = getClass();
try {
Method method = getClass().getMethod(name, new Class[] {});
method.invoke(this, new Object[] { });
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.getTargetException().printStackTrace();
} catch (NoSuchMethodException nsme) {
System.err.println("There is no public " + name + "() method " +
"in the class " + getClass().getName());
} catch (Exception e) {
e.printStackTrace();
}
}
public void thread(final String name) {
Thread later = new Thread() {
public void run() {
method(name);
}
};
later.start();
}
/*
public void thread(String name) {
final Object o = this;
final Class<?> c = getClass();
try {
final Method method = c.getMethod(name, new Class[] {});
Thread later = new Thread() {
public void run() {
try {
method.invoke(o, new Object[] { });
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.getTargetException().printStackTrace();
}
}
};
later.start();
} catch (NoSuchMethodException nsme) {
System.err.println("There is no " + name + "() method " +
"in the class " + getClass().getName());
} catch (Exception e) {
e.printStackTrace();
}
}
*/
//////////////////////////////////////////////////////////////
// SCREEN GRABASS
@ -2813,6 +2888,13 @@ public class PApplet extends Applet
}
static public final double map(double value,
double istart, double istop,
double ostart, double ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
//////////////////////////////////////////////////////////////
@ -4417,7 +4499,8 @@ public class PApplet extends Applet
* "data" folder. However, when exported (as application or applet),
* sketch's data folder is exported as part of the applications jar file,
* and it's not possible to read/write from the jar file in a generic way.
* If you need to read data from the jar file, you should use createInput().
* If you need to read data from the jar file, you should use other methods
* such as createInput(), createReader(), or loadStrings().
*/
public String dataPath(String where) {
// isAbsolute() could throw an access exception, but so will writing
@ -4445,8 +4528,8 @@ public class PApplet extends Applet
static public void createPath(String path) {
createPath(new File(path));
}
static public void createPath(File file) {
try {
String parent = file.getParent();
@ -4455,7 +4538,7 @@ public class PApplet extends Applet
if (!unit.exists()) unit.mkdirs();
}
} catch (SecurityException se) {
System.err.println("You don't have permissions to create " +
System.err.println("You don't have permissions to create " +
file.getAbsolutePath());
}
}
@ -5257,10 +5340,10 @@ public class PApplet extends Applet
/**
* Split a String on a specific delimiter. Unlike Java's String.split()
* Split a String on a specific delimiter. Unlike Java's String.split()
* method, this does not parse the delimiter as a regexp because it's more
* confusing than necessary, and String.split() is always available for
* those who want regexp.
* those who want regexp.
*/
static public String[] split(String what, String delim) {
ArrayList<String> items = new ArrayList<String>();
@ -6345,9 +6428,9 @@ public class PApplet extends Applet
*
* --present put the applet into full screen presentation
* mode. requires java 1.4 or later.
*
*
* --exclusive use full screen exclusive mode when presenting.
* disables new windows or interaction with other
* disables new windows or interaction with other
* monitors, this is like a "game" mode.
*
* --hide-stop use to hide the stop button in situations where
@ -6401,104 +6484,103 @@ public class PApplet extends Applet
System.exit(1);
}
boolean external = false;
int[] location = null;
int[] editorLocation = null;
String name = null;
boolean present = false;
boolean exclusive = false;
Color backgroundColor = Color.BLACK;
Color stopColor = Color.GRAY;
GraphicsDevice displayDevice = null;
boolean hideStop = false;
String param = null, value = null;
// try to get the user folder. if running under java web start,
// this may cause a security exception if the code is not signed.
// http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1159386274
String folder = null;
try {
boolean external = false;
int[] location = null;
int[] editorLocation = null;
folder = System.getProperty("user.dir");
} catch (Exception e) { }
String name = null;
boolean present = false;
boolean exclusive = false;
Color backgroundColor = Color.BLACK;
Color stopColor = Color.GRAY;
GraphicsDevice displayDevice = null;
boolean hideStop = false;
int argIndex = 0;
while (argIndex < args.length) {
int equals = args[argIndex].indexOf('=');
if (equals != -1) {
param = args[argIndex].substring(0, equals);
value = args[argIndex].substring(equals + 1);
String param = null, value = null;
if (param.equals(ARGS_EDITOR_LOCATION)) {
external = true;
editorLocation = parseInt(split(value, ','));
// try to get the user folder. if running under java web start,
// this may cause a security exception if the code is not signed.
// http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1159386274
String folder = null;
try {
folder = System.getProperty("user.dir");
} catch (Exception e) { }
} else if (param.equals(ARGS_DISPLAY)) {
int deviceIndex = Integer.parseInt(value) - 1;
int argIndex = 0;
while (argIndex < args.length) {
int equals = args[argIndex].indexOf('=');
if (equals != -1) {
param = args[argIndex].substring(0, equals);
value = args[argIndex].substring(equals + 1);
//DisplayMode dm = device.getDisplayMode();
//if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) {
if (param.equals(ARGS_EDITOR_LOCATION)) {
external = true;
editorLocation = parseInt(split(value, ','));
} else if (param.equals(ARGS_DISPLAY)) {
int deviceIndex = Integer.parseInt(value) - 1;
//DisplayMode dm = device.getDisplayMode();
//if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) {
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice devices[] = environment.getScreenDevices();
if ((deviceIndex >= 0) && (deviceIndex < devices.length)) {
displayDevice = devices[deviceIndex];
} else {
System.err.println("Display " + value + " does not exist, " +
"using the default display instead.");
}
} else if (param.equals(ARGS_BGCOLOR)) {
if (value.charAt(0) == '#') value = value.substring(1);
backgroundColor = new Color(Integer.parseInt(value, 16));
} else if (param.equals(ARGS_STOP_COLOR)) {
if (value.charAt(0) == '#') value = value.substring(1);
stopColor = new Color(Integer.parseInt(value, 16));
} else if (param.equals(ARGS_SKETCH_FOLDER)) {
folder = value;
} else if (param.equals(ARGS_LOCATION)) {
location = parseInt(split(value, ','));
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice devices[] = environment.getScreenDevices();
if ((deviceIndex >= 0) && (deviceIndex < devices.length)) {
displayDevice = devices[deviceIndex];
} else {
System.err.println("Display " + value + " does not exist, " +
"using the default display instead.");
}
} else if (param.equals(ARGS_BGCOLOR)) {
if (value.charAt(0) == '#') value = value.substring(1);
backgroundColor = new Color(Integer.parseInt(value, 16));
} else if (param.equals(ARGS_STOP_COLOR)) {
if (value.charAt(0) == '#') value = value.substring(1);
stopColor = new Color(Integer.parseInt(value, 16));
} else if (param.equals(ARGS_SKETCH_FOLDER)) {
folder = value;
} else if (param.equals(ARGS_LOCATION)) {
location = parseInt(split(value, ','));
}
} else {
if (args[argIndex].equals(ARGS_PRESENT)) {
present = true;
} else if (args[argIndex].equals(ARGS_EXCLUSIVE)) {
exclusive = true;
} else if (args[argIndex].equals(ARGS_HIDE_STOP)) {
hideStop = true;
} else if (args[argIndex].equals(ARGS_EXTERNAL)) {
external = true;
} else {
if (args[argIndex].equals(ARGS_PRESENT)) {
present = true;
} else if (args[argIndex].equals(ARGS_EXCLUSIVE)) {
exclusive = true;
} else if (args[argIndex].equals(ARGS_HIDE_STOP)) {
hideStop = true;
} else if (args[argIndex].equals(ARGS_EXTERNAL)) {
external = true;
} else {
name = args[argIndex];
break;
}
name = args[argIndex];
break;
}
argIndex++;
}
argIndex++;
}
// Set this property before getting into any GUI init code
//System.setProperty("com.apple.mrj.application.apple.menu.about.name", name);
// This )*)(*@#$ Apple crap don't work no matter where you put it
// (static method of the class, at the top of main, wherever)
// Set this property before getting into any GUI init code
//System.setProperty("com.apple.mrj.application.apple.menu.about.name", name);
// This )*)(*@#$ Apple crap don't work no matter where you put it
// (static method of the class, at the top of main, wherever)
if (displayDevice == null) {
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
displayDevice = environment.getDefaultScreenDevice();
}
if (displayDevice == null) {
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
displayDevice = environment.getDefaultScreenDevice();
}
Frame frame = new Frame(displayDevice.getDefaultConfiguration());
Frame frame = new Frame(displayDevice.getDefaultConfiguration());
/*
Frame frame = null;
if (displayDevice != null) {
@ -6509,195 +6591,191 @@ public class PApplet extends Applet
*/
//Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
// remove the grow box by default
// users who want it back can call frame.setResizable(true)
frame.setResizable(false);
// remove the grow box by default
// users who want it back can call frame.setResizable(true)
frame.setResizable(false);
// Set the trimmings around the image
Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
frame.setIconImage(image);
frame.setTitle(name);
// Set the trimmings around the image
Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
frame.setIconImage(image);
frame.setTitle(name);
// Class c = Class.forName(name);
final PApplet applet;
try {
Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(name);
final PApplet applet = (PApplet) c.newInstance();
// these are needed before init/start
applet.frame = frame;
applet.sketchPath = folder;
applet.args = PApplet.subset(args, 1);
applet.external = external;
// Need to save the window bounds at full screen,
// because pack() will cause the bounds to go to zero.
// http://dev.processing.org/bugs/show_bug.cgi?id=923
Rectangle fullScreenRect = null;
// For 0149, moving this code (up to the pack() method) before init().
// For OpenGL (and perhaps other renderers in the future), a peer is
// needed before a GLDrawable can be created. So pack() needs to be
// called on the Frame before applet.init(), which itself calls size(),
// and launches the Thread that will kick off setup().
// http://dev.processing.org/bugs/show_bug.cgi?id=891
// http://dev.processing.org/bugs/show_bug.cgi?id=908
if (present) {
frame.setUndecorated(true);
frame.setBackground(backgroundColor);
if (exclusive) {
displayDevice.setFullScreenWindow(frame);
fullScreenRect = frame.getBounds();
} else {
DisplayMode mode = displayDevice.getDisplayMode();
fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
frame.setBounds(fullScreenRect);
frame.setVisible(true);
}
}
frame.setLayout(null);
frame.add(applet);
if (present) {
frame.invalidate();
} else {
frame.pack();
}
// insufficient, places the 100x100 sketches offset strangely
//frame.validate();
applet.init();
// Wait until the applet has figured out its width.
// In a static mode app, this will be after setup() has completed,
// and the empty draw() has set "finished" to true.
// TODO make sure this won't hang if the applet has an exception.
while (applet.defaultSize && !applet.finished) {
//System.out.println("default size");
try {
Thread.sleep(5);
} catch (InterruptedException e) {
//System.out.println("interrupt");
}
}
//println("not default size " + applet.width + " " + applet.height);
//println(" (g width/height is " + applet.g.width + "x" + applet.g.height + ")");
if (present) {
// After the pack(), the screen bounds are gonna be 0s
frame.setBounds(fullScreenRect);
applet.setBounds((fullScreenRect.width - applet.width) / 2,
(fullScreenRect.height - applet.height) / 2,
applet.width, applet.height);
if (!hideStop) {
Label label = new Label("stop");
label.setForeground(stopColor);
label.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.exit(0);
}
});
frame.add(label);
Dimension labelSize = label.getPreferredSize();
// sometimes shows up truncated on mac
//System.out.println("label width is " + labelSize.width);
labelSize = new Dimension(100, labelSize.height);
label.setSize(labelSize);
label.setLocation(20, fullScreenRect.height - labelSize.height - 20);
}
// not always running externally when in present mode
if (external) {
applet.setupExternalMessages();
}
} else { // if not presenting
// can't do pack earlier cuz present mode don't like it
// (can't go full screen with a frame after calling pack)
// frame.pack(); // get insets. get more.
Insets insets = frame.getInsets();
int windowW = Math.max(applet.width, MIN_WINDOW_WIDTH) +
insets.left + insets.right;
int windowH = Math.max(applet.height, MIN_WINDOW_HEIGHT) +
insets.top + insets.bottom;
frame.setSize(windowW, windowH);
if (location != null) {
// a specific location was received from PdeRuntime
// (applet has been run more than once, user placed window)
frame.setLocation(location[0], location[1]);
} else if (external) {
int locationX = editorLocation[0] - 20;
int locationY = editorLocation[1];
if (locationX - windowW > 10) {
// if it fits to the left of the window
frame.setLocation(locationX - windowW, locationY);
} else { // doesn't fit
// if it fits inside the editor window,
// offset slightly from upper lefthand corner
// so that it's plunked inside the text area
locationX = editorLocation[0] + 66;
locationY = editorLocation[1] + 66;
if ((locationX + windowW > applet.screen.width - 33) ||
(locationY + windowH > applet.screen.height - 33)) {
// otherwise center on screen
locationX = (applet.screen.width - windowW) / 2;
locationY = (applet.screen.height - windowH) / 2;
}
frame.setLocation(locationX, locationY);
}
} else { // just center on screen
frame.setLocation((applet.screen.width - applet.width) / 2,
(applet.screen.height - applet.height) / 2);
}
// frame.setLayout(null);
// frame.add(applet);
if (backgroundColor == Color.black) { //BLACK) {
// this means no bg color unless specified
backgroundColor = SystemColor.control;
}
frame.setBackground(backgroundColor);
int usableWindowH = windowH - insets.top - insets.bottom;
applet.setBounds((windowW - applet.width)/2,
insets.top + (usableWindowH - applet.height)/2,
applet.width, applet.height);
if (external) {
applet.setupExternalMessages();
} else { // !external
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// handle frame resizing events
applet.setupFrameResizeListener();
// all set for rockin
if (applet.displayable()) {
frame.setVisible(true);
}
}
applet.requestFocus(); // ask for keydowns
//System.out.println("exiting main()");
applet = (PApplet) c.newInstance();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
throw new RuntimeException(e);
}
// these are needed before init/start
applet.frame = frame;
applet.sketchPath = folder;
applet.args = PApplet.subset(args, 1);
applet.external = external;
// Need to save the window bounds at full screen,
// because pack() will cause the bounds to go to zero.
// http://dev.processing.org/bugs/show_bug.cgi?id=923
Rectangle fullScreenRect = null;
// For 0149, moving this code (up to the pack() method) before init().
// For OpenGL (and perhaps other renderers in the future), a peer is
// needed before a GLDrawable can be created. So pack() needs to be
// called on the Frame before applet.init(), which itself calls size(),
// and launches the Thread that will kick off setup().
// http://dev.processing.org/bugs/show_bug.cgi?id=891
// http://dev.processing.org/bugs/show_bug.cgi?id=908
if (present) {
frame.setUndecorated(true);
frame.setBackground(backgroundColor);
if (exclusive) {
displayDevice.setFullScreenWindow(frame);
fullScreenRect = frame.getBounds();
} else {
DisplayMode mode = displayDevice.getDisplayMode();
fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
frame.setBounds(fullScreenRect);
frame.setVisible(true);
}
}
frame.setLayout(null);
frame.add(applet);
if (present) {
frame.invalidate();
} else {
frame.pack();
}
// insufficient, places the 100x100 sketches offset strangely
//frame.validate();
applet.init();
// Wait until the applet has figured out its width.
// In a static mode app, this will be after setup() has completed,
// and the empty draw() has set "finished" to true.
// TODO make sure this won't hang if the applet has an exception.
while (applet.defaultSize && !applet.finished) {
//System.out.println("default size");
try {
Thread.sleep(5);
} catch (InterruptedException e) {
//System.out.println("interrupt");
}
}
//println("not default size " + applet.width + " " + applet.height);
//println(" (g width/height is " + applet.g.width + "x" + applet.g.height + ")");
if (present) {
// After the pack(), the screen bounds are gonna be 0s
frame.setBounds(fullScreenRect);
applet.setBounds((fullScreenRect.width - applet.width) / 2,
(fullScreenRect.height - applet.height) / 2,
applet.width, applet.height);
if (!hideStop) {
Label label = new Label("stop");
label.setForeground(stopColor);
label.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
System.exit(0);
}
});
frame.add(label);
Dimension labelSize = label.getPreferredSize();
// sometimes shows up truncated on mac
//System.out.println("label width is " + labelSize.width);
labelSize = new Dimension(100, labelSize.height);
label.setSize(labelSize);
label.setLocation(20, fullScreenRect.height - labelSize.height - 20);
}
// not always running externally when in present mode
if (external) {
applet.setupExternalMessages();
}
} else { // if not presenting
// can't do pack earlier cuz present mode don't like it
// (can't go full screen with a frame after calling pack)
// frame.pack(); // get insets. get more.
Insets insets = frame.getInsets();
int windowW = Math.max(applet.width, MIN_WINDOW_WIDTH) +
insets.left + insets.right;
int windowH = Math.max(applet.height, MIN_WINDOW_HEIGHT) +
insets.top + insets.bottom;
frame.setSize(windowW, windowH);
if (location != null) {
// a specific location was received from PdeRuntime
// (applet has been run more than once, user placed window)
frame.setLocation(location[0], location[1]);
} else if (external) {
int locationX = editorLocation[0] - 20;
int locationY = editorLocation[1];
if (locationX - windowW > 10) {
// if it fits to the left of the window
frame.setLocation(locationX - windowW, locationY);
} else { // doesn't fit
// if it fits inside the editor window,
// offset slightly from upper lefthand corner
// so that it's plunked inside the text area
locationX = editorLocation[0] + 66;
locationY = editorLocation[1] + 66;
if ((locationX + windowW > applet.screen.width - 33) ||
(locationY + windowH > applet.screen.height - 33)) {
// otherwise center on screen
locationX = (applet.screen.width - windowW) / 2;
locationY = (applet.screen.height - windowH) / 2;
}
frame.setLocation(locationX, locationY);
}
} else { // just center on screen
frame.setLocation((applet.screen.width - applet.width) / 2,
(applet.screen.height - applet.height) / 2);
}
if (backgroundColor == Color.black) { //BLACK) {
// this means no bg color unless specified
backgroundColor = SystemColor.control;
}
frame.setBackground(backgroundColor);
int usableWindowH = windowH - insets.top - insets.bottom;
applet.setBounds((windowW - applet.width)/2,
insets.top + (usableWindowH - applet.height)/2,
applet.width, applet.height);
if (external) {
applet.setupExternalMessages();
} else { // !external
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// handle frame resizing events
applet.setupFrameResizeListener();
// all set for rockin
if (applet.displayable()) {
frame.setVisible(true);
}
}
applet.requestFocus(); // ask for keydowns
//System.out.println("exiting main()");
}
@ -7225,6 +7303,11 @@ public class PApplet extends Applet
}
public float textWidth(char[] chars, int start, int length) {
return g.textWidth(chars, start, length);
}
public void text(char c) {
if (recorder != null) recorder.text(c);
g.text(c);

View File

@ -2604,6 +2604,14 @@ public class PGraphics extends PImage implements PConstants {
}
/**
* TODO not sure if this stays...
*/
public float textWidth(char[] chars, int start, int length) {
return textWidthImpl(chars, start, start + length);
}
/**
* Implementation of returning the text width of
* the chars [start, stop) in the buffer.
@ -2914,8 +2922,8 @@ public class PGraphics extends PImage implements PConstants {
* Emit a sentence of text, defined as a chunk of text without any newlines.
* @param stop non-inclusive, the end of the text in question
*/
private boolean textSentence(char[] buffer, int start, int stop,
float boxWidth, float spaceWidth) {
protected boolean textSentence(char[] buffer, int start, int stop,
float boxWidth, float spaceWidth) {
float runningX = 0;
// Keep track of this separately from index, since we'll need to back up
@ -2980,7 +2988,7 @@ public class PGraphics extends PImage implements PConstants {
}
private void textSentenceBreak(int start, int stop) {
protected void textSentenceBreak(int start, int stop) {
if (textBreakCount == textBreakStart.length) {
textBreakStart = PApplet.expand(textBreakStart);
textBreakStop = PApplet.expand(textBreakStop);

View File

@ -283,9 +283,9 @@ public class PGraphics2D extends PGraphics {
case TRIANGLE_FAN:
// do fill and stroke separately because otherwise
// the lines will be stroked more than necessary
if (fill) {
if (fill || textureImage != null) {
fpolygon.vertexCount = 3;
for (int i = 1; i < vertexCount-1; i++) {
// System.out.println(i + " of " + vertexCount);
@ -311,7 +311,7 @@ public class PGraphics2D extends PGraphics {
fpolygon.vertices[j][TX] = vertices[i+j][TX];
fpolygon.vertices[j][TY] = vertices[i+j][TY];
// System.out.println(fpolygon.vertices[j][TX] + " " + fpolygon.vertices[j][TY]);
if (textureImage != null) {
@ -342,7 +342,7 @@ public class PGraphics2D extends PGraphics {
increment = (shape == TRIANGLES) ? 3 : 1;
// do fill and stroke separately because otherwise
// the lines will be stroked more than necessary
if (fill) {
if (fill || textureImage != null) {
fpolygon.vertexCount = 3;
for (int i = 0; i < vertexCount-2; i += increment) {
for (int j = 0; j < 3; j++) {
@ -379,7 +379,7 @@ public class PGraphics2D extends PGraphics {
break;
case QUADS:
if (fill) {
if (fill || textureImage != null) {
fpolygon.vertexCount = 4;
for (int i = 0; i < vertexCount-3; i += 4) {
for (int j = 0; j < 4; j++) {
@ -412,14 +412,14 @@ public class PGraphics2D extends PGraphics {
break;
case QUAD_STRIP:
if (fill) {
if (fill || textureImage != null) {
fpolygon.vertexCount = 4;
for (int i = 0; i < vertexCount-3; i += 2) {
for (int j = 0; j < 4; j++) {
int jj = i+j;
if (j == 2) jj = i+3; // swap 2nd and 3rd vertex
if (j == 3) jj = i+2;
fpolygon.vertices[j][R] = vertices[jj][R];
fpolygon.vertices[j][G] = vertices[jj][G];
fpolygon.vertices[j][B] = vertices[jj][B];
@ -445,7 +445,7 @@ public class PGraphics2D extends PGraphics {
case POLYGON:
if (isConvex()) {
if (fill) {
if (fill || textureImage != null) {
//System.out.println("convex");
fpolygon.renderPolygon(vertices, vertexCount);
//if (stroke) polygon.unexpand();
@ -463,7 +463,7 @@ public class PGraphics2D extends PGraphics {
}
} else { // not convex
//System.out.println("concave");
if (fill) {
if (fill || textureImage != null) {
// the triangulator produces polygons that don't align
// when smoothing is enabled. but if there is a stroke around
// the polygon, then smoothing can be temporarily disabled.
@ -1041,14 +1041,14 @@ public class PGraphics2D extends PGraphics {
protected void ellipseImpl(float x, float y, float w, float h) {
if (smooth || (strokeWeight != 1) ||
fillAlpha || strokeAlpha || ctm.isWarped()) {
// identical to PGraphics version, but uses POLYGON
// identical to PGraphics version, but uses POLYGON
// for the fill instead of a TRIANGLE_FAN
float radiusH = w / 2;
float radiusV = h / 2;
float centerX = x + radiusH;
float centerY = y + radiusV;
float sx1 = screenX(x, y);
float sy1 = screenY(x, y);
float sx2 = screenX(x+w, y+h);
@ -1423,11 +1423,6 @@ public class PGraphics2D extends PGraphics {
*/
private void simple_image(PImage image, int sx1, int sy1,
int ix1, int iy1, int ix2, int iy2) {
if (imageMode == CENTER) {
sx1 -= image.width / 2;
sy1 -= image.height / 2;
}
int sx2 = sx1 + image.width;
int sy2 = sy1 + image.height;
@ -1703,7 +1698,7 @@ public class PGraphics2D extends PGraphics {
float len = (float) Math.sqrt(dX*dX + dY*dY);
// TODO stroke width should be transformed!
float rh = strokeWeight / len;
float rh = (strokeWeight / len) / 2;
float dx0 = rh * dY;
float dy0 = rh * dX;
@ -1765,7 +1760,7 @@ public class PGraphics2D extends PGraphics {
}
}
/**
* @param max is what to count to
* @param offset is offset to the 'next' vertex
@ -2018,7 +2013,7 @@ public class PGraphics2D extends PGraphics {
public float screenY(float x, float y) {
return ctm.m10 * x + ctm.m11 * y + ctm.m12;
}
//////////////////////////////////////////////////////////////

View File

@ -608,7 +608,7 @@ public class PGraphics3D extends PGraphics {
endShapeStroke(mode);
}
if (fill) {
if (fill || textureImage != null) {
endShapeFill();
}
@ -622,7 +622,7 @@ public class PGraphics3D extends PGraphics {
// render shape and fill here if not saving the shapes for later
// if true, the shapes will be rendered on endDraw
if (!hints[ENABLE_DEPTH_SORT]) {
if (fill) {
if (fill || textureImage != null) {
if (triangleCount > 0) {
renderTriangles(0, triangleCount);
if (raw != null) {
@ -957,8 +957,8 @@ public class PGraphics3D extends PGraphics {
protected void addPoint(int a) {
if (pointCount == points.length) {
int[][] temp = new int[pointCount << 1][LINE_FIELD_COUNT];
System.arraycopy(lines, 0, temp, 0, lineCount);
lines = temp;
System.arraycopy(points, 0, temp, 0, lineCount);
points = temp;
}
points[pointCount][VERTEX1] = a;
//points[pointCount][STROKE_MODE] = strokeCap | strokeJoin;
@ -1135,12 +1135,12 @@ public class PGraphics3D extends PGraphics {
protected void renderLines(int start, int stop) {
for (int i = start; i < stop; i++) {
renderLineVertices(vertices[lines[i][VERTEX1]],
renderLineVertices(vertices[lines[i][VERTEX1]],
vertices[lines[i][VERTEX2]]);
}
}
protected void renderLineVertices(float[] a, float[] b) {
// 2D hack added by ewjordan 6/13/07
// Offset coordinates by a little bit if drawing 2D graphics.
@ -1181,7 +1181,7 @@ public class PGraphics3D extends PGraphics {
float oy2 = b[TY];
// TODO strokeWeight should be transformed!
float weight = a[SW] / 2;
float weight = a[SW] / 2;
// when drawing points with stroke weight, need to extend a bit
if (ox1 == ox2 && oy1 == oy2) {
@ -2615,8 +2615,8 @@ public class PGraphics3D extends PGraphics {
//public void ellipse(float a, float b, float c, float d)
protected void ellipseImpl(float x, float y, float w, float h) {
float radiusH = w / 2;
float radiusV = h / 2;
@ -2632,7 +2632,7 @@ public class PGraphics3D extends PGraphics {
// returning to pre-1.0 version of algorithm because of problems
int rough = (int)(4+Math.sqrt(w+h)*3);
int accuracy = PApplet.constrain(rough, 6, 100);
if (fill) {
// returning to pre-1.0 version of algorithm because of problems
// int rough = (int)(4+Math.sqrt(w+h)*3);
@ -2755,7 +2755,7 @@ public class PGraphics3D extends PGraphics {
}
}
//////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -203,7 +203,7 @@ public class PImage implements PConstants, Cloneable {
public java.awt.Image getImage() {
loadPixels();
int type = (format == RGB) ?
BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage image = new BufferedImage(width, height, type);
WritableRaster wr = image.getRaster();
wr.setDataElements(0, 0, width, height, pixels);
@ -499,7 +499,11 @@ public class PImage implements PConstants, Cloneable {
*/
public PImage get() {
try {
return (PImage) clone();
PImage clone = (PImage) clone();
// don't want to pass this down to the others
// http://dev.processing.org/bugs/show_bug.cgi?id=1245
clone.cacheMap = null;
return clone;
} catch (CloneNotSupportedException e) {
return null;
}

View File

@ -529,9 +529,10 @@ public class PVector {
* @return the angle between the vectors
*/
static public float angleBetween(PVector v1, PVector v2) {
float dot = v1.dot(v2);
float theta = (float) Math.acos(dot / (v1.mag() * v2.mag()));
return theta;
double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
return (float) Math.acos(dot / (v1mag * v2mag));
}

View File

@ -1335,6 +1335,11 @@ public class XMLElement implements Serializable {
}
public String toString() {
return toString(true);
}
public String toString(boolean pretty) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos);