Search in sources :

Example 81 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class SpriteImagePanel method setTextureArea.

public void setTextureArea(int aWidth, int aHeight) {
    Rectangle r = this.getGraphicsBounds();
    this.setGraphicsBounds(new Rectangle(r.x, r.y, aWidth, aHeight));
}
Also used : Rectangle(java.awt.Rectangle)

Example 82 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class SpritesheetController method pack.

private void pack() {
    CustomNode rootNode = (CustomNode) nameTree.getModel().getRoot();
    if (rootNode != null) {
        ArrayList<Rectangle> rectList = new ArrayList<Rectangle>();
        addNodeToRectList(rootNode, rectList);
        if (rectList.size() > 0) {
            Rectangle[] array = new Rectangle[rectList.size()];
            for (int i = 0; i < rectList.size(); ++i) {
                array[i] = rectList.get(i);
            }
            String[] choices = { " Power of two ", " Smallest " };
            int choice = JOptionPane.showOptionDialog(// Center in window.
            this, // Message
            "Would you like the resulting image to use power of two dimensions (eg, 256x512)?", // Title in titlebar
            "Image dimensions?", // Option type
            JOptionPane.YES_NO_OPTION, // messageType
            JOptionPane.QUESTION_MESSAGE, // Icon (none)
            null, // Button text as above.
            choices, // Default button's label
            " ");
            PixelPacker packer = new PixelPacker();
            BufferedImage newImage = packer.packPixels(viewPanel.getImage(), array, (choice == 0));
            viewPanel.setImage(newImage);
            bImageModified = true;
            viewPanel.repaint();
            setModified(true);
            taskChangeListener.taskChanged(this);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage)

Example 83 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class SpritesheetPanel method setImage.

public void setImage(BufferedImage aImage) {
    if (aImage == null) {
        _pix = null;
        this.setEnabled(false);
        return;
    }
    setGraphicsBounds(new Rectangle(0, 0, aImage.getWidth(), aImage.getHeight()));
    _pix = new PixelBuffer(aImage);
}
Also used : Rectangle(java.awt.Rectangle)

Example 84 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class SpritesheetPanel method suggestVisibleSpriteRect.

public Rectangle suggestVisibleSpriteRect() {
    final int edgeInsetPix = 0;
    Rectangle r = new Rectangle((int) (-getOrigin().getX() / getZoom()) + edgeInsetPix, (int) (-getOrigin().getY() / getZoom()) + edgeInsetPix, (int) (80 / getZoom()), (int) (80 / getZoom()));
    if (r.x < 0)
        r.x = 0;
    if (r.y < 0)
        r.y = 0;
    GraphicObject selectedGraphic = null;
    java.util.ArrayList<GraphicObject> selectedGraphics = this.selectedGraphics();
    if (selectedGraphics != null && !selectedGraphics.isEmpty()) {
        selectedGraphic = selectedGraphics.get(selectedGraphics.size() - 1);
    }
    if (selectedGraphic == null) {
        while (r.width > _pix.getImage().getWidth()) {
            r.width /= 2;
            r.width -= 1;
        }
        while (r.height > _pix.getImage().getHeight()) {
            r.height /= 2;
            r.height -= 1;
        }
    } else {
        Rectangle lastRect = selectedGraphic.getRect();
        r.width = lastRect.width;
        r.height = lastRect.height;
        r.x = lastRect.x;
        r.y = lastRect.y;
        if (lastRect.x + lastRect.width * 2 < _pix.getImage().getWidth()) {
            r.x += lastRect.width;
            r.y = lastRect.y;
        } else {
            // row end, start new row, autoscroll the view
            // search backwards for first in this size group       
            GraphicObject found = null;
            if (selectedGraphics != null && !selectedGraphics.isEmpty())
                found = this.selectedGraphics().get(0);
            if (found == null)
                found = _lastAddedGraphic;
            if (found != null) {
                for (int i = _drawStack.indexOf(found); i < _drawStack.size(); i++) {
                    Rectangle rect = _drawStack.get(i).getRect();
                    if (r.width == rect.width && r.height == rect.height && r.y == rect.y) {
                        found = _drawStack.get(i);
                    } else
                        break;
                }
                Rectangle firstRect = found.getRect();
                if (firstRect.y + firstRect.height < _pix.getImage().getHeight()) {
                    r.x = firstRect.x;
                    r.y = firstRect.y + firstRect.height;
                }
                // TODO: not centring properly
                this.setOrigin(new Point((int) (((this.getWidth() - _pix.getImage().getWidth() / 2) / 2) - (r.x) * this.getZoom()), (int) (((this.getHeight() - _pix.getImage().getHeight() / 2) / 2) - (r.y) * this.getZoom())));
            }
        }
    }
    if (r.width <= 0)
        r.width = 1;
    if (r.height <= 0)
        r.height = 1;
    if (r.x + r.width > _pix.getImage().getWidth())
        r.x = _pix.getImage().getWidth() - r.width;
    if (r.y + r.height > _pix.getImage().getHeight())
        r.y = _pix.getImage().getHeight() - r.height;
    return r;
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 85 with Rectangle

use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.

the class AnimationCell method rebuild.

public void rebuild() {
    //System.out.println("Attempting to rebuild animation cell volatile image");
    Rectangle r = getSpreadRect();
    if (r.width <= 0 || r.height <= 0) {
        vImage = null;
        return;
    }
    do {
        vImage = ImageUtil.createVolatileImage(r.width, r.height, java.awt.Transparency.TRANSLUCENT);
        Graphics2D g = null;
        try {
            g = vImage.createGraphics();
            // clear to transparent
            g.setComposite(AlphaComposite.Clear);
            g.fillRect(0, 0, r.width, r.height);
            g.setComposite(AlphaComposite.SrcOver);
            //for (Enumeration<GraphicObject> e = graphicNodeDict.keys(); e.hasMoreElements();)
            for (int i = graphicOrderList.size() - 1; i >= 0; i--) {
                //GraphicObject graphic = e.nextElement();
                GraphicObject graphic = graphicOrderList.get(i);
                // backup selected state and remove... don't want to draw it selected in the cell
                boolean isSelected = graphic.isSelected();
                graphic.setSelected(false);
                Graphics2D g2d = (Graphics2D) g;
                AffineTransform transform = new AffineTransform(g2d.getTransform());
                AffineTransform oldTransform = g2d.getTransform();
                Rectangle gr = graphic.getRect();
                transform.rotate(Math.toRadians(graphic.getAngle()), -r.x + gr.x + gr.width / 2, -r.y + gr.y + gr.height / 2);
                g2d.setTransform(transform);
                graphic.draw(g2d, new Point(-r.x, -r.y), 1.0f, 1.0f, false);
                g2d.setTransform(oldTransform);
                // restore selected state
                graphic.setSelected(isSelected);
            }
        } finally {
            g.dispose();
        }
    } while (vImage.contentsLost());
}
Also used : Rectangle(java.awt.Rectangle) AffineTransform(java.awt.geom.AffineTransform) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

Rectangle (java.awt.Rectangle)809 Point (java.awt.Point)201 Dimension (java.awt.Dimension)81 BufferedImage (java.awt.image.BufferedImage)68 Graphics2D (java.awt.Graphics2D)65 Color (java.awt.Color)48 Insets (java.awt.Insets)47 ArrayList (java.util.ArrayList)37 Font (java.awt.Font)29 Test (org.junit.Test)28 IOException (java.io.IOException)27 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Paint (java.awt.Paint)23 GradientPaint (java.awt.GradientPaint)22 FontMetrics (java.awt.FontMetrics)21 Graphics (java.awt.Graphics)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Robot (java.awt.Robot)19 File (java.io.File)19 PeakResult (gdsc.smlm.results.PeakResult)18