Added #1731 Image viewer zoom support

This commit is contained in:
Jindra Petřík
2022-10-23 16:50:55 +02:00
parent 41fe9616a1
commit 1bfbe84ee9
6 changed files with 175 additions and 44 deletions
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.ReadOnlyTagList;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.action.Action;
@@ -48,6 +49,7 @@ import com.jpexs.decompiler.flash.types.SOUNDINFO;
import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle;
import com.jpexs.decompiler.flash.tags.DefineButton2Tag;
import com.jpexs.decompiler.flash.tags.DefineButtonTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.DisplayObjectCacheKey;
import com.jpexs.decompiler.flash.types.BUTTONCONDACTION;
import com.jpexs.helpers.ByteArrayRange;
@@ -93,6 +95,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
@@ -165,6 +168,8 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
private TextTag newTextTag;
private boolean showObjectsUnderCursor;
private int msPerFrame;
private final boolean lowQuality = false;
@@ -1506,7 +1511,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
return zoomAvailable;
}
public void setTimelined(final Timelined drawable, final SWF swf, int frame) {
public void setTimelined(final Timelined drawable, final SWF swf, int frame, boolean showObjectsUnderCursor) {
Stage stage = new Stage(drawable) {
@Override
public void callFrame(int frame) {
@@ -1611,6 +1616,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
}
}
this.showObjectsUnderCursor = showObjectsUnderCursor;
fireMediaDisplayStateChanged();
}
@@ -1720,6 +1726,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
fireMediaDisplayStateChanged();
}
showObjectsUnderCursor = false;
textTag = null;
newTextTag = null;
displayObjectCache.clear();
@@ -2199,32 +2206,39 @@ public final class ImagePanel extends JPanel implements MediaDisplay {
StringBuilder ret = new StringBuilder();
if (cursorPosition != null) {
ret.append(" [").append(cursorPosition.x).append(",").append(cursorPosition.y).append("] : ");
ret.append(" [").append(cursorPosition.x).append(",").append(cursorPosition.y).append("]");
if (showObjectsUnderCursor) {
ret.append(" : ");
}
}
boolean handCursor = renderContext.mouseOverButton != null;
boolean first = true;
for (int i = renderContext.stateUnderCursor.size() - 1; i >= 0; i--) {
DepthState ds = renderContext.stateUnderCursor.get(i);
if (!first) {
ret.append(", ");
if (showObjectsUnderCursor) {
boolean first = true;
for (int i = renderContext.stateUnderCursor.size() - 1; i >= 0; i--) {
DepthState ds = renderContext.stateUnderCursor.get(i);
if (!first) {
ret.append(", ");
}
first = false;
CharacterTag c = swf.getCharacter(ds.characterId);
ret.append(c.toString());
if (ds.depth > 0) {
ret.append(" ");
ret.append(AppStrings.translate("imagePanel.depth"));
ret.append(" ");
ret.append(ds.depth);
}
}
first = false;
CharacterTag c = swf.getCharacter(ds.characterId);
ret.append(c.toString());
if (ds.depth > 0) {
ret.append(" ");
ret.append(AppStrings.translate("imagePanel.depth"));
ret.append(" ");
ret.append(ds.depth);
if (first) {
ret.append(" - ");
}
}
if (first) {
ret.append(" - ");
}
ButtonTag lastMouseOverButton;
synchronized (ImagePanel.class) {
if (timer == thisTimer) {
@@ -47,6 +47,7 @@ import com.jpexs.decompiler.flash.exporters.ShapeExporter;
import com.jpexs.decompiler.flash.exporters.SoundExporter;
import com.jpexs.decompiler.flash.exporters.SymbolClassExporter;
import com.jpexs.decompiler.flash.exporters.TextExporter;
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.modes.BinaryDataExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ButtonExportMode;
import com.jpexs.decompiler.flash.exporters.modes.FontExportMode;
@@ -115,12 +116,18 @@ import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG4Tag;
import com.jpexs.decompiler.flash.tags.DefineBitsTag;
import com.jpexs.decompiler.flash.tags.DefineShape2Tag;
import com.jpexs.decompiler.flash.tags.DefineSoundTag;
import com.jpexs.decompiler.flash.tags.DefineSpriteTag;
import com.jpexs.decompiler.flash.tags.DoActionTag;
import com.jpexs.decompiler.flash.tags.DoInitActionTag;
import com.jpexs.decompiler.flash.tags.EndTag;
import com.jpexs.decompiler.flash.tags.FileAttributesTag;
import com.jpexs.decompiler.flash.tags.JPEGTablesTag;
import com.jpexs.decompiler.flash.tags.MetadataTag;
import com.jpexs.decompiler.flash.tags.PlaceObjectTag;
import com.jpexs.decompiler.flash.tags.ShowFrameTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.TagInfo;
import com.jpexs.decompiler.flash.tags.UnknownTag;
@@ -150,8 +157,18 @@ import com.jpexs.decompiler.flash.treeitems.FolderItem;
import com.jpexs.decompiler.flash.treeitems.HeaderItem;
import com.jpexs.decompiler.flash.treeitems.SWFList;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import com.jpexs.decompiler.flash.types.CXFORM;
import com.jpexs.decompiler.flash.types.FILLSTYLE;
import static com.jpexs.decompiler.flash.types.FILLSTYLE.CLIPPED_BITMAP;
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
import com.jpexs.decompiler.flash.types.MATRIX;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE;
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
import com.jpexs.decompiler.flash.types.sound.SoundFormat;
import com.jpexs.decompiler.flash.xfl.FLAVersion;
import com.jpexs.helpers.ByteArrayRange;
@@ -193,6 +210,7 @@ import java.awt.event.MouseEvent;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -1846,7 +1864,6 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
}
public Set<SWF> getAllSwfs() {
List<SWF> allSwfs = new ArrayList<>();
for (SWFList slist : getSwfs()) {
@@ -2509,6 +2526,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
new CancellableWorker<Void>() {
private int countAs2 = 0;
private int countAs3 = 0;
@Override
public Void doInBackground() throws Exception {
new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true), new ScriptImporterProgressListener() {
@@ -2696,7 +2714,6 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
ViewMessages.showMessageDialog(MainPanel.this, translate("message.info.importXml"), translate("message.info"), JOptionPane.INFORMATION_MESSAGE, Configuration.showImportXmlInfo);
List<TreeItem> sel = tagTree.getSelected();
Set<SWF> swfs = new HashSet<>();
for (TreeItem item : sel) {
@@ -3612,7 +3629,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (treeItem instanceof SWF) {
SWF swf = (SWF) treeItem;
if (internalViewer) {
previewPanel.showImagePanel(swf, swf, -1);
previewPanel.showImagePanel(swf, swf, -1, true);
} else {
previewPanel.setParametersPanelVisible(false);
//if (flashPanel != null) { //same for flashPanel2
@@ -3637,7 +3654,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
} else if (treeItem instanceof ImageTag) {
ImageTag imageTag = (ImageTag) treeItem;
previewPanel.setImageReplaceButtonVisible(!((Tag) imageTag).isReadOnly() && imageTag.importSupported(), imageTag instanceof DefineBitsJPEG3Tag || imageTag instanceof DefineBitsJPEG4Tag);
previewPanel.showImagePanel(imageTag.getImageCached());
SWF imageSWF = makeTimelinedImage(imageTag);
previewPanel.showImagePanel(imageSWF, imageSWF, 0, false);
} else if ((treeItem instanceof DrawableTag) && (!(treeItem instanceof TextTag)) && (!(treeItem instanceof FontTag)) && internalViewer) {
final Tag tag = (Tag) treeItem;
@@ -3650,11 +3668,11 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
previewPanel.setParametersPanelVisible(false);
previewPanel.showImagePanel(timelined, tag.getSwf(), -1);
previewPanel.showImagePanel(timelined, tag.getSwf(), -1, true);
} else if (treeItem instanceof Frame && internalViewer) {
Frame fn = (Frame) treeItem;
SWF swf = fn.getSwf();
previewPanel.showImagePanel(fn.timeline.timelined, swf, fn.frame);
previewPanel.showImagePanel(fn.timeline.timelined, swf, fn.frame, true);
} else if ((treeItem instanceof SoundTag)) { //&& isInternalFlashViewerSelected() && (Arrays.asList("mp3", "wav").contains(((SoundTag) tagObj).getExportFormat())))) {
previewPanel.showImagePanel(new SerializableImage(View.loadImage("sound32")));
previewPanel.setImageReplaceButtonVisible(((Tag) treeItem).isReadOnly() && (treeItem instanceof DefineSoundTag), false);
@@ -3937,6 +3955,103 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
return makeTimelined(tag, -1);
}
public static SWF makeTimelinedImage(ImageTag imageTag) {
SWF swf = new SWF();
int w = (int) (imageTag.getImageDimension().getWidth() * SWF.unitDivisor);
int h = (int) (imageTag.getImageDimension().getHeight() * SWF.unitDivisor);
swf.displayRect = new RECT(0, w, 0, h);
swf.frameCount = 1;
swf.frameRate = 1;
try {
JPEGTablesTag jpegTablesTag = null;
if (imageTag instanceof DefineBitsTag) {
jpegTablesTag = imageTag.getSwf().getJtt();
}
ImageTag imageTagCopy = (ImageTag) imageTag.cloneTag();
imageTagCopy.setSwf(swf);
int imageCharId = imageTag.getCharacterId();
DefineShape2Tag shapeTag = new DefineShape2Tag(swf);
int shapeCharId = imageCharId + 1;
shapeTag.shapeId = shapeCharId;
shapeTag.shapeBounds = new RECT(swf.displayRect);
SHAPEWITHSTYLE shapeData = new SHAPEWITHSTYLE();
FILLSTYLEARRAY fillStyleArray = new FILLSTYLEARRAY();
FILLSTYLE fillStyles[] = new FILLSTYLE[1];
FILLSTYLE fillStyle = new FILLSTYLE();
fillStyle.bitmapId = imageCharId;
fillStyle.inShape3 = false;
fillStyle.fillStyleType = CLIPPED_BITMAP;
fillStyle.bitmapMatrix = Matrix.getScaleInstance(SWF.unitDivisor).toMATRIX();
fillStyles[0] = fillStyle;
fillStyleArray.fillStyles = fillStyles;
shapeData.fillStyles = fillStyleArray;
shapeData.lineStyles = new LINESTYLEARRAY();
List<SHAPERECORD> shapeRecords = new ArrayList<>();
StyleChangeRecord scr = new StyleChangeRecord();
scr.stateFillStyle0 = true;
scr.fillStyle0 = 1;
shapeRecords.add(scr);
StyleChangeRecord scr2 = new StyleChangeRecord();
scr2.stateMoveTo = true;
scr2.moveDeltaX = 0;
scr2.moveDeltaY = 0;
scr2.calculateBits();
shapeRecords.add(scr2);
StraightEdgeRecord ser1 = new StraightEdgeRecord();
ser1.vertLineFlag = true;
ser1.deltaY = h;
ser1.calculateBits();
shapeRecords.add(ser1);
StraightEdgeRecord ser2 = new StraightEdgeRecord();
ser2.deltaX = w;
shapeRecords.add(ser2);
StraightEdgeRecord ser3 = new StraightEdgeRecord();
ser3.vertLineFlag = true;
ser3.deltaY = -h;
shapeRecords.add(ser3);
StraightEdgeRecord ser4 = new StraightEdgeRecord();
ser4.deltaX = -w;
shapeRecords.add(ser4);
shapeRecords.add(new EndShapeRecord());
shapeData.shapeRecords = shapeRecords;
shapeData.numFillBits = 1;
shapeData.numLineBits = 0;
shapeTag.shapes = shapeData;
PlaceObjectTag placeTag = new PlaceObjectTag(swf, shapeCharId, 1, new Matrix().toMATRIX(), null);
ShowFrameTag showFrameTag = new ShowFrameTag(swf);
EndTag endTag = new EndTag(swf);
if (jpegTablesTag != null) {
swf.addTag(jpegTablesTag);
}
swf.addTag(imageTagCopy);
swf.addTag(shapeTag);
swf.addTag(placeTag);
swf.addTag(showFrameTag);
swf.addTag(endTag);
} catch (InterruptedException | IOException ex) {
//ignore
}
return swf;
}
public static Timelined makeTimelined(final Tag tag, final int fontFrameNum) {
return new Timelined() {
@@ -559,11 +559,11 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
showCardLeft(FLASH_VIEWER_CARD);
}
public void showImagePanel(Timelined timelined, SWF swf, int frame) {
public void showImagePanel(Timelined timelined, SWF swf, int frame, boolean showObjectsUnderCursor) {
showCardLeft(DRAW_PREVIEW_CARD);
parametersPanel.setVisible(false);
imagePlayControls.setMedia(imagePanel);
imagePanel.setTimelined(timelined, swf, frame);
imagePanel.setTimelined(timelined, swf, frame, showObjectsUnderCursor);
}
public void showImagePanel(SerializableImage image) {
@@ -601,7 +601,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
private void showFontPage(FontTag fontTag) {
if (!mainPanel.isAdobeFlashPlayerEnabled() /*|| ft instanceof GFxDefineCompactedFont*/) {
showImagePanel(MainPanel.makeTimelined(fontTag), fontTag.getSwf(), fontPageNum);
showImagePanel(MainPanel.makeTimelined(fontTag), fontTag.getSwf(), fontPageNum, true);
}
}
@@ -619,7 +619,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
public void showTextPanel(TextTag textTag) {
if (!mainPanel.isAdobeFlashPlayerEnabled() /*|| ft instanceof GFxDefineCompactedFont*/) {
showImagePanel(MainPanel.makeTimelined(textTag), textTag.getSwf(), 0);
showImagePanel(MainPanel.makeTimelined(textTag), textTag.getSwf(), 0, true);
}
showCardRight(CARDTEXTPANEL);
@@ -717,7 +717,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
placeSplitPane.setDividerLocation((int) (0.6 * this.getWidth()));
placeGenericPanel.setEditMode(false, tag);
placeImagePanel.selectDepth(-1);
placeImagePanel.setTimelined(((Tag) tag).getTimelined(), ((Tag) tag).getSwf(), frame);
placeImagePanel.setTimelined(((Tag) tag).getTimelined(), ((Tag) tag).getSwf(), frame, true);
placeImagePanel.selectDepth(tag.getDepth());
parametersPanel.setVisible(false);
placeEditButton.setVisible(!tag.isReadOnly());
@@ -1004,7 +1004,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
int pageCount = getFontPageCount(fontTag);
fontPageNum = (fontPageNum + pageCount - 1) % pageCount;
if (!mainPanel.isAdobeFlashPlayerEnabled() /*|| ft instanceof GFxDefineCompactedFont*/) {
imagePanel.setTimelined(MainPanel.makeTimelined(fontTag, fontPageNum), fontTag.getSwf(), 0);
imagePanel.setTimelined(MainPanel.makeTimelined(fontTag, fontPageNum), fontTag.getSwf(), 0, true);
}
}
@@ -1013,7 +1013,7 @@ public class PreviewPanel extends JPersistentSplitPane implements TagEditorPanel
int pageCount = getFontPageCount(fontTag);
fontPageNum = (fontPageNum + 1) % pageCount;
if (!mainPanel.isAdobeFlashPlayerEnabled() /*|| ft instanceof GFxDefineCompactedFont*/) {
imagePanel.setTimelined(MainPanel.makeTimelined(fontTag, fontPageNum), fontTag.getSwf(), 0);
imagePanel.setTimelined(MainPanel.makeTimelined(fontTag, fontPageNum), fontTag.getSwf(), 0, true);
}
}
@@ -730,22 +730,22 @@ public class AddScriptDialog extends AppDialog {
int f = ((MyFrame) ((MyTreeNode) tnode.getParent()).getData()).frame;
Object parent = ((MyTreeNode) tnode.getParent().getParent()).getData();
if (parent instanceof DefineSpriteTag) {
instancePreviewPanel.showImagePanel((DefineSpriteTag) parent, swf, f - 1);
instancePreviewPanel.showImagePanel((DefineSpriteTag) parent, swf, f - 1, true);
} else {
instancePreviewPanel.showImagePanel(swf, swf, f - 1);
instancePreviewPanel.showImagePanel(swf, swf, f - 1, true);
}
} else if (tnode.getData() instanceof DefineSpriteTag) {
instancePreviewPanel.selectImageDepth(-1);
instancePreviewPanel.showImagePanel((DefineSpriteTag) tnode.getData(), swf, -1);
instancePreviewPanel.showImagePanel((DefineSpriteTag) tnode.getData(), swf, -1, true);
} else if (tnode.getData() instanceof MyFrame) {
instancePreviewPanel.selectImageDepth(-1);
int f = ((MyFrame) tnode.getData()).frame;
Object parent = ((MyTreeNode) tnode.getParent()).getData();
if (parent instanceof DefineSpriteTag) {
instancePreviewPanel.showImagePanel((DefineSpriteTag) parent, swf, f - 1);
instancePreviewPanel.showImagePanel((DefineSpriteTag) parent, swf, f - 1, true);
} else {
instancePreviewPanel.showImagePanel(swf, swf, f - 1);
instancePreviewPanel.showImagePanel(swf, swf, f - 1, true);
}
}
checkEnabled();
@@ -759,7 +759,7 @@ public class AddScriptDialog extends AppDialog {
checkEnabled();
return;
}
spriteInitPreviewPanel.showImagePanel(spriteInitList.getSelectedValue(), swf, -1);
spriteInitPreviewPanel.showImagePanel(spriteInitList.getSelectedValue(), swf, -1, true);
checkEnabled();
}
@@ -771,7 +771,7 @@ public class AddScriptDialog extends AppDialog {
checkEnabled();
return;
}
framePreviewPanel.showImagePanel(swf, swf, selectedIndex);
framePreviewPanel.showImagePanel(swf, swf, selectedIndex, true);
int f = selectedIndex + 1;
if (!frameTextField.getText().equals("" + f)) {
@@ -783,7 +783,7 @@ public class AddScriptDialog extends AppDialog {
private void buttonValueChanged(ListSelectionEvent e) {
buttonPreviewPanel.showEmpty();
if (buttonList.getSelectedIndex() >= 0) {
buttonPreviewPanel.showImagePanel(MainPanel.makeTimelined(buttonList.getSelectedValue()), swf, -1);
buttonPreviewPanel.showImagePanel(MainPanel.makeTimelined(buttonList.getSelectedValue()), swf, -1, true);
}
checkEnabled();
@@ -799,14 +799,14 @@ public class AddScriptDialog extends AppDialog {
}
MyTreeNode tnode = (MyTreeNode) selection.getLastPathComponent();
if (tnode.getData() instanceof DefineSpriteTag) {
spriteFramePreviewPanel.showImagePanel((DefineSpriteTag) tnode.getData(), swf, -1);
spriteFramePreviewPanel.showImagePanel((DefineSpriteTag) tnode.getData(), swf, -1, true);
} else if (tnode.getData() instanceof MyFrame) {
int f = ((MyFrame) tnode.getData()).frame;
Object parent = ((MyTreeNode) tnode.getParent()).getData();
if (parent instanceof DefineSpriteTag) {
spriteFramePreviewPanel.showImagePanel((DefineSpriteTag) parent, swf, f - 1);
spriteFramePreviewPanel.showImagePanel((DefineSpriteTag) parent, swf, f - 1, true);
} else {
spriteFramePreviewPanel.showImagePanel(swf, swf, f - 1);
spriteFramePreviewPanel.showImagePanel(swf, swf, f - 1, true);
}
if (!spriteFrameTextField.getText().equals("" + f)) {
spriteFrameTextField.setText("" + f);
@@ -49,7 +49,7 @@ public class TimelineViewPanel extends JPanel {
timeline.setTimelined(timelined);
add(new JPersistentSplitPane(JSplitPane.HORIZONTAL_SPLIT, timeline, previewPanel = new ImagePanel(), Configuration.guiTimeLineSplitPaneDividerLocationPercent));
previewPanel.setTimelined(timelined, timelined.getTimeline().swf, 0);
previewPanel.setTimelined(timelined, timelined.getTimeline().swf, 0, true);
//previewPanel.setPreferredSize(new Dimension(400,300));
previewPanel.pause();
previewPanel.gotoFrame(0);