Search in sources :

Example 11 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)

Example 12 with Rectangle

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

the class AnimationCell method draw.

public void draw(final Graphics g, final Rectangle destRect) {
    if (vImage == null)
        return;
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    int valid = vImage.validate(gc);
    if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
        rebuild();
    }
    if (vImage != null) {
        Rectangle r = destRect;
        g.drawImage(vImage, r.x, r.y, r.width, r.height, null);
    }
}
Also used : Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 13 with Rectangle

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

the class AnimationStripPanel method paintComponent.

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // slots
    for (int i = 0; i < slotList.size(); ++i) {
        Slot slot = slotList.get(i);
        slot.draw(g);
    }
    // dragged slots
    for (int i = 0; i < slotList.size(); ++i) {
        Slot draggedSlot = slotList.get(i);
        if (draggedSlot.isDragged() && draggedSlot.getDragImage() != null) {
            g.drawImage(draggedSlot.getDragImage(), mousePoint.x, draggedSlot.getRect().y, null);
            if (insertBeforeSlotIndex >= 0) {
                g.setColor(Color.RED);
                int insertXPos = 0;
                if (insertBeforeSlotIndex < slotList.size()) {
                    insertXPos = slotList.get(insertBeforeSlotIndex).getRect().x;
                } else if (insertBeforeSlotIndex == slotList.size()) {
                    // last slot, draw inser marker at end
                    Rectangle slotRect = slotList.get(insertBeforeSlotIndex - 1).getRect();
                    insertXPos = slotRect.x + slotRect.width;
                }
                g.fillRect(insertXPos - 1, 0, 3, this.getHeight());
            }
        }
    }
    // animation marker
    g.setColor(Color.BLUE);
    for (int i = 0; i < slotList.size(); ++i) {
        if (i == currentSlotInAnimation) {
            Slot slot = slotList.get(i);
            Rectangle r = slot.getRect();
            g.drawRect(r.x, r.y, r.width, r.height);
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Example 14 with Rectangle

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

the class SpriteImageController method addNodeToPanel.

private void addNodeToPanel(CustomNode aNode, BufferedImage aImage) {
    if (aNode.isLeaf()) {
        GraphicObject sb = (GraphicObject) aNode.getCustomObject();
        // what we have here is actually a SelectionBox - we need to change it
        // into a SpriteGraphic
        Rectangle r = sb.getRect();
        SpriteGraphic graphic = new SpriteGraphic(aImage, new java.awt.Point(r.x, r.y), r);
        aNode.setCustomObject(graphic);
        int w = aImage.getWidth();
        int h = aImage.getHeight();
        textureWidthField.setText(Integer.toString(w));
        textureHeightField.setText(Integer.toString(h));
        viewPanel.setTextureArea(w, h);
        viewPanel.addGraphic(graphic);
    } else {
        for (int i = 0; i < aNode.getChildCount(); ++i) {
            addNodeToPanel((CustomNode) aNode.getChildAt(i), aImage);
        }
    }
}
Also used : Rectangle(java.awt.Rectangle)

Example 15 with Rectangle

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

the class SpriteImageController method addSpriteButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void addSpriteButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_addSpriteButtonActionPerformed
    File[] selectedFiles = this.showSetImageChooser();
    if (selectedFiles != null) {
        CustomNode parentNode = (CustomNode) nameTree.getSelectedNodeDir();
        if (parentNode == null)
            parentNode = _lastSelectedDirNode;
        if (parentNode == null)
            parentNode = (CustomNode) nameTree.getModel().getRoot();
        ArrayList<GraphicObject> graphicList = new ArrayList();
        for (int i = 0; i < selectedFiles.length; ++i) {
            try {
                BufferedImage bufferedImage = ImageIO.read(selectedFiles[i]);
                SpriteGraphic graphic = new SpriteGraphic(bufferedImage, new java.awt.Point(0, 0), new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()));
                graphicList.add(graphic);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(this, "Could not import " + selectedFiles[i].getName(), "Image not added", JOptionPane.ERROR_MESSAGE);
            }
        }
        cmdManager.execute(new AddGraphicListToSheetCommand(nameTree, parentNode, viewPanel, graphicList));
    }
}
Also used : ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) File(java.io.File)

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