From f0bc22f6de7ffd342fe5815780c513369df0b949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 31 Dec 2022 20:32:21 +0100 Subject: [PATCH] Spliting multiple points --- .../decompiler/flash/gui/ImagePanel.java | 73 ++++++++------- .../flash/gui/PointUpdateListener.java | 4 +- .../decompiler/flash/gui/PreviewPanel.java | 88 +++++++------------ 3 files changed, 76 insertions(+), 89 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 1267330dc..c5f41956e 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -281,8 +281,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { private List pointsUnderCursor = new ArrayList<>(); private List selectedPoints = new ArrayList<>(); - private Integer pathPointUnderCursor = null; - private Double pathPointPosition = null; + private List pathPointsUnderCursor = new ArrayList<>(); private DisplayPoint closestPoint = null; @@ -336,18 +335,18 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } } - private boolean fireEdgeSplit(List points, int position, double splitPoint) { + private boolean fireEdgeSplit(int position, double splitPoint) { boolean result = true; for (PointUpdateListener listener : pointUpdateListeners) { - result = result && listener.edgeSplit(points, position, splitPoint); + result = result && listener.edgeSplit(position, splitPoint); } return result; } - private boolean firePointRemoved(List points, int position) { + private boolean firePointRemoved(int position) { boolean result = true; for (PointUpdateListener listener : pointUpdateListeners) { - result = result && listener.pointRemoved(points, position); + result = result && listener.pointRemoved(position); } return result; } @@ -1028,7 +1027,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } }); for (int i : selectedPointsDesc) { - firePointRemoved(hilightedPoints, i); + firePointRemoved(i); } selectedPoints.clear(); repaint(); @@ -1156,12 +1155,20 @@ public final class ImagePanel extends JPanel implements MediaDisplay { calculatePointsXY(); } - if (ctrlDown && pathPointUnderCursor != null) { - fireEdgeSplit(hilightedPoints, pathPointUnderCursor, pathPointPosition); + if (ctrlDown && !pathPointsUnderCursor.isEmpty()) { + /*List positions = new ArrayList<>(); + List splitPositions = new ArrayList<>(); + + for(DistanceItem di:pathPointsUnderCursor) { + positions.add(di.pathPoint); + splitPositions.add(di.pathPosition); + }*/ + for (DistanceItem di:pathPointsUnderCursor) { + fireEdgeSplit(di.pathPoint, di.pathPosition); + } selectedPoints.clear(); pointsUnderCursor.clear(); - pathPointUnderCursor = null; - pathPointPosition = 0.0; + pathPointsUnderCursor.clear(); repaint(); } updateScrollBarMinMax(); @@ -1732,23 +1739,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { repaint(); } } - } - - class DistanceItem { - - public double distance; - public int pathPoint; - public double pathPosition; - public DisplayPoint closestPoint; - - public DistanceItem(double distance, int pathPoint, double pathPosition, DisplayPoint closestPoint) { - this.distance = distance; - this.pathPoint = pathPoint; - this.pathPosition = pathPosition; - this.closestPoint = closestPoint; - } - - } + } @Override public void mouseMoved(MouseEvent e) { @@ -1833,11 +1824,11 @@ public final class ImagePanel extends JPanel implements MediaDisplay { distanceList.sort(new Comparator() { @Override public int compare(DistanceItem o1, DistanceItem o2) { - return Double.compare(o1.distance, o2.distance); + return o2.pathPoint - o1.pathPoint; //Double.compare(o1.distance, o2.distance); } }); if (dragStart == null) { - if (!distanceList.isEmpty()) { + /*if (!distanceList.isEmpty()) { DistanceItem di = distanceList.get(0); pathPointUnderCursor = di.pathPoint; pathPointPosition = di.pathPosition; @@ -1846,7 +1837,8 @@ public final class ImagePanel extends JPanel implements MediaDisplay { pathPointUnderCursor = null; pathPointPosition = null; closestPoint = null; - } + }*/ + pathPointsUnderCursor = distanceList; pointsUnderCursor = newPointsUnderCursor; } return; @@ -3426,7 +3418,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { Cursor newCursor; if (!pointsUnderCursor.isEmpty()) { newCursor = movePointCursor; - } else if (pathPointUnderCursor != null) { + } else if (!pathPointsUnderCursor.isEmpty()) { if (iconPanel.isCtrlDown()) { newCursor = addPointCursor; } else { @@ -3970,3 +3962,20 @@ public final class ImagePanel extends JPanel implements MediaDisplay { return null; } } + + +class DistanceItem { + + public double distance; + public int pathPoint; + public double pathPosition; + public DisplayPoint closestPoint; + + public DistanceItem(double distance, int pathPoint, double pathPosition, DisplayPoint closestPoint) { + this.distance = distance; + this.pathPoint = pathPoint; + this.pathPosition = pathPosition; + this.closestPoint = closestPoint; + } + +} \ No newline at end of file diff --git a/src/com/jpexs/decompiler/flash/gui/PointUpdateListener.java b/src/com/jpexs/decompiler/flash/gui/PointUpdateListener.java index 2c5e0ce49..79cbdf24a 100644 --- a/src/com/jpexs/decompiler/flash/gui/PointUpdateListener.java +++ b/src/com/jpexs/decompiler/flash/gui/PointUpdateListener.java @@ -25,7 +25,7 @@ import java.util.List; public interface PointUpdateListener { public void pointsUpdated(List points); - public boolean edgeSplit(List points, int position, double splitPoint); + public boolean edgeSplit(int position, double splitPoint); - public boolean pointRemoved(List points, int position); + public boolean pointRemoved(int position); } diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index b0b38ce1a..ce5cd24ab 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -837,7 +837,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel } @Override - public boolean edgeSplit(List points, int position, double splitPoint) { + public boolean edgeSplit(int position, double splitPoint) { List selectedRecords = new ArrayList<>(); List otherRecords = null; @@ -860,7 +860,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel Reference importantRecordPosRef = new Reference<>(0); - if (splitRecords(importantRecordPosRef, points, selectedRecords, position, splitPoint) && otherRecords != null) { + if (splitRecords(importantRecordPosRef, selectedRecords, position, splitPoint) && otherRecords != null) { int importantRecordPos = importantRecordPosRef.getVal(); int otherPosition = 0; int otherImportantRecordPos = 0; @@ -886,15 +886,15 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel break; } } - splitRecords(importantRecordPosRef, null, otherRecords, otherPosition, splitPoint); + splitRecords(importantRecordPosRef, otherRecords, otherPosition, splitPoint); } - + refreshHilightedPoints(); clearCache(); displayEditImagePanel.repaint(); return false; } - private boolean splitRecords(Reference importantRecordPosRef, List points, List selectedRecords, int position, double splitPoint) { + private boolean splitRecords(Reference importantRecordPosRef, List selectedRecords, int position, double splitPoint) { int pointsPos = 0; int x = 0; int y = 0; @@ -920,10 +920,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel ser.deltaX -= newSer.deltaX; ser.deltaY -= newSer.deltaY; ser.simplify(); - selectedRecords.add(i + 1, newSer); - if (points != null) { - points.add(position, new DisplayPoint(new Point2D.Double(x + ser.deltaX, y + ser.deltaY))); - } + selectedRecords.add(i + 1, newSer); importantRecordPosRef.setVal(importantRecordPos); return true; } @@ -956,12 +953,6 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel newCer.anchorDeltaX = (int) Math.round(right.get(2).getX() - right.get(1).getX()); newCer.anchorDeltaY = (int) Math.round(right.get(2).getY() - right.get(1).getY()); selectedRecords.add(i + 1, newCer); - if (points != null) { - points.remove(position); - points.add(position, new DisplayPoint(new Point2D.Double(left.get(1).getX(), left.get(1).getY()), false)); - points.add(position + 1, new DisplayPoint(new Point2D.Double(left.get(2).getX(), left.get(2).getY()))); - points.add(position + 2, new DisplayPoint(new Point2D.Double(right.get(1).getX(), right.get(1).getY()), false)); - } importantRecordPosRef.setVal(importantRecordPos); return true; } @@ -983,7 +974,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel } @Override - public boolean pointRemoved(List points, int position) { + public boolean pointRemoved(int position) { List selectedRecords = new ArrayList<>(); List otherRecords = null; @@ -1005,7 +996,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel } Reference importantRecordPosRef = new Reference<>(0); - if (removePoint(importantRecordPosRef, points, selectedRecords, position) && otherRecords != null) { + if (removePoint(importantRecordPosRef, selectedRecords, position) && otherRecords != null) { int importantRecordPos = importantRecordPosRef.getVal(); int otherPosition = 0; int otherImportantRecordPos = 0; @@ -1031,15 +1022,15 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel break; } } - removePoint(importantRecordPosRef, null, otherRecords, otherPosition); + removePoint(importantRecordPosRef, otherRecords, otherPosition); } - + refreshHilightedPoints(); clearCache(); displayEditImagePanel.repaint(); return true; } - private boolean removePoint(Reference importantRecordPosRef, List points, List selectedRecords, int position) { + private boolean removePoint(Reference importantRecordPosRef,List selectedRecords, int position) { int pointsPos = 0; int importantRecordPos = 0; int x = 0; @@ -1065,11 +1056,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel nextSer.generalLineFlag = true; nextSer.deltaX += ser.deltaX; nextSer.deltaY += ser.deltaY; - selectedRecords.remove(i); - - if (points != null) { - points.remove(position); - } + selectedRecords.remove(i); importantRecordPosRef.setVal(importantRecordPos); return true; @@ -1078,11 +1065,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel CurvedEdgeRecord cer = (CurvedEdgeRecord) nextRec; ser.generalLineFlag = true; ser.deltaX += cer.controlDeltaX + cer.anchorDeltaX; - ser.deltaY += cer.controlDeltaY + cer.anchorDeltaY; - if (points != null) { - points.remove(position + 1); - points.remove(position); - } + ser.deltaY += cer.controlDeltaY + cer.anchorDeltaY; selectedRecords.remove(i + 1); importantRecordPosRef.setVal(importantRecordPos); return true; @@ -1101,10 +1084,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel ser.deltaX = cer.controlDeltaX + cer.anchorDeltaX; ser.deltaY = cer.controlDeltaY + cer.anchorDeltaY; ser.simplify(); - selectedRecords.set(i, ser); - if (points != null) { - points.remove(position); - } + selectedRecords.set(i, ser); //No need to update otherRecords importantRecordPosRef.setVal(importantRecordPos); return false; @@ -1118,12 +1098,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel ser.deltaY = cer.controlDeltaY + cer.anchorDeltaY + nextCer.controlDeltaY + nextCer.anchorDeltaY; ser.simplify(); selectedRecords.set(i, ser); - selectedRecords.remove(i + 1); - if (points != null) { - points.remove(pointsPos + 2); - points.remove(pointsPos + 1); - points.remove(pointsPos); - } + selectedRecords.remove(i + 1); importantRecordPosRef.setVal(importantRecordPos); return true; } @@ -1133,11 +1108,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel nextSer.deltaX += cer.controlDeltaX + cer.anchorDeltaX; nextSer.deltaY += cer.controlDeltaY + cer.anchorDeltaY; nextSer.simplify(); - selectedRecords.remove(i); - if (points != null) { - points.remove(pointsPos + 1); - points.remove(pointsPos); - } + selectedRecords.remove(i); importantRecordPosRef.setVal(importantRecordPos); return true; } @@ -2258,8 +2229,6 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel displayEditShowEndButton.setVisible(false); morphShowSpace.setVisible(false); - List selectedRecords = new ArrayList<>(); - if (displayEditTag instanceof ShapeTag) { ShapeTag shape = (ShapeTag) displayEditTag; @@ -2268,9 +2237,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel if (shape instanceof DefineShape4Tag) { DefineShape4Tag shape4 = (DefineShape4Tag) shape; oldShapeEdgeBounds = shape4.edgeBounds; - } - - selectedRecords = shape.shapes.shapeRecords; + } } if (displayEditTag instanceof MorphShapeTag) { MorphShapeTag morphShape = (MorphShapeTag) displayEditTag; @@ -2282,14 +2249,27 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel DefineMorphShape2Tag morphShape2 = (DefineMorphShape2Tag) morphShape; oldShapeEdgeBounds = morphShape2.startEdgeBounds; oldEndShapeEdgeBounds = morphShape2.endEdgeBounds; - } - + } + } + refreshHilightedPoints(); + + mainPanel.setEditingStatus(); + } + + private void refreshHilightedPoints() { + List selectedRecords = new ArrayList<>(); + if (displayEditTag instanceof ShapeTag) { + ShapeTag shape = (ShapeTag) displayEditTag; + selectedRecords = shape.shapes.shapeRecords; + } + if (displayEditTag instanceof MorphShapeTag) { + MorphShapeTag morphShape = (MorphShapeTag) displayEditTag; if (morphDisplayMode == MORPH_START) { selectedRecords = morphShape.startEdges.shapeRecords; } if (morphDisplayMode == MORPH_END) { selectedRecords = morphShape.endEdges.shapeRecords; - } + } } int x = 0; int y = 0; @@ -2320,8 +2300,6 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel y = rec.changeY(y); } displayEditImagePanel.setHilightedPoints(points); - - mainPanel.setEditingStatus(); } private void transformDisplayEditTagButtonActionPerformed(ActionEvent evt) {