Search in sources :

Example 51 with AlphaComposite

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);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Point2D(java.awt.geom.Point2D) AlphaComposite(java.awt.AlphaComposite) Point(java.awt.Point) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point)

Example 52 with AlphaComposite

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);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet)

Example 53 with AlphaComposite

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);
}
Also used : AlphaComposite(java.awt.AlphaComposite) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 54 with AlphaComposite

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);
}
Also used : AlphaComposite(java.awt.AlphaComposite)

Example 55 with 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);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Aggregations

AlphaComposite (java.awt.AlphaComposite)80 Composite (java.awt.Composite)56 Graphics2D (java.awt.Graphics2D)56 Color (java.awt.Color)24 Paint (java.awt.Paint)10 ButtonModel (javax.swing.ButtonModel)10 FontMetrics (java.awt.FontMetrics)9 BufferedImage (java.awt.image.BufferedImage)9 ColorUIResource (javax.swing.plaf.ColorUIResource)9 UIResource (javax.swing.plaf.UIResource)8 GradientPaint (java.awt.GradientPaint)6 Shape (java.awt.Shape)6 Area (java.awt.geom.Area)6 Rectangle2D (java.awt.geom.Rectangle2D)6 Point (java.awt.Point)5 RoundRectangle2D (java.awt.geom.RoundRectangle2D)5 Icon (javax.swing.Icon)5 JMenuBar (javax.swing.JMenuBar)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 AffineTransform (java.awt.geom.AffineTransform)4