use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.
the class MintTitlePane method paintBackground.
/**
* {@inheritDoc}
*/
@Override
public void paintBackground(Graphics g) {
if (isActive()) {
Graphics2D g2D = (Graphics2D) g;
Composite composite = g2D.getComposite();
if (backgroundImage != null) {
g.drawImage(backgroundImage, 0, 0, null);
AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaValue);
g2D.setComposite(alpha);
}
JTattooUtilities.fillVerGradient(g, AbstractLookAndFeel.getTheme().getWindowTitleColors(), 0, 0, getWidth(), getHeight());
g2D.setComposite(composite);
} else {
JTattooUtilities.fillVerGradient(g, AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors(), 0, 0, getWidth(), getHeight());
}
}
use of java.awt.AlphaComposite in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method setColor.
/**
* Sets the current color for this graphics context.
*
* @param color the color (<code>null</code> permitted but ignored).
*
* @see #getColor()
*/
public void setColor(Color color) {
if (color == null) {
return;
}
org.eclipse.swt.graphics.Color swtColor = getSwtColorFromPool(color);
this.gc.setForeground(swtColor);
// handle transparency and compositing.
if (this.composite instanceof AlphaComposite) {
AlphaComposite acomp = (AlphaComposite) this.composite;
switch(acomp.getRule()) {
case AlphaComposite.SRC_OVER:
this.gc.setAlpha((int) (color.getAlpha() * acomp.getAlpha()));
break;
default:
this.gc.setAlpha(color.getAlpha());
break;
}
}
}
use of java.awt.AlphaComposite in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method setComposite.
/**
* Sets the current composite. This implementation currently supports
* only the {@link AlphaComposite} class.
*
* @param comp the composite (<code>null</code> not permitted).
*/
public void setComposite(Composite comp) {
if (comp == null) {
throw new IllegalArgumentException("Null 'comp' argument.");
}
this.composite = comp;
if (comp instanceof AlphaComposite) {
AlphaComposite acomp = (AlphaComposite) comp;
int alpha = (int) (acomp.getAlpha() * 0xFF);
this.gc.setAlpha(alpha);
}
}
use of java.awt.AlphaComposite in project hutool by looly.
the class GifCaptcha method graphicsImage.
/**
* 画随机码图
*
* @param fontColor 随机字体颜色
* @param words 字符数组
* @param flag 透明度使用
* @return BufferedImage
*/
private BufferedImage graphicsImage(char[] chars, Color[] fontColor, char[] words, int flag) {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 或得图形上下文
Graphics2D g2d = image.createGraphics();
// 利用指定颜色填充背景
g2d.setColor(ObjectUtil.defaultIfNull(this.background, Color.WHITE));
g2d.fillRect(0, 0, width, height);
AlphaComposite ac;
// 字符的y坐标
float y = (height >> 1) + (font.getSize() >> 1);
float m = 1.0f * (width - (chars.length * font.getSize())) / chars.length;
// 字符的x坐标
float x = Math.max(m / 2.0f, 2);
g2d.setFont(font);
// 指定透明度
if (null != this.textAlpha) {
g2d.setComposite(this.textAlpha);
}
for (int i = 0; i < chars.length; i++) {
ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(chars.length, flag, i));
g2d.setComposite(ac);
g2d.setColor(fontColor[i]);
g2d.drawOval(RandomUtil.randomInt(width), RandomUtil.randomInt(height), RandomUtil.randomInt(5, 30), 5 + RandomUtil.randomInt(5, 30));
// 绘制椭圆边框
g2d.drawString(words[i] + "", x + (font.getSize() + m) * i, y);
}
g2d.dispose();
return image;
}
use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.
the class GraphicsTests method initContext.
public void initContext(TestEnvironment env, Context ctx) {
ctx.graphics = env.getGraphics();
int w = env.getWidth();
int h = env.getHeight();
ctx.size = env.getIntValue(sizeList);
ctx.outdim = getOutputSize(ctx.size, ctx.size);
ctx.pixscale = 1.0;
if (hasGraphics2D) {
Graphics2D g2d = (Graphics2D) ctx.graphics;
AlphaComposite ac = (AlphaComposite) env.getModifier(compRules);
if (env.isEnabled(doExtraAlpha)) {
ac = AlphaComposite.getInstance(ac.getRule(), 0.125f);
}
g2d.setComposite(ac);
if (env.isEnabled(doXor)) {
g2d.setXORMode(Color.white);
}
if (env.isEnabled(doClipping)) {
Polygon p = new Polygon();
p.addPoint(0, 0);
p.addPoint(w, 0);
p.addPoint(0, h);
p.addPoint(w, h);
p.addPoint(0, 0);
g2d.clip(p);
}
Transform tx = (Transform) env.getModifier(transforms);
Dimension envdim = new Dimension(w, h);
tx.init(g2d, ctx, envdim);
w = envdim.width;
h = envdim.height;
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, env.getModifier(renderHint));
}
switch(env.getIntValue(animList)) {
case 0:
ctx.animate = false;
ctx.maxX = 3;
ctx.maxY = 1;
ctx.orgX = (w - ctx.outdim.width) / 2;
ctx.orgY = (h - ctx.outdim.height) / 2;
break;
case 1:
ctx.animate = true;
ctx.maxX = Math.max(Math.min(32, w - ctx.outdim.width), 3);
ctx.maxY = 1;
ctx.orgX = (w - ctx.outdim.width - ctx.maxX) / 2;
ctx.orgY = (h - ctx.outdim.height) / 2;
break;
case 2:
ctx.animate = true;
ctx.maxX = (w - ctx.outdim.width) + 1;
ctx.maxY = (h - ctx.outdim.height) + 1;
ctx.maxX = adjustWidth(ctx.maxX, ctx.maxY);
ctx.maxX = Math.max(ctx.maxX, 3);
ctx.maxY = Math.max(ctx.maxY, 1);
// ctx.orgX = ctx.orgY = 0;
break;
}
ctx.initX = ctx.maxX / 2;
ctx.initY = ctx.maxY / 2;
}
Aggregations