Merge branch 'master' into doclet-changes

This commit is contained in:
Rune Madsen
2021-07-06 11:13:40 +02:00
143 changed files with 4194 additions and 4275 deletions
+10 -1
View File
@@ -92,11 +92,20 @@ public class PImageAWT extends PImage {
}
/** Set the high bits of all pixels to opaque. */
protected void opaque() {
for (int i = 0; i < pixels.length; i++) {
pixels[i] = 0xFF000000 | pixels[i];
}
}
/**
* Use the getNative() method instead, which allows library interfaces to be
* written in a cross-platform fashion for desktop, Android, and others.
* This is still included for PGraphics objects, which may need the image.
*/
@Override
public Image getImage() { // ignore
return (Image) getNative();
}
@@ -153,7 +162,7 @@ public class PImageAWT extends PImage {
// "Filthy Rich Clients" by Chet Haase and Romain Guy
// Additional modifications and simplifications have been added,
// plus a fix to deal with an infinite loop if images are expanded.
// http://code.google.com/p/processing/issues/detail?id=1463
// https://github.com/processing/processing/issues/1501
static private BufferedImage shrinkImage(BufferedImage img,
int targetWidth, int targetHeight) {
int type = (img.getTransparency() == Transparency.OPAQUE) ?
+65 -218
View File
@@ -55,6 +55,7 @@ import processing.core.PConstants;
import processing.core.PGraphics;
import processing.core.PImage;
import processing.core.PSurfaceNone;
import processing.event.Event;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
@@ -70,7 +71,7 @@ public class PSurfaceAWT extends PSurfaceNone {
// Trying Frame again with a11 to see if this avoids some Swing nastiness.
// In the past, AWT Frames caused some problems on Windows and Linux,
// but those may not be a problem for our reworked PSurfaceAWT class.
Frame frame;
JFrame frame;
// Note that x and y may not be zero, depending on the display configuration
Rectangle screenRect;
@@ -187,7 +188,6 @@ public class PSurfaceAWT extends PSurfaceNone {
public class SmoothCanvas extends Canvas {
private Dimension oldSize = new Dimension(0, 0);
private Dimension newSize = new Dimension(0, 0);
// Turns out getParent() returns a JPanel on a JFrame. Yech.
@@ -218,69 +218,27 @@ public class PSurfaceAWT extends PSurfaceNone {
@Override
public void validate() {
super.validate();
newSize.width = getWidth();
newSize.height = getHeight();
// if (oldSize.equals(newSize)) {
//// System.out.println("validate() return " + oldSize);
// return;
// } else {
Dimension newSize = getSize();
if (!oldSize.equals(newSize)) {
// System.out.println("validate() render old=" + oldSize + " -> new=" + newSize);
oldSize = newSize;
sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor);
// try {
render();
// } catch (IllegalStateException ise) {
// System.out.println(ise.getMessage());
// }
}
}
@Override
public void update(Graphics g) {
// System.out.println("updating");
paint(g);
}
@Override
public void paint(Graphics screen) {
// System.out.println("painting");
// if (useStrategy) {
render();
/*
if (graphics != null) {
System.out.println("drawing to screen " + canvas);
screen.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
}
*/
// } else {
//// new Exception("painting").printStackTrace(System.out);
//// if (graphics.image != null) { // && !sketch.insideDraw) {
// if (onscreen != null) {
//// synchronized (graphics.image) {
// // Needs the width/height to be set so that retina images are properly scaled down
//// screen.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
// synchronized (offscreenLock) {
// screen.drawImage(onscreen, 0, 0, sketchWidth, sketchHeight, null);
// }
// }
// }
}
}
/*
@Override
public void addNotify() {
// System.out.println("adding notify");
super.addNotify();
// prior to Java 7 on OS X, this no longer works [121222]
// createBufferStrategy(2);
}
*/
synchronized protected void render() {
if (canvas.isDisplayable() &&
@@ -291,7 +249,6 @@ public class PSurfaceAWT extends PSurfaceNone {
BufferStrategy strategy = canvas.getBufferStrategy();
if (strategy != null) {
// Render single frame
// try {
do {
// The following loop ensures that the contents of the drawing buffer
// are consistent in case the underlying surface was recreated
@@ -312,65 +269,6 @@ public class PSurfaceAWT extends PSurfaceNone {
}
/*
protected void blit() {
// Other folks that call render() (i.e. paint()) are already on the EDT.
// We need to be using the EDT since we're messing with the Canvas
// object and BufferStrategy and friends.
//EventQueue.invokeLater(new Runnable() {
//public void run() {
//((SmoothCanvas) canvas).render();
//}
//});
if (useStrategy) {
// Not necessary to be on the EDT to update BufferStrategy
//((SmoothCanvas) canvas).render();
render();
} else {
if (graphics.image != null) {
BufferedImage graphicsImage = (BufferedImage) graphics.image;
if (offscreen == null ||
offscreen.getWidth() != graphicsImage.getWidth() ||
offscreen.getHeight() != graphicsImage.getHeight()) {
System.out.println("creating new image");
offscreen = (BufferedImage)
canvas.createImage(graphicsImage.getWidth(),
graphicsImage.getHeight());
// off = offscreen.getGraphics();
}
// synchronized (offscreen) {
Graphics2D off = (Graphics2D) offscreen.getGraphics();
// off.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1));
off.drawImage(graphicsImage, 0, 0, null);
// }
off.dispose();
synchronized (offscreenLock) {
BufferedImage temp = onscreen;
onscreen = offscreen;
offscreen = temp;
}
canvas.repaint();
}
}
}
*/
/*
@Override
public int displayDensity() {
return shim.displayDensity();
}
@Override
public int displayDensity(int display) {
return shim.displayDensity(display);
}
*/
@Override
public void selectInput(String prompt, String callback,
File file, Object callbackObject) {
@@ -398,28 +296,6 @@ public class PSurfaceAWT extends PSurfaceNone {
this.sketch = sketch;
}
/*
public Frame initOffscreen() {
Frame dummy = new Frame();
dummy.pack(); // get legit AWT graphics
// but don't show it
return dummy;
}
*/
/*
@Override
public Component initComponent(PApplet sketch) {
this.sketch = sketch;
// needed for getPreferredSize() et al
sketchWidth = sketch.sketchWidth();
sketchHeight = sketch.sketchHeight();
return canvas;
}
*/
@Override
public void initFrame(final PApplet sketch) {/*, int backgroundColor,
@@ -504,11 +380,7 @@ public class PSurfaceAWT extends PSurfaceNone {
// backgroundColor = WINDOW_BGCOLOR;
// }
final Color windowColor = new Color(sketch.sketchWindowColor(), false);
if (frame instanceof JFrame) {
((JFrame) frame).getContentPane().setBackground(windowColor);
} else {
frame.setBackground(windowColor);
}
frame.getContentPane().setBackground(windowColor);
// Put the p5 logo in the Frame's corner to override the Java coffee cup.
setProcessingIcon(frame);
@@ -561,7 +433,7 @@ public class PSurfaceAWT extends PSurfaceNone {
if (fullScreen) {
frame.invalidate();
} else {
// } else {
// frame.pack();
}
@@ -677,7 +549,7 @@ public class PSurfaceAWT extends PSurfaceNone {
}
frame.setIconImages(iconImages);
} catch (Exception e) { } // harmless; keep this to ourselves
} catch (Exception ignored) { } // harmless; keep this to ourselves
} else { // handle OS X differently
if (!dockIconSpecified()) { // don't override existing -Xdock param
@@ -1147,27 +1019,24 @@ public class PSurfaceAWT extends PSurfaceNone {
* in cases where frame.setResizable(true) is called.
*/
private void setupFrameResizeListener() {
frame.addWindowStateListener(new WindowStateListener() {
@Override
// Detecting when the frame is resized in order to handle the frame
// maximization bug in OSX:
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8036935
public void windowStateChanged(WindowEvent e) {
// This seems to be firing when dragging the window on OS X
// Detecting when the frame is resized in order to handle the frame
// maximization bug in OSX:
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8036935
frame.addWindowStateListener(e -> {
// This seems to be firing when dragging the window on OS X
// https://github.com/processing/processing/issues/3092
if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
// Supposedly, sending the frame to back and then front is a
// workaround for this bug:
// http://stackoverflow.com/a/23897602
// but is not working for me...
//frame.toBack();
//frame.toFront();
// Packing the frame works, but that causes the window to collapse
// on OS X when the window is dragged. Changing to addNotify() for
// https://github.com/processing/processing/issues/3092
if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
// Supposedly, sending the frame to back and then front is a
// workaround for this bug:
// http://stackoverflow.com/a/23897602
// but is not working for me...
//frame.toBack();
//frame.toFront();
// Packing the frame works, but that causes the window to collapse
// on OS X when the window is dragged. Changing to addNotify() for
// https://github.com/processing/processing/issues/3092
//frame.pack();
frame.addNotify();
}
//frame.pack();
frame.addNotify();
}
});
@@ -1319,21 +1188,39 @@ public class PSurfaceAWT extends PSurfaceNone {
// Switching to getModifiersEx() for 4.0a2 because of Java 9 deprecation.
// Had trouble with this in the past and rolled it back because it was
// optional at the time. This time around, just need to iron out the issue.
// http://code.google.com/p/processing/issues/detail?id=1294
// http://code.google.com/p/processing/issues/detail?id=1332
// https://github.com/processing/processing/issues/1332
// https://github.com/processing/processing/issues/1370
int modifiers = nativeEvent.getModifiersEx();
int peButton = 0;
if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
// Technically should be java.awt.event.MouseEvent.BUTTON1 through BUTTON3
// but those are equal to 1, 2, and 3, and this is more readable.
if (nativeEvent.getButton() == 1) {
peButton = PConstants.LEFT;
} else if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
} else if (nativeEvent.getButton() == 2) {
peButton = PConstants.CENTER;
} else if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
} else if (nativeEvent.getButton() == 3) {
peButton = PConstants.RIGHT;
}
// getModifiersEx() has different constants, so need to re-map
// to the masks we're using in processing.event.Event
int peModifiers = 0;
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
peModifiers |= Event.SHIFT;
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
peModifiers |= Event.CTRL;
}
if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
peModifiers |= Event.META;
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
peModifiers |= Event.ALT;
}
sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
peAction, modifiers,
peAction, peModifiers,
nativeEvent.getX() / windowScaleFactor,
nativeEvent.getY() / windowScaleFactor,
peButton,
@@ -1357,21 +1244,24 @@ public class PSurfaceAWT extends PSurfaceNone {
int modifiers = event.getModifiersEx();
/*
// int peModifiers = event.getModifiersEx() &
// (InputEvent.SHIFT_DOWN_MASK |
// InputEvent.CTRL_DOWN_MASK |
// InputEvent.META_DOWN_MASK |
// InputEvent.ALT_DOWN_MASK);
int peModifiers = event.getModifiers() &
(InputEvent.SHIFT_MASK |
InputEvent.CTRL_MASK |
InputEvent.META_MASK |
InputEvent.ALT_MASK);
*/
// getModifiersEx() has different constants, so need to re-map
// to the masks we're using in processing.event.Event.
// If authors want more detail, they can use the native object.
int peModifiers = 0;
if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
peModifiers |= Event.SHIFT;
}
if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
peModifiers |= Event.CTRL;
}
if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
peModifiers |= Event.META;
}
if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
peModifiers |= Event.ALT;
}
sketch.postEvent(new KeyEvent(event, event.getWhen(),
peAction, modifiers,
peAction, peModifiers,
event.getKeyChar(), event.getKeyCode()));
}
@@ -1413,12 +1303,7 @@ public class PSurfaceAWT extends PSurfaceNone {
}
});
canvas.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
nativeMouseEvent(e);
}
});
canvas.addMouseWheelListener(this::nativeMouseEvent);
canvas.addKeyListener(new KeyListener() {
@@ -1426,12 +1311,10 @@ public class PSurfaceAWT extends PSurfaceNone {
nativeKeyEvent(e);
}
public void keyReleased(java.awt.event.KeyEvent e) {
nativeKeyEvent(e);
}
public void keyTyped(java.awt.event.KeyEvent e) {
nativeKeyEvent(e);
}
@@ -1452,37 +1335,6 @@ public class PSurfaceAWT extends PSurfaceNone {
}
/*
public void addListeners(Component comp) {
comp.addMouseListener(this);
comp.addMouseWheelListener(this);
comp.addMouseMotionListener(this);
comp.addKeyListener(this);
comp.addFocusListener(this);
}
public void removeListeners(Component comp) {
comp.removeMouseListener(this);
comp.removeMouseWheelListener(this);
comp.removeMouseMotionListener(this);
comp.removeKeyListener(this);
comp.removeFocusListener(this);
}
*/
// /**
// * Call to remove, then add, listeners to a component.
// * Avoids issues with double-adding.
// */
// public void updateListeners(Component comp) {
// removeListeners(comp);
// addListeners(comp);
// }
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
@@ -1569,9 +1421,4 @@ public class PSurfaceAWT extends PSurfaceNone {
}
};
}
void debug(String format, Object ... args) {
System.out.format(format + "%n", args);
}
}
+179 -13
View File
@@ -1,14 +1,8 @@
package processing.awt;
import java.awt.Desktop;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.*;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
@@ -16,10 +10,6 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.geom.AffineTransform;
import javax.imageio.IIOImage;
@@ -156,6 +146,182 @@ public class ShimAWT implements PConstants {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static public void fromNativeImage(Image img, PImage out) {
out.format = RGB;
out.pixels = null;
if (img instanceof BufferedImage) {
BufferedImage bi = (BufferedImage) img;
out.width = bi.getWidth();
out.height = bi.getHeight();
int type = bi.getType();
if (type == BufferedImage.TYPE_3BYTE_BGR ||
type == BufferedImage.TYPE_4BYTE_ABGR) {
out.pixels = new int[out.width * out.height];
bi.getRGB(0, 0, out.width, out.height, out.pixels, 0, out.width);
if (type == BufferedImage.TYPE_4BYTE_ABGR) {
out.format = ARGB;
// } else {
// opaque();
}
} else {
DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
out.pixels = ((DataBufferInt) db).getData();
if (type == BufferedImage.TYPE_INT_ARGB) {
out.format = ARGB;
// } else if (type == BufferedImage.TYPE_INT_RGB) {
// opaque();
}
}
}
}
if ((out.pixels != null) && (out.format == RGB)) {
for (int i = 0; i < out.pixels.length; i++) {
out.pixels[i] |= 0xFF000000;
}
}
// Implements fall-through if not DataBufferInt above, or not a
// known type, or not DataBufferInt for the data itself.
if (out.pixels == null) { // go the old school Java 1.0 route
out.width = img.getWidth(null);
out.height = img.getHeight(null);
out.pixels = new int[out.width * out.height];
PixelGrabber pg =
new PixelGrabber(img, 0, 0, out.width, out.height, out.pixels, 0, out.width);
try {
pg.grabPixels();
} catch (InterruptedException e) { }
}
out.pixelDensity = 1;
out.pixelWidth = out.width;
out.pixelHeight = out.height;
}
// /** Set the high bits of all pixels to opaque. */
// protected void opaque() {
// for (int i = 0; i < pixels.length; i++) {
// pixels[i] = 0xFF000000 | pixels[i];
// }
// }
static public Object getNativeImage(PImage img) {
img.loadPixels();
int type = (img.format == RGB) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage image =
new BufferedImage(img.pixelWidth, img.pixelHeight, type);
WritableRaster wr = image.getRaster();
wr.setDataElements(0, 0, img.pixelWidth, img.pixelHeight, img.pixels);
return image;
}
static public void resizeImage(PImage img, int w, int h) { // ignore
if (w <= 0 && h <= 0) {
throw new IllegalArgumentException("width or height must be > 0 for resize");
}
if (w == 0) { // Use height to determine relative size
float diff = (float) h / (float) img.height;
w = (int) (img.width * diff);
} else if (h == 0) { // Use the width to determine relative size
float diff = (float) w / (float) img.width;
h = (int) (img.height * diff);
}
BufferedImage bimg =
shrinkImage((BufferedImage) img.getNative(), w*img.pixelDensity, h*img.pixelDensity);
PImage temp = new PImageAWT(bimg);
img.pixelWidth = temp.width;
img.pixelHeight = temp.height;
// Get the resized pixel array
img.pixels = temp.pixels;
img.width = img.pixelWidth / img.pixelDensity;
img.height = img.pixelHeight / img.pixelDensity;
// Mark the pixels array as altered
img.updatePixels();
}
// Adapted from getFasterScaledInstance() method from page 111 of
// "Filthy Rich Clients" by Chet Haase and Romain Guy
// Additional modifications and simplifications have been added,
// plus a fix to deal with an infinite loop if images are expanded.
// https://github.com/processing/processing/issues/1501
static private BufferedImage shrinkImage(BufferedImage img,
int targetWidth, int targetHeight) {
int type = (img.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage outgoing = img;
BufferedImage scratchImage = null;
Graphics2D g2 = null;
int prevW = outgoing.getWidth();
int prevH = outgoing.getHeight();
boolean isTranslucent = img.getTransparency() != Transparency.OPAQUE;
// Use multi-step technique: start with original size, then scale down in
// multiple passes with drawImage() until the target size is reached
int w = img.getWidth();
int h = img.getHeight();
do {
if (w > targetWidth) {
w /= 2;
// if this is the last step, do the exact size
if (w < targetWidth) {
w = targetWidth;
}
} else if (targetWidth >= w) {
w = targetWidth;
}
if (h > targetHeight) {
h /= 2;
if (h < targetHeight) {
h = targetHeight;
}
} else if (targetHeight >= h) {
h = targetHeight;
}
if (scratchImage == null || isTranslucent) {
// Use a single scratch buffer for all iterations and then copy
// to the final, correctly-sized image before returning
scratchImage = new BufferedImage(w, h, type);
g2 = scratchImage.createGraphics();
}
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(outgoing, 0, 0, w, h, 0, 0, prevW, prevH, null);
prevW = w;
prevH = h;
outgoing = scratchImage;
} while (w != targetWidth || h != targetHeight);
if (g2 != null) {
g2.dispose();
}
// If we used a scratch buffer that is larger than our target size,
// create an image of the right size and copy the results into it
if (targetWidth != outgoing.getWidth() ||
targetHeight != outgoing.getHeight()) {
scratchImage = new BufferedImage(targetWidth, targetHeight, type);
g2 = scratchImage.createGraphics();
g2.drawImage(outgoing, 0, 0, null);
g2.dispose();
outgoing = scratchImage;
}
return outgoing;
}
static protected String[] loadImageFormats; // list of ImageIO formats
@@ -509,7 +675,7 @@ public class ShimAWT implements PConstants {
/**
* @param display the display number to check
* display - the display number to check
* (1-indexed to match the Preferences dialog box)
*/
/*
+90 -373
View File
@@ -81,7 +81,9 @@ import processing.opengl.*;
* project of our (tiny) size, we should be focusing on the future, rather
* than working around legacy Java code.
*/
@SuppressWarnings({"unused", "FinalStaticMethod"})
public class PApplet implements PConstants {
//public class PApplet extends PSketch { // possible in the next alpha
/** Full name of the Java version (i.e. 1.5.0_11). */
static public final String javaVersionName =
System.getProperty("java.version");
@@ -294,7 +296,7 @@ public class PApplet implements PConstants {
* be <b>pixelWidth*pixelHeight</b>, not <b>width*height</b>.
*
* @webref environment
* @webBrief The actual pixel heigh when using high resolution display
* @webBrief The actual pixel height when using high resolution display
* @see PApplet#pixelWidth
* @see #pixelDensity(int)
* @see #displayDensity()
@@ -521,7 +523,7 @@ public class PApplet implements PConstants {
// been released already. Otherwise the events are inconsistent, e.g.
// Left Pressed - Left Drag - CTRL Pressed - Right Drag - Right Released.
// See: https://github.com/processing/processing/issues/5672
private boolean macosxLeftButtonWithCtrlPressed;
private boolean macosCtrlClick;
/** @deprecated Use a mouse event handler that passes an event instead. */
@@ -724,7 +726,7 @@ public class PApplet implements PConstants {
// messages to send if attached as an external vm
/**
* Position of the upper-lefthand corner of the editor window
* Position of the upper left-hand corner of the editor window
* that launched this applet.
*/
static public final String ARGS_EDITOR_LOCATION = "--editor-location";
@@ -1342,7 +1344,7 @@ public class PApplet implements PConstants {
Map<String, RegisteredMethods> registerMap = new ConcurrentHashMap<>();
class RegisteredMethod {
static class RegisteredMethod {
Object object;
Method method;
@@ -1394,6 +1396,7 @@ public class PApplet implements PConstants {
}
// Clear the entries queued for removal (if any)
for (Object object : removals) {
//noinspection SuspiciousMethodCalls
entries.remove(object);
}
removals = null; // clear this out
@@ -1401,6 +1404,7 @@ public class PApplet implements PConstants {
void add(Object object, Method method) {
//noinspection SuspiciousMethodCalls
if (!entries.contains(object)) {
entries.add(new RegisteredMethod(object, method));
} else {
@@ -1417,6 +1421,7 @@ public class PApplet implements PConstants {
*/
public void remove(Object object) {
if (removals == null) {
//noinspection SuspiciousMethodCalls
entries.remove(object);
} else {
// Currently iterating the list of methods, remove this afterwards
@@ -1533,7 +1538,7 @@ public class PApplet implements PConstants {
/**
*
* The <b>setup()</b> function is run once, when the program starts. It's used
* to define initial enviroment properties such as screen size and to load media
* to define initial environment properties such as screen size and to load media
* such as images and fonts as the program starts. There can only be one
* <b>setup()</b> function for each program and it shouldn't be called again
* after its initial execution.<br />
@@ -1827,72 +1832,6 @@ public class PApplet implements PConstants {
this.outputPath = path;
}
}
/*
if (!renderer.equals(sketchRenderer())) {
if (external) {
// The PDE should have parsed it, but something still went wrong
final String msg =
String.format("Something bad happened when calling " +
"size(%d, %d, %s, %s)", w, h, renderer, path);
throw new RuntimeException(msg);
} else {
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.");
}
}
*/
// size() shouldn't actually do anything here [3.0a8]
// surface.setSize(w, h);
// this won't be absolute, which will piss off PDF [3.0a8]
// 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();
// */
// }
}
@@ -2009,24 +1948,9 @@ public class PApplet implements PConstants {
public PGraphics createGraphics(int w, int h,
String renderer, String path) {
return makeGraphics(w, h, renderer, path, false);
/*
if (path != null) {
path = savePath(path);
}
PGraphics pg = makeGraphics(w, h, renderer, path, false);
//pg.parent = this; // why wasn't setParent() used before 3.0a6?
//pg.setParent(this); // make save() work
// Nevermind, parent is set in makeGraphics()
return pg;
*/
}
// public PGraphics makePrimaryGraphics(int wide, int high) {
// return makeGraphics(wide, high, sketchRenderer(), null, true);
// }
/**
* Version of createGraphics() used internally.
* @param path A path (or null if none), can be absolute or relative ({@link PApplet#savePath} will be called)
@@ -2034,14 +1958,6 @@ public class PApplet implements PConstants {
protected PGraphics makeGraphics(int w, int h,
String renderer, String path,
boolean primary) {
// 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)) {
throw new RuntimeException("createGraphics() with P2D requires size() to use P2D or P3D");
@@ -2092,12 +2008,12 @@ public class PApplet implements PConstants {
}
} catch (ClassNotFoundException cnfe) {
// if (cnfe.getMessage().indexOf("processing.opengl.PGraphicsOpenGL") != -1) {
// throw new RuntimeException(openglError +
// " (The library .jar file is missing.)");
// } else {
// Clarify the error message for less confusion on 4.x
if (renderer.equals(FX2D)) {
renderer = "JavaFX";
}
if (external) {
throw new RuntimeException("You need to use \"Import Library\" " +
throw new RuntimeException("Please use Sketch \u2192 Import Library " +
"to add " + renderer + " to your sketch.");
} else {
throw new RuntimeException("The " + renderer +
@@ -2466,13 +2382,13 @@ public class PApplet implements PConstants {
* overloaded to do something more useful.
*/
protected void handleMouseEvent(MouseEvent event) {
// http://dev.processing.org/bugs/show_bug.cgi?id=170
// https://processing.org/bugs/bugzilla/170.html
// also prevents mouseExited() on the mac from hosing the mouse
// position, because x/y are bizarre values on the exit event.
// see also the id check below.. both of these go together.
// Not necessary to set mouseX/Y on RELEASE events because the
// actual position will have been set by a PRESS or DRAG event.
// However, PRESS events might come without a preceeding move,
// However, PRESS events might come without a preceding move,
// if the sketch window gains focus on that PRESS.
final int action = event.getAction();
if (action == MouseEvent.DRAG ||
@@ -2486,20 +2402,33 @@ public class PApplet implements PConstants {
int button = event.getButton();
// If running on Mac OS, allow ctrl-click as right mouse.
if (PApplet.platform == PConstants.MACOS && event.getButton() == PConstants.LEFT) {
// If running on Mac OS, allow ctrl-click as right mouse click.
// Handled inside PApplet so that the same logic need not be redone
// for each Surface independently, since the code seems to be identical:
// no native code backing Surface objects (AWT, JavaFX, JOGL) handle it.
if (PApplet.platform == PConstants.MACOS &&
button == PConstants.LEFT) {
if (action == MouseEvent.PRESS && event.isControlDown()) {
macosxLeftButtonWithCtrlPressed = true;
// The ctrl key may only be down during the press, but we need to store
// it so that the drag or release still is considered a right-click.
macosCtrlClick = true;
}
if (macosxLeftButtonWithCtrlPressed) {
if (macosCtrlClick) {
button = PConstants.RIGHT;
// Recreate the Event object as a right-click, and unset the CTRL flag,
// since it's not a ctrl-right-click, it's just a right click.
int modifiers = event.getModifiers() & ~Event.CTRL;
event = new MouseEvent(event.getNative(), event.getMillis(),
event.getAction(), event.getModifiers(),
event.getAction(), modifiers,
event.getX(), event.getY(),
button, event.getCount());
}
if (action == MouseEvent.RELEASE) {
macosxLeftButtonWithCtrlPressed = false;
if (action == MouseEvent.CLICK) {
// Un-set the variable for the next time around.
// (This won't affect the current event being handled.)
// Changed to CLICK instead of RELEASE for 4.0a6, because the click
// event will fire after the press/drag/release events have fired.
macosCtrlClick = false;
}
}
@@ -3652,7 +3581,7 @@ public class PApplet implements PConstants {
* Called to dispose of resources and shut down the sketch.
* Destroys the thread, dispose the renderer,and notify listeners.
* <p>
* Not to be called or overriden by users. If called multiple times,
* Not to be called or overridden by users. If called multiple times,
* will only notify listeners once. Register a dispose listener instead.
*/
public void dispose() {
@@ -3912,14 +3841,6 @@ public class PApplet implements PConstants {
* (<a href="https://github.com/processing/processing/issues/3791">Issue
* 3791</a>).
*
* <h3>Advanced</h3> Set a custom cursor to an image with a specific hotspot.
* Only works with JDK 1.2 and later. Currently seems to be broken on Java 1.4
* for Mac OS X
* <p>
* Based on code contributed by Amit Pitaru, plus additional code to handle
* Java versions via reflection by Jonathan Feinberg. Reflection removed for
* release 0128 and later.
*
* @webref environment
* @webBrief Sets the cursor to a predefined symbol, an image, or makes it
* visible if already hidden
@@ -4048,25 +3969,13 @@ public class PApplet implements PConstants {
if (o == null) {
sb.append("null");
} else {
sb.append(o.toString());
sb.append(o);
}
}
System.out.print(sb.toString());
System.out.print(sb);
}
/*
static public void print(Object what) {
if (what == null) {
// special case since this does fuggly things on > 1.1
System.out.print("null");
} else {
System.out.println(what.toString());
}
}
*/
/**
*
* The <b>println()</b> function writes to the console area, the black
@@ -4176,7 +4085,7 @@ public class PApplet implements PConstants {
} else if (what.getClass().isArray()) {
printArray(what);
} else {
System.out.println(what.toString());
System.out.println(what);
System.out.flush();
}
}
@@ -4202,7 +4111,7 @@ public class PApplet implements PConstants {
*/
static public void printArray(Object what) {
if (what == null) {
// special case since this does fuggly things on > 1.1
// special case since this does fugly things on > 1.1
System.out.println("null");
} else {
@@ -5257,7 +5166,7 @@ public class PApplet implements PConstants {
// [toxi 040903]
// make perlin noise quality user controlled to allow
// for different levels of detail. lower values will produce
// smoother results as higher octaves are surpressed
// smoother results as higher octaves are suppressed
/**
*
@@ -5469,26 +5378,6 @@ public class PApplet implements PConstants {
// DATA I/O
// /**
// * @webref input:files
// * @brief Creates a new XML object
// * @param name the name to be given to the root element of the new XML object
// * @return an XML object, or null
// * @see XML
// * @see PApplet#loadXML(String)
// * @see PApplet#parseXML(String)
// * @see PApplet#saveXML(XML, String)
// */
// public XML createXML(String name) {
// try {
// return new XML(name);
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
/**
* Reads the contents of a file or URL and creates an XML
* object with its values. If a file is specified, it must
@@ -5837,18 +5726,6 @@ public class PApplet implements PConstants {
}
// /**
// * @webref input:files
// * @see Table
// * @see PApplet#loadTable(String)
// * @see PApplet#saveTable(Table, String)
// */
// public Table createTable() {
// return new Table();
// }
/**
* Reads the contents of a file or URL and creates an Table object with its
* values. If a file is specified, it must be located in the sketch's "data"
@@ -6069,7 +5946,7 @@ public class PApplet implements PConstants {
* distributed should be included with a sketch.<br />
* <br />
* The <b>size</b> parameter states the font size you want to generate. The
* <b>smooth</b> parameter specifies if the font should be antialiased or not.
* <b>smooth</b> parameter specifies if the font should be anti-aliased or not.
* The <b>charset</b> parameter is an array of chars that specifies the
* characters to generate.<br />
* <br />
@@ -6091,7 +5968,7 @@ public class PApplet implements PConstants {
* @param size
* point size of the font
* @param smooth
* true for an antialiased font, false for aliased
* true for an anti-aliased font, false for aliased
* @param charset
* array containing characters to be generated
* @see PFont
@@ -6114,32 +5991,6 @@ public class PApplet implements PConstants {
// FILE/FOLDER SELECTION
/*
private Frame selectFrame;
private Frame selectFrame() {
if (frame != null) {
selectFrame = frame;
} else if (selectFrame == null) {
Component comp = getParent();
while (comp != null) {
if (comp instanceof Frame) {
selectFrame = (Frame) comp;
break;
}
comp = comp.getParent();
}
// Who you callin' a hack?
if (selectFrame == null) {
selectFrame = new Frame();
}
}
return selectFrame;
}
*/
/**
* Open a platform-specific file chooser dialog to select a file for input.
* After the selection is made, the selected File will be passed to the
@@ -6157,7 +6008,7 @@ public class PApplet implements PConstants {
* if (selection == null) {
* println("Window was closed or the user hit cancel.");
* } else {
* println("User selected " + fileSeleted.getAbsolutePath());
* println("User selected " + fileSelected.getAbsolutePath());
* }
* }
* </pre>
@@ -6482,7 +6333,8 @@ public class PApplet implements PConstants {
files = false;
} else if (opt.equals("hidden")) {
hidden = true;
} else if (opt.equals("relative")) {
} else //noinspection StatementWithEmptyBody
if (opt.equals("relative")) {
// ignored
} else {
throw new RuntimeException(opt + " is not a listFiles() option");
@@ -6558,7 +6410,7 @@ public class PApplet implements PConstants {
*/
static public String checkExtension(String filename) {
// Don't consider the .gz as part of the name, createInput()
// and createOuput() will take care of fixing that up.
// and createOutput() will take care of fixing that up.
if (filename.toLowerCase().endsWith(".gz")) {
filename = filename.substring(0, filename.length() - 3);
}
@@ -7756,7 +7608,7 @@ public class PApplet implements PConstants {
if (platform == WINDOWS && !disableAWT) {
desktopFolder = ShimAWT.getWindowsDesktop();
} else {
throw new UnsupportedOperationException("Could not find a suitable Desktop foldder");
throw new UnsupportedOperationException("Could not find a suitable Desktop folder");
}
}
}
@@ -8015,6 +7867,7 @@ public class PApplet implements PConstants {
* number of array elements to be copied
* @see PApplet#concat(boolean[], boolean[])
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
static public void arrayCopy(Object src, int srcPosition,
Object dst, int dstPosition,
int length) {
@@ -8025,6 +7878,7 @@ public class PApplet implements PConstants {
* Convenience method for arraycopy().
* Identical to <CODE>arraycopy(src, 0, dst, 0, length);</CODE>
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
static public void arrayCopy(Object src, Object dst, int length) {
System.arraycopy(src, 0, dst, 0, length);
}
@@ -8034,6 +7888,7 @@ public class PApplet implements PConstants {
* the source into the destination array.
* Identical to <CODE>arraycopy(src, 0, dst, 0, src.length);</CODE>
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
static public void arrayCopy(Object src, Object dst) {
System.arraycopy(src, 0, dst, 0, Array.getLength(src));
}
@@ -8041,6 +7896,7 @@ public class PApplet implements PConstants {
/**
* Use arrayCopy() instead.
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
@Deprecated
static public void arraycopy(Object src, int srcPosition,
Object dst, int dstPosition,
@@ -8051,6 +7907,7 @@ public class PApplet implements PConstants {
/**
* Use arrayCopy() instead.
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
@Deprecated
static public void arraycopy(Object src, Object dst, int length) {
System.arraycopy(src, 0, dst, 0, length);
@@ -8059,6 +7916,7 @@ public class PApplet implements PConstants {
/**
* Use arrayCopy() instead.
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
@Deprecated
static public void arraycopy(Object src, Object dst) {
System.arraycopy(src, 0, dst, 0, Array.getLength(src));
@@ -8174,6 +8032,7 @@ public class PApplet implements PConstants {
return expand(array, len > 0 ? len << 1 : 1);
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static public Object expand(Object list, int newSize) {
Class<?> type = list.getClass().getComponentType();
Object temp = Array.newInstance(type, newSize);
@@ -8432,9 +8291,10 @@ public class PApplet implements PConstants {
return outgoing;
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static final public Object splice(Object list, Object value, int index) {
Class<?> type = list.getClass().getComponentType();
Object outgoing = null;
Object outgoing;
int length = Array.getLength(list);
// check whether item being spliced in is an array
@@ -8581,6 +8441,7 @@ public class PApplet implements PConstants {
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static public Object subset(Object list, int start, int count) {
Class<?> type = list.getClass().getComponentType();
Object outgoing = Array.newInstance(type, count);
@@ -8650,6 +8511,7 @@ public class PApplet implements PConstants {
return c;
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static public Object concat(Object a, Object b) {
Class<?> type = a.getClass().getComponentType();
int alength = Array.getLength(a);
@@ -8875,7 +8737,7 @@ public class PApplet implements PConstants {
* parameter divides the <b>str</b> parameter. Therefore, if you use
* characters such parentheses and brackets that are used with regular
* expressions as a part of the <b>delim</b> parameter, you'll need to put two
* blackslashes (\\\\) in front of the character (see example above). You can
* backslashes (\\\\) in front of the character (see example above). You can
* read more about
* <a href="http://en.wikipedia.org/wiki/Regular_expression">regular
* expressions</a> and
@@ -8904,7 +8766,7 @@ public class PApplet implements PConstants {
}
// make sure that there is something in the input string
//if (chars.length > 0) {
// if the last char is a delimeter, get rid of it..
// if the last char is a delimiter, get rid of it..
//if (chars[chars.length-1] == delim) splitCount--;
// on second thought, i don't agree with this, will disable
//}
@@ -9092,16 +8954,6 @@ public class PApplet implements PConstants {
// CASTING FUNCTIONS, INSERTED BY PREPROC
/**
* Convert a char to a boolean. 'T', 't', and '1' will become the
* boolean value true, while 'F', 'f', or '0' will become false.
*/
/*
static final public boolean parseBoolean(char what) {
return ((what == 't') || (what == 'T') || (what == '1'));
}
*/
/**
* <p>Convert an integer to a boolean. Because of how Java handles upgrading
* numbers, this will also cover byte and char (as they will upgrade to
@@ -9113,13 +8965,6 @@ public class PApplet implements PConstants {
return (what != 0);
}
/*
// removed because this makes no useful sense
static final public boolean parseBoolean(float what) {
return (what != 0);
}
*/
/**
* Convert the string "true" or "false" to a boolean.
* @return true if 'what' is "true" or "TRUE", false otherwise
@@ -9130,34 +8975,6 @@ public class PApplet implements PConstants {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/*
// removed, no need to introduce strange syntax from other languages
static final public boolean[] parseBoolean(char what[]) {
boolean outgoing[] = new boolean[what.length];
for (int i = 0; i < what.length; i++) {
outgoing[i] =
((what[i] == 't') || (what[i] == 'T') || (what[i] == '1'));
}
return outgoing;
}
*/
/**
* Convert a byte array to a boolean array. Each element will be
* evaluated identical to the integer case, where a byte equal
* to zero will return false, and any other value will return true.
* @return array of boolean elements
*/
/*
static final public boolean[] parseBoolean(byte what[]) {
boolean outgoing[] = new boolean[what.length];
for (int i = 0; i < what.length; i++) {
outgoing[i] = (what[i] != 0);
}
return outgoing;
}
*/
/**
* Convert an int array to a boolean array. An int equal
* to zero will return false, and any other value will return true.
@@ -9171,17 +8988,6 @@ public class PApplet implements PConstants {
return outgoing;
}
/*
// removed, not necessary... if necessary, convert to int array first
static final public boolean[] parseBoolean(float what[]) {
boolean outgoing[] = new boolean[what.length];
for (int i = 0; i < what.length; i++) {
outgoing[i] = (what[i] != 0);
}
return outgoing;
}
*/
static final public boolean[] parseBoolean(String[] what) {
boolean[] outgoing = new boolean[what.length];
for (int i = 0; i < what.length; i++) {
@@ -9208,13 +9014,6 @@ public class PApplet implements PConstants {
return (byte) what;
}
/*
// nixed, no precedent
static final public byte[] parseByte(String what) { // note: array[]
return what.getBytes();
}
*/
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static final public byte[] parseByte(boolean[] what) {
@@ -9249,24 +9048,8 @@ public class PApplet implements PConstants {
return outgoing;
}
/*
static final public byte[][] parseByte(String what[]) { // note: array[][]
byte outgoing[][] = new byte[what.length][];
for (int i = 0; i < what.length; i++) {
outgoing[i] = what[i].getBytes();
}
return outgoing;
}
*/
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/*
static final public char parseChar(boolean what) { // 0/1 or T/F ?
return what ? 't' : 'f';
}
*/
static final public char parseChar(byte what) {
return (char) (what & 0xff);
}
@@ -9275,28 +9058,8 @@ public class PApplet implements PConstants {
return (char) what;
}
/*
static final public char parseChar(float what) { // nonsensical
return (char) what;
}
static final public char[] parseChar(String what) { // note: array[]
return what.toCharArray();
}
*/
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/*
static final public char[] parseChar(boolean what[]) { // 0/1 or T/F ?
char outgoing[] = new char[what.length];
for (int i = 0; i < what.length; i++) {
outgoing[i] = what[i] ? 't' : 'f';
}
return outgoing;
}
*/
static final public char[] parseChar(byte[] what) {
char[] outgoing = new char[what.length];
for (int i = 0; i < what.length; i++) {
@@ -9305,15 +9068,6 @@ public class PApplet implements PConstants {
return outgoing;
}
static final public char[] parseChar(int what[]) {
char outgoing[] = new char[what.length];
for (int i = 0; i < what.length; i++) {
outgoing[i] = (char) what[i];
}
return outgoing;
}
/*
static final public char[] parseChar(int[] what) {
char[] outgoing = new char[what.length];
for (int i = 0; i < what.length; i++) {
@@ -9322,15 +9076,6 @@ public class PApplet implements PConstants {
return outgoing;
}
static final public char[][] parseChar(String what[]) { // note: array[][]
char outgoing[][] = new char[what.length][];
for (int i = 0; i < what.length; i++) {
outgoing[i] = what[i].toCharArray();
}
return outgoing;
}
*/
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static final public int parseInt(boolean what) {
@@ -9394,7 +9139,7 @@ public class PApplet implements PConstants {
return list;
}
static final public int[] parseInt(byte[] what) { // note this unsigns
static final public int[] parseInt(byte[] what) { // note this un-signs
int[] list = new int[what.length];
for (int i = 0; i < what.length; i++) {
list[i] = (what[i] & 0xff);
@@ -9455,12 +9200,6 @@ public class PApplet implements PConstants {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/*
static final public float parseFloat(boolean what) {
return what ? 1 : 0;
}
*/
/**
* Convert an int to a float value. Also handles bytes because of
* Java's rules for upgrading values.
@@ -9476,7 +9215,7 @@ public class PApplet implements PConstants {
static final public float parseFloat(String what, float otherwise) {
try {
return Float.parseFloat(what);
} catch (NumberFormatException e) { }
} catch (NumberFormatException ignored) { }
return otherwise;
}
@@ -9574,6 +9313,7 @@ public class PApplet implements PConstants {
// INT NUMBER FORMATTING
static public String nf(float num) {
int inum = (int) num;
if (num == inum) {
@@ -9582,6 +9322,7 @@ public class PApplet implements PConstants {
return str(num);
}
static public String[] nf(float[] nums) {
String[] outgoing = new String[nums.length];
for (int i = 0; i < nums.length; i++) {
@@ -9590,16 +9331,16 @@ public class PApplet implements PConstants {
return outgoing;
}
/**
* Integer number formatter.
*/
static private NumberFormat int_nf;
static private int int_nf_digits;
static private boolean int_nf_commas;
/**
*
* Utility function for formatting numbers into strings. There are two
* versions: one for formatting floats, and one for formatting ints. The
* values for the <b>digits</b> and <b>right</b> parameters should always be
@@ -9623,7 +9364,6 @@ public class PApplet implements PConstants {
* @see <a href=
* "https://processing.org/reference/intconvert_.html">int(float)</a>
*/
static public String[] nf(int[] nums, int digits) {
String[] formatted = new String[nums.length];
for (int i = 0; i < formatted.length; i++) {
@@ -9632,6 +9372,7 @@ public class PApplet implements PConstants {
return formatted;
}
/**
* @param num the number to format
*/
@@ -9650,8 +9391,8 @@ public class PApplet implements PConstants {
return int_nf.format(num);
}
/**
*
* Utility function for formatting numbers into strings and placing
* appropriate commas to mark units of 1000. There are four versions: one for
* formatting ints, one for formatting an array of ints, one for formatting
@@ -9660,8 +9401,8 @@ public class PApplet implements PConstants {
* The value for the <b>right</b> parameter should always be a positive
* integer.<br />
* <br />
* For a non-US locale, this will insert periods instead of commas, or
* whatever is apprioriate for that region.
* For a non-US locale, this will insert periods instead of commas,
* or whatever is appropriate for that region.
*
* @webref data:string_functions
* @webBrief Utility function for formatting numbers into strings and placing
@@ -9701,14 +9442,6 @@ public class PApplet implements PConstants {
/**
* number format signed (or space)
* Formats a number but leaves a blank space in the front
* when it's positive so that it can be properly aligned with
* numbers that have a negative sign in front of them.
*/
/**
*
* Utility function for formatting numbers into strings. Similar to
* <b>nf()</b> but leaves a blank space in front of positive numbers so
* they align with negative numbers in spite of the minus symbol. There are
@@ -9716,18 +9449,19 @@ public class PApplet implements PConstants {
* values for the <b>digits</b>, <b>left</b>, and <b>right</b> parameters
* should always be positive integers.
*
* @webref data:string_functions
* @webBrief Utility function for formatting numbers into strings
* @param num the number to format
* @param digits number of digits to pad with zeroes
* @see PApplet#nf(float, int, int)
* @see PApplet#nfp(float, int, int)
* @see PApplet#nfc(float, int)
*/
* @webref data:string_functions
* @webBrief Utility function for formatting numbers into strings
* @param num the number to format
* @param digits number of digits to pad with zeroes
* @see PApplet#nf(float, int, int)
* @see PApplet#nfp(float, int, int)
* @see PApplet#nfc(float, int)
*/
static public String nfs(int num, int digits) {
return (num < 0) ? nf(num, digits) : (' ' + nf(num, digits));
}
/**
* @param nums the numbers to format
*/
@@ -9739,15 +9473,8 @@ public class PApplet implements PConstants {
return formatted;
}
//
/**
* number format positive (or plus)
* Formats a number, always placing a - or + sign
* in the front when it's negative or positive.
*/
/**
*
* Utility function for formatting numbers into strings. Similar to <b>nf()</b>
* but puts a "+" in front of positive numbers and a "-" in front of negative
* numbers. There are two versions: one for formatting floats, and one for
@@ -9767,6 +9494,8 @@ public class PApplet implements PConstants {
static public String nfp(int num, int digits) {
return (num < 0) ? nf(num, digits) : ('+' + nf(num, digits));
}
/**
* @param nums the numbers to format
*/
@@ -10291,7 +10020,7 @@ public class PApplet implements PConstants {
* <PRE>
* Parameters useful for launching or also used by the PDE:
*
* --location=x,y Upper-lefthand corner of where the applet
* --location=x,y Upper left-hand corner of where the applet
* should appear on screen. If not used,
* the default is to center on the main screen.
*
@@ -10330,7 +10059,7 @@ public class PApplet implements PConstants {
*
* --external set when the applet is being used by the PDE
*
* --editor-location=x,y position of the upper-lefthand corner of the
* --editor-location=x,y position of the upper left-hand corner of the
* editor window, for placement of applet window
*
* All parameters *after* the sketch class name are passed to the sketch
@@ -10387,11 +10116,9 @@ public class PApplet implements PConstants {
// also suspecting that these "not showing up" bugs might be EDT issues.
static public void runSketch(final String[] args,
final PApplet constructedSketch) {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace();
uncaughtThrowable = e;
}
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
e.printStackTrace();
uncaughtThrowable = e;
});
// This doesn't work, need to mess with Info.plist instead
@@ -10439,7 +10166,7 @@ public class PApplet implements PConstants {
// boolean spanDisplays = false;
int density = -1;
String param = null, value = null;
String param, value;
String folder = calcSketchPath();
int argIndex = 0;
@@ -10895,15 +10622,6 @@ public class PApplet implements PConstants {
}
/**
* Starts shape recording and returns the PShape object that will
* contain the geometry.
*/
/*
public PShape beginRecord() {
return g.beginRecord();
}
*/
//////////////////////////////////////////////////////////////
@@ -13584,7 +13302,6 @@ public class PApplet implements PConstants {
* @webref transform
* @webBrief Multiplies the current matrix by the one specified through the
* parameters
* @source
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#resetMatrix()
+8 -3
View File
@@ -4237,15 +4237,20 @@ public class PGraphics extends PImage implements PConstants {
* Used by PGraphics to remove the requirement for loading a font.
*/
protected PFont createDefaultFont(float size) {
Font baseFont;
Font baseFont = null;
try {
// For 4.0 alpha 4 and later, include a built-in font
InputStream input = getClass().getResourceAsStream("/font/ProcessingSansPro-Regular.ttf");
baseFont = Font.createFont(Font.TRUETYPE_FONT, input);
if (input != null) {
baseFont = Font.createFont(Font.TRUETYPE_FONT, input);
}
} catch (Exception e) {
// Fall back to how this was handled in 3.x, ugly!
e.printStackTrace(); // dammit
}
if (baseFont == null) {
baseFont = new Font("Lucida Sans", Font.PLAIN, 1);
}
// Create a PFont from this java.awt.Font
@@ -5770,7 +5775,6 @@ public class PGraphics extends PImage implements PConstants {
* @webref transform
* @webBrief Multiplies the current matrix by the one specified through the
* parameters
* @source
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#resetMatrix()
@@ -8592,6 +8596,7 @@ public class PGraphics extends PImage implements PConstants {
public void dispose() { // ignore
saveExecutor.shutdown();
try {
//noinspection ResultOfMethodCallIgnored
saveExecutor.awaitTermination(5000, TimeUnit.SECONDS);
} catch (InterruptedException ignored) { }
}
+45 -26
View File
@@ -24,6 +24,7 @@
package processing.core;
import java.awt.Image;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -257,11 +258,27 @@ public class PImage implements PConstants, Cloneable {
this.width = width;
this.height = height;
this.format = format;
this.pixelDensity = factor;
pixelDensity = factor;
pixelWidth = width * pixelDensity;
pixelHeight = height * pixelDensity;
this.pixels = new int[pixelWidth * pixelHeight];
pixels = new int[pixelWidth * pixelHeight];
}
private void init(int width, int height, int format, int factor,
int[] pixels) { // ignore
this.width = width;
this.height = height;
this.format = format;
pixelDensity = factor;
// these weren't being set in 4.0a3, why? [fry 210615]
pixelWidth = width * pixelDensity;
pixelHeight = height * pixelDensity;
this.pixels = pixels;
}
@@ -287,7 +304,7 @@ public class PImage implements PConstants, Cloneable {
public PImage(int width, int height, int[] pixels,
boolean requiresCheckAlpha, PApplet parent) {
initFromPixels(width, height, pixels, RGB,1);
init(width, height, RGB,1, pixels);
this.parent = parent;
if (requiresCheckAlpha) {
@@ -298,8 +315,7 @@ public class PImage implements PConstants, Cloneable {
public PImage(int width, int height, int[] pixels,
boolean requiresCheckAlpha, PApplet parent,
int format, int factor) {
initFromPixels(width, height, pixels, format, factor);
init(width, height, format, factor, pixels);
this.parent = parent;
if (requiresCheckAlpha) {
@@ -307,17 +323,27 @@ public class PImage implements PConstants, Cloneable {
}
}
private void initFromPixels(int width, int height, int[] pixels, int format, int factor) {
this.width = width;
this.height = height;
this.format = format;
this.pixelDensity = factor;
this.pixels = pixels;
@Deprecated
public PImage(Image img) {
ShimAWT.fromNativeImage(img, this);
}
/**
* Use the getNative() method instead, which allows library interfaces to be
* written in a cross-platform fashion for desktop, Android, and others.
* This is still included for PGraphics objects, which may need the image.
*/
@Deprecated
public Image getImage() { // ignore
return (Image) getNative();
}
public Object getNative() { // ignore
return null;
// TODO temporary solution for maximum backwards compatibility
return ShimAWT.getNativeImage(this);
}
@@ -481,7 +507,8 @@ public class PImage implements PConstants, Cloneable {
* @see PImage#get(int, int, int, int)
*/
public void resize(int w, int h) { // ignore
throw new RuntimeException("resize() not implemented for this PImage type");
//throw new RuntimeException("resize() not implemented for this PImage type");
ShimAWT.resizeImage(this, w, h);
}
@@ -1033,14 +1060,6 @@ public class PImage implements PConstants, Cloneable {
}
/** Set the high bits of all pixels to opaque. */
protected void opaque() {
for (int i = 0; i < pixels.length; i++) {
pixels[i] = 0xFF000000 | pixels[i];
}
}
/**
* Optimized code for building the blur kernel.
* further optimized blur code (approx. 15% for radius=20)
@@ -3357,11 +3376,11 @@ int testFunction(int dst, int src) {
* @param path must be a full path (not relative or simply a filename)
*/
protected boolean saveImpl(String path) {
// TODO Imperfect/temporary solution for alpha 2.
// TODO Imperfect/temporary solution for current 4.x releases
// https://github.com/processing/processing4/wiki/Exorcising-AWT
if (!PApplet.disableAWT) {
return ShimAWT.saveImage(this, path);
}
return false;
//if (!PApplet.disableAWT) { // TODO necessary? will this trigger NEWT?
return ShimAWT.saveImage(this, path);
//}
//return false;
}
}
+6
View File
@@ -0,0 +1,6 @@
package processing.core;
public class PSketch implements PConstants {
// this is a dummy class
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1092,7 +1092,10 @@ public class PSurfaceJOGL implements PSurface {
protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
int peAction) {
// SHIFT, CTRL, META, and ALT are identical to the processing.event.Event,
// so the modifiers are left intact here.
int modifiers = nativeEvent.getModifiers();
// Could limit to just the specific modifiers, but why bother?
/*
int peModifiers = modifiers &
(InputEvent.SHIFT_MASK |
@@ -1159,6 +1162,7 @@ public class PSurfaceJOGL implements PSurface {
protected void nativeKeyEvent(com.jogamp.newt.event.KeyEvent nativeEvent,
int peAction) {
// SHIFT, CTRL, META, and ALT are identical to processing.event.Event
int modifiers = nativeEvent.getModifiers();
// int peModifiers = nativeEvent.getModifiers() &
// (InputEvent.SHIFT_MASK |