This a sample of the RenderingScene class of the JIGAXtended API; it provides support for at least 2 graphics FX that can be combined together by using a bitwise-inclusive-OR combination :
/** angular speed rad/msec for the PerspectiveTransform effect */
public static float perspective_ANGULARSPEED = (float) Math.PI / (24f * 1000f);
/** map for the last transform angular values */
private static Map<String, Float> lastTransformTheta = Collections.synchronizedMap(new HashMap<String, Float>());
/** map for the last transform timestamps */
private static Map<String, Long> lastTransformTime = Collections.synchronizedMap(new HashMap<String, Long>());
/** map for the reflexion fx*/
private static Map<String, GradientPaint> gradients = Collections.synchronizedMap(new HashMap<String, GradientPaint>());
/** reflexion fx on the bottom side */
public final static int FX_DOWNREFLEXION = 4;
/** the rotation FX*/
public final static int FX_ROTATION = 2;
/** the no fx */
public final static int FX_NONE = 1;
/** draws a logo caught with getLogo() using a specific layout position. a rotation effect can be added
@param g2 te Graphics2D isntance where to draw onto
@param logo the file name of the logo to draw
@param size the size at which to draw the logo
@param hpos the horizontal position
@param vpos the vertical postion
@param fx dis/enables the selected FX (a bitwise-inclusive-OR combination of FX)
* @param c the Component to draw onto
* @see #FX_NONE
* @see #FX_ROTATION
* @see #FX_DOWNREFLEXION
1 @see #getLogo(String, Dimension)
@see GUIConsoleOutput#LEFT
@see GUIConsoleOutput#CENTER
@see GUIConsoleOutput#RIGHT
@see GUIConsoleOutput#TOP
@see GUIConsoleOutput#BOTTOM*/
public static void _drawLogo(Component c, Graphics2D g2, String logo, Dimension size, int hpos, int vpos, int fx) throws InterruptedException {
Sprite logo_sp = _getLogo(c, logo, size);
GraphicsJAI g = Sprite.createGraphicsJAI(g2, c);
g.setRenderingHints(Sprite._getRenderingHints());
// screen postioning
Point translate = new Point(0, 0);
Insets insets = new Insets(10, 10, 10, 10);
switch (hpos) {
case GUIConsoleOutput.LEFT:
translate.x = insets.left;
break;
case GUIConsoleOutput.CENTER:
translate.x = (int) ((float) c.getWidth() / 2.0f - (float) size.width / 2.0f);
break;
case GUIConsoleOutput.RIGHT:
translate.x = -insets.right + (int) (c.getWidth() - size.width);
break;
default:
break;
}
switch (vpos) {
case GUIConsoleOutput.TOP:
translate.y = insets.top;
break;
case GUIConsoleOutput.CENTER:
translate.y = (int) ((float) c.getHeight() / 2.0f - (float) size.height / 2.0f);
break;
case GUIConsoleOutput.BOTTOM:
translate.y = -insets.bottom + (int) (c.getHeight() - size.height);
break;
default:
break;
}
AffineTransform tx = null;
AffineTransform tx2 = null;
System.err.println("FX " + logo + " fx & rotation = " + (fx & FX_ROTATION) + " fx & reflexion = " + (fx & FX_DOWNREFLEXION));
if ((fx & FX_ROTATION) != 0) {
long now = System.currentTimeMillis();
if (!(lastTransformTime.get(logo) instanceof Long)) {
lastTransformTime.put(logo, now);
}
float lastTransformTheta = RenderingScene.lastTransformTheta.containsKey(logo) ? RenderingScene.lastTransformTheta.get(logo) : (1f - 1f / 360f) * 2f * (float) Math.PI;
lastTransformTheta -= (float) (now - lastTransformTime.get(logo)) * perspective_ANGULARSPEED;
lastTransformTheta = lastTransformTheta % (2f * (float) Math.PI);
tx = AffineTransform.getRotateInstance(lastTransformTheta, (float) size.width / 2f, (float) size.height / 2f);
tx2 = (fx & FX_DOWNREFLEXION) != 0 ? AffineTransform.getRotateInstance(-lastTransformTheta, (float) size.width / 2f, (float) size.height / 2f) : tx;
RenderingScene.lastTransformTheta.put(logo, lastTransformTheta);
lastTransformTime.put(logo, now);
}
if ((fx & FX_DOWNREFLEXION) != 0) {
Sprite shadow = (Sprite) logo_sp.clone();
if (shadow == null) {
return;
}
shadow.setTX(tx2);
shadow.setFlipEnabled(true, Sprite.VERTICAL);
shadow.setCompositeEnabled(true);
if (!(gradients.get(logo) instanceof GradientPaint)) {
gradients.put(logo, new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f), 0, (float) size.height * 0.66f, new Color(1.0f, 1.0f, 1.0f, 0.0f), false));
} else if (gradients.get(logo).getPoint2().distance(gradients.get(logo).getPoint1()) != (float) size.height * 0.66f) {
gradients.put(logo, new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f), 0, (float) size.height * 0.66f, new Color(1.0f, 1.0f, 1.0f, 0.0f), false));
}
Paint shadow_gradient = gradients.get(logo);
shadow.setPaint(shadow_gradient);
shadow.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, 1.0f));
shadow.validate();
g.translate(translate.x, translate.y + size.height);
shadow.draw(c, g);
g.translate(-translate.x, -translate.y - size.height);
}
g.translate(translate.x, translate.y);
logo_sp.validate();
logo_sp.draw(c, g, tx, null);
g.translate(-translate.x, -translate.y);
}