FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

trying... to... simplify. · danhett/processing@1b9e12e · GitHub

Repository navigation

Commit 1b9e12e

Browse files
committed
trying... to... simplify.
1 parent ce11c08 commit 1b9e12e

9 files changed

Lines changed: 591 additions & 372 deletions

File tree

‎core/src/processing/core/PApplet.java‎

Lines changed: 76 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2012-14 The Processing Foundation
6+
Copyright (c) 2012-15 The Processing Foundation
77
Copyright (c) 2004-12 Ben Fry and Casey Reas
88
Copyright (c) 2001-04 Massachusetts Institute of Technology
99
@@ -24,15 +24,14 @@
2424

2525
package processing.core;
2626

27-
// used for setting bg colors and whatnot
2827
import java.awt.Canvas;
28+
// used for setting bg colors and whatnot
2929
import java.awt.Color;
3030
// use for the link() command (and maybe open()?)
3131
import java.awt.Desktop;
3232
import java.awt.EventQueue;
3333
import java.awt.FileDialog;
3434
import java.awt.Font;
35-
// for the Frame object (deprecate?)
3635
import java.awt.Frame;
3736
import java.awt.Image;
3837
import java.awt.Toolkit;
@@ -66,26 +65,33 @@
6665
* Window Size and Full Screen</A> page on the Wiki has useful information
6766
* about sizing, multiple displays, full screen, etc.
6867
* <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().
7973
* <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.
8485
* <p/>
8586
* As of Processing 3.0, we have removed Applet as the base class for PApplet.
8687
* This means that we can remove lots of legacy code, however one downside is
8788
* that it's no longer possible (without extra code) to embed a PApplet into
8889
* 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.
8995
*/
9096
public class PApplet implements PConstants {
9197
//public class PApplet extends Applet
@@ -1614,9 +1620,7 @@ public PGraphics createGraphics(int w, int h) {
16141620
*
16151621
*/
16161622
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);
16201624
}
16211625

16221626

