Search in sources :

Example 36 with Composite

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);
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) BufferedImage(java.awt.image.BufferedImage)

Example 37 with Composite

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);
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite)

Example 38 with Composite

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);
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) Composite(java.awt.Composite) Color(java.awt.Color) AffineTransform(java.awt.geom.AffineTransform) Paint(java.awt.Paint) Font(java.awt.Font) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D)

Example 39 with Composite

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);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 40 with 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);
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Aggregations

Composite (java.awt.Composite)294 AlphaComposite (java.awt.AlphaComposite)279 Graphics2D (java.awt.Graphics2D)134 Paint (java.awt.Paint)103 Rectangle2D (java.awt.geom.Rectangle2D)103 Color (java.awt.Color)81 Shape (java.awt.Shape)80 BasicStroke (java.awt.BasicStroke)55 Stroke (java.awt.Stroke)52 BufferedImage (java.awt.image.BufferedImage)51 AffineTransform (java.awt.geom.AffineTransform)39 Line2D (java.awt.geom.Line2D)38 Point (java.awt.Point)36 Rectangle (java.awt.Rectangle)36 Font (java.awt.Font)33 Point2D (java.awt.geom.Point2D)31 GradientPaint (java.awt.GradientPaint)27 Iterator (java.util.Iterator)26 PlotOrientation (org.jfree.chart.plot.PlotOrientation)25 GeneralPath (java.awt.geom.GeneralPath)24