mirror of
https://github.com/processing/processing4.git
synced 2026-02-13 18:35:37 +01:00
initial sizing, fonts, images, etc
This commit is contained in:
@@ -29,6 +29,8 @@ import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import com.oroinc.text.regex.*;
|
||||
|
||||
|
||||
public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
@@ -71,6 +73,52 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
int x1 = parentLoc.x - 20;
|
||||
int y1 = parentLoc.y;
|
||||
|
||||
// try to figure out the size of the applet from the code
|
||||
|
||||
int initialWidth = PApplet.DEFAULT_WIDTH;
|
||||
int initialHeight = PApplet.DEFAULT_HEIGHT;
|
||||
|
||||
try {
|
||||
PatternMatcher matcher = new Perl5Matcher();
|
||||
PatternCompiler compiler = new Perl5Compiler();
|
||||
|
||||
// this matches against any uses of the size() function,
|
||||
// whether they contain numbers of variables or whatever.
|
||||
// this way, no warning is shown if size() isn't actually
|
||||
// used in the applet, which is the case especially for
|
||||
// beginners that are cutting/pasting from the reference.
|
||||
String sizing =
|
||||
"[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\S+)\\s*\\);";
|
||||
Pattern pattern = compiler.compile(sizing);
|
||||
|
||||
// adds a space at the beginning, in case size() is the very
|
||||
// first thing in the program (very common), since the regexp
|
||||
// needs to check for things in front of it.
|
||||
PatternMatcherInput input =
|
||||
new PatternMatcherInput(" " + sketch.code[0].program);
|
||||
if (matcher.contains(input, pattern)) {
|
||||
MatchResult result = matcher.getMatch();
|
||||
try {
|
||||
initialWidth = Integer.parseInt(result.group(1).toString());
|
||||
initialHeight = Integer.parseInt(result.group(2).toString());
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
/*
|
||||
// found a reference to size, but it didn't
|
||||
// seem to contain numbers
|
||||
final String message =
|
||||
"The size of this applet could not automatically be\n" +
|
||||
"determined from your code. You'll have to edit the\n" +
|
||||
"HTML file to set the size of the applet.";
|
||||
|
||||
PdeBase.showWarning("Could not find applet size", message, null);
|
||||
*/
|
||||
}
|
||||
} // else no size() command found
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // later fail silently
|
||||
}
|
||||
|
||||
try {
|
||||
if (sketch.externalRuntime) {
|
||||
// if there was a saved location (this guy has been run more than
|
||||
@@ -104,6 +152,7 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
sketch.classPath + PdeSketchbook.librariesClassPath,
|
||||
"processing.core.PApplet",
|
||||
location,
|
||||
PApplet.EXT_SIZE + initialWidth + "," + initialHeight,
|
||||
PApplet.EXT_SKETCH_FOLDER + sketch.folder.getAbsolutePath(),
|
||||
sketch.mainClassName
|
||||
};
|
||||
@@ -181,21 +230,37 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
|
||||
window.setLayout(null);
|
||||
if (editor.presenting) {
|
||||
/*
|
||||
window.setBounds((screen.width - applet.width) / 2,
|
||||
(screen.height - applet.height) / 2,
|
||||
applet.width, applet.height);
|
||||
applet.setBounds(0, 0, applet.width, applet.height);
|
||||
*/
|
||||
window.setBounds((screen.width - initialWidth) / 2,
|
||||
(screen.height - initialHeight) / 2,
|
||||
initialWidth, initialHeight);
|
||||
applet.setBounds(0, 0, initialWidth, initialHeight);
|
||||
|
||||
} else {
|
||||
Insets insets = window.getInsets();
|
||||
//System.out.println(insets);
|
||||
|
||||
if ((applet.width != 0) &&
|
||||
(applet.height != 0) &&
|
||||
(applet.width != PApplet.DEFAULT_WIDTH) &&
|
||||
(applet.height != PApplet.DEFAULT_HEIGHT)) {
|
||||
initialWidth = applet.width;
|
||||
initialHeight = applet.height;
|
||||
}
|
||||
|
||||
int minW = PdePreferences.getInteger("run.window.width.minimum");
|
||||
int minH = PdePreferences.getInteger("run.window.height.minimum");
|
||||
int windowW =
|
||||
Math.max(applet.width, minW) + insets.left + insets.right;
|
||||
Math.max(initialWidth, minW) + insets.left + insets.right;
|
||||
//Math.max(applet.width, minW) + insets.left + insets.right;
|
||||
int windowH =
|
||||
Math.max(applet.height, minH) + insets.top + insets.bottom;
|
||||
Math.max(initialHeight, minH) + insets.top + insets.bottom;
|
||||
//Math.max(applet.height, minH) + insets.top + insets.bottom;
|
||||
|
||||
if (x1 - windowW > 10) { // if it fits to the left of the window
|
||||
window.setBounds(x1 - windowW, y1, windowW, windowH);
|
||||
@@ -218,11 +283,18 @@ public class PdeRuntime implements PdeMessageConsumer {
|
||||
Color windowBgColor = PdePreferences.getColor("run.window.bgcolor");
|
||||
window.setBackground(windowBgColor);
|
||||
|
||||
/*
|
||||
applet.setBounds((windowW - applet.width)/2,
|
||||
insets.top + ((windowH -
|
||||
insets.top - insets.bottom) -
|
||||
applet.height)/2,
|
||||
windowW, windowH);
|
||||
*/
|
||||
applet.setBounds((windowW - initialWidth)/2,
|
||||
insets.top + ((windowH -
|
||||
insets.top - insets.bottom) -
|
||||
initialHeight)/2,
|
||||
windowW, windowH);
|
||||
}
|
||||
|
||||
applet.setVisible(true); // no effect
|
||||
|
||||
@@ -165,6 +165,10 @@ public class PApplet extends Applet
|
||||
|
||||
static public final int DEFAULT_WIDTH = 100;
|
||||
static public final int DEFAULT_HEIGHT = 100;
|
||||
|
||||
protected int INITIAL_WIDTH = DEFAULT_WIDTH;
|
||||
protected int INITIAL_HEIGHT = DEFAULT_HEIGHT;
|
||||
|
||||
public int width, height;
|
||||
|
||||
protected RegisteredMethods sizeMethods;
|
||||
@@ -186,6 +190,7 @@ public class PApplet extends Applet
|
||||
//static public final String EXTERNAL_FLAG = "--external=";
|
||||
//static public final char EXTERNAL_EXACT_LOCATION = 'e';
|
||||
static public final String EXT_LOCATION = "--location=";
|
||||
static public final String EXT_SIZE = "--size=";
|
||||
static public final String EXT_EXACT_LOCATION = "--exact-location=";
|
||||
static public final String EXT_SKETCH_FOLDER = "--sketch-folder=";
|
||||
|
||||
@@ -255,10 +260,14 @@ public class PApplet extends Applet
|
||||
|
||||
|
||||
public void createGraphics() {
|
||||
Dimension size = getSize();
|
||||
|
||||
if (PApplet.jdkVersion >= 1.3) {
|
||||
g = new PGraphics2(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
g = new PGraphics2(size.width, size.height);
|
||||
//DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
} else {
|
||||
g = new PGraphics(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
g = new PGraphics(size.width, size.height);
|
||||
//g = new PGraphics(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,8 +277,11 @@ public class PApplet extends Applet
|
||||
// buffer so as not to re-allocate all that memory again
|
||||
if (g.width != 0) {
|
||||
g = new PGraphics3(g.width, g.height);
|
||||
|
||||
} else {
|
||||
g = new PGraphics3(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
Dimension size = getSize();
|
||||
g = new PGraphics3(size.width, size.height);
|
||||
//DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
}
|
||||
// it's ok to call this, because depth() is only getting called
|
||||
// at least inside of setup, so things can be drawn just
|
||||
@@ -444,7 +456,7 @@ public class PApplet extends Applet
|
||||
if (!looping) {
|
||||
redraw = true;
|
||||
if (thread != null) {
|
||||
thread.interrupt(); // wake from sleep
|
||||
//thread.interrupt(); // wake from sleep
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,7 +466,7 @@ public class PApplet extends Applet
|
||||
if (!looping) {
|
||||
looping = true;
|
||||
if (thread != null) {
|
||||
thread.interrupt(); // wake from sleep
|
||||
//thread.interrupt(); // wake from sleep
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -469,7 +481,7 @@ public class PApplet extends Applet
|
||||
fpsLastMillis = 0;
|
||||
|
||||
if (thread != null) {
|
||||
thread.interrupt(); // wake from sleep
|
||||
//thread.interrupt(); // wake from sleep
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1985,7 +1997,9 @@ public class PApplet extends Applet
|
||||
try {
|
||||
tracker.waitForAll();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace(); // non-fatal, right?
|
||||
// don't bother, since this may be interrupted by draw
|
||||
// or noLoop or something like that
|
||||
//e.printStackTrace(); // non-fatal, right?
|
||||
}
|
||||
|
||||
PImage image = new PImage(awtImage);
|
||||
@@ -4224,6 +4238,9 @@ v PApplet.this.stop();
|
||||
//if (args[0].indexOf(EXTERNAL_FLAG) == 0) external = true;
|
||||
String name = null;
|
||||
|
||||
int initialWidth = PApplet.DEFAULT_WIDTH;
|
||||
int initialHeight = PApplet.DEFAULT_HEIGHT;
|
||||
|
||||
int argIndex = 0;
|
||||
while (argIndex < args.length) {
|
||||
if (args[argIndex].indexOf(EXT_LOCATION) == 0) {
|
||||
@@ -4244,6 +4261,13 @@ v PApplet.this.stop();
|
||||
} else if (args[argIndex].indexOf(EXT_SKETCH_FOLDER) == 0) {
|
||||
folder = args[argIndex].substring(EXT_SKETCH_FOLDER.length());
|
||||
|
||||
} else if (args[argIndex].indexOf(EXT_SIZE) == 0) {
|
||||
String sizeStr = args[argIndex].substring(EXT_SIZE.length());
|
||||
int initial[] = toInt(split(sizeStr, ','));
|
||||
initialWidth = initial[0];
|
||||
initialHeight = initial[1];
|
||||
//System.out.println("initial: " + initialWidth + " " + initialHeight);
|
||||
|
||||
} else {
|
||||
name = args[argIndex];
|
||||
break;
|
||||
@@ -4259,6 +4283,9 @@ v PApplet.this.stop();
|
||||
PApplet applet = (PApplet) c.newInstance();
|
||||
applet.frame = frame;
|
||||
|
||||
applet.INITIAL_WIDTH = initialWidth;
|
||||
applet.INITIAL_HEIGHT = initialHeight;
|
||||
|
||||
// these are needed before init/start
|
||||
applet.folder = folder;
|
||||
int argc = args.length - (argIndex+1);
|
||||
@@ -4288,8 +4315,10 @@ v PApplet.this.stop();
|
||||
int windowH =
|
||||
Math.max(applet.height, minH) + insets.top + insets.bottom;
|
||||
*/
|
||||
int windowW = 120 + insets.left + insets.right;
|
||||
int windowH = 120 + insets.top + insets.bottom;
|
||||
//int windowW = 120 + insets.left + insets.right;
|
||||
//int windowH = 120 + insets.top + insets.bottom;
|
||||
int windowW = initialWidth + insets.left + insets.right;
|
||||
int windowH = initialHeight + insets.top + insets.bottom;
|
||||
frame.setSize(windowW, windowH);
|
||||
|
||||
if (exactLocation) {
|
||||
@@ -4328,9 +4357,9 @@ v PApplet.this.stop();
|
||||
applet.height)/2,
|
||||
windowW, windowH);
|
||||
*/
|
||||
applet.setBounds((windowW - 100) / 2,
|
||||
insets.top + ((windowH - insets.top - insets.bottom) -
|
||||
100)/2,
|
||||
applet.setBounds((windowW - initialWidth) / 2,
|
||||
insets.top + ((windowH - insets.top -
|
||||
insets.bottom) - initialHeight)/2,
|
||||
windowW, windowH);
|
||||
|
||||
applet.setupExternal(frame);
|
||||
|
||||
@@ -428,18 +428,16 @@ public class PFont implements PConstants {
|
||||
float lextent = (float) leftExtent[glyph] / fwidth;
|
||||
float textent = (float) topExtent[glyph] / fheight;
|
||||
|
||||
//int savedTextureMode = parent.textureMode;
|
||||
boolean savedStroke = parent.stroke;
|
||||
|
||||
//parent.textureMode = IMAGE_SPACE;
|
||||
//parent.drawing_text = true;
|
||||
parent.stroke = false;
|
||||
|
||||
float x1 = x + lextent * size;
|
||||
float y1 = y - textent * size;
|
||||
float x2 = x1 + bwidth * size;
|
||||
float y2 = y1 + high * size;
|
||||
|
||||
parent.imageImpl(images[glyph],
|
||||
x1, y1, x2-x1, y2-y1,
|
||||
0, 0, width[glyph], height[glyph]);
|
||||
|
||||
/*
|
||||
// this code was moved here (instead of using parent.image)
|
||||
// because now images use tint() for their coloring, which
|
||||
// internally is kind of a hack because it temporarily sets
|
||||
@@ -447,6 +445,13 @@ public class PFont implements PConstants {
|
||||
// rather than doubling up the hack with this hack, the code
|
||||
// is just included here instead.
|
||||
|
||||
//int savedTextureMode = parent.textureMode;
|
||||
boolean savedStroke = parent.stroke;
|
||||
|
||||
//parent.textureMode = IMAGE_SPACE;
|
||||
//parent.drawing_text = true;
|
||||
parent.stroke = false;
|
||||
|
||||
//System.out.println(x1 + " " + y1 + " " + x2 + " " + y2);
|
||||
|
||||
parent.beginShape(QUADS);
|
||||
@@ -455,17 +460,16 @@ public class PFont implements PConstants {
|
||||
parent.vertex(x1, y2, z, 0, height[glyph]);
|
||||
parent.vertex(x2, y2, z, width[glyph], height[glyph]);
|
||||
parent.vertex(x2, y1, z, width[glyph], 0);
|
||||
/*
|
||||
parent.vertex(x1, y1, z);
|
||||
parent.vertex(x1, y2, z);
|
||||
parent.vertex(x2, y2, z);
|
||||
parent.vertex(x2, y1, z);
|
||||
*/
|
||||
//parent.vertex(x1, y1, z);
|
||||
//parent.vertex(x1, y2, z);
|
||||
//parent.vertex(x2, y2, z);
|
||||
//parent.vertex(x2, y1, z);
|
||||
parent.endShape();
|
||||
|
||||
//parent.textureMode = savedTextureMode;
|
||||
//parent.drawing_text = false;
|
||||
parent.stroke = savedStroke;
|
||||
*/
|
||||
|
||||
} else { // SCREEN_SPACE
|
||||
int xx = (int) x + leftExtent[glyph];;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#C:\jdk-1.4.2_05\bin
|
||||
#/cygdrive/c/jdk-1.4.2_05/bin/javadoc -d doc processing.core *.java
|
||||
/cygdrive/c/jdk-1.4.2_05/bin/javadoc -d doc *.java
|
||||
jikes -d . +D *.java
|
||||
#jikes -d . +D PApplet.java
|
||||
|
||||
@@ -8,6 +8,7 @@ X arc with stroke only draws the arc shape itself
|
||||
X may need a 'wedge' function to draw a stroke around the whole thing
|
||||
X only allocate stencil and zbuffer on first call to depth()
|
||||
X this will require changes to PTriangle and PLine inside their loops
|
||||
X try running javadoc
|
||||
|
||||
covered in previous
|
||||
X before graphics engine change, attach jogl stuff
|
||||
@@ -37,6 +38,7 @@ X vertices max out at 512.. make it grow
|
||||
X add gzipInput and gzipOutput
|
||||
X light(x, y, z, c1, c2, c3, TYPE)
|
||||
X also BLight with same constructor, and on() and off() fxn
|
||||
X make sure applet is stopping in draw mode
|
||||
|
||||
api changes
|
||||
X removed circle.. it's dumb when ellipse() is in there
|
||||
@@ -103,6 +105,8 @@ X not a problem for the main PGraphics, but for any others created to draw on
|
||||
opengl
|
||||
X make light() functions actually do something in PGraphicsGL
|
||||
X box() and sphere() working again
|
||||
X make opengl work in draw mode
|
||||
X set initial size using --size=
|
||||
|
||||
api todos
|
||||
_ sphere x,y,z,r or box w,h,d.. need to make them consistent
|
||||
@@ -111,20 +115,17 @@ _ should we switch to curveVertex(1,2,3) (ala curveto)
|
||||
_ because some confusion with mixing types of curves
|
||||
_ how to force PGraphics() instead of PGraphics2()
|
||||
|
||||
_ make opengl work in draw mode
|
||||
|
||||
_ lighting totally sucks
|
||||
|
||||
_ make sure applet is stopping in draw mode
|
||||
|
||||
_ also have a simple way to hook in triangle leeches to PGraphics3
|
||||
|
||||
_ implement PGraphics2.curveVertex()
|
||||
_ get text working again
|
||||
_ also colored text, requires tint() to work properly
|
||||
|
||||
_ move textMode and textSpace back out of PFont
|
||||
_ use die() to fail in font situations
|
||||
_ can't, just use a RuntimeException
|
||||
|
||||
_ also have a simple way to hook in triangle leeches to PGraphics3
|
||||
|
||||
_ implement PGraphics2.curveVertex()
|
||||
|
||||
_ get PGraphics.java engine working again
|
||||
|
||||
_ default to single byte input from serial port
|
||||
@@ -133,19 +134,13 @@ _ or serial.setDelimiter() to fire message on delim
|
||||
|
||||
_ die() may need to throw a RuntimeException
|
||||
|
||||
_ textFont with a named font can use the renderer/os font
|
||||
_ PFont.list() to return string list of all the available fonts
|
||||
_ for postscript, can grab the real font
|
||||
_ -> altho problem here is that really the fonts just need a name
|
||||
_ since needs to render to screen as well
|
||||
|
||||
_ fix lighting in PGraphics3
|
||||
//
|
||||
|
||||
lighting
|
||||
_ lighting totally sucks (both PGraphics3 and PGraphicsGL)
|
||||
_ bring in materials for opengl as well?
|
||||
_ don't include a class, just make it similar to the light functions
|
||||
|
||||
//
|
||||
|
||||
_ remove SCREEN_SPACE altogether?
|
||||
|
||||
_ be consistent about getXxx() methods
|
||||
@@ -180,6 +175,12 @@ _ that if applet is 500x500, centers on a 800x600 window
|
||||
_ though how do you get the screen size?
|
||||
_ screen.width and screen.height?
|
||||
|
||||
_ textFont with a named font can use the renderer/os font
|
||||
_ PFont.list() to return string list of all the available fonts
|
||||
_ for postscript, can grab the real font
|
||||
_ -> altho problem here is that really the fonts just need a name
|
||||
_ since needs to render to screen as well
|
||||
|
||||
//
|
||||
|
||||
0078
|
||||
|
||||
10
todo.txt
10
todo.txt
@@ -7,6 +7,11 @@ X get source and build on osx (or is it shipped by default?)
|
||||
X make sure that fink is not in the path when building
|
||||
X what are the args to configure a release version?
|
||||
X update linux version of jikes
|
||||
X look for size() method to determine default size of applet
|
||||
X (same as applet exporter function)
|
||||
o when using core graphics, don't show applet frame until first frame
|
||||
o (in opengl, open frame early, make sure this isn't inhibited)
|
||||
X probably can't do this, since don't know at runtime if it's gl
|
||||
|
||||
create a new sketch
|
||||
create a new tab named "a"
|
||||
@@ -31,11 +36,6 @@ can tell, is to Save As once, make at least one change, then Save.
|
||||
|
||||
what happens if folder already exists on save as?
|
||||
|
||||
_ look for size() method to determine default size of applet
|
||||
_ (same as applet exporter function)
|
||||
_ when using core graphics, don't show applet frame until first frame
|
||||
_ (in opengl, open frame early, make sure this isn't inhibited)
|
||||
|
||||
_ add tool to hit 'next' to go through examples
|
||||
_ just make it "next file in folder" since examples are all over
|
||||
_ also need to copy examples locally
|
||||
|
||||
Reference in New Issue
Block a user