mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
implement imageMode(CENTER)
This commit is contained in:
@@ -1386,6 +1386,11 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh,
|
||||
PImage src) {
|
||||
if (imageMode == CENTER) {
|
||||
dx -= src.width/2; // not sw, since it's already cropped
|
||||
dy -= src.height/2;
|
||||
}
|
||||
|
||||
WritableRaster raster = ((BufferedImage) image).getRaster();
|
||||
if ((sx == 0) && (sy == 0) && (sw == src.width) && (sh == src.height)) {
|
||||
raster.setDataElements(dx, dy, src.width, src.height, src.pixels);
|
||||
|
||||
@@ -400,6 +400,10 @@ public class PImage implements PConstants, Cloneable {
|
||||
int sw = src.width;
|
||||
int sh = src.height;
|
||||
|
||||
if (imageMode == CENTER) {
|
||||
dx -= src.width/2;
|
||||
dy -= src.height/2;
|
||||
}
|
||||
if (dx < 0) { // off left edge
|
||||
sx -= dx;
|
||||
sw += dx;
|
||||
|
||||
@@ -7,6 +7,7 @@ o write up examples for these instead?
|
||||
o start an integration section?
|
||||
X get() in java2d not honoring imageMode or rectMode
|
||||
X add imageMode(CENTER) implementation
|
||||
X add a bunch of changes to the reference to support this
|
||||
|
||||
cleanup
|
||||
X switch to requestImage() (done in 0145)
|
||||
|
||||
@@ -2457,6 +2457,10 @@ public class PGraphicsOpenGL extends PGraphics3D {
|
||||
* vertically. Both have their components all swapped to native.
|
||||
*/
|
||||
public void set(int x, int y, PImage source) {
|
||||
if (imageMode == CENTER) {
|
||||
x -= source.width / 2;
|
||||
y -= source.height / 2;
|
||||
}
|
||||
int backup[] = new int[source.pixels.length];
|
||||
System.arraycopy(source.pixels, 0, backup, 0, source.pixels.length);
|
||||
javaToNativeARGB(source);
|
||||
|
||||
Reference in New Issue
Block a user