@@ -1627,12 +1631,17 @@ public PGraphics createGraphics(int w, int h, String renderer) {
16271631
*/
16281632
public PGraphics createGraphics(int w, int h,
16291633
String renderer, String path) {
1634+
return makeGraphics(w, h, renderer, savePath(path), false);
1635+
/*
16301636
if (path != null) {
16311637
path = savePath(path);
16321638
}
16331639
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()
16351643
return pg;
1644+
*/
16361645
}
16371646

16381647

@@ -1641,13 +1650,12 @@ public PGraphics createGraphics(int w, int h,
16411650
// }
16421651

16431652

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+
*/
16511659
protected PGraphics makeGraphics(int w, int h,
16521660
String renderer, String path,
16531661
boolean primary) {
@@ -1677,13 +1685,12 @@ protected PGraphics makeGraphics(int w, int h,
16771685
pg.setParent(this);
16781686
pg.setPrimary(primary);
16791687
if (path != null) {
1680-
// Wrap in sketchPath() because it has to be absolute
1681-
pg.setPath(sketchPath(path));
1688+
pg.setPath(path);
16821689
}
16831690
// pg.setQuality(sketchQuality());
1684-
if (!primary) {
1685-
surface.initImage(pg, w, h);
1686-
}
1691+
// if (!primary) {
1692+
// surface.initImage(pg, w, h);
1693+
// }
16871694
pg.setSize(w, h);
16881695

16891696
// everything worked, return it
@@ -1738,12 +1745,19 @@ protected PGraphics makeGraphics(int w, int h,
17381745
if (platform == MACOSX) {
17391746
e.printStackTrace(System.out); // OS X bug (still true?)
17401747
}
1748+
e.printStackTrace();
17411749
throw new RuntimeException(e.getMessage());
17421750
}
17431751
}
17441752
}
17451753

17461754

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+
17471761
/**
17481762
* ( begin auto-generated from createImage.xml )
17491763
*
@@ -9370,9 +9384,8 @@ public void run() {
93709384

93719385

93729386
/**
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.
93769389
*/
93779390
static protected void runSketchEDT(final String[] args,
93789391
final PApplet constructedApplet) {
@@ -9512,6 +9525,7 @@ static protected void runSketchEDT(final String[] args,
95129525
// Frame frame =
95139526
// surface.initFrame(applet, backgroundColor,
95149527
// displayIndex, present, spanDisplays);
9528+
95159529
PSurface surface =
95169530
applet.initSurface(backgroundColor, displayIndex, fullScreen, spanDisplays);
95179531

@@ -9528,15 +9542,15 @@ static protected void runSketchEDT(final String[] args,
95289542
// // In a static mode app, this will be after setup() has completed,
95299543
// // and the empty draw() has set "finished" to true.
95309544
// // 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+
}
95409554

95419555
if (fullScreen) {
95429556
//surface.placeFullScreen(hideStop);
@@ -9565,10 +9579,16 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex,
95659579
// } catch (Exception e) {
95669580
// throw new RuntimeException(e);
95679581
// }
9568-
g = makePrimaryGraphics();
9582+
g = createPrimaryGraphics();
95699583
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+
}
95729592

95739593
init();
95749594

@@ -9578,6 +9598,11 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex,
95789598
// moving it to init() 141114
95799599
//applet.start();
95809600

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+
/*
95819606
// Wait until the applet has figured out its width.
95829607
// In a static mode app, this will be after setup() has completed,
95839608
// and the empty draw() has set "finished" to true.
@@ -9591,6 +9616,8 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex,
95919616
//System.out.println("interrupt");
95929617
}
95939618
}
9619+
*/
9620+
95949621
// System.out.println("out of default size loop, " + width + " " + height);
95959622
// convenience to avoid another 'get' from the static main() method
95969623
return surface;
@@ -9618,7 +9645,7 @@ protected PSurface initSurface(Color backgroundColor, int displayIndex,
96189645
* sketch.init() // start the animation thread
96199646
*/
96209647
public Canvas getCanvas() {
9621-
g = makePrimaryGraphics();
9648+
g = createPrimaryGraphics();
96229649
surface = g.createSurface();
96239650
return surface.initCanvas(this);
96249651
}

‎core/src/processing/core/PGraphics.java‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public class PGraphics extends PImage implements PConstants {
168168
/// true if defaults() has been called a first time
169169
protected boolean settingsInited;
170170

171-
/// true if defaults() has been called a first time
171+
/// true if settings should be re-applied on next beginDraw()
172172
protected boolean reapplySettings;
173173

174174
/// set to a PGraphics object being used inside a beginRaw/endRaw() block
@@ -516,6 +516,9 @@ public class PGraphics extends PImage implements PConstants {
516516
*/
517517
public Image image;
518518

519+
/** Surface object that we're talking to */
520+
protected PSurface surface;
521+
519522
// ........................................................
520523

521524
// internal color for setting/calculating
@@ -653,7 +656,7 @@ public class PGraphics extends PImage implements PConstants {
653656
* vertex() calls will be based on coordinates that are
654657
* based on the IMAGE or NORMALIZED.
655658
*/
656-
public int textureMode = IMAGE;
659+
public int textureMode = IMAGE;
657660

658661
/**
659662
* Current horizontal coordinate for texture, will always
@@ -683,6 +686,11 @@ public class PGraphics extends PImage implements PConstants {
683686

684687
// INTERNAL
685688

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+
686694

687695
public PGraphics() {
688696
// Allows subclasses to override
@@ -691,6 +699,8 @@ public PGraphics() {
691699

692700
public void setParent(PApplet parent) { // ignore
693701
this.parent = parent;
702+
// Some renderers (OpenGL) need to know what smoothing level will be used
703+
// before the rendering surface is even created.
694704
quality = parent.sketchQuality();
695705
}
696706

@@ -737,17 +747,20 @@ public void setSize(int w, int h) { // ignore
737747
width = w;
738748
height = h;
739749

750+
/** {@link PImage.pixelFactor} set in {@link PImage#PImage()} */
740751
pixelWidth = width * pixelFactor;
741752
pixelHeight = height * pixelFactor;
742753

743-
// allocate();
744-
reapplySettings();
754+
// if (surface != null) {
755+
// allocate();
756+
// }
757+
// reapplySettings();
758+
reapplySettings = true;
745759
}
746760

747761

748762
// /**
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.
751764
// */
752765
// protected void allocate() { }
753766

@@ -764,7 +777,7 @@ public void dispose() { // ignore
764777

765778

766779
public PSurface createSurface() { // ignore
767-
return new PSurfaceAWT(this);
780+
return surface = new PSurfaceAWT(this);
768781
}
769782

770783

@@ -950,7 +963,7 @@ protected void defaultSettings() { // ignore
950963

951964
settingsInited = true;
952965
// defaultSettings() overlaps reapplySettings(), don't do both
953-
//reapplySettings = false;
966+
reapplySettings = false;
954967
}
955968

956969

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL