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);
}
use of java.awt.AlphaComposite in project cytoscape-impl by cytoscape.
the class ImageAnnotationImpl method drawAnnotation.
@Override
public void drawAnnotation(Graphics g, double x, double y, double scaleFactor) {
super.drawAnnotation(g, x, y, scaleFactor);
Graphics2D g2 = (Graphics2D) g;
// Get the stroke
int border = (int) Math.round(getBorderWidth() * scaleFactor);
int width = (int) Math.round(shapeWidth * scaleFactor / getZoom()) - border * 2 + 1;
int height = (int) Math.round(shapeHeight * scaleFactor / getZoom()) - border * 2 + 1;
int xInt = (int) Math.round(x * scaleFactor) + border + 1;
int yInt = (int) Math.round(y * scaleFactor) + border + 1;
// System.out.println("ImageAnnotationImpl: drawAnnotation - width="+width+", height="+height+", border="+border);
// System.out.println("ImageAnnotationImpl: drawAnnotation - x="+x+",y="+y+", xInt="+xInt+", yInt="+yInt);
BufferedImage newImage = resizeImage(width, height);
if (newImage == null)
return;
// boolean selected = isSelected();
// setSelected(false);
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
g2.setComposite(ac);
g2.drawImage(newImage, xInt, yInt, null);
// GraphicsUtilities.drawShape(g, 0, 0,
// getWidth()-1, getHeight()-1, this, false);
// setSelected(selected);
}
Aggregations