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());
}
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);
}
}
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);
}
}
}
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);
}
}
}
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));
}
}
Aggregations