From e38f404878a8c7691b04a0f337313984999dfa87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 6 Oct 2024 18:22:12 +0200 Subject: [PATCH] Remove frame. --- .../decompiler/flash/timeline/DepthState.java | 1 + .../decompiler/flash/easygui/MainFrame.java | 11 +- .../flash/easygui/TimelineBodyPanel.java | 142 +++++++++++++++++- .../decompiler/flash/gui/ImagePanel.java | 1 + 4 files changed, 151 insertions(+), 4 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/DepthState.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/DepthState.java index dcdc034f0..062af5c5f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/DepthState.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/DepthState.java @@ -241,6 +241,7 @@ public class DepthState { public void setMATRIX(MATRIX matrix) { this.matrix = matrix; this.placeObjectTag.setMatrix(matrix); + this.placeObjectTag.setPlaceFlagHasMatrix(matrix != null); } /** diff --git a/src/com/jpexs/decompiler/flash/easygui/MainFrame.java b/src/com/jpexs/decompiler/flash/easygui/MainFrame.java index 5e60b7eda..797bc15a9 100644 --- a/src/com/jpexs/decompiler/flash/easygui/MainFrame.java +++ b/src/com/jpexs/decompiler/flash/easygui/MainFrame.java @@ -102,6 +102,7 @@ public class MainFrame extends JFrame { if (pl != null) { timelinePanel.setDepth(pl.getDepth()); } + transformPanel.setVisible(pl != null); } }); @@ -114,7 +115,7 @@ public class MainFrame extends JFrame { MATRIX previousMatrix = null; synchronized (stagePanel) { DepthState ds = stagePanel.getTimelined().getTimeline().getFrame(frame).layers.get(depth); - previousMatrix = ds.matrix; + previousMatrix = ds.placeObjectTag.getMatrix(); } final Point2D regPoint = stagePanel.getRegistrationPoint(); @@ -129,7 +130,9 @@ public class MainFrame extends JFrame { public void doOperation() { timelinePanel.setFrame(frame, depth); DepthState ds = stagePanel.getTimelined().getTimeline().getFrame(frame).layers.get(depth); - ds.setMATRIX(newMatrix); + ds.placeObjectTag.setMatrix(newMatrix); + ds.placeObjectTag.setPlaceFlagHasMatrix(newMatrix != null); + stagePanel.getTimelined().resetTimeline(); stagePanel.repaint(); if (transformEnabled()) { stagePanel.freeTransformDepth(depth); @@ -144,7 +147,9 @@ public class MainFrame extends JFrame { public void undoOperation() { timelinePanel.setFrame(frame, depth); DepthState ds = stagePanel.getTimelined().getTimeline().getFrame(frame).layers.get(depth); - ds.setMATRIX(fpreviousMatrix); + ds.placeObjectTag.setMatrix(fpreviousMatrix); + ds.placeObjectTag.setPlaceFlagHasMatrix(fpreviousMatrix != null); + stagePanel.getTimelined().resetTimeline(); stagePanel.repaint(); if (transformEnabled()) { stagePanel.freeTransformDepth(depth); diff --git a/src/com/jpexs/decompiler/flash/easygui/TimelineBodyPanel.java b/src/com/jpexs/decompiler/flash/easygui/TimelineBodyPanel.java index 61aeb05de..64d5483a6 100644 --- a/src/com/jpexs/decompiler/flash/easygui/TimelineBodyPanel.java +++ b/src/com/jpexs/decompiler/flash/easygui/TimelineBodyPanel.java @@ -444,17 +444,23 @@ public class TimelineBodyPanel extends JPanel implements MouseListener, KeyListe addKeyFrameEmptyBeforeMenuItem.addActionListener(this::addKeyFrameEmptyBefore); JMenuItem addFrameMenuItem = new JMenuItem("Add frame"); addFrameMenuItem.addActionListener(this::addFrame); + JMenuItem removeFrameMenuItem = new JMenuItem("Remove frame"); + removeFrameMenuItem.addActionListener(this::removeFrame); if (!thisEmpty) { popupMenu.add(addKeyFrameMenuItem); } - + if (thisEmpty && previousEmpty && somethingBefore && !somethingAfter) { popupMenu.add(addKeyFrameEmptyBeforeMenuItem); } if (!emptyDepth) { popupMenu.add(addFrameMenuItem); } + + if (!thisEmpty || somethingAfter) { + popupMenu.add(removeFrameMenuItem); + } if (popupMenu.getComponentCount() > 0) { popupMenu.show(this, e.getX(), e.getY()); @@ -462,6 +468,140 @@ public class TimelineBodyPanel extends JPanel implements MouseListener, KeyListe } } + private void removeFrame(ActionEvent e) { + final int fframe = frame; + final int fdepth = depth; + undoManager.doOperation(new TimelinedTagListDoableOperation(timeline.timelined) { + + @Override + public void doOperation() { + super.doOperation(); + Timelined timelined = timeline.timelined; + ReadOnlyTagList tags = timelined.getTags(); + int f = timelined.getFrameCount(); + List lastFrameDepthTags = new ArrayList<>(); + DepthState ds = timeline.getFrame(fframe).layers.get(fdepth); + if (ds != null && ds.key) { + PlaceObjectTypeTag po = ds.placeObjectTag; + ShowFrameTag sf = timeline.getFrame(fframe).showFrameTag; + int pos = sf == null ? tags.size() : timelined.indexOfTag(sf); + for (int i = pos + 1; i < tags.size(); i++) { + Tag t = tags.get(i); + if (t instanceof RemoveObject2Tag) { + RemoveObject2Tag rt = (RemoveObject2Tag) t; + if (rt.depth == fdepth) { + timelined.removeTag(po); + timelined.removeTag(rt); + i--; + i--; + } + } + if (t instanceof ShowFrameTag) { + break; + } + } + } + + + + boolean endsWithRemove = false; + for (int i = tags.size() - 1; i >= 0; i--) { + Tag t = tags.get(i); + if (t instanceof PlaceObjectTypeTag) { + PlaceObjectTypeTag pt = (PlaceObjectTypeTag) t; + if (pt.getDepth() == fdepth) { + break; + } + } + if (t instanceof RemoveTag) { + RemoveTag rt = (RemoveTag) t; + if (rt.getDepth() == fdepth) { + endsWithRemove = true; + break; + } + } + } + + for (int i = tags.size() - 1; i >= 0; i--) { + Tag t = tags.get(i); + if (t instanceof PlaceObjectTypeTag) { + PlaceObjectTypeTag pt = (PlaceObjectTypeTag) t; + if (pt.getDepth() == fdepth) { + lastFrameDepthTags.add(pt); + timelined.removeTag(i); + } + } + if (t instanceof RemoveTag) { + RemoveTag rt = (RemoveTag) t; + if (rt.getDepth() == fdepth) { + lastFrameDepthTags.add(rt); + timelined.removeTag(i); + } + } + if (t instanceof ShowFrameTag) { + for (Tag lt : lastFrameDepthTags) { + timelined.addTag(i, lt); + } + lastFrameDepthTags.clear(); + f--; + if (f == fframe) { + break; + } + } + } + + if (!endsWithRemove) { + RemoveTag rt = new RemoveObject2Tag(timelined.getSwf()); + rt.setTimelined(timelined); + rt.setDepth(fdepth); + Tag lt = tags.get(tags.size() - 1); + if (lt instanceof ShowFrameTag) { + timelined.addTag(tags.size() - 1, rt); + } else { + timelined.addTag(lt); + } + } + + + timelined.resetTimeline(); + + /*System.err.println("=====AFTER======="); + f = 0; + int i = 0; + for (Tag t : timelined.getTags()) { + if (t instanceof ShowFrameTag) { + System.err.println("" + i + ": frame " + f); + f++; + } else { + System.err.println("" + i + ": " + t); + } + i++; + }*/ + + timeline = timelined.getTimeline(); + + refresh(); + fireChanged(); + repaint(); + } + + @Override + public void undoOperation() { + super.undoOperation(); + timeline = timeline.timelined.getTimeline(); + + refresh(); + fireChanged(); + repaint(); + } + + @Override + public String getDescription() { + return "Remove frame"; + } + }); + } + private void addKeyFrame(ActionEvent e) { if (timeline.getFrame(frame).layers.get(depth).key) { return; diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index f88473e87..588c22fd1 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -1156,6 +1156,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { if (transformSelectionMode) { if (mode == Cursor.DEFAULT_CURSOR) { freeTransformDepth(-1); + selectDepth(-1); firePlaceObjectSelected(); } } else if ((altDown && !selectionMode) || selectionMode) {