Search in sources :

Example 6 with Rectangle

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

the class AnimationStripPanel method mousePressed.

public void mousePressed(MouseEvent evt) {
    Point p = evt.getPoint();
    controller.stripIndexSelected(-1);
    boolean selectedSlot = false;
    for (int i = 0; i < slotList.size(); ++i) {
        Slot slot = slotList.get(i);
        slot.setSelected(false);
        Rectangle rect = slot.getRect();
        if (MathUtil.pointRectCollide(p, rect)) {
            slot.setSelected(true);
            controller.stripIndexSelected(i);
            //slot.setDragged(true);
            controller.setWorkingCell(slot.getCell());
            selectedSlot = true;
        }
    }
    if (!selectedSlot)
        controller.setWorkingCell(null);
    repaint();
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 7 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 8 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 9 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 10 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)

Aggregations

Rectangle (java.awt.Rectangle)654 Point (java.awt.Point)147 BufferedImage (java.awt.image.BufferedImage)61 Dimension (java.awt.Dimension)49 Graphics2D (java.awt.Graphics2D)48 Insets (java.awt.Insets)36 Color (java.awt.Color)31 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 GraphicsConfiguration (java.awt.GraphicsConfiguration)21 IOException (java.io.IOException)21 Robot (java.awt.Robot)19 PeakResult (gdsc.smlm.results.PeakResult)18 File (java.io.File)18 Font (java.awt.Font)17 FontMetrics (java.awt.FontMetrics)17 MemoryPeakResults (gdsc.smlm.results.MemoryPeakResults)16 SampleModel (java.awt.image.SampleModel)15 Component (java.awt.Component)14 ImagePlus (ij.ImagePlus)13