Last active
November 21, 2015 19:20
-
-
Save atduskgreg/ad689ff9685345ae6cee to your computer and use it in GitHub Desktop.
Example of creating a Processing sketch with multiple windows. NOTE: this doesn't work in Processing 3.0. See the Processing 3.0 version here: https://gist.github.com/atduskgreg/666e46c8408e2a33b09a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Frame; | |
PWindow w; | |
void setup() { | |
size(320, 240); | |
w = new PWindow(100, 100, 500, 200); | |
} | |
void draw() { | |
background(255, 0, 0); | |
fill(255); | |
rect(10, 10, frameCount, 10); | |
w.app.background(0, 0, 255); | |
w.app.fill(100); | |
w.app.rect(10, 20, frameCount, 10); | |
w.app.redraw(); | |
} | |
void mousePressed(){ | |
println("mousePressed"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PWindow extends Frame { | |
PWindowApp app; | |
PWindow(int x, int y, int w, int h) { | |
setBounds(x,y,w,h); | |
app = new PWindowApp(); | |
app.setParent(this); | |
add(app); | |
app.init(); | |
show(); | |
} | |
} | |
class PWindowApp extends PApplet { | |
Frame parent; | |
void setParent(Frame _parent){ | |
parent = _parent; | |
} | |
void setup() { | |
size(parent.getWidth(), parent.getHeight()); | |
noLoop(); | |
} | |
void draw() { | |
} | |
// all mouse, keyboard events work in here as expected | |
// TODO: Could there be an API for defining these from the outside? | |
void mousePressed(){ | |
println("second app mouse pressed"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment