Search in sources :

Example 56 with Graphics2D

use of java.awt.Graphics2D in project processing by processing.

the class Toolkit method prepareGraphics.

/**
   * Handles scaling for high-res displays, also sets text anti-aliasing
   * options to be far less ugly than the defaults.
   * Moved to a utility function because it's used in several classes.
   * @return a Graphics2D object, as a bit o sugar
   */
public static Graphics2D prepareGraphics(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    //float z = zoom * (Toolkit.isRetina() ? 2 : 1);
    if (Toolkit.isRetina()) {
        // scale everything 2x, will be scaled down when drawn to the screen
        g2.scale(2, 2);
    }
    //g2.scale(z, z);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    if (Toolkit.isRetina()) {
        // Looks great on retina, not so great (with our font) on 1x
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    }
    zoomStroke(g2);
    return g2;
}
Also used : Graphics2D(java.awt.Graphics2D)

Example 57 with Graphics2D

use of java.awt.Graphics2D in project processing by processing.

the class PSurfaceAWT method render.

/*
    @Override
    public void addNotify() {
//      System.out.println("adding notify");
      super.addNotify();
      // prior to Java 7 on OS X, this no longer works [121222]
//    createBufferStrategy(2);
    }
    */
protected synchronized void render() {
    if (canvas.isDisplayable() && graphics.image != null) {
        if (canvas.getBufferStrategy() == null) {
            canvas.createBufferStrategy(2);
        }
        BufferStrategy strategy = canvas.getBufferStrategy();
        if (strategy != null) {
            //        try {
            do {
                // are consistent in case the underlying surface was recreated
                do {
                    Graphics2D draw = (Graphics2D) strategy.getDrawGraphics();
                    // draw to width/height, since this may be a 2x image
                    draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
                    draw.dispose();
                } while (strategy.contentsRestored());
                // Display the buffer
                strategy.show();
            // Repeat the rendering if the drawing buffer was lost
            } while (strategy.contentsLost());
        }
    }
}
Also used : Graphics2D(java.awt.Graphics2D)

Example 58 with Graphics2D

use of java.awt.Graphics2D in project javatari by ppeccin.

the class DeepBorder method paintBorder.

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color color = newBrightness(c.getBackground(), -.3f);
    g2.setColor(newAlpha(color, 40));
    g2.drawRoundRect(x, y + 2, width - 1, height - 4, radius, radius);
    g2.setColor(newAlpha(color, 90));
    g2.drawRoundRect(x + 1, y + 1, width - 3, height - 2, radius, radius);
    g2.setColor(newAlpha(color, 255));
    g2.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
    g2.dispose();
}
Also used : Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 59 with Graphics2D

use of java.awt.Graphics2D in project javatari by ppeccin.

the class MonitorPanel method displayClear.

@Override
public void displayClear() {
    Graphics2D canvasGraphics = displayGraphics();
    canvasGraphics.setColor(Color.BLACK);
    canvasGraphics.clearRect(0, 0, getWidth(), getHeight());
    displayFinishFrame(canvasGraphics);
}
Also used : Graphics2D(java.awt.Graphics2D)

Example 60 with Graphics2D

use of java.awt.Graphics2D in project javatari by ppeccin.

the class ConsolePanel method paintComponent.

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Insets ins = getInsets();
    int initialHeight = HEIGHT - (getHeight() - ins.top - ins.bottom);
    g.drawImage(panelImage, ins.left, ins.top, getWidth() - ins.right, getHeight() - ins.bottom, 0, initialHeight, getWidth() - ins.left - ins.right, initialHeight + getHeight() - ins.top - ins.bottom, null);
    int panelBottom = getHeight() - ins.bottom;
    // Inserted Cartridge
    if (cartridgeInserted) {
        g.drawImage(cartridgeImage, ins.left + 141, panelBottom - 94, null);
        // Cartridge Label
        ((Graphics2D) g).setComposite(AlphaComposite.SrcOver);
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        SwingUtilities.paintComponent(g, cartridgeLabelComponent, this, ins.left + 158, panelBottom - 85, 154, 27);
    }
    // Cartridge change keys
    if (screen.isCartridgeChangeEnabled() && initialHeight < HEIGHT - 10)
        g.drawImage(changeCartKeysImage, ins.left + 173, panelBottom - 32, null);
    paintHotspots(g);
    // Controls state
    if (controlsStateReport.isEmpty())
        return;
    if (!controlsStateReport.get(Control.POWER))
        g.drawImage(powerDownImage, ins.left + 33, panelBottom - 87, null);
    if (controlsStateReport.get(Control.BLACK_WHITE))
        g.drawImage(colorDownImage, ins.left + 97, panelBottom - 87, null);
    if (controlsStateReport.get(Control.SELECT))
        g.drawImage(selectDownImage, ins.left + 353, panelBottom - 87, null);
    if (controlsStateReport.get(Control.RESET))
        g.drawImage(resetDownImage, ins.left + 416, panelBottom - 87, null);
    if (controlsStateReport.get(Control.DIFFICULTY0))
        g.drawImage(p0DiffDownImage, ins.left + 164, panelBottom - 131, null);
    if (controlsStateReport.get(Control.DIFFICULTY1))
        g.drawImage(p1DiffDownImage, ins.left + 277, panelBottom - 131, null);
}
Also used : Insets(java.awt.Insets) Graphics2D(java.awt.Graphics2D)

Aggregations

Graphics2D (java.awt.Graphics2D)624 BufferedImage (java.awt.image.BufferedImage)338 Color (java.awt.Color)118 Font (java.awt.Font)58 Rectangle (java.awt.Rectangle)48 BasicStroke (java.awt.BasicStroke)46 AffineTransform (java.awt.geom.AffineTransform)44 Rectangle2D (java.awt.geom.Rectangle2D)41 Point (java.awt.Point)34 FontMetrics (java.awt.FontMetrics)32 Dimension (java.awt.Dimension)31 IOException (java.io.IOException)28 GradientPaint (java.awt.GradientPaint)27 Image (java.awt.Image)27 VolatileImage (java.awt.image.VolatileImage)26 TextLayout (java.awt.font.TextLayout)24 File (java.io.File)23 Graphics (java.awt.Graphics)22 GraphicsConfiguration (java.awt.GraphicsConfiguration)21 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20