diff --git a/OutlawEditor/pom.xml b/OutlawEditor/pom.xml index 0bfc4a97..b37f5e36 100644 --- a/OutlawEditor/pom.xml +++ b/OutlawEditor/pom.xml @@ -111,13 +111,6 @@ - javafx-packager javafx-packager diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/Editor.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/Editor.java index 5627badc..1f1cc817 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/Editor.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/Editor.java @@ -67,7 +67,7 @@ public abstract class Editor implements DataObserver { startY = Math.min(y1, y2); endX = Math.max(x1, x2); endY = Math.max(y1, y2); - if (startX + startY + endX + endY == 0) { + if (startX + startY + endX + endY <= 0) { selectInfo = null; } else { selectInfo = "x1/" + startX + "/y1/" + startY + "/x2/" + endX + "/y2/" + endY; @@ -79,7 +79,6 @@ public abstract class Editor implements DataObserver { } String selectInfo; - public String getSelectionInfo() { if (selectInfo == null) { return getSelectedAllInfo(); diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ImageEditor.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ImageEditor.java index 49cf8d8d..89dab96a 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ImageEditor.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ImageEditor.java @@ -23,7 +23,7 @@ public abstract class ImageEditor extends Editor { public static enum DrawMode { - Toggle, Pencil1px, Pencil3px, Pencil5px, Rectangle, Circle, Stamp + Toggle, Pencil1px, Pencil3px, Pencil5px, Rectangle, Circle, Stamp, Select } abstract public EnumMap getState(); diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/apple/AppleImageEditor.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/apple/AppleImageEditor.java index 7b0c63b4..699e7f3d 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/apple/AppleImageEditor.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/apple/AppleImageEditor.java @@ -7,7 +7,6 @@ * 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 java.io.File; @@ -55,7 +54,10 @@ public class AppleImageEditor extends ImageEditor implements EventHandler state = new EnumMap<>(StateVars.class); + @Override public EnumMap getState() { return state; @@ -113,17 +118,21 @@ public class AppleImageEditor extends ImageEditor implements EventHandler clip = new HashMap<>(); clip.put(DataFormat.IMAGE, currentImage); clip.put(DataFormat.PLAIN_TEXT, "selection/image/" + Application.gameData.getImage().indexOf(getEntity()) + "/" + getSelectionInfo()); Clipboard.getSystemClipboard().setContent(clip); + copyData = Arrays.copyOf(getImageData(), getImageData().length); } @Override @@ -416,6 +449,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler> " + contentPath); if (contentPath.startsWith("selection/map")) { String[] bufferDetails = contentPath.substring(14).split("/"); @@ -437,18 +471,65 @@ public class AppleImageEditor extends ImageEditor implements EventHandler d.getPlatform().equals(getPlatform().name())).findFirst().orElse(null); + if (platformData == null) { + throw new NullPointerException("Unable to paste from source image, no matching platform data."); + } + sourceData = platformData.getValue(); + } + if ("all".equals(bufferDetails[1])) { - Image sourceImage = Application.gameData.getImage().get(imageNumber); - for (PlatformData data : sourceImage.getDisplayData()) { - if (data.getPlatform().equals(getPlatform().toString())) { - setData(Arrays.copyOf(data.getValue(), data.getValue().length)); - redraw(); - return true; + setData(Arrays.copyOf(sourceData, sourceData.length)); + redraw(); + return true; + } else { + int xStart = Integer.parseInt(bufferDetails[2]); + int yStart = Integer.parseInt(bufferDetails[4]); + int xEnd = Integer.parseInt(bufferDetails[6]); + int yEnd = Integer.parseInt(bufferDetails[8]); + byte[] targetData = getImageData(); + int pasteX = lastActionX; + int pasteY = lastActionY; + // fix odd/even: Try to nudge left or right where it might work best. + if ((xStart%2) != pasteX %2) { + if (pasteX == 0 || pasteX % 7 > 3 || (pasteX + (xEnd-xStart)/7) < getWidth()) { + pasteX++; + } else { + pasteX--; } } - System.err.println("Unable to paste from source image, no matching platform data."); - } else { - System.err.println("Unable to paste partial images at this time... sorry. :-("); + System.out.println("Paste to "+pasteX+","+pasteY); + for (int sourceY = yStart, targetY = pasteY; sourceY <= yEnd; sourceY++, targetY++) { + if (targetY < 0 || targetY >= getHeight()) { + continue; + } + int sourceRow = sourceY * getWidth(); + int targetRow = targetY * getWidth(); + for (int sourceX = xStart, targetX = pasteX; sourceX <= xEnd; sourceX++, targetX++) { + if (targetX < 0 || targetX/7 >= getWidth()) { + continue; + } + int targetLoc = targetRow + targetX/7; + byte sourceByte = sourceData[sourceRow + sourceX/7]; + byte targetByte = targetData[targetLoc]; + int targetBit = targetX % 7; + int sourceBit = sourceX % 7; + // Remove hi-bit and image bit + targetByte &= 0x07f ^ (1 << targetBit); + // Copy hi-bit + targetByte |= sourceByte & 0x080; + // Copy x bit + targetByte |= ((sourceByte >> sourceBit) & 1) << targetBit; + targetData[targetLoc] = targetByte; + } + } + setDataAndRedraw(targetData); + return true; } } return false; @@ -456,12 +537,16 @@ public class AppleImageEditor extends ImageEditor implements EventHandler { rescale(newWidth, newHeight); - }, () -> { + }, () -> { crop(newWidth, newHeight); }); }