Search in sources :

Example 46 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class PeekMetrics method checkAlpha.

/**
     * Record information about drawing done
     * with the supplied <code>Composite</code>.
     */
private void checkAlpha(Composite composite) {
    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();
        if (alpha != 1.0 || (rule != AlphaComposite.SRC && rule != AlphaComposite.SRC_OVER)) {
            mHasCompositing = true;
        }
    } else {
        mHasCompositing = true;
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Paint(java.awt.Paint)

Example 47 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class D3DSurfaceData method validatePipe.

public void validatePipe(SunGraphics2D sg2d) {
    TextPipe textpipe;
    boolean validated = false;
    // for the surface which had any XOR rendering done to.
    if (sg2d.compositeState >= sg2d.COMP_XOR) {
        super.validatePipe(sg2d);
        sg2d.imagepipe = d3dImagePipe;
        disableAccelerationForSurface();
        return;
    }
    if (/* CompositeType.SrcNoEa (any color) */
    (sg2d.compositeState <= sg2d.COMP_ISCOPY && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) || /* CompositeType.SrcOver (any color) */
    (sg2d.compositeState == sg2d.COMP_ALPHA && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR && (((AlphaComposite) sg2d.composite).getRule() == AlphaComposite.SRC_OVER)) || /* CompositeType.Xor (any color) */
    (sg2d.compositeState == sg2d.COMP_XOR && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR)) {
        textpipe = d3dTextPipe;
    } else {
        // do this to initialize textpipe correctly; we will attempt
        // to override the non-text pipes below
        super.validatePipe(sg2d);
        textpipe = sg2d.textpipe;
        validated = true;
    }
    PixelToParallelogramConverter txPipe = null;
    D3DRenderer nonTxPipe = null;
    if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
        if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
            if (sg2d.compositeState <= sg2d.COMP_XOR) {
                txPipe = d3dTxRenderPipe;
                nonTxPipe = d3dRenderPipe;
            }
        } else if (sg2d.compositeState <= sg2d.COMP_ALPHA) {
            if (D3DPaints.isValid(sg2d)) {
                txPipe = d3dTxRenderPipe;
                nonTxPipe = d3dRenderPipe;
            }
        // custom paints handled by super.validatePipe() below
        }
    } else {
        if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
            if (graphicsDevice.isCapPresent(CAPS_AA_SHADER) && (sg2d.imageComp == CompositeType.SrcOverNoEa || sg2d.imageComp == CompositeType.SrcOver)) {
                if (!validated) {
                    super.validatePipe(sg2d);
                    validated = true;
                }
                PixelToParallelogramConverter aaConverter = new PixelToParallelogramConverter(sg2d.shapepipe, d3dAAPgramPipe, 1.0 / 8.0, 0.499, false);
                sg2d.drawpipe = aaConverter;
                sg2d.fillpipe = aaConverter;
                sg2d.shapepipe = aaConverter;
            } else if (sg2d.compositeState == sg2d.COMP_XOR) {
                // install the solid pipes when AA and XOR are both enabled
                txPipe = d3dTxRenderPipe;
                nonTxPipe = d3dRenderPipe;
            }
        }
    // other cases handled by super.validatePipe() below
    }
    if (txPipe != null) {
        if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
            sg2d.drawpipe = txPipe;
            sg2d.fillpipe = txPipe;
        } else if (sg2d.strokeState != sg2d.STROKE_THIN) {
            sg2d.drawpipe = txPipe;
            sg2d.fillpipe = nonTxPipe;
        } else {
            sg2d.drawpipe = nonTxPipe;
            sg2d.fillpipe = nonTxPipe;
        }
        // Note that we use the transforming pipe here because it
        // will examine the shape and possibly perform an optimized
        // operation if it can be simplified.  The simplifications
        // will be valid for all STROKE and TRANSFORM types.
        sg2d.shapepipe = txPipe;
    } else {
        if (!validated) {
            super.validatePipe(sg2d);
        }
    }
    // install the text pipe based on our earlier decision
    sg2d.textpipe = textpipe;
    // always override the image pipe with the specialized D3D pipe
    sg2d.imagepipe = d3dImagePipe;
}
Also used : AlphaComposite(java.awt.AlphaComposite) TextPipe(sun.java2d.pipe.TextPipe) PixelToParallelogramConverter(sun.java2d.pipe.PixelToParallelogramConverter)

Example 48 with AlphaComposite

use of java.awt.AlphaComposite in project dbeaver by dbeaver.

the class GraphicsToGraphics2DAdaptor method setAlpha.

@Override
public void setAlpha(int alpha) {
    swtGraphics.setAlpha(alpha);
    currentState.alpha = alpha;
    Composite composite = getGraphics2D().getComposite();
    if (composite instanceof AlphaComposite) {
        AlphaComposite newComposite = AlphaComposite.getInstance(((AlphaComposite) composite).getRule(), (float) alpha / (float) 255);
        getGraphics2D().setComposite(newComposite);
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite)

Example 49 with AlphaComposite

use of java.awt.AlphaComposite in project Lucee by lucee.

the class Image method setTranparency.

public void setTranparency(float percent) throws ExpressionException {
    if (percent == -1)
        return;
    tranparency = percent;
    AlphaComposite rule = AlphaComposite.getInstance(3, 1.0F - (percent / 100.0F));
    getGraphics().setComposite(rule);
}
Also used : AlphaComposite(java.awt.AlphaComposite)

Example 50 with AlphaComposite

use of java.awt.AlphaComposite in project litiengine by gurkenlabs.

the class OrthogonalMapRenderer method getLayerImage.

/**
 * Gets the layer image.
 *
 * @param layer
 *          the layer
 * @param map
 *          the map
 * @return the layer image
 */
private synchronized BufferedImage getLayerImage(final ITileLayer layer, final IMap map, boolean includeAnimationTiles) {
    // if we have already retrived the image, use the one from the cache to
    // draw the layer
    final String cacheKey = MessageFormat.format("{0}_{1}", getCacheKey(map), layer.getName());
    if (ImageCache.MAPS.containsKey(cacheKey)) {
        return ImageCache.MAPS.get(cacheKey);
    }
    final BufferedImage bufferedImage = ImageProcessing.getCompatibleImage(layer.getSizeInTiles().width * map.getTileSize().width, layer.getSizeInTiles().height * map.getTileSize().height);
    // we need a graphics 2D object to work with transparency
    final Graphics2D imageGraphics = bufferedImage.createGraphics();
    // set alpha value of the tiles by the layers value
    final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
    imageGraphics.setComposite(ac);
    layer.getTiles().parallelStream().forEach(tile -> {
        // get the tile from the tileset image
        final int index = layer.getTiles().indexOf(tile);
        if (tile.getGridId() == 0) {
            return;
        }
        if (!includeAnimationTiles && MapUtilities.hasAnimation(map, tile)) {
            return;
        }
        final Image tileTexture = getTileImage(map, tile);
        // draw the tile on the layer image
        final int x = index % layer.getSizeInTiles().width * map.getTileSize().width;
        final int y = index / layer.getSizeInTiles().width * map.getTileSize().height;
        RenderEngine.renderImage(imageGraphics, tileTexture, x, y);
    });
    ImageCache.MAPS.put(cacheKey, bufferedImage);
    return bufferedImage;
}
Also used : AlphaComposite(java.awt.AlphaComposite) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) 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