use of java.awt.Composite in project smile by haifengl.
the class Graphics method fillPolygon.
/**
* Fill polygon. The coordinates are in logical coordinates. This also supports
* basic alpha compositing rules for combining source and destination
* colors to achieve blending and transparency effects with graphics and images.
*
* @param alpha the constant alpha to be multiplied with the alpha of the
* source. alpha must be a floating point number in the inclusive range
* [0.0, 1.0].
*/
public void fillPolygon(float alpha, double[]... coord) {
int[][] c = new int[coord.length][2];
for (int i = 0; i < coord.length; i++) {
c[i] = projection.screenProjection(coord[i]);
}
int[] x = new int[c.length];
for (int i = 0; i < c.length; i++) {
x[i] = c[i][0];
}
int[] y = new int[c.length];
for (int i = 0; i < c.length; i++) {
y[i] = c[i][1];
}
Composite cs = g2d.getComposite();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g2d.fillPolygon(x, y, c.length);
g2d.setComposite(cs);
}
use of java.awt.Composite in project android_frameworks_base by ParanoidAndroid.
the class GcSnapshot method createCustomGraphics.
/**
* Creates a new {@link Graphics2D} based on the {@link Paint} parameters.
* <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used.
*/
private Graphics2D createCustomGraphics(Graphics2D original, Paint_Delegate paint, boolean compositeOnly, boolean forceSrcMode) {
// make new one graphics
Graphics2D g = (Graphics2D) original.create();
if (paint.isAntiAliased()) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
boolean customShader = false;
// get the shader first, as it'll replace the color if it can be used it.
if (compositeOnly == false) {
Shader_Delegate shaderDelegate = paint.getShader();
if (shaderDelegate != null) {
if (shaderDelegate.isSupported()) {
java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
assert shaderPaint != null;
if (shaderPaint != null) {
g.setPaint(shaderPaint);
customShader = true;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_SHADER, shaderDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// if no shader, use the paint color
if (customShader == false) {
g.setColor(new Color(paint.getColor(), true));
}
// set the stroke
g.setStroke(paint.getJavaStroke());
}
// the alpha for the composite. Always opaque if the normal paint color is used since
// it contains the alpha
int alpha = (compositeOnly || customShader) ? paint.getAlpha() : 0xFF;
if (forceSrcMode) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, (float) alpha / 255.f));
} else {
boolean customXfermode = false;
Xfermode_Delegate xfermodeDelegate = paint.getXfermode();
if (xfermodeDelegate != null) {
if (xfermodeDelegate.isSupported()) {
Composite composite = xfermodeDelegate.getComposite(alpha);
assert composite != null;
if (composite != null) {
g.setComposite(composite);
customXfermode = true;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_XFERMODE, xfermodeDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// that will handle the alpha.
if (customXfermode == false && alpha != 0xFF) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha / 255.f));
}
}
return g;
}
use of java.awt.Composite in project EnrichmentMapApp by BaderLab.
the class ColorGradientWidget method clearImage.
/**
* Utility function to clean the background of the image.
*/
private void clearImage(Graphics2D image2D) {
// set the alpha composite on the image, and clear its area
Composite origComposite = image2D.getComposite();
image2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
image2D.setComposite(origComposite);
}
use of java.awt.Composite in project jdk8u_jdk by JetBrains.
the class GDIRenderer method doFillSpans.
// REMIND: This is just a hack to get WIDE lines to honor the
// necessary hinted pixelization rules. This should be replaced
// by a native FillSpans method or a getHintedStrokeGeneralPath()
// method that could be filled by the doShape method more quickly.
public void doFillSpans(SunGraphics2D sg2d, SpanIterator si) {
int[] box = new int[4];
GDIWindowSurfaceData sd;
try {
sd = (GDIWindowSurfaceData) sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
Region clip = sg2d.getCompClip();
Composite comp = sg2d.composite;
int eargb = sg2d.eargb;
while (si.nextSpan(box)) {
doFillRect(sd, clip, comp, eargb, box[0], box[1], box[2] - box[0], box[3] - box[1]);
}
}
Aggregations