use of java.awt.AlphaComposite in project litiengine by gurkenlabs.
the class OrthogonalMapRenderer method renderTileLayerImage.
/**
* Renders the tiles from the specified layer that lie within the bounds of
* the viewport. This rendering of static tiles is cached when when the
* related graphics setting is enabled, which tremendously improves the
* rendering performance.
*
* @param g
* @param layer
* @param map
* @param viewport
*/
private void renderTileLayerImage(final Graphics2D g, final ITileLayer layer, final IMap map, final Rectangle2D viewport) {
final Point startTile = MapUtilities.getTile(map, new Point2D.Double(viewport.getX(), viewport.getY()));
final Point endTile = MapUtilities.getTile(map, new Point2D.Double(viewport.getMaxX(), viewport.getMaxY()));
final double viewportOffsetX = -(viewport.getX() - startTile.x * map.getTileSize().width) + layer.getPosition().x;
final double viewportOffsetY = -(viewport.getY() - startTile.y * map.getTileSize().height) + layer.getPosition().y;
// set alpha value of the tiles by the layers value
final Composite oldComp = g.getComposite();
final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
g.setComposite(ac);
final int startX = MathUtilities.clamp(startTile.x, 0, layer.getSizeInTiles().width);
final int endX = MathUtilities.clamp(endTile.x, 0, layer.getSizeInTiles().width);
final int startY = MathUtilities.clamp(startTile.y, 0, layer.getSizeInTiles().height);
final int endY = MathUtilities.clamp(endTile.y, 0, layer.getSizeInTiles().height);
final double offsetX = viewportOffsetX + (startX - startTile.x) * map.getTileSize().width;
final double offsetY = viewportOffsetY + (startY - startTile.y) * map.getTileSize().height;
for (int x = startX; x <= endX; x++) {
for (int y = startY; y <= endY; y++) {
ITile tile = layer.getTile(x, y);
if (tile == null) {
continue;
}
final Image tileTexture = getTileImage(map, tile);
RenderEngine.renderImage(g, tileTexture, offsetX + (x - startX) * map.getTileSize().width, offsetY + (y - startY) * map.getTileSize().height);
}
}
g.setComposite(oldComp);
}
use of java.awt.AlphaComposite in project litiengine by gurkenlabs.
the class OrthogonalMapRenderer method renderImageLayer.
private void renderImageLayer(Graphics2D g, IImageLayer layer, Rectangle2D viewport) {
final Composite oldComp = g.getComposite();
final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
g.setComposite(ac);
final double viewportOffsetX = -viewport.getX() + layer.getPosition().x;
final double viewportOffsetY = -viewport.getY() + layer.getPosition().y;
Spritesheet sprite = Spritesheet.find(layer.getImage().getSource());
if (sprite == null) {
return;
}
RenderEngine.renderImage(g, sprite.getImage(), viewportOffsetX, viewportOffsetY);
g.setComposite(oldComp);
}
use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method validateColor.
/*
* Validate the eargb and pixel fields against the current color.
*
* The eargb field must take into account the extraAlpha
* value of an AlphaComposite. It may also take into account
* the Fsrc Porter-Duff blending function if such a function is
* a constant (see handling of Clear mode below). For instance,
* by factoring in the (Fsrc == 0) state of the Clear mode we can
* use a SrcNoEa loop just as easily as a general Alpha loop
* since the math will be the same in both cases.
*
* The pixel field will always be the best pixel data choice for
* the final result of all calculations applied to the eargb field.
*
* Note that this method is only necessary under the following
* conditions:
* (paintState <= PAINT_ALPHA_COLOR &&
* compositeState <= COMP_CUSTOM)
* though nothing bad will happen if it is run in other states.
*/
final void validateColor() {
int eargb;
if (imageComp == CompositeType.Clear) {
eargb = 0;
} else {
eargb = foregroundColor.getRGB();
if (compositeState <= COMP_ALPHA && imageComp != CompositeType.SrcNoEa && imageComp != CompositeType.SrcOverNoEa) {
AlphaComposite alphacomp = (AlphaComposite) composite;
int a = Math.round(alphacomp.getAlpha() * (eargb >>> 24));
eargb = (eargb & 0x00ffffff) | (a << 24);
}
}
this.eargb = eargb;
this.pixel = surfaceData.pixelFor(eargb);
}
use of java.awt.AlphaComposite in project pentaho-kettle by pentaho.
the class SwingGC method setAlpha.
public void setAlpha(int alpha) {
this.alpha = alpha;
AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 255);
gc.setComposite(alphaComposite);
}
use of java.awt.AlphaComposite in project cytoscape-impl by cytoscape.
the class ImageAnnotationImpl method paint.
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
if (image == null)
return;
// Get the stroke
int border = (int) Math.round(getBorderWidth() * getZoom());
// Calculate the new width & height
int width = getWidth() - border;
int height = getHeight() - border;
if (resizedImage == null || resizedImage.getWidth() != width || resizedImage.getHeight() != height)
resizedImage = resizeImage(width, height);
int x = 0;
int y = 0;
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
g2.setComposite(ac);
g2.drawImage(resizedImage, x + border + 1, y + border + 1, this);
super.paint(g);
}
Aggregations