From 65446df2262b76a3f30811bdf89b5289e857c114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 27 Sep 2014 12:46:19 +0200 Subject: [PATCH] Issue #618 internal viewer: zoom in, zoom out --- .../decompiler/flash/gui/ImagePanel.java | 92 ++++++++++++++---- .../flash/gui/graphics/zoomin16.png | Bin 0 -> 725 bytes .../flash/gui/graphics/zoomout16.png | Bin 0 -> 708 bytes .../flash/gui/locales/MainFrame.properties | 6 +- 4 files changed, 78 insertions(+), 20 deletions(-) create mode 100644 src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png create mode 100644 src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index a93e9ce53..4a0438057 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -53,6 +53,7 @@ import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -71,6 +72,8 @@ import javax.swing.JPanel; public final class ImagePanel extends JPanel implements ActionListener, MediaDisplay { static final String ACTION_SELECT_BKCOLOR = "SELECTCOLOR"; + static final String ACTION_ZOOMIN = "ZOOMIN"; + static final String ACTION_ZOOMOUT = "ZOOMOUT"; private Timelined timelined; private boolean stillFrame = false; @@ -86,7 +89,12 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis private final IconPanel iconPanel; private int time = 0; private int selectedDepth = -1; - public double zoom = 1.0; + private double zoom = 1.0; + private double realZoom = 1.0; + private JLabel percentLabel = new JLabel("100%"); + + public static final int ZOOM_DECADE_STEPS = 10; + public static final double ZOOM_MULTIPLIER = Math.pow(10, 1.0 / ZOOM_DECADE_STEPS); public void selectDepth(int depth) { if (depth != selectedDepth) { @@ -316,6 +324,21 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis selectColorButton.addActionListener(this); selectColorButton.setActionCommand(ACTION_SELECT_BKCOLOR); selectColorButton.setToolTipText(AppStrings.translate("button.selectbkcolor.hint")); + + JButton zoomInButton = new JButton(View.getIcon("zoomin16")); + zoomInButton.addActionListener(this); + zoomInButton.setActionCommand(ACTION_ZOOMIN); + zoomInButton.setToolTipText(AppStrings.translate("button.zoomin.hint")); + + JButton zoomOutButton = new JButton(View.getIcon("zoomout16")); + zoomOutButton.addActionListener(this); + zoomOutButton.setActionCommand(ACTION_ZOOMOUT); + zoomOutButton.setToolTipText(AppStrings.translate("button.zoomout.hint")); + + buttonsPanel.add(percentLabel); + updateZoom(); + buttonsPanel.add(zoomInButton); + buttonsPanel.add(zoomOutButton); buttonsPanel.add(selectColorButton); bottomPanel.add(buttonsPanel, BorderLayout.EAST); add(bottomPanel, BorderLayout.SOUTH); @@ -399,21 +422,52 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis }); } + + private static double roundZoom(double realZoom,int mantisa){ + double l10 = Math.log10(realZoom); + int lg = (int)(-Math.floor(l10)+mantisa-1); + if(lg<0){ + lg = 0; + } + BigDecimal bd = new BigDecimal(String.valueOf(realZoom)).setScale(lg, BigDecimal.ROUND_HALF_UP); + return bd.doubleValue(); + } + + private void updateZoom() { + double pctzoom = roundZoom(realZoom*100, 3); + String r = "" + pctzoom; + zoom = pctzoom / 100.0; + if (r.endsWith(".0")) { + r = r.substring(0, r.length() - 2); + } + percentLabel.setText("" + r + "%"); + drawFrame(); + } + @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals(ACTION_SELECT_BKCOLOR)) { - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - Color newColor = JColorChooser.showDialog(null, AppStrings.translate("dialog.selectbkcolor.title"), View.swfBackgroundColor); - if (newColor != null) { - View.swfBackgroundColor = newColor; - setBackground(newColor); - repaint(); + switch (e.getActionCommand()) { + case ACTION_SELECT_BKCOLOR: + View.execInEventDispatch(new Runnable() { + @Override + public void run() { + Color newColor = JColorChooser.showDialog(null, AppStrings.translate("dialog.selectbkcolor.title"), View.swfBackgroundColor); + if (newColor != null) { + View.swfBackgroundColor = newColor; + setBackground(newColor); + repaint(); + } } - } - }); - + }); + break; + case ACTION_ZOOMIN: + realZoom *= ZOOM_MULTIPLIER; + updateZoom(); + break; + case ACTION_ZOOMOUT: + realZoom /= ZOOM_MULTIPLIER; + updateZoom(); + break; } } @@ -520,7 +574,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis } private static SerializableImage getFrame(SWF swf, int frame, int time, Timelined drawable, DepthState stateUnderCursor, int mouseButton, int selectedDepth, double zoom) { - String key = "drawable_" + frame + "_" + drawable.hashCode() + "_" + mouseButton + "_depth" + selectedDepth + "_" + (stateUnderCursor == null ? "out" : stateUnderCursor.hashCode())+"_"+zoom; + String key = "drawable_" + frame + "_" + drawable.hashCode() + "_" + mouseButton + "_depth" + selectedDepth + "_" + (stateUnderCursor == null ? "out" : stateUnderCursor.hashCode()) + "_" + zoom; SerializableImage img = SWF.getFromCache(key); if (img == null) { if (drawable instanceof BoundedTag) { @@ -529,13 +583,13 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (rect == null) { //??? Why? rect = new RECT(0, 0, 1, 1); } - int width = (int)(rect.getWidth()*zoom); - int height = (int)(rect.getHeight()*zoom); + int width = (int) (rect.getWidth() * zoom); + int height = (int) (rect.getHeight() * zoom); SerializableImage image = new SerializableImage((int) (width / SWF.unitDivisor) + 1, (int) (height / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB); image.fillTransparent(); Matrix m = new Matrix(); - m.translate(-rect.Xmin, -rect.Ymin); + m.translate(-rect.Xmin * zoom, -rect.Ymin * zoom); m.scale(zoom); drawable.getTimeline().toImage(frame, time, frame, stateUnderCursor, mouseButton, image, m, new ColorTransform()); @@ -654,8 +708,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis List outlines = new ArrayList<>(); Matrix m = new Matrix(); RECT rect = timelined.getTimeline().displayRect; - m.translate(-rect.Xmin, -rect.Ymin); - m.scale(1); + m.translate(-rect.Xmin * zoom, -rect.Ymin * zoom); + m.scale(zoom); timelined.getTimeline().getObjectsOutlines(frame, time, frame, stateUnderCursor, mouseButton, m, objs, outlines); for (int i = 0; i < outlines.size(); i++) { diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png b/src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png new file mode 100644 index 0000000000000000000000000000000000000000..cdf0a52fe03715dcdf399e59c8071c4572dc51f7 GIT binary patch literal 725 zcmV;`0xJE9P)m%7v+TE=2L@ zAc44q=tejYU5HLZGooZ=NXsV%)bU*sTokj@jZSo^9&w{ke7#VNQ*1zG!rIRk_@ zCqOr;g6B6CM1oPv1(~U4k@Gd+5tN0(j@GA*K*busv3Lb0UyXuowiRkTRZ#85JN!eC z_8ZVW>+upx5C#N|BTv2dK_EW@%(@F6yu1sZv>T3gm&*mIkvej1R4=RyYw#mS zx}c)#2z<)=VQ1|=ux>5PwjVE+J!Q84EQyG-j9SFYV*6AQj$Gb(7!KJE!k5iQ@O3K$ z@0NQZ)>b7&TaFd~Ciolk*Q(7cL+9cB`Y;G@rr`tk5Hdjv+))zSdlF#gI!>6`zB<@i zaKYP!9!Pl&5VMjydlq1x&}37{RQY+SSBXX-w?kCLKK%bXFYU6{?d+nH00000NkvXX Hu0mjfTSP*+ literal 0 HcmV?d00001 diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png b/src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png new file mode 100644 index 0000000000000000000000000000000000000000..07bf98a79cfea526e250703356dbefdb6b80d166 GIT binary patch literal 708 zcmV;#0z3VQP)TNkCP1&*^7LC~A?iZQEu_hKZoQoXI zA7tfTv}|~Fb8b^XuP>qvDk=)P)vYKtT12;}bKn-mwHWl`1Bb)&{XXC4IY$Nnvj5@N zfekg1Y}gcI!)Cq|u?lR+A{2&=d~S$}&0ei1|7pO6jkZ$6%&{R8TNpk>=dV#j&aWqO zgE~4pNU_-giktFkY-J5_XDlv`7+j?n3mXtxgadILp+c<9cr~t!x1LM6m69Z~V#pLL z22Cs~BoIdtZHTjo7Q|_U0a2OmSF=gCGFB$RVZIP(pixmBqE!^15yd!#9Z{Wh)zB%o zikBFa!WJPvMB(noe(U;k1e~Y|r$}@wh*Ymykd6>E3t69z5DT&Jq-fSG-dPdU{SG;i zbSb3<`RfKgJD|lQC`6(Cdut1PbDV&$M=Y?U)x)A(0iQN+gAeOBg2Z6fr$_Is!%M70 z=n*z7{*s%3rO7yazIO)}qa&~o@WZ=R>!b#mOSR zlCR8M*iRy2j7!PmWiiegA>Og~W1?FLk0*NI^}`$RW