mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
significant api cleaning and sorting things out for graphics
This commit is contained in:
+17
-7
@@ -4381,6 +4381,11 @@ v PApplet.this.stop();
|
||||
}
|
||||
|
||||
|
||||
public void loadPixels() {
|
||||
g.loadPixels();
|
||||
}
|
||||
|
||||
|
||||
public void updatePixels() {
|
||||
g.updatePixels();
|
||||
}
|
||||
@@ -4406,11 +4411,6 @@ v PApplet.this.stop();
|
||||
}
|
||||
|
||||
|
||||
public PImage get() {
|
||||
return g.get();
|
||||
}
|
||||
|
||||
|
||||
public void set(int x, int y, int c) {
|
||||
g.set(x, y, c);
|
||||
}
|
||||
@@ -4775,8 +4775,8 @@ v PApplet.this.stop();
|
||||
|
||||
|
||||
public void image(PImage image,
|
||||
float a, float b, float c, float d) {
|
||||
g.image(image, a, b, c, d);
|
||||
float x, float y, float c, float d) {
|
||||
g.image(image, x, y, c, d);
|
||||
}
|
||||
|
||||
|
||||
@@ -5272,4 +5272,14 @@ v PApplet.this.stop();
|
||||
public final float brightness(int what) {
|
||||
return g.brightness(what);
|
||||
}
|
||||
|
||||
|
||||
public void mask(int alpha[]) {
|
||||
g.mask(alpha);
|
||||
}
|
||||
|
||||
|
||||
public void mask(PImage alpha) {
|
||||
g.mask(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
+112
-82
@@ -643,6 +643,10 @@ public class PGraphics extends PImage implements PConstants {
|
||||
x, y);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("bezierVertex() can only be used with " +
|
||||
"LINE_LOOP and POLYGON shapes");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,11 +808,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
y1 -= vradius;
|
||||
}
|
||||
|
||||
draw_rect(x1, y1, x2, y2);
|
||||
rectImpl(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
protected void draw_rect(float x1, float y1, float x2, float y2) {
|
||||
protected void rectImpl(float x1, float y1, float x2, float y2) {
|
||||
// TODO write rect drawing function
|
||||
}
|
||||
|
||||
@@ -845,11 +849,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
y = b - d/2f;
|
||||
}
|
||||
|
||||
draw_ellipse(x, y, w, h);
|
||||
ellipseImpl(x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
protected void draw_ellipse(float x, float y, float w, float h) {
|
||||
protected void ellipseImpl(float x, float y, float w, float h) {
|
||||
// TODO draw an ellipse
|
||||
}
|
||||
|
||||
@@ -893,12 +897,12 @@ public class PGraphics extends PImage implements PConstants {
|
||||
while (stop < start) stop += TWO_PI;
|
||||
}
|
||||
|
||||
draw_arc(start, stop, x, y, w, h);
|
||||
arcImpl(start, stop, x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
protected void draw_arc(float start, float stop,
|
||||
float x, float y, float w, float h) {
|
||||
protected void arcImpl(float start, float stop,
|
||||
float x, float y, float w, float h) {
|
||||
}
|
||||
|
||||
|
||||
@@ -1338,60 +1342,55 @@ public class PGraphics extends PImage implements PConstants {
|
||||
// IMAGE
|
||||
|
||||
|
||||
|
||||
protected void draw_image(PImage image,
|
||||
float x1, float y1, float x2, float y2,
|
||||
int u1, int v1, int u2, int v2) {
|
||||
// TODO blit an image to the screen
|
||||
}
|
||||
|
||||
|
||||
public void image(PImage image, float x, float y) {
|
||||
if ((imageMode == CORNER) ||
|
||||
(imageMode == CORNERS)) {
|
||||
draw_image(image,
|
||||
x, y, x + image.width, y + image.height,
|
||||
0, 0, image.width, image.height);
|
||||
|
||||
} else if ((imageMode == CENTER) ||
|
||||
(imageMode == CENTER_RADIUS)) {
|
||||
draw_image(image,
|
||||
x - image.width/2.0f, y - image.height/2.0f,
|
||||
x + image.width/2.0f, y + image.height/2.0f,
|
||||
0, 0, image.width, image.height);
|
||||
}
|
||||
imageImpl(image,
|
||||
x, y, image.width, image.height,
|
||||
0, 0, image.width, image.height);
|
||||
}
|
||||
|
||||
|
||||
public void image(PImage image,
|
||||
float a, float b, float c, float d) {
|
||||
image(image, a, b, c, d, 0, 0, image.width, image.height);
|
||||
float x, float y, float c, float d) {
|
||||
image(image, x, y, c, d, 0, 0, image.width, image.height);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* u, v coordinates are always based on image space location,
|
||||
* regardless of the current textureMode().
|
||||
*/
|
||||
public void image(PImage image,
|
||||
float a, float b, float c, float d,
|
||||
int u1, int v1, int u2, int v2) {
|
||||
if (imageMode == CORNER) {
|
||||
draw_image(image,
|
||||
a, b, a+c, b+d,
|
||||
u1, v1, u2, v2);
|
||||
imageImpl(image,
|
||||
a, b, c, d,
|
||||
u1, v1, u2, v2);
|
||||
|
||||
} else if (imageMode == CORNERS) {
|
||||
draw_image(image,
|
||||
a, b, c, d,
|
||||
u1, v1, u2, v2);
|
||||
imageImpl(image,
|
||||
a, b, c - a, d - b,
|
||||
u1, v1, u2, v2);
|
||||
|
||||
/*
|
||||
} else if ((imageMode == CENTER) ||
|
||||
(imageMode == CENTER_RADIUS)) {
|
||||
draw_image(image,
|
||||
a - c/2f, b - d/2f,
|
||||
a + c/2f, b + d/2f,
|
||||
u1, v1, u2, v2);
|
||||
imageImpl(image,
|
||||
a - c/2f, b - d/2f,
|
||||
a + c/2f, b + d/2f,
|
||||
u1, v1, u2, v2);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void imageImpl(PImage image,
|
||||
float x, float y, float w, float h,
|
||||
int u1, int v1, int u2, int v2) {
|
||||
// TODO blit an image to the screen
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1585,8 +1584,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
* And they might kick our a-- for the confusion.
|
||||
*/
|
||||
public void rotate(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
|
||||
float c = (float) Math.cos(angle);
|
||||
float s = (float) Math.sin(angle);
|
||||
|
||||
applyMatrix(c, -s, 0, s, c, 0);
|
||||
}
|
||||
|
||||
@@ -1673,7 +1675,6 @@ public class PGraphics extends PImage implements PConstants {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Apply a 3x2 affine transformation matrix.
|
||||
*/
|
||||
@@ -1705,11 +1706,21 @@ public class PGraphics extends PImage implements PConstants {
|
||||
* Print the current model (or "transformation") matrix.
|
||||
*/
|
||||
public void printMatrix() {
|
||||
int big = (int) abs(max(max(abs(m00), abs(m01), abs(m02)),
|
||||
max(abs(m10), abs(m11), abs(m12))));
|
||||
float big = Math.abs(m00);
|
||||
if (Math.abs(m01) > big) big = Math.abs(m01);
|
||||
if (Math.abs(m02) > big) big = Math.abs(m02);
|
||||
if (Math.abs(m10) > big) big = Math.abs(m10);
|
||||
if (Math.abs(m11) > big) big = Math.abs(m11);
|
||||
if (Math.abs(m12) > big) big = Math.abs(m12);
|
||||
|
||||
// avoid infinite loop
|
||||
if (Float.isNaN(big) || Float.isInfinite(big)) {
|
||||
big = 8; // set to something arbitrary
|
||||
}
|
||||
|
||||
int d = 1;
|
||||
while ((big /= 10) != 0) d++; // cheap log()
|
||||
int bigi = (int) big;
|
||||
while ((bigi /= 10) != 0) d++; // cheap log()
|
||||
|
||||
System.out.println(PApplet.nfs(m00, d, 4) + " " +
|
||||
PApplet.nfs(m01, d, 4) + " " +
|
||||
@@ -1726,7 +1737,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// CAMERA
|
||||
// CAMERA (none are supported in 2D)
|
||||
|
||||
|
||||
public void cameraMode(int mode) {
|
||||
@@ -2309,7 +2320,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// PIXELS
|
||||
// COLOR MANIPULATION
|
||||
|
||||
// these functions are really slow, but easy to use
|
||||
// if folks are advanced enough to want something faster,
|
||||
@@ -2469,48 +2480,48 @@ public class PGraphics extends PImage implements PConstants {
|
||||
// also might be faster that way. hmm.
|
||||
|
||||
|
||||
private final float mag(float a, float b) {
|
||||
return (float)Math.sqrt(a*a + b*b);
|
||||
}
|
||||
//private final float mag(float a, float b) {
|
||||
//return (float)Math.sqrt(a*a + b*b);
|
||||
//}
|
||||
|
||||
private final float mag(float a, float b, float c) {
|
||||
return (float)Math.sqrt(a*a + b*b + c*c);
|
||||
}
|
||||
//private final float mag(float a, float b, float c) {
|
||||
//return (float)Math.sqrt(a*a + b*b + c*c);
|
||||
//}
|
||||
|
||||
private final float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
//private final float max(float a, float b) {
|
||||
//return (a > b) ? a : b;
|
||||
//}
|
||||
|
||||
private final float max(float a, float b, float c) {
|
||||
return Math.max(a, Math.max(b, c));
|
||||
}
|
||||
//private final float max(float a, float b, float c) {
|
||||
//return Math.max(a, Math.max(b, c));
|
||||
//}
|
||||
|
||||
private final float sq(float a) {
|
||||
return a*a;
|
||||
}
|
||||
//private final float sq(float a) {
|
||||
//return a*a;
|
||||
//}
|
||||
|
||||
private final float sqrt(float a) {
|
||||
return (float)Math.sqrt(a);
|
||||
}
|
||||
//private final float sqrt(float a) {
|
||||
//return (float)Math.sqrt(a);
|
||||
//}
|
||||
|
||||
private final float abs(float a) {
|
||||
return (a < 0) ? -a : a;
|
||||
}
|
||||
//private final float abs(float a) {
|
||||
//return (a < 0) ? -a : a;
|
||||
//}
|
||||
|
||||
private final float sin(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
//private final float sin(float angle) {
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//return (float)Math.sin(angle);
|
||||
//}
|
||||
|
||||
private final float cos(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
//private final float cos(float angle) {
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//return (float)Math.cos(angle);
|
||||
//}
|
||||
|
||||
private final float tan(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.tan(angle);
|
||||
}
|
||||
//private final float tan(float angle) {
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//return (float)Math.tan(angle);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
@@ -2537,5 +2548,24 @@ public class PGraphics extends PImage implements PConstants {
|
||||
|
||||
//class Shape extends Path {
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Cannot be used on PGraphics, use get(0, 0, width, height) first,
|
||||
* and then mask() the image that's returned. The problem is that the
|
||||
* results are too complicated across different implementations,
|
||||
* and this implementation represents only a minimal speedup versus
|
||||
* the amount of confusion it creates.
|
||||
*/
|
||||
public void mask(int alpha[]) {
|
||||
throw new RuntimeException("mask() cannot be used on PGraphics");
|
||||
}
|
||||
|
||||
|
||||
public void mask(PImage alpha) {
|
||||
throw new RuntimeException("mask() cannot be used on PGraphics");
|
||||
}
|
||||
}
|
||||
|
||||
+178
-228
@@ -24,12 +24,9 @@
|
||||
|
||||
package processing.core;
|
||||
|
||||
//import java.applet.*;
|
||||
import java.awt.*;
|
||||
//import java.awt.event.*;
|
||||
import java.awt.geom.*;
|
||||
import java.awt.image.*;
|
||||
//import java.io.*;
|
||||
|
||||
|
||||
// Graphics, GeneralPath, AffineTransform, BasicStroke, Graphics2D
|
||||
@@ -49,6 +46,11 @@ public class PGraphics2 extends PGraphics {
|
||||
Rectangle2D.Float rect = new Rectangle2D.Float();
|
||||
Arc2D.Float arc = new Arc2D.Float();
|
||||
|
||||
protected Color tintColorObject;
|
||||
protected Color fillColorObject;
|
||||
protected Color strokeColorObject;
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -333,15 +335,15 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// SHAPES
|
||||
|
||||
|
||||
/*
|
||||
protected void fill_shape(Shape s) {
|
||||
if (fill) {
|
||||
graphics.setColor(fillColorObject);
|
||||
graphics.fill(s);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
protected void stroke_shape(Shape s) {
|
||||
if (stroke) {
|
||||
@@ -362,9 +364,10 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void point(float x, float y) {
|
||||
//graphics.setColor(strokeColorObject);
|
||||
//graphics.drawLine(x1, y1, x2, y2);
|
||||
line(x, y, x, y);
|
||||
}
|
||||
|
||||
@@ -389,7 +392,24 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
public void rect(float x1, float y1, float x2, float y2) {
|
||||
public void quad(float x1, float y1, float x2, float y2,
|
||||
float x3, float y3, float x4, float y4) {
|
||||
GeneralPath gp = new GeneralPath();
|
||||
gp.moveTo(x1, y1);
|
||||
gp.lineTo(x2, y2);
|
||||
gp.lineTo(x3, y3);
|
||||
gp.lineTo(x4, y4);
|
||||
gp.closePath();
|
||||
|
||||
draw_shape(gp);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
protected void rectImpl(float x1, float y1, float x2, float y2) {
|
||||
/*
|
||||
switch (rectMode) {
|
||||
case CORNERS:
|
||||
rect.setFrameFromDiagonal(x1, y1, x2, y2);
|
||||
@@ -404,23 +424,13 @@ public class PGraphics2 extends PGraphics {
|
||||
rect.setFrame(x1 - x2/2.0f, y1 - y2/2.0f, x1 + x2/2.0f, y1 + y2/2.0f);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
rect.setFrame(x1, y1, x2-x1, y2-y1);
|
||||
draw_shape(rect);
|
||||
}
|
||||
|
||||
|
||||
public void quad(float x1, float y1, float x2, float y2,
|
||||
float x3, float y3, float x4, float y4) {
|
||||
GeneralPath gp = new GeneralPath();
|
||||
gp.moveTo(x1, y1);
|
||||
gp.lineTo(x2, y2);
|
||||
gp.lineTo(x3, y3);
|
||||
gp.lineTo(x4, y4);
|
||||
gp.closePath();
|
||||
|
||||
draw_shape(gp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void ellipse(float a, float b, float c, float d) {
|
||||
float x = a;
|
||||
float y = b;
|
||||
@@ -445,45 +455,22 @@ public class PGraphics2 extends PGraphics {
|
||||
ellipse.setFrame(x, y, w, h);
|
||||
draw_shape(ellipse);
|
||||
}
|
||||
|
||||
/*
|
||||
public void arc(float start, float stop,
|
||||
float x, float y, float radius) {
|
||||
arc(start, stop, x, y, radius, radius);
|
||||
}
|
||||
*/
|
||||
|
||||
protected void ellipseImpl(float x, float y, float w, float h) {
|
||||
ellipse.setFrame(x, y, w, h);
|
||||
draw_shape(ellipse);
|
||||
}
|
||||
|
||||
public void arc(float start, float stop,
|
||||
float a, float b, float c, float d) {
|
||||
float x = a;
|
||||
float y = b;
|
||||
float w = c;
|
||||
float h = d;
|
||||
|
||||
if (ellipseMode == CORNERS) {
|
||||
w = c - a;
|
||||
h = d - b;
|
||||
|
||||
} else if (ellipseMode == CENTER_RADIUS) {
|
||||
x = a - c;
|
||||
y = b - d;
|
||||
w = c * 2;
|
||||
h = d * 2;
|
||||
|
||||
} else if (ellipseMode == CENTER) {
|
||||
x = a - c/2f;
|
||||
y = b - d/2f;
|
||||
}
|
||||
|
||||
public void arcImpl(float start, float stop,
|
||||
float x, float y, float w, float h) {
|
||||
arc.setArc(x, y, w, h, start, stop-start, Arc2D.PIE);
|
||||
draw_shape(arc);
|
||||
}
|
||||
|
||||
|
||||
//public void circle(float x, float y, float radius) {
|
||||
//ellipse(x, y, radius, radius);
|
||||
//}
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void bezier(float x1, float y1,
|
||||
@@ -524,40 +511,10 @@ public class PGraphics2 extends PGraphics {
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// IMAGES
|
||||
|
||||
|
||||
protected void draw_image(PImage image,
|
||||
float x1, float y1, float x2, float y2,
|
||||
protected void imageImpl(PImage who,
|
||||
float x, float y, float w, float h,
|
||||
int u1, int v1, int u2, int v2) {
|
||||
graphics.drawImage((Image) image.cache,
|
||||
(int) x1, (int) y1, (int) x2, (int) y2,
|
||||
u1, v1, u2, v2, null);
|
||||
}
|
||||
|
||||
|
||||
public void image(PImage image, float x1, float y1) {
|
||||
check_image_cache(image);
|
||||
super.image(image, x1, y1);
|
||||
}
|
||||
|
||||
|
||||
public void image(PImage image,
|
||||
float a, float b, float c, float d) {
|
||||
check_image_cache(image);
|
||||
super.image(image, a, b, c, d);
|
||||
}
|
||||
|
||||
|
||||
public void image(PImage image,
|
||||
float a, float b, float c, float d,
|
||||
int u1, int v1, int u2, int v2) {
|
||||
check_image_cache(image);
|
||||
super.image(image, a, b, c, d, u1, v1, u2, v2);
|
||||
}
|
||||
|
||||
|
||||
protected void check_image_cache(PImage who) {
|
||||
if (who.cache == null) {
|
||||
who.cache = new BufferedImage(who.width, who.height,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -577,52 +534,19 @@ public class PGraphics2 extends PGraphics {
|
||||
who.width); // scan size
|
||||
who.pixelsUpdated();
|
||||
}
|
||||
|
||||
int x2 = (int) (x + w);
|
||||
int y2 = (int) (y + h);
|
||||
|
||||
graphics.drawImage((Image) who.cache,
|
||||
(int) x, (int) y, x2, y2,
|
||||
u1, v1, u2, v2, null);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/*
|
||||
public void textFont(PFont which);
|
||||
|
||||
public void textSize(float size);
|
||||
|
||||
public void textFont(PFont which, float size);
|
||||
|
||||
public void textLeading(float leading);
|
||||
|
||||
public void textMode(int mode);
|
||||
|
||||
public void textSpace(int space);
|
||||
|
||||
public void text(char c, float x, float y);
|
||||
|
||||
public void text(char c, float x, float y, float z);
|
||||
|
||||
public void text(String s, float x, float y);
|
||||
|
||||
public void text(String s, float x, float y, float z);
|
||||
|
||||
public void text(String s, float x, float y, float w, float h);
|
||||
|
||||
public void text(String s, float x1, float y1, float z, float x2, float y2);
|
||||
|
||||
public void text(int num, float x, float y);
|
||||
|
||||
public void text(int num, float x, float y, float z);
|
||||
|
||||
public void text(float num, float x, float y);
|
||||
|
||||
public void text(float num, float x, float y, float z);
|
||||
*/
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// MATRIX
|
||||
|
||||
|
||||
public void translate(float tx, float ty) {
|
||||
graphics.translate(tx, ty);
|
||||
}
|
||||
@@ -643,6 +567,9 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void push() {
|
||||
if (transformCount == transformStack.length) {
|
||||
throw new RuntimeException("push() cannot use push more than " +
|
||||
@@ -701,31 +628,48 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// STROKE
|
||||
|
||||
protected void calc_tint() {
|
||||
super.calc_tint();
|
||||
// TODO actually implement tinted images
|
||||
tintColorObject = new Color(tintColor);
|
||||
}
|
||||
|
||||
protected void calc_fill() {
|
||||
super.calc_fill();
|
||||
fillColorObject = new Color(fillColor);
|
||||
}
|
||||
|
||||
protected void calc_stroke() {
|
||||
super.calc_stroke();
|
||||
strokeColorObject = new Color(strokeColor);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void strokeWeight(float weight) {
|
||||
super.strokeWeight(weight);
|
||||
setStroke();
|
||||
set_stroke();
|
||||
}
|
||||
|
||||
|
||||
public void strokeJoin(int join) {
|
||||
super.strokeJoin(join);
|
||||
setStroke();
|
||||
set_stroke();
|
||||
}
|
||||
|
||||
|
||||
public void strokeCap(int cap) {
|
||||
super.strokeCap(cap);
|
||||
setStroke();
|
||||
set_stroke();
|
||||
}
|
||||
|
||||
|
||||
protected void setStroke() {
|
||||
protected void set_stroke() {
|
||||
int cap = BasicStroke.CAP_BUTT;
|
||||
if (strokeCap == ROUND) {
|
||||
cap = BasicStroke.CAP_ROUND;
|
||||
@@ -744,34 +688,8 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// STROKE/FILL/BACKGROUND
|
||||
|
||||
|
||||
protected Color tintColorObject;
|
||||
protected Color fillColorObject;
|
||||
protected Color strokeColorObject;
|
||||
|
||||
protected void calc_tint() {
|
||||
super.calc_tint();
|
||||
// TODO actually implement tinted images
|
||||
tintColorObject = new Color(tintColor);
|
||||
}
|
||||
|
||||
protected void calc_fill() {
|
||||
super.calc_fill();
|
||||
//graphics.setPaint(new Color(fillColor));
|
||||
fillColorObject = new Color(fillColor);
|
||||
}
|
||||
|
||||
protected void calc_stroke() {
|
||||
super.calc_stroke();
|
||||
///graphics.setStroke(new Color(fillColor));
|
||||
strokeColorObject = new Color(strokeColor);
|
||||
}
|
||||
|
||||
|
||||
public void background(PImage image) {
|
||||
if ((image.width != width) || (image.height != height)) {
|
||||
@@ -783,10 +701,10 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
// make sure it's been properly updated
|
||||
check_image_cache(image);
|
||||
|
||||
//check_image_cache(image);
|
||||
// blit image to the screen
|
||||
graphics.drawImage((BufferedImage) image.cache, 0, 0, null);
|
||||
//graphics.drawImage((BufferedImage) image.cache, 0, 0, null);
|
||||
imageImpl(image, 0, 0, width, height, 0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -809,23 +727,42 @@ public class PGraphics2 extends PGraphics {
|
||||
// FROM PIMAGE
|
||||
|
||||
|
||||
public void alpha(int alpha[]) {
|
||||
// does nothing in PGraphics
|
||||
public void smooth() {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
|
||||
public void alpha(PImage alpha) {
|
||||
// does nothing in PGraphics
|
||||
|
||||
public void noSmooth() {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
}
|
||||
|
||||
public void filter(int kind) {
|
||||
// TODO
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void loadPixels() {
|
||||
((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
|
||||
}
|
||||
|
||||
public void filter(int kind, float param) {
|
||||
// TODO
|
||||
|
||||
public void updatePixels() {
|
||||
updatePixels(0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
public void updatePixels(int x, int y, int c, int d) {
|
||||
((BufferedImage) image).setRGB(x, y,
|
||||
(imageMode == CORNER) ? c : (c - x),
|
||||
(imageMode == CORNER) ? d : (d - y),
|
||||
pixels, 0, width);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public int get(int x, int y) {
|
||||
return ((BufferedImage) image).getRGB(x, y);
|
||||
}
|
||||
@@ -838,59 +775,12 @@ public class PGraphics2 extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
public void set(int x, int y, int c) {
|
||||
((BufferedImage) image).setRGB(x, y, c);
|
||||
}
|
||||
|
||||
|
||||
public void copy(PImage src, int dx, int dy) {
|
||||
// TODO if this image is not ARGB or RGB, needs to behave differently
|
||||
// (if it's gray, need to copy gray pixels)
|
||||
// for alpha, just leave it be.. copy() doesn't composite
|
||||
((BufferedImage) image).setRGB(dx, dy, src.width, src.height,
|
||||
src.pixels, 0, src.width);
|
||||
}
|
||||
|
||||
|
||||
public void copy(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
public void copy(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
public void blend(PImage src, int sx, int sy, int dx, int dy, int mode) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
public void blend(int sx, int sy, int dx, int dy, int mode) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
public void blend(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
public void blend(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is used to both set the pixels[] array so that it can be
|
||||
* manipulated, and it also returns a PImage object that can be
|
||||
* messed with directly.
|
||||
*/
|
||||
/*
|
||||
public PImage get() {
|
||||
//PImage outgoing = new PImage(width, height);
|
||||
// int[] getRGB(int startX, int startY, int w, int h,
|
||||
@@ -901,23 +791,83 @@ public class PGraphics2 extends PGraphics {
|
||||
((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
|
||||
return new PImage(pixels, width, height, RGB);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void set(int x, int y, int argb) {
|
||||
((BufferedImage) image).setRGB(x, y, argb);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void filter(int kind) {
|
||||
loadPixels();
|
||||
super.filter(kind);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void filter(int kind, float param) {
|
||||
loadPixels();
|
||||
super.filter(kind, param);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void copy(PImage src, int dx, int dy) {
|
||||
loadPixels();
|
||||
super.copy(src, dx, dy);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void copy(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2) {
|
||||
loadPixels();
|
||||
super.copy(src, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void blend(PImage src, int sx, int sy, int dx, int dy, int mode) {
|
||||
loadPixels();
|
||||
super.blend(src, sx, sy, dx, dy, mode);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void blend(int sx, int sy, int dx, int dy, int mode) {
|
||||
loadPixels();
|
||||
super.blend(sx, sy, dx, dy, mode);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void blend(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode) {
|
||||
loadPixels();
|
||||
super.blend(sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, mode);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void blend(PImage src, int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode) {
|
||||
loadPixels();
|
||||
super.blend(src, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, mode);
|
||||
updatePixels();
|
||||
}
|
||||
|
||||
|
||||
public void save(String filename) {
|
||||
//static boolean write(RenderedImage im, String formatName, File output)
|
||||
// maybe use ImageIO.save(File file) here if it's available?
|
||||
get().save(filename);
|
||||
}
|
||||
loadPixels();
|
||||
super.save(filename);
|
||||
|
||||
|
||||
public void smooth() {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
|
||||
|
||||
public void noSmooth() {
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
//boolean ImageIO.write(RenderedImage im, String formatName, File output)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
// reset the cameraMode if PERSPECTIVE or ORTHOGRAPHIC
|
||||
// will just be ignored if CUSTOM, the user's hosed anyways
|
||||
//if (depth) cameraMode(this.cameraMode);
|
||||
cameraMode(this.cameraMode);
|
||||
}
|
||||
|
||||
|
||||
@@ -923,6 +923,8 @@ public class PGraphics3 extends PGraphics {
|
||||
}
|
||||
|
||||
protected void render_triangles() {
|
||||
//public void render_triangles() {
|
||||
//System.out.println("PGraphics3 render triangles");
|
||||
for (int i = 0; i < triangleCount; i ++) {
|
||||
float a[] = vertices[triangles[i][VERTEX1]];
|
||||
float b[] = vertices[triangles[i][VERTEX2]];
|
||||
|
||||
@@ -295,6 +295,14 @@ public class PImage implements PConstants, Cloneable {
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* For subclasses where the pixels[] buffer isn't set by default,
|
||||
* this should copy all data into the pixels[] array
|
||||
*/
|
||||
public void loadPixels() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark all pixels as needing update.
|
||||
*/
|
||||
@@ -405,6 +413,7 @@ public class PImage implements PConstants, Cloneable {
|
||||
* Convenience method to avoid an extra cast,
|
||||
* and the exception handling.
|
||||
*/
|
||||
/*
|
||||
public PImage get() {
|
||||
try {
|
||||
return (PImage) clone();
|
||||
@@ -412,6 +421,7 @@ public class PImage implements PConstants, Cloneable {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public void set(int x, int y, int c) {
|
||||
|
||||
+117
-82
@@ -6,83 +6,6 @@ package processing.core;
|
||||
|
||||
public interface PMethods {
|
||||
|
||||
public void imageMode(int mode);
|
||||
|
||||
public void smooth();
|
||||
|
||||
public void noSmooth();
|
||||
|
||||
//
|
||||
|
||||
public void modified();
|
||||
|
||||
public void modified(int x, int y);
|
||||
|
||||
public void modified(int x1, int y1, int x2, int y2);
|
||||
|
||||
public void resetModified(); // <<<<< MORE CONSISTENT NAME NEEDED
|
||||
|
||||
//
|
||||
|
||||
public int get(int x, int y);
|
||||
|
||||
public PImage get(int x, int y, int w, int h);
|
||||
|
||||
public PImage get();
|
||||
|
||||
public void set(int x, int y, int c);
|
||||
|
||||
//
|
||||
|
||||
public void alpha(int alpha[]);
|
||||
|
||||
public void alpha(PImage alpha);
|
||||
|
||||
public void filter(int kind);
|
||||
|
||||
public void filter(int kind, float param);
|
||||
|
||||
public void copy(PImage src, int dx, int dy);
|
||||
|
||||
public void copy(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2);
|
||||
|
||||
public void copy(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2);
|
||||
|
||||
public void blend(int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(PImage src,
|
||||
int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode);
|
||||
|
||||
public void blend(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode);
|
||||
|
||||
//
|
||||
|
||||
/*
|
||||
// WOULD LIKE A NICER NAME
|
||||
static public boolean saveHeaderTIF(OutputStream output,
|
||||
int width, int height);
|
||||
|
||||
static public boolean saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height);
|
||||
|
||||
// WOULD LIKE A NICER NAME
|
||||
static public boolean saveHeaderTGA(OutputStream output,
|
||||
int width, int height);
|
||||
|
||||
static public boolean saveTGA(OutputStream output, int pixels[],
|
||||
int width, int height);
|
||||
*/
|
||||
|
||||
public void save(String filename);
|
||||
|
||||
//
|
||||
|
||||
public void beginFrame();
|
||||
@@ -149,7 +72,7 @@ public interface PMethods {
|
||||
|
||||
public void rect(float x1, float y1, float x2, float y2);
|
||||
|
||||
//protected void draw_rect(float x1, float y1, float x2, float y2);
|
||||
//protected void rectImpl(float x1, float y1, float x2, float y2);
|
||||
|
||||
// REMOVED public void circle(float x, float y, float radius);
|
||||
|
||||
@@ -157,7 +80,7 @@ public interface PMethods {
|
||||
|
||||
public void ellipse(float x, float y, float hradius, float vradius);
|
||||
|
||||
//protected void draw_ellipse(float x, float y, float hradius, float vradius);
|
||||
//protected void ellipseImpl(float x, float y, float hradius, float vradius);
|
||||
|
||||
// REMOVED public void arcMode(int mode);
|
||||
|
||||
@@ -167,7 +90,7 @@ public interface PMethods {
|
||||
public void arc(float start, float stop,
|
||||
float x, float y, float hr, float vr);
|
||||
|
||||
//protected void draw_arc(float start, float stop,
|
||||
//protected void arcImpl(float start, float stop,
|
||||
// float x, float y, float hr, float vr);
|
||||
|
||||
//
|
||||
@@ -294,6 +217,8 @@ public interface PMethods {
|
||||
|
||||
public void scale(float x, float y, float z);
|
||||
|
||||
//
|
||||
|
||||
public void push();
|
||||
|
||||
public void pop();
|
||||
@@ -438,6 +363,116 @@ public interface PMethods {
|
||||
|
||||
//
|
||||
|
||||
// color(), alpha(), red(), green(), blue(),
|
||||
// hue(), saturation(), brightness()
|
||||
//public final int color(int gray)
|
||||
|
||||
//public final int color(float gray)
|
||||
|
||||
//public final int color(int gray, int alpha)
|
||||
|
||||
//public final int color(float gray, float alpha)
|
||||
|
||||
//public final int color(int x, int y, int z)
|
||||
|
||||
//public final int color(float x, float y, float z)
|
||||
|
||||
//public final int color(int x, int y, int z, int a)
|
||||
|
||||
//public final int color(float x, float y, float z, float a)
|
||||
|
||||
//public final float alpha(int what)
|
||||
|
||||
//public final float red(int what)
|
||||
|
||||
//public final float green(int what)
|
||||
|
||||
//public final float blue(int what)
|
||||
|
||||
//public final float hue(int what)
|
||||
|
||||
//public final float saturation(int what)
|
||||
|
||||
//public final float brightness(int what)
|
||||
|
||||
//
|
||||
|
||||
|
||||
public void imageMode(int mode);
|
||||
|
||||
public void smooth();
|
||||
|
||||
public void noSmooth();
|
||||
|
||||
//
|
||||
|
||||
public void loadPixels();
|
||||
|
||||
public void updatePixels();
|
||||
|
||||
public void updatePixels(int x, int y, int c, int d);
|
||||
|
||||
public void pixelsUpdated();
|
||||
|
||||
//
|
||||
|
||||
public int get(int x, int y);
|
||||
|
||||
public PImage get(int x, int y, int c, int d);
|
||||
|
||||
//public PImage get(); // too abstract/confusing
|
||||
|
||||
public void set(int x, int y, int argb);
|
||||
|
||||
//
|
||||
|
||||
public void mask(int alpha[]);
|
||||
|
||||
public void mask(PImage alpha);
|
||||
|
||||
public void filter(int kind);
|
||||
|
||||
public void filter(int kind, float param);
|
||||
|
||||
//
|
||||
|
||||
public void copy(PImage src, int dx, int dy);
|
||||
|
||||
public void copy(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2);
|
||||
|
||||
public void copy(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2);
|
||||
|
||||
public void blend(int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(PImage src,
|
||||
int sx, int sy, int dx, int dy, int mode);
|
||||
|
||||
public void blend(int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode);
|
||||
|
||||
public void blend(PImage src,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
int dx1, int dy1, int dx2, int dy2, int mode);
|
||||
|
||||
//
|
||||
|
||||
/*
|
||||
// WOULD LIKE A NICER NAME
|
||||
static public boolean saveHeaderTIF(OutputStream output,
|
||||
int width, int height);
|
||||
|
||||
static public boolean saveTIF(OutputStream output, int pixels[],
|
||||
int width, int height);
|
||||
|
||||
// WOULD LIKE A NICER NAME
|
||||
static public boolean saveHeaderTGA(OutputStream output,
|
||||
int width, int height);
|
||||
|
||||
static public boolean saveTGA(OutputStream output, int pixels[],
|
||||
int width, int height);
|
||||
*/
|
||||
|
||||
public void save(String filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ X arcMode is gone.. just uses ellipseMode()
|
||||
X save tga and tif methods are static and public
|
||||
X imageMode(CORNER) and CORNERS are the only usable versions
|
||||
|
||||
_ alpha(PImage) is now called mask() instead?
|
||||
_ already have an alpha() function that gets alpha bits
|
||||
_ sphere x,y,z,r or box w,h,d.. need to make them consistent
|
||||
|
||||
_ the updatePixels() in PGraphics has to be overridden (from PImage)
|
||||
|
||||
Reference in New Issue
Block a user