diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 4a0438057..2111239dd 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -74,6 +74,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis static final String ACTION_SELECT_BKCOLOR = "SELECTCOLOR"; static final String ACTION_ZOOMIN = "ZOOMIN"; static final String ACTION_ZOOMOUT = "ZOOMOUT"; + static final String ACTION_ZOOMFIT = "ZOOMFIT"; + static final String ACTION_ZOOMNONE = "ZOOMNONE"; private Timelined timelined; private boolean stillFrame = false; @@ -335,10 +337,22 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis zoomOutButton.setActionCommand(ACTION_ZOOMOUT); zoomOutButton.setToolTipText(AppStrings.translate("button.zoomout.hint")); + JButton zoomFitButton = new JButton(View.getIcon("zoomfit16")); + zoomFitButton.addActionListener(this); + zoomFitButton.setActionCommand(ACTION_ZOOMFIT); + zoomFitButton.setToolTipText(AppStrings.translate("button.zoomfit.hint")); + + JButton zoomNoneButton = new JButton(View.getIcon("zoomnone16")); + zoomNoneButton.addActionListener(this); + zoomNoneButton.setActionCommand(ACTION_ZOOMNONE); + zoomNoneButton.setToolTipText(AppStrings.translate("button.zoomnone.hint")); + buttonsPanel.add(percentLabel); updateZoom(); buttonsPanel.add(zoomInButton); buttonsPanel.add(zoomOutButton); + buttonsPanel.add(zoomNoneButton); + buttonsPanel.add(zoomFitButton); buttonsPanel.add(selectColorButton); bottomPanel.add(buttonsPanel, BorderLayout.EAST); add(bottomPanel, BorderLayout.SOUTH); @@ -422,19 +436,18 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis }); } - - private static double roundZoom(double realZoom,int mantisa){ + private static double roundZoom(double realZoom, int mantisa) { double l10 = Math.log10(realZoom); - int lg = (int)(-Math.floor(l10)+mantisa-1); - if(lg<0){ + 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(); + } + 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); + double pctzoom = roundZoom(realZoom * 100, 3); String r = "" + pctzoom; zoom = pctzoom / 100.0; if (r.endsWith(".0")) { @@ -462,15 +475,46 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis break; case ACTION_ZOOMIN: realZoom *= ZOOM_MULTIPLIER; - updateZoom(); + updateZoom(); break; case ACTION_ZOOMOUT: - realZoom /= ZOOM_MULTIPLIER; - updateZoom(); + realZoom /= ZOOM_MULTIPLIER; + updateZoom(); + break; + case ACTION_ZOOMNONE: + realZoom = 1.0; + updateZoom(); + break; + case ACTION_ZOOMFIT: + realZoom = zoomToFit(); + updateZoom(); break; } } + private double zoomToFit() { + if (timelined instanceof BoundedTag) { + RECT bounds = ((BoundedTag) timelined).getRect(new HashSet()); + double w1 = bounds.getWidth() / SWF.unitDivisor; + double h1 = bounds.getHeight() / SWF.unitDivisor; + + double w2 = getWidth(); + double h2 = getHeight(); + + double w; + double h; + h = h1 * w2 / w1; + if (h > h2) { + w = w1 * h2 / h1; + h = h2; + } else { + w = w2; + } + return (double) w / (double) w1; + } + return 1; + } + public void setImage(byte[] data) { setBackground(View.swfBackgroundColor); if (timer != null) { @@ -627,12 +671,6 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis } } } - /*drawable.getTimeline().getObjectsOutlines(frame, frame, stateUnderCursor, mouseButton, m, dss, os); - - //gg.setTransform(AffineTransform.getTranslateInstance(0, 0)); - for(Shape s:os){ - gg.draw(SHAPERECORD.twipToPixelShape(s)); - }*/ img = image; } diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/zoomfit16.png b/src/com/jpexs/decompiler/flash/gui/graphics/zoomfit16.png new file mode 100644 index 000000000..168bcd5ba Binary files /dev/null and b/src/com/jpexs/decompiler/flash/gui/graphics/zoomfit16.png differ diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png b/src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png index cdf0a52fe..73924a771 100644 Binary files a/src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png and b/src/com/jpexs/decompiler/flash/gui/graphics/zoomin16.png differ diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/zoomnone16.png b/src/com/jpexs/decompiler/flash/gui/graphics/zoomnone16.png new file mode 100644 index 000000000..f1c202c54 Binary files /dev/null and b/src/com/jpexs/decompiler/flash/gui/graphics/zoomnone16.png differ diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png b/src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png index 07bf98a79..ab862b796 100644 Binary files a/src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png and b/src/com/jpexs/decompiler/flash/gui/graphics/zoomout16.png differ diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index a5c187174..1afd4d3c9 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -507,4 +507,6 @@ binarydata.swfInside = It looks like there is SWF inside this binary data tag. C #after version 3.0.0 button.zoomin.hint = Zoom in -button.zoomout.hint = Zoom out \ No newline at end of file +button.zoomout.hint = Zoom out +button.zoomfit.hint = Zoom to fit +button.zoomnone.hint = Zoom to 1:1 \ No newline at end of file