You can now paste maps into the image editor with no loss of quality!

This commit is contained in:
Brendan Robert 2013-08-20 18:17:14 -05:00
parent 908d248af6
commit 57b83cebd8
5 changed files with 34 additions and 6 deletions

1
OutlawEditor/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/*~

View File

@ -2,6 +2,7 @@ package org.badvision.outlaweditor;
import javafx.scene.image.WritableImage;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.xml.Map;
/*
* To change this template, choose Tools | Templates
@ -21,5 +22,6 @@ public abstract class ImageRenderer {
public abstract WritableImage renderPreview(TileMap map, int startX, int startY);
public abstract WritableImage renderScanline(WritableImage currentImage, int y, byte[] imageData);
public abstract byte[] generatePreview(TileMap map, int x1, int y1);
}

View File

@ -5,6 +5,7 @@
package org.badvision.outlaweditor.apple;
import java.util.HashMap;
import java.util.Map;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Menu;
@ -20,6 +21,7 @@ import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.ImageEditor;
import org.badvision.outlaweditor.Platform;
import org.badvision.outlaweditor.data.DataObserver;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.xml.Image;
import org.badvision.outlaweditor.data.xml.PlatformData;
@ -375,8 +377,25 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
importImage(image);
}
}
//selection/map/2/x1/0/y1/0/x2/19/y2/11
public boolean pasteAppContent(String contentPath) {
System.out.println("Clipboard >> "+contentPath);
if (contentPath.startsWith("selection/map")) {
String[] bufferDetails = contentPath.substring(14).split("/");
int mapNumber = Integer.parseInt(bufferDetails[0]);
Map<String,Integer> details = new HashMap<>();
for (int i = 1; i < bufferDetails.length; i+=2) {
details.put(bufferDetails[i], Integer.parseInt(bufferDetails[i+1]));
}
TileMap map = new TileMap(Application.gameData.getMap().get(mapNumber));
byte[] buf = getPlatform().imageRenderer.generatePreview(
map,
details.get("x1"),
details.get("y1"));
setData(buf);
redraw();
return true;
}
return false;
}

View File

@ -11,6 +11,7 @@ import org.badvision.outlaweditor.ImageRenderer;
import org.badvision.outlaweditor.Platform;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.xml.Map;
import org.badvision.outlaweditor.data.xml.Tile;
/**
@ -18,7 +19,7 @@ import org.badvision.outlaweditor.data.xml.Tile;
* @author brobert
*/
public class AppleImageRenderer extends ImageRenderer {
//
public static int BLACK = 0xff000000;
public static int WHITE = 0xffffffff;
// scanline is 20 16-bit words
@ -30,13 +31,13 @@ public class AppleImageRenderer extends ImageRenderer {
}
@Override
public WritableImage renderPreview(TileMap map, int startX, int startY) {
public byte[] generatePreview(TileMap map, int x1, int y1) {
byte[] buffer = createImageBuffer();
int pos = 0;
for (int y = 0; y < 12; y++) {
for (int yy = 0; yy < 16; yy++) {
for (int x = 0; x < 20; x++) {
Tile t = map.get(x + startX, y + startY);
Tile t = map.get(x + x1, y + y1);
if (t == null) {
buffer[pos++] = 0;
buffer[pos++] = 0;
@ -48,7 +49,12 @@ public class AppleImageRenderer extends ImageRenderer {
}
}
}
return renderImage(null, buffer);
return buffer;
}
@Override
public WritableImage renderPreview(TileMap map, int startX, int startY) {
return renderImage(null, generatePreview(map, startX, startY));
}
@Override

Binary file not shown.