use of java.awt.Composite in project litiengine by gurkenlabs.
the class MapRenderer method renderImageLayer.
protected static void renderImageLayer(Graphics2D g, IImageLayer layer, final IMap map, Rectangle2D viewport, float opacity) {
Spritesheet sprite = Resources.spritesheets().get(layer.getImage().getSource());
BufferedImage img;
if (sprite == null) {
img = Resources.images().get(layer.getImage().getAbsoluteSourcePath());
} else {
img = sprite.getImage();
}
if (img == null) {
return;
}
final Composite oldComp = g.getComposite();
final AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
g.setComposite(ac);
final double viewportOffsetX = layer.getOffset().x - viewport.getX();
final double viewportOffsetY = layer.getOffset().y - viewport.getY();
ImageRenderer.render(g, img, viewportOffsetX, viewportOffsetY);
g.setComposite(oldComp);
final LayerRenderEvent event = new LayerRenderEvent(g, map, layer);
for (LayerRenderedListener listener : layerRenderedListeners) {
listener.rendered(event);
}
}
use of java.awt.Composite in project archi by archimatetool.
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);
}
}
use of java.awt.Composite in project powerbot by powerbot.
the class PaintEvent method call.
/**
* {@inheritDoc}
*/
@Override
public void call(final EventListener e) {
if (graphics == null) {
try {
((PaintListener) e).repaint(null);
} catch (final Exception ignored) {
}
return;
}
final Graphics2D g2 = (Graphics2D) graphics;
final Color b = g2.getBackground();
final Shape l = g2.getClip();
final Color c = g2.getColor();
final Composite m = g2.getComposite();
final Font f = g2.getFont();
final Paint p = g2.getPaint();
final RenderingHints r = g2.getRenderingHints();
final Stroke s = g2.getStroke();
final AffineTransform t = g2.getTransform();
try {
((PaintListener) e).repaint(graphics);
} catch (final Exception ex) {
ex.printStackTrace();
}
g2.setBackground(b);
g2.setClip(l);
g2.setColor(c);
g2.setComposite(m);
g2.setFont(f);
g2.setPaint(p);
g2.setRenderingHints(r);
g2.setStroke(s);
g2.setTransform(t);
}
use of java.awt.Composite in project sirix by sirixdb.
the class ProgressGlassPane method paintComponent.
@Override
protected void paintComponent(Graphics g) {
// enables anti-aliasing
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// gets the current clipping area
Rectangle clip = g.getClipBounds();
// sets a 65% translucent composite
AlphaComposite alpha = AlphaComposite.SrcOver.derive(0.65f);
Composite composite = g2.getComposite();
g2.setComposite(alpha);
// fills the background
g2.setColor(getBackground());
g2.fillRect(clip.x, clip.y, clip.width, clip.height);
// centers the progress bar on screen
FontMetrics metrics = g.getFontMetrics();
int x = (getWidth() - BAR_WIDTH) / 2;
int y = (getHeight() - BAR_HEIGHT - metrics.getDescent()) / 2;
// draws the text
g2.setColor(TEXT_COLOR);
g2.drawString(message, x, y);
// goes to the position of the progress bar
y += metrics.getDescent();
// computes the size of the progress indicator
int w = (int) (BAR_WIDTH * ((float) progress / 100.0f));
int h = BAR_HEIGHT;
// draws the content of the progress bar
Paint paint = g2.getPaint();
// bar's background
Paint gradient = new GradientPaint(x, y, GRADIENT_COLOR1, x, y + h, GRADIENT_COLOR2);
g2.setPaint(gradient);
g2.fillRect(x, y, BAR_WIDTH, BAR_HEIGHT);
// actual progress
gradient = new LinearGradientPaint(x, y, x, y + h, GRADIENT_FRACTIONS, GRADIENT_COLORS);
g2.setPaint(gradient);
g2.fillRect(x, y, w, h);
g2.setPaint(paint);
// draws the progress bar border
g2.drawRect(x, y, BAR_WIDTH, BAR_HEIGHT);
g2.setComposite(composite);
}
use of java.awt.Composite in project logisim-evolution by reds-heig.
the class LogisimToolbarItem method paintIcon.
public void paintIcon(Component destination, Graphics g) {
if (!isSelectable() && g instanceof Graphics2D) {
Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
((Graphics2D) g).setComposite(c);
}
if (icon == null) {
int simple = AppPreferences.getScaled(AppPreferences.IconSize) >> 2;
g.setColor(new Color(255, 128, 128));
g.fillRect(simple, simple, 2 * simple, 2 * simple);
g.setColor(Color.BLACK);
g.drawLine(simple, simple, 3 * simple, 3 * simple);
g.drawLine(simple, 3 * simple, 3 * simple, simple);
g.drawRect(simple, simple, 2 * simple, 2 * simple);
} else {
icon.paintIcon(destination, g, 0, 1);
}
}
Aggregations