Added copy data feature to export monitor listings of images. Doesn't do anything for other editors except probably throw stack traces.

This commit is contained in:
badvision 2017-03-21 00:30:24 -05:00
parent 4ee9116e82
commit d5c51236f4
11 changed files with 115 additions and 23 deletions

View File

@ -52,6 +52,8 @@ public abstract class Editor<T, D> implements DataObserver<T> {
abstract public void copy();
abstract public void copyData();
abstract public void paste();
abstract public void select();

View File

@ -89,5 +89,10 @@ public class GlobalEditor extends Editor<Global, Void>{
private GameData getGameData() {
return ApplicationState.getInstance().getGameData();
}
@Override
public void copyData() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -562,6 +562,11 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
return ApplicationState.getInstance().getCurrentPlatform();
}
@Override
public void copyData() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public static enum DrawMode {
Pencil1px, Pencil3px, Pencil5px, FilledRect, TileEraser(false), ScriptPencil(false), Select(false);

View File

@ -429,7 +429,14 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
return getPlatformData(getPlatform()).getHeight();
}
byte[] copyData = null;
@Override
public void copyData() {
java.util.Map<DataFormat, Object> clip = new HashMap<>();
clip.put(DataFormat.PLAIN_TEXT, AppleNTSCGraphics.generateHgrMonitorListing(getPlatformData()));
Clipboard.getSystemClipboard().setContent(clip);
}
byte[] copyBuffer = null;
@Override
public void copy() {
@ -437,7 +444,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
clip.put(DataFormat.IMAGE, currentImage);
clip.put(DataFormat.PLAIN_TEXT, "selection/image/" + ApplicationState.getInstance().getGameData().getImage().indexOf(getEntity()) + "/" + getSelectionInfo());
Clipboard.getSystemClipboard().setContent(clip);
copyData = Arrays.copyOf(getImageData(), getImageData().length);
copyBuffer = Arrays.copyOf(getImageData(), getImageData().length);
}
@Override
@ -474,7 +481,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
Image sourceImage = ApplicationState.getInstance().getGameData().getImage().get(selection.get("image"));
byte[] sourceData;
if (sourceImage.equals(getEntity())) {
sourceData = copyData;
sourceData = copyBuffer;
} else {
PlatformData platformData = sourceImage.getDisplayData().stream().filter(d -> d.getPlatform().equals(getPlatform().name())).findFirst().orElse(null);
if (platformData == null) {
@ -555,30 +562,14 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
UIAction.openImageConversionModal(image, ditherEngine, getWidth(), getHeight(), this::setDataAndRedraw);
}
private int calculateHiresOffset(int y) {
return calculateTextOffset(y >> 3) + ((y & 7) << 10);
}
private int calculateTextOffset(int y) {
return ((y & 7) << 7) + 40 * (y >> 3);
}
@Override
public void exportImage() {
byte[] output = new byte[0x02000];
int counter = 0;
for (int y = 0; y < getHeight(); y++) {
int offset = calculateHiresOffset(y);
for (int x = 0; x < getWidth(); x++) {
output[offset + x] = getImageData()[counter++];
}
}
File out = FileUtils.getFile(null, "Export image", true, FileUtils.Extension.BINARY, FileUtils.Extension.ALL);
if (out == null) {
return;
}
try (FileOutputStream outStream = new FileOutputStream(out)) {
outStream.write(output);
outStream.write(AppleNTSCGraphics.getAppleHGRBinary(getPlatformData()));
outStream.flush();
} catch (IOException ex) {
Logger.getLogger(AppleImageEditor.class.getName()).log(Level.SEVERE, null, ex);

View File

@ -7,9 +7,10 @@
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.badvision.outlaweditor.apple;
import org.badvision.outlaweditor.data.xml.PlatformData;
/**
*
* @author brobert
@ -18,7 +19,7 @@ public class AppleNTSCGraphics {
// i Range [-0.5957, 0.5957]
public static final double MAX_I = 0.5957;
// q Range [-0.5226, 0.5226]
public static final double MAX_Q = 0.5226;
public static final double MAX_Y = 1;
@ -122,7 +123,63 @@ public class AppleNTSCGraphics {
}
}
static public int calculateHiresOffset(int y) {
return calculateTextOffset(y >> 3) + ((y & 7) << 10);
}
static public int calculateTextOffset(int y) {
return ((y & 7) << 7) + 40 * (y >> 3);
}
static {
initPalettes();
}
public static String generateHgrMonitorListing(PlatformData data) {
StringBuilder listing = new StringBuilder();
for (int y = 0; y < data.getHeight(); y++) {
int pos = calculateHiresOffset(y) + 0x02000;
listing.append("\n").append(Integer.toHexString(pos)).append(":");
for (int x = 0; x < data.getWidth(); x++) {
int val = data.getValue()[data.getWidth() * y + x] & 0x0ff;
listing.append(Integer.toHexString(val)).append(" ");
}
}
listing.append("\n");
return listing.toString();
}
static byte[] getAppleHGRBinary(PlatformData platformData) {
byte[] output = new byte[0x02000];
int counter = 0;
for (int y = 0; y < platformData.getHeight(); y++) {
int offset = calculateHiresOffset(y);
for (int x = 0; x < platformData.getWidth(); x++) {
output[offset + x] = platformData.getValue()[counter++];
}
}
return output;
}
public static Object generateDhgrMonitorListing(PlatformData data) {
StringBuilder listing = new StringBuilder();
for (int y = 0; y < data.getHeight(); y++) {
int pos = calculateHiresOffset(y) + 0x02000;
listing.append("\n").append(Integer.toHexString(pos)).append(":");
for (int x = 1; x < data.getWidth(); x+=2) {
int val = data.getValue()[data.getWidth() * y + x] & 0x0ff;
listing.append(Integer.toHexString(val)).append(" ");
}
}
for (int y = 0; y < data.getHeight(); y++) {
int pos = calculateHiresOffset(y) + 0x04000;
listing.append("\n").append(Integer.toHexString(pos)).append(":");
for (int x = 0; x < data.getWidth(); x+=2) {
int val = data.getValue()[data.getWidth() * y + x] & 0x0ff;
listing.append(Integer.toHexString(val)).append(" ");
}
}
listing.append("\n");
return listing.toString();
}
}

View File

@ -295,4 +295,9 @@ public class AppleTileEditor extends TileEditor {
+ DataUtilities.getHexValue((int) (color.getGreen() * 255))
+ DataUtilities.getHexValue((int) (color.getBlue() * 255));
}
@Override
public void copyData() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -10,9 +10,12 @@
package org.badvision.outlaweditor.apple.dhgr;
import java.util.HashMap;
import org.badvision.outlaweditor.apple.*;
import javafx.event.EventHandler;
import javafx.scene.control.Menu;
import javafx.scene.input.Clipboard;
import javafx.scene.input.DataFormat;
import javafx.scene.input.MouseEvent;
import org.badvision.outlaweditor.api.Platform;
import org.badvision.outlaweditor.data.DataObserver;
@ -77,5 +80,12 @@ public class AppleDHGRImageEditor extends AppleImageEditor implements EventHandl
*/
@Override
public void crop(int newWidth, int newHeight) {
}
}
@Override
public void copyData() {
java.util.Map<DataFormat, Object> clip = new HashMap<>();
clip.put(DataFormat.PLAIN_TEXT, AppleNTSCGraphics.generateDhgrMonitorListing(getPlatformData()));
Clipboard.getSystemClipboard().setContent(clip);
}
}

View File

@ -250,4 +250,9 @@ public class AppleDHGRTileEditor extends TileEditor {
TileUtils.redrawTile(getEntity());
}
}
@Override
public void copyData() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -41,6 +41,9 @@ public abstract class ApplicationMenuController {
@FXML
abstract public void onEditCopy(ActionEvent event);
@FXML
abstract public void onEditCopyData(ActionEvent event);
@FXML
abstract public void onEditPaste(ActionEvent event);

View File

@ -78,6 +78,14 @@ public class ApplicationMenuControllerImpl extends ApplicationMenuController {
}
}
@Override
public void onEditCopyData(ActionEvent event) {
ApplicationUIController mainController = ApplicationUIController.getController();
if (mainController.getVisibleEditor() != null) {
mainController.getVisibleEditor().copyData();
}
}
@Override
public void onEditPaste(ActionEvent event) {
ApplicationUIController mainController = ApplicationUIController.getController();

View File

@ -19,6 +19,7 @@
<items>
<MenuItem mnemonicParsing="false" onAction="#onEditSelect" text="Select" />
<MenuItem mnemonicParsing="false" onAction="#onEditCopy" text="Copy" />
<MenuItem mnemonicParsing="false" onAction="#onEditCopyData" text="Copy Data" />
<MenuItem mnemonicParsing="false" onAction="#onEditPaste" text="Paste" />
<MenuItem mnemonicParsing="false" onAction="#performUndo" text="Undo">
<accelerator>