/*
* if ((renderMode & MODE_TILE) != 0) { throw new
* InterruptedException("unable to paint with the tile mode enabled"); }
*/
if (!renderableImpl.isJava2DModeEnabled()) {
throw new JXAException("unable to paint if the Java2D mode is disabled");
}
if (!SwingUtilities.isEventDispatchThread()) {
System.err.println(JXAenvUtils.log("painting outside EDT !", JXAenvUtils.LVL.APP_WRN));
}
renderableImpl.io.obs = pobs;
Throwable interrupt_ = null;
boolean complete = true;
Sprite clone = null;
fx &= ~GLFX.bits._getAllBitRanges();
/*
* if (renderableImpl.isTileModeEnabled()) { if (isDebugEnabled()) {
* System.err.println(toString() + " : tile mode disables fx in java2d
* render mode !"); } fx = gfx.FX_NONE; }
*/
if (fx != gfx.FX_NONE) {
clone = (Sprite) clone();
}
final Monitor monitor = renderableImpl.validateMonitor;
synchronized (monitor) {
while (validating) {
if (DebugMap._getInstance().isDebugLevelEnabled(gfx.DBUG)) {
DebugMap._getInstance().tickPrintln(System.out, "validating " + toString() + " sprite's waiting for...", false);
}
monitor.wait(1000);
}
if (!valid) {
if (isDebugEnabled()) {
System.err.println("." + (!valid ? "!INVALID!" : ""));
}
return false;
}
painting = true;
final Monitor monitor1 = renderableImpl.imageSynch;
synchronized (monitor1) {
Shape backgroundClip = g2.getClip();
try {
waitFor(data);
if (data == null && !renderableImpl.isTileModeEnabled() || tileSrc == null && renderableImpl.isTileModeEnabled()) {
throw new JXAException("Sprite " + toString() + " has no data to draw ! try (re)validate().");
} else {
if (DebugMap._getInstance().isDebugLevelEnabled(gfx.DBUG)) {
DebugMap._getInstance().tickPrintln(System.out, ">>>>>> Java2D draw image size : " + renderableImpl.bounds.getWidth() + "x" + renderableImpl.bounds.getHeight() + " on clip : " + g2.getClipBounds() + " <<<<<< " + toString(), false);
}
}
AffineTransform baseTx = new AffineTransform();
if (tx != null) {
baseTx.concatenate(tx);
}
PerspectiveTransform basePtx = new PerspectiveTransform();
if (ptx != null) {
basePtx.concatenate(ptx);
}
if (_paintStatus) {
g2.drawString("sprite v", (int) renderableImpl.bounds.getX(), (int) renderableImpl.bounds.getY());
}
if (baseTx.getScaleX() == 0.0 || baseTx.getScaleY() == 0.0 || baseTx.getDeterminant() == 0.0) {
if (DebugMap._getInstance().isDebugLevelEnabled(gfx.DBUG)) {
DebugMap._getInstance().tickPrintln(System.out, "transform " + toString() + " contains Zero, so is avoided. TX=" + baseTx, true);
}
throw new JXAException(toString() + " transform failed! " + baseTx);
}
if (!renderableImpl.isTileModeEnabled()) {
if (data.getWidth(renderableImpl.io.obs) <= 0 || data.getHeight(renderableImpl.io.obs) <= 0) {
throw new JXAException(toString() + " image data size was not available!");
}
}
if (!basePtx.isIdentity()) {
basePtx.preConcatenate(baseTx.createInverse());
double[] perspectiveTransform = new double[]{0, 0, renderableImpl.bounds.getWidth(), 0, renderableImpl.bounds.getWidth(), renderableImpl.bounds.getHeight(), 0, renderableImpl.bounds.getHeight()};
basePtx.inverseTransform(perspectiveTransform, 0, perspectiveTransform, 0, 4);
Polygon perspectiveTransformPoly = new Polygon();
for (int i = 0; i < perspectiveTransform.length; i += 2) {
perspectiveTransformPoly.addPoint((int) perspectiveTransform[i], (int) perspectiveTransform[i + 1]);
}
if (DebugMap._getInstance().isDebugLevelEnabled(gfx.DBUG)) {
DebugMap._getInstance().tickPrintln(System.out, "Warped area : " + perspectiveTransformPoly.getBounds(), false);
}
g2.translate(getLocation().x, getLocation().y);
g2.clip(perspectiveTransformPoly);
if (isDebugEnabled()) {
g2.draw(perspectiveTransformPoly);
}
g2.translate(-getLocation().x, -getLocation().y);
} else if (!baseTx.isIdentity() && basePtx.isIdentity()) {
Rectangle transform = baseTx.createTransformedShape(new Rectangle(renderableImpl.bounds.getSize())).getBounds();
if (DebugMap._getInstance().isDebugLevelEnabled(gfx.DBUG)) {
DebugMap._getInstance().tickPrintln(System.out, "TXShape : " + transform, false);
}
if (transform.getSize().height <= 1 || transform.getSize().width <= 1) {
throw new JXAException(toString() + " transform failed! " + transform);
}
g2.translate(getLocation().x, getLocation().y);
g2.clip(transform);
if (isDebugEnabled()) {
g2.draw(transform);
}
g2.translate(-getLocation().x, -getLocation().y);
} else {
g2.clip(renderableImpl.bounds);
}
if (isDebugEnabled()) {
g2.draw(renderableImpl.bounds);
}
AffineTransform fx_tx = new AffineTransform();
AffineTransform fx_tx_mirror = new AffineTransform();
long now = System.currentTimeMillis();
if (DebugMap._getInstance().isDebugLevelEnabled(gfx.DBUG)) {
DebugMap._getInstance().tickPrint(System.out, "FX : ", false);
for (gfx select : gfx.values()) {
if ((select.bit() & fx) != 0) {
DebugMap._getInstance().tickPrint(System.out, " " + select, false);
}
}
DebugMap._getInstance().tickPrintln(System.out, ".", false);
}
/**
* START SCROLLLING
*/
if ((fx & gfx.FX_SCROLLING.bit()) != 0) {
if (!(Sprite.fx.FX_lastTransformScrolling.get(hashCode()) instanceof AffineTransform)) {
Sprite.fx.FX_lastTransformScrolling.put(hashCode(), new AffineTransform());
}
if (!(Sprite.fx.FX_lastTransformTime.get(hashCode()) instanceof Long)) {
Sprite.fx.FX_lastTransformTime.put(hashCode(), now);
}
double translateH, translateV;
translateH = (fx & gfx.FX_HORIZONTAL.bit()) != 0 ? Sprite.fx.FX_overallSPEED * (now - Sprite.fx.FX_lastTransformTime.get(hashCode())) : 0f;
translateV = (fx & gfx.FX_VERTICAL.bit()) != 0 ? Sprite.fx.FX_overallSPEED * (now - Sprite.fx.FX_lastTransformTime.get(hashCode())) : 0f;
Sprite.fx.FX_lastTransformScrolling.get(hashCode()).setToTranslation(-((Math.abs(Sprite.fx.FX_lastTransformScrolling.get(hashCode()).getTranslateX()) + translateH) % renderableImpl.bounds.width), -((Math.abs(Sprite.fx.FX_lastTransformScrolling.get(hashCode()).getTranslateY()) + translateV) % renderableImpl.bounds.height));
fx_tx.preConcatenate(Sprite.fx.FX_lastTransformScrolling.get(hashCode()));
double mX = 1, mY = 1;
if ((fx & gfx.FX_REFLEXION.bit()) != 0) {
if ((fx & (gfx.FX_RIGHT.bit() | gfx.FX_LEFT.bit())) != 0) {
mX = -1;
}
if ((fx & (gfx.FX_TOP.bit() | gfx.FX_BOTTOM.bit())) != 0) {
mY = -1;
}
}
fx_tx_mirror.preConcatenate(AffineTransform.getTranslateInstance(mX * fx_tx.getTranslateX(), mY * fx_tx.getTranslateY()));
Sprite.fx.FX_lastTransformTime.put(hashCode(), now);
}
/**
* END SCROLLLING
*/
/**
* START ROTQTION
*/
if ((fx & gfx.FX_ROTATION.bit()) != 0) {
if (!(Sprite.fx.FX_lastTransformTime.get(hashCode()) instanceof Long)) {
Sprite.fx.FX_lastTransformTime.put(hashCode(), now);
}
float lastTransformTheta = Sprite.fx.FX_lastTransformTheta.containsKey(hashCode()) ? Sprite.fx.FX_lastTransformTheta.get(hashCode()) : (1f - 1f / 360f) * 2f * (float) Math.PI;
float rotationSpeed = Sprite.fx.FX_overallRADIALSPEED * 360f / (2f * (float) Math.PI);
if ((fx - (fx & (GLFX.bits._getAllBits() | GLFX.bits._getAllBitRanges()))) != 0) {
rotationSpeed = fx - (fx & (GLFX.bits._getAllBits() | GLFX.bits._getAllBitRanges()));
rotationSpeed /= 1000f;
}
lastTransformTheta -= (float) (now - Sprite.fx.FX_lastTransformTime.get(hashCode())) * rotationSpeed;
lastTransformTheta = lastTransformTheta % (2f * (float) Math.PI);
fx_tx.preConcatenate(AffineTransform.getRotateInstance(lastTransformTheta, (float) renderableImpl.bounds.width / 2f, (float) renderableImpl.bounds.height / 2f));
fx_tx_mirror.preConcatenate(AffineTransform.getRotateInstance(-lastTransformTheta, (float) renderableImpl.bounds.width / 2f, (float) renderableImpl.bounds.height / 2f));
Sprite.fx.FX_lastTransformTheta.put(hashCode(), lastTransformTheta);
Sprite.fx.FX_lastTransformTime.put(hashCode(), now);
}
/**
* END ROTQTION
*/
/**
* START RELEXION + SHADOW
*/
if ((fx & (gfx.FX_REFLEXION.bit() | gfx.FX_SHADOW.bit())) != 0) {
Sprite shadow = clone;
if (shadow == null) {
throw new JXAException("clone failed to recover data");
}
shadow.setCompositeEnabled(true);
shadow.setTX(fx_tx);
if ((fx & gfx.FX_REFLEXION.bit()) != 0 && (fx & (gfx.FX_TOP.bit() | gfx.FX_BOTTOM.bit() | gfx.FX_LEFT.bit() | gfx.FX_RIGHT.bit())) != 0) {
shadow.setTX(fx_tx_mirror);
if ((fx & (gfx.FX_TOP.bit() | gfx.FX_BOTTOM.bit())) != 0) {
shadow.setFlipEnabled(true, Sprite.VERTICAL);
}
if ((fx & (gfx.FX_LEFT.bit() | gfx.FX_RIGHT.bit())) != 0) {
shadow.setFlipEnabled(true, Sprite.HORIZONTAL);
}
Point endPoint = new Point(0, 0);
Point startPoint = new Point(0, 0);
if ((fx & gfx.FX_TOP.bit()) != 0) {
startPoint = new Point(0, (int) ((float) renderableImpl.bounds.height * .66f));
endPoint = new Point(0, 0);
}
if ((fx & gfx.FX_BOTTOM.bit()) != 0) {
startPoint = new Point(0, 0);
endPoint = new Point(0, (int) ((float) renderableImpl.bounds.height * .66f));
}
if ((fx & gfx.FX_LEFT.bit()) != 0) {
startPoint = new Point(0, 0);
endPoint = new Point((int) ((float) renderableImpl.bounds.width * .66f), 0);
}
if ((fx & gfx.FX_RIGHT.bit()) != 0) {
startPoint = new Point((int) ((float) renderableImpl.bounds.width * .66f), 0);
endPoint = new Point(0, 0);
}
if (!(FX_gradients.get(hashCode()) instanceof GradientPaint)) {
FX_gradients.put(hashCode(), new GradientPaint(startPoint.x, startPoint.y, new Color(1.0f, 1.0f, 1.0f, 1.0f), endPoint.x, endPoint.y, new Color(1.0f, 1.0f, 1.0f, 0.0f), false));
} else if (FX_gradients.get(hashCode()).getPoint2().distance(FX_gradients.get(hashCode()).getPoint1()) != startPoint.distance(endPoint)) {
FX_gradients.put(hashCode(), new GradientPaint(startPoint.x, startPoint.y, new Color(1.0f, 1.0f, 1.0f, 1.0f), endPoint.x, endPoint.y, new Color(1.0f, 1.0f, 1.0f, 0.0f), false));
}
Paint shadow_gradient = FX_gradients.get(hashCode());
shadow.setPaint(shadow_gradient);
shadow.setComposite(AlphaComposite.DstIn);
if (fx_color != null) {
shadow.runValidate();
shadow.setFlipEnabled(false, NONE);
shadow.setComposited(false);
shadow.setPaint(null);
shadow.setComposite(AlphaComposite.SrcAtop);
shadow.setColor(fx_color);
}
} else {
shadow.setColor(fx_color);
shadow.setComposite(AlphaComposite.SrcIn);
}
shadow.runValidate();
Shape clip = g2.getClip();
g2.setClip(backgroundClip);
if ((fx & gfx.FX_BACKGROUND.bit()) != 0 && (fx & gfx.FX_REPEAT.bit()) != 0) {
for (int j = -1; j < Math.ceil((float) backgroundClip.getBounds().getHeight() / (float) renderableImpl.bounds.height); j++) {
for (int i = -1; i < Math.ceil((float) backgroundClip.getBounds().getWidth() / (float) renderableImpl.bounds.width); i++) {
int mh = (fx & gfx.FX_REFLEXION.bit()) != 0 && (fx & gfx.FX_BOTTOM.bit()) != 0 ? 2 : 1;
mh = (fx & gfx.FX_REFLEXION.bit()) != 0 && (fx & gfx.FX_TOP.bit()) != 0 ? -1 : mh;
int mw = (fx & gfx.FX_REFLEXION.bit()) != 0 && (fx & gfx.FX_RIGHT.bit()) != 0 ? 2 : 1;
mw = (fx & gfx.FX_REFLEXION.bit()) != 0 && (fx & gfx.FX_LEFT.bit()) != 0 ? -1 : mw;
shadow.setLocation((int) backgroundClip.getBounds().getX() + ((fx & gfx.FX_HORIZONTAL.bit()) != 0 ? i : 0) * mw * renderableImpl.bounds.width, (int) backgroundClip.getBounds().getY() + ((fx & gfx.FX_VERTICAL.bit()) != 0 ? j : 0) * mh * renderableImpl.bounds.height);
shadow.setLocation(shadow.getLocation().x + fx_loc.x, shadow.getLocation().y + fx_loc.y);
complete = shadow.draw(renderableImpl.io.obs, g2) && complete;
if ((fx & gfx.FX_HORIZONTAL.bit()) == 0) {
break;
}
}
if ((fx & gfx.FX_VERTICAL.bit()) == 0) {
break;
}
}
} else {
if ((fx & gfx.FX_REFLEXION.bit()) != 0) {
if ((fx & gfx.FX_BOTTOM.bit()) != 0) {
shadow.setLocation((int) renderableImpl.bounds.getX(), (int) renderableImpl.bounds.getMaxY());
}
if ((fx & gfx.FX_TOP.bit()) != 0) {
shadow.setLocation((int) renderableImpl.bounds.getX(), (int) (renderableImpl.bounds.getY() - renderableImpl.bounds.getHeight()));
}
if ((fx & gfx.FX_LEFT.bit()) != 0) {
shadow.setLocation((int) (renderableImpl.bounds.getX() - renderableImpl.bounds.getWidth()), (int) renderableImpl.bounds.getY());
}
if ((fx & gfx.FX_RIGHT.bit()) != 0) {
shadow.setLocation((int) renderableImpl.bounds.getMaxX(), (int) renderableImpl.bounds.getY());
}
}
shadow.setLocation(shadow.getLocation().x + fx_loc.x, shadow.getLocation().y + fx_loc.y);
shadow.draw(renderableImpl.io.obs, g2);
}
g2.setClip(clip);
}
/**
* END RELEXION + SHADOW
*/
/**
* START BACKGROUND + REPEAT
*/
if ((fx & gfx.FX_BACKGROUND.bit()) != 0 && (fx & gfx.FX_REPEAT.bit()) != 0) {
g2.setClip(backgroundClip);
for (int j = -1; j < Math.ceil((float) backgroundClip.getBounds().getHeight() / (float) renderableImpl.bounds.height); j++) {
for (int i = -1; i < Math.ceil((float) backgroundClip.getBounds().getWidth() / (float) renderableImpl.bounds.width); i++) {
setLocation((int) backgroundClip.getBounds().getX() + ((fx & gfx.FX_HORIZONTAL.bit()) != 0 ? i : 0) * renderableImpl.bounds.width, (int) backgroundClip.getBounds().getY() + ((fx & gfx.FX_VERTICAL.bit()) != 0 ? j : 0) * renderableImpl.bounds.height);
Point loc = getLocation();
/*
* setLocation(loc.x + fx_loc.x, loc.y +
* fx_loc.y);
*/
if ((fx & gfx.FX_SCROLLING.bit()) != 0 && (fx & gfx.FX_REPEAT.bit()) != 0) {
setLocation(getLocation().x + renderableImpl.bounds.width, getLocation().y + renderableImpl.bounds.height);
if ((fx & gfx.FX_HORIZONTAL.bit()) != 0 && (fx & gfx.FX_VERTICAL.bit()) != 0) {
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
setLocation(getLocation().x - renderableImpl.bounds.width, getLocation().y);
if ((fx & gfx.FX_VERTICAL.bit()) != 0) {
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
setLocation(getLocation().x + renderableImpl.bounds.width, getLocation().y - renderableImpl.bounds.height);
if ((fx & gfx.FX_HORIZONTAL.bit()) != 0) {
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
}
setLocation(loc);
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
setLocation(
renderableImpl.bounds.getBounds().getLocation());
if ((fx & gfx.FX_HORIZONTAL.bit()) == 0) {
break;
}
}
if ((fx & gfx.FX_VERTICAL.bit()) == 0) {
break;
}
}
} else {
/**
* END BACKGROUND + REPEAT
*/
/**
* START SCROLLING + REPEAT
*/
if ((fx & gfx.FX_SCROLLING.bit()) != 0 && (fx & gfx.FX_REPEAT.bit()) != 0) {
Point loc = getLocation();
setLocation(
getLocation().x + renderableImpl.bounds.width, getLocation().y + renderableImpl.bounds.height);
if ((fx & gfx.FX_HORIZONTAL.bit()) != 0 && (fx & gfx.FX_VERTICAL.bit()) != 0) {
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
setLocation(getLocation().x - renderableImpl.bounds.width, getLocation().y);
if ((fx & gfx.FX_VERTICAL.bit()) != 0) {
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
setLocation(getLocation().x + renderableImpl.bounds.width, getLocation().y - renderableImpl.bounds.height);
if ((fx & gfx.FX_HORIZONTAL.bit()) != 0) {
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
setLocation(loc);
}
/**
* END SCROLLING + REPEAT
*/
complete = __draw0(renderableImpl.io.obs, g2, baseTx, basePtx, fx_tx) && complete;
}
} catch (Exception e) {
if (isDebugEnabled()) {
e.printStackTrace();
}
interrupt_ = e;
} finally {
g2.setClip(backgroundClip);
if (fx != gfx.FX_NONE) {
if (clone instanceof Sprite) {
clone.clearResource();
}
}
if (isHardwareAccel()) {
clearResource(); /*
* free video memory
*/
}
painting = false;
monitor1.notifyAll();
}
}
}
if (interrupt_ instanceof Throwable) {
JXAException e = new JXAException("Sprite " + toString() + " caught an interruption.", interrupt_);
throw e;
}
return complete;
}