| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/dimr/processing/master/core/src/processing/core/PApplet.java | [Back] [Original] |
* Note that because this is stored as a float, the values may not be * exactly 1.3 or 1.4. The PDE will make 1.8 or whatever into * a float automatically, so outside the PDE, make sure you're comparing * against 1.3f or 1.4f, which will have the same amount of error * (i.e. 1.40000001). This could just be a double, but since Processing * only uses floats, it's safer as a float because specifying a double * (with this narrow case especially) with the preprocessor is awkward. *
* @deprecated Java 10 is around the corner. Use javaPlatform when you need
* a number for comparisons, i.e. "if (javaPlatform >= 7)".
*/
@Deprecated
public static final float javaVersion =
new Float(javaVersionName.substring(0, 3));
// public static final float javaVersion =
// new Float(javaVersionName.substring(0, javaVersionName.indexOf(".", 2))).floatValue();
// // Making this a String in 3.0, in anticipation of Java 10
// public static final String javaVersion = "1." + javaPlatform;
/**
* Current platform in use, one of the
* PConstants WINDOWS, MACOSX, MACOS9, LINUX or OTHER.
*/
static public int platform;
static {
String osname = System.getProperty("os.name");
if (osname.indexOf("Mac") != -1) {
platform = MACOSX;
} else if (osname.indexOf("Windows") != -1) {
platform = WINDOWS;
} else if (osname.equals("Linux")) { // true for the ibm vm
platform = LINUX;
} else {
platform = OTHER;
}
}
/**
* Whether to use native (AWT) dialogs for selectInput and selectOutput.
* The native dialogs on Linux tend to be pretty awful. With selectFolder()
* this is ignored, because there is no native folder selector, except on
* Mac OS X. On OS X, the native folder selector will be used unless
* useNativeSelect is set to false.
*/
static public boolean useNativeSelect = (platform != LINUX);
/** The PGraphics renderer associated with this PApplet */
public PGraphics g;
/**
* ( begin auto-generated from displayWidth.xml )
*
* System variable which stores the width of the computer screen. For
* example, if the current screen resolution is 1024x768,
* displayWidth is 1024 and displayHeight is 768. These
* dimensions are useful when exporting full-screen applications.
*
* To ensure that the sketch takes over the entire screen, use "Present"
* instead of "Run". Otherwise the window will still have a frame border
* around it and not be placed in the upper corner of the screen. On Mac OS
* X, the menu bar will remain present unless "Present" mode is used.
*
* ( end auto-generated )
*/
public int displayWidth;
/**
* ( begin auto-generated from displayHeight.xml )
*
* System variable that stores the height of the computer screen. For
* example, if the current screen resolution is 1024x768,
* displayWidth is 1024 and displayHeight is 768. These
* dimensions are useful when exporting full-screen applications.
*
* To ensure that the sketch takes over the entire screen, use "Present"
* instead of "Run". Otherwise the window will still have a frame border
* around it and not be placed in the upper corner of the screen. On Mac OS
* X, the menu bar will remain present unless "Present" mode is used.
*
* ( end auto-generated )
*/
public int displayHeight;
/** A leech graphics object that is echoing all events. */
public PGraphics recorder;
/**
* Command line options passed in from main().
* This does not include the arguments passed in to PApplet itself.
* @see PApplet#main
*/
public String[] args;
/**
* Path to sketch folder. Previously undocumented, made private in 3.0a5
* so that people use the sketchPath() method and it's inited properly.
* Call sketchPath() once to set the default.
*/
private String sketchPath;
// public String sketchPath;
static final boolean DEBUG = false;
// static final boolean DEBUG = true;
/** Default width and height for sketch when not specified */
static public final int DEFAULT_WIDTH = 100;
static public final int DEFAULT_HEIGHT = 100;
// /**
// * Exception thrown when size() is called the first time.
// *
// * This is used internally so that setup() is forced to run twice
// * when the renderer is changed. This is the only way for us to handle
// * invoking the new renderer while also in the midst of rendering.
// */
// static public class RendererChangeException extends RuntimeException { }
/**
* 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.
*/
// public boolean defaultSize;
// /** Storage for the current renderer size to avoid re-allocation. */
// Dimension currentSize = new Dimension();
/**
* ( begin auto-generated from pixels.xml )
*
* Array containing the values for all the pixels in the display window.
* These values are of the color datatype. This array is the size of the
* display window. For example, if the image is 100x100 pixels, there will
* be 10000 values and if the window is 200x300 pixels, there will be 60000
* values. The index value defines the position of a value within
* the array. For example, the statement color b = pixels[230] will
* set the variable b to be equal to the value at that location in
* the array.
*
* Before accessing this array, the data must loaded with the
* loadPixels() function. After the array data has been modified,
* the updatePixels() function must be run to update the changes.
* Without loadPixels(), running the code may (or will in future
* releases) result in a NullPointerException.
*
* ( end auto-generated )
*
* @webref image:pixels
* @see PApplet#loadPixels()
* @see PApplet#updatePixels()
* @see PApplet#get(int, int, int, int)
* @see PApplet#set(int, int, int)
* @see PImage
*/
public int[] pixels;
/**
* ( begin auto-generated from width.xml )
*
* System variable which stores the width of the display window. This value
* is set by the first parameter of the size() function. For
* example, the function call size(320, 240) sets the width
* variable to the value 320. The value of width is zero until
* size() is called.
*
* ( end auto-generated )
* @webref environment
* @see PApplet#height
* @see PApplet#size(int, int)
*/
public int width = DEFAULT_WIDTH;
/**
* ( begin auto-generated from height.xml )
*
* System variable which stores the height of the display window. This
* value is set by the second parameter of the size() function. For
* example, the function call size(320, 240) sets the height
* variable to the value 240. The value of height is zero until
* size() is called.
*
* ( end auto-generated )
*
* @webref environment
* @see PApplet#width
* @see PApplet#size(int, int)
*/
public int height = DEFAULT_HEIGHT;
/**
* ( begin auto-generated from pixelWidth.xml )
*
* When pixelDensity(2) is used to make use of a high resolution
* display (called a Retina display on OS X or high-dpi on Windows and
* Linux), the width and height of the sketch do not change, but the
* number of pixels is doubled. As a result, all operations that use pixels
* (like loadPixels(), get(), set(), etc.) happen
* in this doubled space. As a convenience, the variables pixelWidth
* and pixelHeight hold the actual width and height of the sketch
* in pixels. This is useful for any sketch that uses the pixels[]
* array, for instance, because the number of elements in the array will
* be pixelWidth*pixelHeight, not width*height.
*
* ( end auto-generated )
*
* @webref environment
* @see PApplet#pixelHeight
* @see #pixelDensity(int)
* @see #displayDensity()
*/
public int pixelWidth;
/**
* ( begin auto-generated from pixelHeight.xml )
*
* When pixelDensity(2) is used to make use of a high resolution
* display (called a Retina display on OS X or high-dpi on Windows and
* Linux), the width and height of the sketch do not change, but the
* number of pixels is doubled. As a result, all operations that use pixels
* (like loadPixels(), get(), set(), etc.) happen
* in this doubled space. As a convenience, the variables pixelWidth
* and pixelHeight hold the actual width and height of the sketch
* in pixels. This is useful for any sketch that uses the pixels[]
* array, for instance, because the number of elements in the array will
* be pixelWidth*pixelHeight, not width*height.
*
* ( end auto-generated )
*
* @webref environment
* @see PApplet#pixelWidth
* @see #pixelDensity(int)
* @see #displayDensity()
*/
public int pixelHeight;
/**
* Keeps track of ENABLE_KEY_REPEAT hint
*/
protected boolean keyRepeatEnabled = false;
/**
* ( begin auto-generated from mouseX.xml )
*
* The system variable mouseX always contains the current horizontal
* coordinate of the mouse.
*
* ( end auto-generated )
* @webref input:mouse
* @see PApplet#mouseY
* @see PApplet#pmouseX
* @see PApplet#pmouseY
* @see PApplet#mousePressed
* @see PApplet#mousePressed()
* @see PApplet#mouseReleased()
* @see PApplet#mouseClicked()
* @see PApplet#mouseMoved()
* @see PApplet#mouseDragged()
* @see PApplet#mouseButton
* @see PApplet#mouseWheel(MouseEvent)
*
*
*/
public int mouseX;
/**
* ( begin auto-generated from mouseY.xml )
*
* The system variable mouseY always contains the current vertical
* coordinate of the mouse.
*
* ( end auto-generated )
* @webref input:mouse
* @see PApplet#mouseX
* @see PApplet#pmouseX
* @see PApplet#pmouseY
* @see PApplet#mousePressed
* @see PApplet#mousePressed()
* @see PApplet#mouseReleased()
* @see PApplet#mouseClicked()
* @see PApplet#mouseMoved()
* @see PApplet#mouseDragged()
* @see PApplet#mouseButton
* @see PApplet#mouseWheel(MouseEvent)
*
*/
public int mouseY;
/**
* ( begin auto-generated from pmouseX.xml )
*
* The system variable pmouseX always contains the horizontal
* position of the mouse in the frame previous to the current frame.
*
* You may find that pmouseX and pmouseY have different
* values inside draw() and inside events like mousePressed()
* and mouseMoved(). This is because they're used for different
* roles, so don't mix them. Inside draw(), pmouseX and
* pmouseY update only once per frame (once per trip through your
* draw()). But, inside mouse events, they update each time the
* event is called. If they weren't separated, then the mouse would be read
* only once per frame, making response choppy. If the mouse variables were
* always updated multiple times per frame, using line(pmouseX,
* pmouseY, mouseX, mouseY) inside draw() would have lots
* of gaps, because pmouseX may have changed several times in
* between the calls to line(). Use pmouseX and
* pmouseY inside draw() if you want values relative to the
* previous frame. Use pmouseX and pmouseY inside the mouse
* functions if you want continuous response.
*
* ( end auto-generated )
* @webref input:mouse
* @see PApplet#mouseX
* @see PApplet#mouseY
* @see PApplet#pmouseY
* @see PApplet#mousePressed
* @see PApplet#mousePressed()
* @see PApplet#mouseReleased()
* @see PApplet#mouseClicked()
* @see PApplet#mouseMoved()
* @see PApplet#mouseDragged()
* @see PApplet#mouseButton
* @see PApplet#mouseWheel(MouseEvent)
*/
public int pmouseX;
/**
* ( begin auto-generated from pmouseY.xml )
*
* The system variable pmouseY always contains the vertical position
* of the mouse in the frame previous to the current frame. More detailed
* information about how pmouseY is updated inside of draw()
* and mouse events is explained in the reference for pmouseX.
*
* ( end auto-generated )
* @webref input:mouse
* @see PApplet#mouseX
* @see PApplet#mouseY
* @see PApplet#pmouseX
* @see PApplet#mousePressed
* @see PApplet#mousePressed()
* @see PApplet#mouseReleased()
* @see PApplet#mouseClicked()
* @see PApplet#mouseMoved()
* @see PApplet#mouseDragged()
* @see PApplet#mouseButton
* @see PApplet#mouseWheel(MouseEvent)
*/
public int pmouseY;
/**
* Previous mouseX/Y for the draw loop, separated out because this is
* separate from the pmouseX/Y when inside the mouse event handlers.
* See emouseX/Y for an explanation.
*/
protected int dmouseX, dmouseY;
/**
* The pmouseX/Y for the event handlers (mousePressed(), mouseDragged() etc)
* these are different because mouse events are queued to the end of
* draw, so the previous position has to be updated on each event,
* as opposed to the pmouseX/Y that's used inside draw, which is expected
* to be updated once per trip through draw().
*/
protected int emouseX, emouseY;
/**
* Used to set pmouseX/Y to mouseX/Y the first time mouseX/Y are used,
* otherwise pmouseX/Y are always zero, causing a nasty jump.
*
* Just using (frameCount == 0) won't work since mouseXxxxx() * may not be called until a couple frames into things. *
* @deprecated Please refrain from using this variable, it will be removed * from future releases of Processing because it cannot be used consistently * across platforms and input methods. */ @Deprecated public boolean firstMouse = true; /** * ( begin auto-generated from mouseButton.xml ) * * Processing automatically tracks if the mouse button is pressed and which * button is pressed. The value of the system variable mouseButton * is either LEFT, RIGHT, or CENTER depending on which * button is pressed. * * ( end auto-generated ) * *
* If it's a coded key, i.e. UP/DOWN/CTRL/SHIFT/ALT,
* this will be set to CODED (0xffff or 65535).
*
* @webref input:keyboard
* @see PApplet#keyCode
* @see PApplet#keyPressed
* @see PApplet#keyPressed()
* @see PApplet#keyReleased()
*/
public char key;
/**
* ( begin auto-generated from keyCode.xml )
*
* The variable keyCode is used to detect special keys such as the
* UP, DOWN, LEFT, RIGHT arrow keys and ALT, CONTROL, SHIFT. When checking
* for these keys, it's first necessary to check and see if the key is
* coded. This is done with the conditional "if (key == CODED)" as shown in
* the example.
*
* The keys included in the ASCII specification (BACKSPACE, TAB, ENTER,
* RETURN, ESC, and DELETE) do not require checking to see if they key is
* coded, and you should simply use the key variable instead of
* keyCode If you're making cross-platform projects, note that the
* ENTER key is commonly used on PCs and Unix and the RETURN key is used
* instead on Macintosh. Check for both ENTER and RETURN to make sure your
* program will work for all platforms.
*
* For users familiar with Java, the values for UP and DOWN are simply
* shorter versions of Java's KeyEvent.VK_UP and KeyEvent.VK_DOWN. Other
* keyCode values can be found in the Java KeyEvent reference.
*
* ( end auto-generated )
*
*
* For the arrow keys, keyCode will be one of UP, DOWN, LEFT and RIGHT. * Also available are ALT, CONTROL and SHIFT. A full set of constants * can be obtained from java.awt.event.KeyEvent, from the VK_XXXX variables. * * @webref input:keyboard * @see PApplet#key * @see PApplet#keyPressed * @see PApplet#keyPressed() * @see PApplet#keyReleased() */ public int keyCode; /** * ( begin auto-generated from keyPressed_var.xml ) * * The boolean system variable keyPressed is true if any key * is pressed and false if no keys are pressed. * * ( end auto-generated ) * @webref input:keyboard * @see PApplet#key * @see PApplet#keyCode * @see PApplet#keyPressed() * @see PApplet#keyReleased() */ public boolean keyPressed; /** * The last KeyEvent object passed into a mouse function. * @deprecated Use a key event handler that passes an event instead. */ @Deprecated public KeyEvent keyEvent; /** * ( begin auto-generated from focused.xml ) * * Confirms if a Processing program is "focused", meaning that it is active * and will accept input from mouse or keyboard. This variable is "true" if * it is focused and "false" if not. This variable is often used when you * want to warn people they need to click on or roll over an applet before * it will work. * * ( end auto-generated ) * @webref environment */ public boolean focused = false; // /** // * Confirms if a Processing program is running inside a web browser. This // * variable is "true" if the program is online and "false" if not. // */ // @Deprecated // public boolean online = false; // // This is deprecated because it's poorly named (and even more poorly // // understood). Further, we'll probably be removing applets soon, in which // // case this won't work at all. If you want this feature, you can check // // whether getAppletContext() returns null. /** * Time in milliseconds when the applet was started. *
* Used by the millis() function. */ long millisOffset = System.currentTimeMillis(); /** * ( begin auto-generated from frameRate_var.xml ) * * The system variable frameRate contains the approximate frame rate * of the software as it executes. The initial value is 10 fps and is * updated with each frame. The value is averaged (integrated) over several * frames. As such, this value won't be valid until after 5-10 frames. * * ( end auto-generated ) * @webref environment * @see PApplet#frameRate(float) * @see PApplet#frameCount */ public float frameRate = 10; protected boolean looping = true; /** flag set to true when a redraw is asked for by the user */ protected boolean redraw = true; /** * ( begin auto-generated from frameCount.xml ) * * The system variable frameCount contains the number of frames * displayed since the program started. Inside setup() the value is * 0 and and after the first iteration of draw it is 1, etc. * * ( end auto-generated ) * @webref environment * @see PApplet#frameRate(float) * @see PApplet#frameRate */ public int frameCount; /** true if the sketch has stopped permanently. */ public volatile boolean finished; /** used by the UncaughtExceptionHandler, so has to be static */ static Throwable uncaughtThrowable; // public, but undocumented.. removing for 3.0a5 // /** // * true if the animation thread is paused. // */ // public volatile boolean paused; /** * true if exit() has been called so that things shut down * once the main thread kicks off. */ protected boolean exitCalled; // messages to send if attached as an external vm /** * Position of the upper-lefthand corner of the editor window * that launched this applet. */ static public final String ARGS_EDITOR_LOCATION = "--editor-location"; static public final String ARGS_EXTERNAL = "--external"; /** * Location for where to position the applet window on screen. *
* This is used by the editor to when saving the previous applet * location, or could be used by other classes to launch at a * specific position on-screen. */ static public final String ARGS_LOCATION = "--location"; /** Used by the PDE to suggest a display (set in prefs, passed on Run) */ static public final String ARGS_DISPLAY = "--display"; // static public final String ARGS_SPAN_DISPLAYS = "--span"; static public final String ARGS_WINDOW_COLOR = "--window-color"; static public final String ARGS_PRESENT = "--present"; static public final String ARGS_STOP_COLOR = "--stop-color"; static public final String ARGS_HIDE_STOP = "--hide-stop"; /** * Allows the user or PdeEditor to set a specific sketch folder path. *
* 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-path"; /** * When run externally to a PdeEditor, * this is sent by the sketch when it quits. */ static public final String EXTERNAL_STOP = "__STOP__"; /** * When run externally to a PDE Editor, this is sent by the applet * whenever the window is moved. *
* This is used so that the editor can re-open the sketch window * in the same position as the user last left it. */ static public final String EXTERNAL_MOVE = "__MOVE__"; /** true if this sketch is being run by the PDE */ boolean external = false; static final String ERROR_MIN_MAX = "Cannot use min() or max() on an empty array."; // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . protected PSurface surface; public PSurface getSurface() { return surface; } /** * A dummy frame to keep compatibility with 2.x code * and encourage users to update. */ public Frame frame; // public Frame getFrame() { // return frame; // } // // // public void setFrame(Frame frame) { // this.frame = frame; // } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . // /** // * Applet initialization. This can do GUI work because the components have // * not been 'realized' yet: things aren't visible, displayed, etc. // */ // public void init() { //// println("init() called " + Integer.toHexString(hashCode())); // // using a local version here since the class variable is deprecated //// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); //// screenWidth = screen.width; //// screenHeight = screen.height; // // defaultSize = true; // finished = false; // just for clarity // // // this will be cleared by draw() if it is not overridden // looping = true; // redraw = true; // draw this guy at least once // firstMouse = true; // // // calculated dynamically on first call //// // Removed in 2.1.2, brought back for 2.1.3. Usually sketchPath is set //// // inside runSketch(), but if this sketch takes care of calls to init() //// // when PApplet.main() is not used (i.e. it's in a Java application). //// // THe path needs to be set here so that loadXxxx() functions work. //// if (sketchPath == null) { //// sketchPath = calcSketchPath(); //// } // // // set during Surface.initFrame() //// // Figure out the available display width and height. //// // No major problem if this fails, we have to try again anyway in //// // handleDraw() on the first (== 0) frame. //// checkDisplaySize(); // //// // Set the default size, until the user specifies otherwise //// int w = sketchWidth(); //// int h = sketchHeight(); //// defaultSize = (w == DEFAULT_WIDTH) && (h == DEFAULT_HEIGHT); //// //// g = makeGraphics(w, h, sketchRenderer(), null, true); //// // Fire component resize event //// setSize(w, h); //// setPreferredSize(new Dimension(w, h)); //// //// width = g.width; //// height = g.height; // // surface.startThread(); // } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . boolean insideSettings; String renderer = JAVA2D; // int quality = 2; int smooth = 1; // default smoothing (whatever that means for the renderer) boolean fullScreen; int display = -1; // use default GraphicsDevice[] displayDevices; // Unlike the others above, needs to be public to support // the pixelWidth and pixelHeight fields. public int pixelDensity = 1; String outputPath; OutputStream outputStream; // Background default needs to be different from the default value in // PGraphics.backgroundColor, otherwise size(100, 100) bg spills over. // https://github.com/processing/processing/issues/2297 int windowColor = 0xffDDDDDD; /** * @param method "size" or "fullScreen" * @param args parameters passed to the function so we can show the user * @return true if safely inside the settings() method */ boolean insideSettings(String method, Object... args) { if (insideSettings) { return true; } final String url = "https://processing.org/reference/" + method + "_.html"; if (!external) { // post a warning for users of Eclipse and other IDEs StringList argList = new StringList(args); System.err.println("When not using the PDE, " + method + "() can only be used inside settings()."); System.err.println("Remove the " + method + "() method from setup(), and add the following:"); System.err.println("public void settings() {"); System.err.println(" " + method + "(" + argList.join(", ") + ");"); System.err.println("}"); } throw new IllegalStateException(method + "() cannot be used here, see " + url); } void handleSettings() { insideSettings = true; // Need the list of display devices to be queried already for usage below. // https://github.com/processing/processing/issues/3295 // https://github.com/processing/processing/issues/3296 // Not doing this from a static initializer because it may cause // PApplet to cache and the values to stick through subsequent runs. // Instead make it a runtime thing and a local variable. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = ge.getDefaultScreenDevice(); displayDevices = ge.getScreenDevices(); // Default or unparsed will be -1, spanning will be 0, actual displays will // be numbered from 1 because it's too weird to say "display 0" in prefs. if (display > 0 && display
| Web Proxy Viewer | New URL | Original Page |