import java.awt.Component; //导入方法依赖的package包/类
public void draw(Graphics g, int x, int y, Component obs, double zoom) {
if (alpha == 1.0) {
piece.draw(g, x, y, obs, zoom);
return;
}
if (opaque.isChanged()) {
int trans = VASSAL.tools.TransparentFilter.getOffscreenEquivalent(obs.getBackground().getRGB(), obs);
VASSAL.tools.TransparentFilter filter = new VASSAL.tools.TransparentFilter();
filter.setAlpha(alpha);
filter.setAlpha(0.0, trans);
im = opaque.getImage(obs);
Image im2 = obs.createImage(im.getWidth(obs), im.getHeight(obs));
Graphics2D gg = (Graphics2D) im2.getGraphics();
gg.drawImage(im, 0, 0, obs);
gg.dispose();
im = obs.createImage(new FilteredImageSource
(im2.getSource(), filter));
offset = new Point(piece.boundingBox().x,
piece.boundingBox().y);
/*
im = opaque.getImage(obs);
final Image im2 = obs.createImage(im.getWidth(obs), im.getHeight(obs));
final Graphics2D gg = (Graphics2D) im2.getGraphics();
gg.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha));
gg.drawImage(im, 0, 0, obs);
gg.dispose();
offset = new Point(piece.boundingBox().x,
piece.boundingBox().y);
*/
}
Image scaled = im;
if (zoom != 1.0) {
scaled = GameModule.getGameModule().getDataArchive().getScaledImage(im,zoom);
}
g.drawImage(scaled,
x + (int) (zoom * offset.x),
y + (int) (zoom * offset.y),
obs);
}