| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | /* | |
| 4 | 4 | Part of the Processing project - http://processing.org | |
| 5 | 5 | ||
| 6 | - Copyright (c) 2012-14 The Processing Foundation | ||
| 6 | + Copyright (c) 2012-15 The Processing Foundation | ||
| 7 | 7 | Copyright (c) 2004-12 Ben Fry and Casey Reas | |
| 8 | 8 | Copyright (c) 2001-04 Massachusetts Institute of Technology | |
| 9 | 9 | ||
@@ -24,15 +24,14 @@ | |||
| 24 | 24 | ||
| 25 | 25 | package processing.core; | |
| 26 | 26 | ||
| 27 | - // used for setting bg colors and whatnot | ||
| 28 | 27 | import java.awt.Canvas; | |
| 28 | + // used for setting bg colors and whatnot | ||
| 29 | 29 | import java.awt.Color; | |
| 30 | 30 | // use for the link() command (and maybe open()?) | |
| 31 | 31 | import java.awt.Desktop; | |
| 32 | 32 | import java.awt.EventQueue; | |
| 33 | 33 | import java.awt.FileDialog; | |
| 34 | 34 | import java.awt.Font; | |
| 35 | - // for the Frame object (deprecate?) | ||
| 36 | 35 | import java.awt.Frame; | |
| 37 | 36 | import java.awt.Image; | |
| 38 | 37 | import java.awt.Toolkit; | |
@@ -66,26 +65,33 @@ | |||
| 66 | 65 | * Window Size and Full Screen</A> page on the Wiki has useful information | |
| 67 | 66 | * about sizing, multiple displays, full screen, etc. | |
| 68 | 67 | * <p/> | |
| 69 | - * Processing uses active mode rendering in all cases. All animation tasks | ||
| 70 | - * happen on the "Processing Animation Thread". The setup() and draw() methods | ||
| 71 | - * are handled by that thread, and events (like mouse movement and key presses, | ||
| 72 | - * which are fired by the event dispatch thread or EDT) are queued to be safely | ||
| 73 | - * handled at the end of draw(). For code that needs to run on the EDT, | ||
| 74 | - * use EventQueue.invokeLater(). When doing so, be careful to synchronize | ||
| 75 | - * between that code (since invokeLater() will make your code run from the EDT) | ||
| 76 | - * and the Processing animation thread. Use of a callback function or the | ||
| 77 | - * registerXxx() methods in PApplet can help ensure that your code doesn't do | ||
| 78 | - * something naughty. | ||
| 68 | + * Processing uses active mode rendering. All animation tasks happen on the | ||
| 69 | + * "Processing Animation Thread". The setup() and draw() methods are handled | ||
| 70 | + * by that thread, and events (like mouse movement and key presses, which are | ||
| 71 | + * fired by the event dispatch thread or EDT) are queued to be safely handled | ||
| 72 | + * at the end of draw(). | ||
| 79 | 73 | * <p/> | |
| 80 | - * As of Processing 2.0, we have discontinued support for versions of Java | ||
| 81 | - * prior to 1.6. We don't have enough people to support it, and for a | ||
| 82 | - * project of our (tiny) size, we should be focusing on the future, rather | ||
| 83 | - * than working around legacy Java code. | ||
| 74 | + * Starting with 3.0a6, blit operations are on the EDT, so as not to cause | ||
| 75 | + * GUI problems with Swing and AWT. In the case of the default renderer, the | ||
| 76 | + * sketch renders to an offscreen image, then the EDT is asked to bring that | ||
| 77 | + * image to the screen. | ||
| 78 | + * <p/> | ||
| 79 | + * For code that needs to run on the EDT, use EventQueue.invokeLater(). When | ||
| 80 | + * doing so, be careful to synchronize between that code and the Processing | ||
| 81 | + * animation thread. That is, you can't call Processing methods from the EDT | ||
| 82 | + * or at any random time from another thread. Use of a callback function or | ||
| 83 | + * the registerXxx() methods in PApplet can help ensure that your code doesn't | ||
| 84 | + * do something naughty. | ||
| 84 | 85 | * <p/> | |
| 85 | 86 | * As of Processing 3.0, we have removed Applet as the base class for PApplet. | |
| 86 | 87 | * This means that we can remove lots of legacy code, however one downside is | |
| 87 | 88 | * that it's no longer possible (without extra code) to embed a PApplet into | |
| 88 | 89 | * another Java application. | |
| 90 | + * <p/> | ||
| 91 | + * As of Processing 3.0, we have discontinued support for versions of Java | ||
| 92 | + * prior to 1.8. We don't have enough people to support it, and for a | ||
| 93 | + * project of our (tiny) size, we should be focusing on the future, rather | ||
| 94 | + * than working around legacy Java code. | ||
| 89 | 95 | */ | |
| 90 | 96 | public class PApplet implements PConstants { | |
| 91 | 97 | //public class PApplet extends Applet | |
@@ -1614,9 +1620,7 @@ public PGraphics createGraphics(int w, int h) { | |||
| 1614 | 1620 | * | |
| 1615 | 1621 | */ | |
| 1616 | 1622 | public PGraphics createGraphics(int w, int h, String renderer) { | |
| 1617 | - PGraphics pg = makeGraphics(w, h, renderer, null, false); | ||
| 1618 | - //pg.parent = this; // make save() work | ||
| 1619 | - return pg; | ||
| 1623 | + return createGraphics(w, h, renderer, null); | ||
| 1620 | 1624 | } | |
| 1621 | 1625 | ||
| 1622 | 1626 | ||
@@ -1627,12 +1631,17 @@ public PGraphics createGraphics(int w, int h, String renderer) { | |||
| 1627 | 1631 | */ | |
| 1628 | 1632 | public PGraphics createGraphics(int w, int h, | |
| 1629 | 1633 | String renderer, String path) { | |
| 1634 | + return makeGraphics(w, h, renderer, savePath(path), false); | ||
| 1635 | + /* | ||
| 1630 | 1636 | if (path != null) { | |
| 1631 | 1637 | path = savePath(path); | |
| 1632 | 1638 | } | |
| 1633 | 1639 | PGraphics pg = makeGraphics(w, h, renderer, path, false); | |
| 1634 | - pg.parent = this; // make save() work | ||
| 1640 | + //pg.parent = this; // why wasn't setParent() used before 3.0a6? | ||
| 1641 | + //pg.setParent(this); // make save() work | ||
| 1642 | + // Nevermind, parent is set in makeGraphics() | ||
| 1635 | 1643 | return pg; | |
| 1644 | + */ | ||
| 1636 | 1645 | } | |
| 1637 | 1646 | ||
| 1638 | 1647 | ||
@@ -1641,13 +1650,12 @@ public PGraphics createGraphics(int w, int h, | |||
| 1641 | 1650 | // } | |
| 1642 | 1651 | ||
| 1643 | 1652 | ||
| 1644 | - /** Create default renderer, likely to be resized, but needed for surface init. */ | ||
| 1645 | - protected PGraphics makePrimaryGraphics() { | ||
| 1646 | - return makeGraphics(sketchWidth(), sketchHeight(), sketchRenderer(), null, true); | ||
| 1647 | - } | ||
| 1648 | - | ||
| 1649 | - | ||
| 1650 | - /** Version of createGraphics() used internally. */ | ||
| 1653 | + /** | ||
| 1654 | + * Version of createGraphics() used internally. | ||
| 1655 | + * @param path A full (not relative) path. | ||
| 1656 | + * {@link PApplet#createGraphics} will call | ||
| 1657 | + * {@link PApplet#savePath} first. | ||
| 1658 | + */ | ||
| 1651 | 1659 | protected PGraphics makeGraphics(int w, int h, | |
| 1652 | 1660 | String renderer, String path, | |
| 1653 | 1661 | boolean primary) { | |
@@ -1677,13 +1685,12 @@ protected PGraphics makeGraphics(int w, int h, | |||
| 1677 | 1685 | pg.setParent(this); | |
| 1678 | 1686 | pg.setPrimary(primary); | |
| 1679 | 1687 | if (path != null) { | |
| 1680 | - // Wrap in sketchPath() because it has to be absolute | ||
| 1681 | - pg.setPath(sketchPath(path)); | ||
| 1688 | + pg.setPath(path); | ||
| 1682 | 1689 | } | |
| 1683 | 1690 | // pg.setQuality(sketchQuality()); | |
| 1684 | - if (!primary) { | ||
| 1685 | - surface.initImage(pg, w, h); | ||
| 1686 | - } | ||
| 1691 | + // if (!primary) { | ||
| 1692 | + // surface.initImage(pg, w, h); | ||
| 1693 | + // } | ||
| 1687 | 1694 | pg.setSize(w, h); | |
| 1688 | 1695 | ||
| 1689 | 1696 | // everything worked, return it | |
@@ -1738,12 +1745,19 @@ protected PGraphics makeGraphics(int w, int h, | |||
| 1738 | 1745 | if (platform == MACOSX) { | |
| 1739 | 1746 | e.printStackTrace(System.out); // OS X bug (still true?) | |
| 1740 | 1747 | } | |
| 1748 | + e.printStackTrace(); | ||
| 1741 | 1749 | throw new RuntimeException(e.getMessage()); | |
| 1742 | 1750 | } | |
| 1743 | 1751 | } | |
| 1744 | 1752 | } | |
| 1745 | 1753 | ||
| 1746 | 1754 | ||
| 1755 | + /** Create default renderer, likely to be resized, but needed for surface init. */ | ||
| 1756 | + protected PGraphics createPrimaryGraphics() { | ||
| 1757 | + return makeGraphics(sketchWidth(), sketchHeight(), sketchRenderer(), null, true); | ||
| 1758 | + } | ||
| 1759 | + | ||
| 1760 | + | ||
| 1747 | 1761 | /** | |
| 1748 | 1762 | * ( begin auto-generated from createImage.xml ) | |
| 1749 | 1763 | * | |
@@ -9370,9 +9384,8 @@ public void run() { | |||
| 9370 | 9384 | ||
| 9371 | 9385 | ||
| 9372 | 9386 | /** | |
| 9373 | - * Moving this to the EDT for 3.0a6 because the main() messes with AWT | ||
| 9374 | - * components (or even Swing components, presumably). Hoping to get more | ||
| 9375 | - * consistent behavior across platforms and implementations. | ||
| 9387 | + * Moving this to the EDT for 3.0a6 because that's the proper thing to do | ||
| 9388 | + * when messing with AWT/Swing components. And boy, do we mess with 'em. | ||
| 9376 | 9389 | */ | |
| 9377 | 9390 | static protected void runSketchEDT(final String[] args, | |
| 9378 | 9391 | final PApplet constructedApplet) { | |
@@ -9512,6 +9525,7 @@ static protected void runSketchEDT(final String[] args, | |||
| 9512 | 9525 | // Frame frame = | |
| 9513 | 9526 | // surface.initFrame(applet, backgroundColor, | |
| 9514 | 9527 | // displayIndex, present, spanDisplays); | |
| 9528 | + | ||
| 9515 | 9529 | PSurface surface = | |
| 9516 | 9530 | applet.initSurface(backgroundColor, displayIndex, fullScreen, spanDisplays); | |
| 9517 | 9531 | ||
@@ -9528,15 +9542,15 @@ static protected void runSketchEDT(final String[] args, | |||
| 9528 | 9542 | // // In a static mode app, this will be after setup() has completed, | |
| 9529 | 9543 | // // and the empty draw() has set "finished" to true. | |
| 9530 | 9544 | // // TODO make sure this won't hang if the applet has an exception. | |
| 9531 | - // while (applet.defaultSize && !applet.finished) { | ||
| 9532 | - // //System.out.println("default size"); | ||
| 9533 | - // try { | ||
| 9534 | - // Thread.sleep(5); | ||
| 9535 | - // | ||
| 9536 | - // } catch (InterruptedException e) { | ||
| 9537 | - // //System.out.println("interrupt"); | ||
| 9538 | - // } | ||
| 9539 | - // } | ||
| 9545 | + while (applet.defaultSize && !applet.finished) { | ||
| 9546 | + //System.out.println("default size"); | ||
| 9547 | + try { | ||
| 9548 | + Thread.sleep(5); | ||
| 9549 | + | ||
| 9550 | + } catch (InterruptedException e) { | ||
| 9551 | + //System.out.println("interrupt"); | ||
| 9552 | + } | ||
| 9553 | + } | ||
| 9540 | 9554 | ||
| 9541 | 9555 | if (fullScreen) { | |
| 9542 | 9556 | //surface.placeFullScreen(hideStop); | |
@@ -9565,10 +9579,16 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex, | |||
| 9565 | 9579 | // } catch (Exception e) { | |
| 9566 | 9580 | // throw new RuntimeException(e); | |
| 9567 | 9581 | // } | |
| 9568 | - g = makePrimaryGraphics(); | ||
| 9582 | + g = createPrimaryGraphics(); | ||
| 9569 | 9583 | surface = g.createSurface(); | |
| 9570 | - frame = surface.initFrame(this, backgroundColor, displayIndex, present, spanDisplays); | ||
| 9571 | - surface.setTitle(getClass().getName()); | ||
| 9584 | + if (g.displayable()) { | ||
| 9585 | + frame = surface.initFrame(this, backgroundColor, displayIndex, present, spanDisplays); | ||
| 9586 | + //surface.setTitle(getClass().getName()); | ||
| 9587 | + frame.setTitle(getClass().getName()); | ||
| 9588 | + // } else { | ||
| 9589 | + // // TODO necessary? | ||
| 9590 | + // surface.initOffscreen(this); | ||
| 9591 | + } | ||
| 9572 | 9592 | ||
| 9573 | 9593 | init(); | |
| 9574 | 9594 | ||
@@ -9578,6 +9598,11 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex, | |||
| 9578 | 9598 | // moving it to init() 141114 | |
| 9579 | 9599 | //applet.start(); | |
| 9580 | 9600 | ||
| 9601 | + // Removing this for 3.0a6. sketchWidth/Height() methods should give us | ||
| 9602 | + // good values for most cases, and removes the hackery seen here. | ||
| 9603 | + // TODO May need to keep since setup() may take a while, so why not have | ||
| 9604 | + // it first render offscreen before showing. | ||
| 9605 | + /* | ||
| 9581 | 9606 | // Wait until the applet has figured out its width. | |
| 9582 | 9607 | // In a static mode app, this will be after setup() has completed, | |
| 9583 | 9608 | // and the empty draw() has set "finished" to true. | |
@@ -9591,6 +9616,8 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex, | |||
| 9591 | 9616 | //System.out.println("interrupt"); | |
| 9592 | 9617 | } | |
| 9593 | 9618 | } | |
| 9619 | + */ | ||
| 9620 | + | ||
| 9594 | 9621 | // System.out.println("out of default size loop, " + width + " " + height); | |
| 9595 | 9622 | // convenience to avoid another 'get' from the static main() method | |
| 9596 | 9623 | return surface; | |
@@ -9618,7 +9645,7 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex, | |||
| 9618 | 9645 | * sketch.init() // start the animation thread | |
| 9619 | 9646 | */ | |
| 9620 | 9647 | public Canvas getCanvas() { | |
| 9621 | - g = makePrimaryGraphics(); | ||
| 9648 | + g = createPrimaryGraphics(); | ||
| 9622 | 9649 | surface = g.createSurface(); | |
| 9623 | 9650 | return surface.initCanvas(this); | |
| 9624 | 9651 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -168,7 +168,7 @@ public class PGraphics extends PImage implements PConstants { | |||
| 168 | 168 | /// true if defaults() has been called a first time | |
| 169 | 169 | protected boolean settingsInited; | |
| 170 | 170 | ||
| 171 | - /// true if defaults() has been called a first time | ||
| 171 | + /// true if settings should be re-applied on next beginDraw() | ||
| 172 | 172 | protected boolean reapplySettings; | |
| 173 | 173 | ||
| 174 | 174 | /// set to a PGraphics object being used inside a beginRaw/endRaw() block | |
@@ -516,6 +516,9 @@ public class PGraphics extends PImage implements PConstants { | |||
| 516 | 516 | */ | |
| 517 | 517 | public Image image; | |
| 518 | 518 | ||
| 519 | + /** Surface object that we're talking to */ | ||
| 520 | + protected PSurface surface; | ||
| 521 | + | ||
| 519 | 522 | // ........................................................ | |
| 520 | 523 | ||
| 521 | 524 | // internal color for setting/calculating | |
@@ -653,7 +656,7 @@ public class PGraphics extends PImage implements PConstants { | |||
| 653 | 656 | * vertex() calls will be based on coordinates that are | |
| 654 | 657 | * based on the IMAGE or NORMALIZED. | |
| 655 | 658 | */ | |
| 656 | - public int textureMode = IMAGE; | ||
| 659 | + public int textureMode = IMAGE; | ||
| 657 | 660 | ||
| 658 | 661 | /** | |
| 659 | 662 | * Current horizontal coordinate for texture, will always | |
@@ -683,6 +686,11 @@ public class PGraphics extends PImage implements PConstants { | |||
| 683 | 686 | ||
| 684 | 687 | // INTERNAL | |
| 685 | 688 | ||
| 689 | + // Most renderers will only override the default implementation of one or | ||
| 690 | + // two of the setXxxx() methods, so they're broken out here since the | ||
| 691 | + // default implementations for each are simple, obvious, and common. | ||
| 692 | + // They're also separate to avoid a monolithic and fragile constructor. | ||
| 693 | + | ||
| 686 | 694 | ||
| 687 | 695 | public PGraphics() { | |
| 688 | 696 | // Allows subclasses to override | |
@@ -691,6 +699,8 @@ public PGraphics() { | |||
| 691 | 699 | ||
| 692 | 700 | public void setParent(PApplet parent) { // ignore | |
| 693 | 701 | this.parent = parent; | |
| 702 | + // Some renderers (OpenGL) need to know what smoothing level will be used | ||
| 703 | + // before the rendering surface is even created. | ||
| 694 | 704 | quality = parent.sketchQuality(); | |
| 695 | 705 | } | |
| 696 | 706 | ||
@@ -737,17 +747,20 @@ public void setSize(int w, int h) { // ignore | |||
| 737 | 747 | width = w; | |
| 738 | 748 | height = h; | |
| 739 | 749 | ||
| 750 | + /** {@link PImage.pixelFactor} set in {@link PImage#PImage()} */ | ||
| 740 | 751 | pixelWidth = width * pixelFactor; | |
| 741 | 752 | pixelHeight = height * pixelFactor; | |
| 742 | 753 | ||
| 743 | - // allocate(); | ||
| 744 | - reapplySettings(); | ||
| 754 | + // if (surface != null) { | ||
| 755 | + // allocate(); | ||
| 756 | + // } | ||
| 757 | + // reapplySettings(); | ||
| 758 | + reapplySettings = true; | ||
| 745 | 759 | } | |
| 746 | 760 | ||
| 747 | 761 | ||
| 748 | 762 | // /** | |
| 749 | - // * Allocate memory for this renderer. Generally will need to be implemented | ||
| 750 | - // * for all renderers. | ||
| 763 | + // * Allocate memory or an image buffer for this renderer. | ||
| 751 | 764 | // */ | |
| 752 | 765 | // protected void allocate() { } | |
| 753 | 766 | ||
@@ -764,7 +777,7 @@ public void dispose() { // ignore | |||
| 764 | 777 | ||
| 765 | 778 | ||
| 766 | 779 | public PSurface createSurface() { // ignore | |
| 767 | - return new PSurfaceAWT(this); | ||
| 780 | + return surface = new PSurfaceAWT(this); | ||
| 768 | 781 | } | |
| 769 | 782 | ||
| 770 | 783 | ||
@@ -950,7 +963,7 @@ protected void defaultSettings() { // ignore | |||
| 950 | 963 | ||
| 951 | 964 | settingsInited = true; | |
| 952 | 965 | // defaultSettings() overlaps reapplySettings(), don't do both | |
| 953 | - //reapplySettings = false; | ||
| 966 | + reapplySettings = false; | ||
| 954 | 967 | } | |
| 955 | 968 | ||
| 956 | 969 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments