From 86e6b9df389c6e43bc595389f11c3c9c7a70ce6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 15 Mar 2014 12:06:21 +0100 Subject: [PATCH] mouse movement over buttons fixed --- .../decompiler/flash/gui/ImagePanel.java | 181 ++++++++++-------- .../decompiler/flash/timeline/Frame.java | 1 + .../decompiler/flash/timeline/Timeline.java | 40 ++-- .../com/jpexs/helpers/SerializableImage.java | 8 +- 4 files changed, 133 insertions(+), 97 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index bfaa55b3f..4a4875dd4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -95,15 +95,18 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis private List dss; private List outlines; - public void setImg(SerializableImage img, List dss, List outlines) { - this.img = img; - this.dss = dss; + public synchronized void setOutlines(List dss, List outlines) { this.outlines = outlines; + this.dss = dss; + } + + public void setImg(SerializableImage img) { + this.img = img; calcRect(); repaint(); } - public List getObjectsUnderPoint(Point p) { + public synchronized List getObjectsUnderPoint(Point p) { List ret = new ArrayList<>(); for (int i = 0; i < outlines.size(); i++) { if (outlines.get(i).contains(p)) { @@ -194,65 +197,70 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis iconPanel.removeMouseMotionListener(l); } - private void updatePos(MouseEvent e) { + private void updatePos(MouseEvent e, boolean draw) { if (e == null) { return; } - lastMouseEvent = e; - boolean handCursor = false; - DepthState newStateUnderCursor = null; - if (timelined != null) { - Timeline tim = ((Timelined) timelined).getTimeline(); - BoundedTag bounded = (BoundedTag) timelined; - RECT rect = bounded.getRect(); - int width = rect.getWidth(); - double scale = 1.0; - /*if (width > swf.displayRect.getWidth()) { - scale = (double) swf.displayRect.getWidth() / (double) width; - }*/ - Matrix m = new Matrix(); - m.translate(-rect.Xmin, -rect.Ymin); - m.scale(scale); - Point p = e.getPoint(); - p = iconPanel.toImagePoint(p); - int x = p.x; - int y = p.y; - List objs = new ArrayList<>(); - objs = iconPanel.getObjectsUnderPoint(p); - String ret = ""; + synchronized (iconPanel) { + lastMouseEvent = e; + boolean handCursor = false; + DepthState newStateUnderCursor = null; + if (timelined != null) { - ret += " [" + x + "," + y + "] : "; + Timeline tim = ((Timelined) timelined).getTimeline(); + BoundedTag bounded = (BoundedTag) timelined; + RECT rect = bounded.getRect(); + int width = rect.getWidth(); + double scale = 1.0; + /*if (width > swf.displayRect.getWidth()) { + scale = (double) swf.displayRect.getWidth() / (double) width; + }*/ + Matrix m = new Matrix(); + m.translate(-rect.Xmin, -rect.Ymin); + m.scale(scale); + Point p = e.getPoint(); + p = iconPanel.toImagePoint(p); + int x = p.x; + int y = p.y; + List objs = new ArrayList<>(); + objs = iconPanel.getObjectsUnderPoint(p); + String ret = ""; - boolean first = true; - for (int i = 0; i < objs.size(); i++) { - DepthState ds = objs.get(i); - if (!first) { - ret += ", "; - } - first = false; - CharacterTag c = tim.swf.characters.get(ds.characterId); - if (c instanceof ButtonTag) { - newStateUnderCursor = ds; - handCursor = true; - } - ret += c.toString(); - if (timelined instanceof ButtonTag) { - handCursor = true; - } - } - if (first) { - ret += " - "; - } - debugLabel.setText(ret); + ret += " [" + x + "," + y + "] : "; - if (handCursor) { - iconPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } else { - iconPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - if (newStateUnderCursor != stateUnderCursor) { - stateUnderCursor = newStateUnderCursor; - drawFrame(); + boolean first = true; + for (int i = 0; i < objs.size(); i++) { + DepthState ds = objs.get(i); + if (!first) { + ret += ", "; + } + first = false; + CharacterTag c = tim.swf.characters.get(ds.characterId); + if (c instanceof ButtonTag) { + newStateUnderCursor = ds; + handCursor = true; + } + ret += c.toString(); + if (timelined instanceof ButtonTag) { + handCursor = true; + } + } + if (first) { + ret += " - "; + } + debugLabel.setText(ret); + + if (handCursor) { + iconPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + } else { + iconPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + if (newStateUnderCursor != stateUnderCursor) { + stateUnderCursor = newStateUnderCursor; + if (draw) { + drawFrame(); + } + } } } } @@ -294,14 +302,14 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis @Override public void mousePressed(MouseEvent e) { mouseButton = e.getButton(); - updatePos(e); + updatePos(e, true); drawFrame(); } @Override public void mouseReleased(MouseEvent e) { mouseButton = 0; - updatePos(e); + updatePos(e, true); drawFrame(); } @@ -310,12 +318,12 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis @Override public void mouseMoved(MouseEvent e) { - updatePos(e); + updatePos(e, true); } @Override public void mouseDragged(MouseEvent e) { - updatePos(e); + updatePos(e, true); } }); @@ -347,7 +355,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis timelined = null; loaded = true; try { - iconPanel.setImg(new SerializableImage(ImageIO.read(new ByteArrayInputStream(data))), new ArrayList(), new ArrayList()); + iconPanel.setImg(new SerializableImage(ImageIO.read(new ByteArrayInputStream(data)))); + iconPanel.setOutlines(new ArrayList(), new ArrayList()); } catch (IOException ex) { Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); } @@ -370,7 +379,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis loaded = true; if (drawable.getTimeline().frames.isEmpty()) { - iconPanel.setImg(null, new ArrayList(), new ArrayList()); + iconPanel.setImg(null); + iconPanel.setOutlines(new ArrayList(), new ArrayList()); return; } frame = 0; @@ -386,7 +396,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis timelined = null; loaded = true; stillFrame = true; - iconPanel.setImg(image, new ArrayList(), new ArrayList()); + iconPanel.setImg(image); + iconPanel.setOutlines(new ArrayList(), new ArrayList()); } @Override @@ -424,7 +435,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis private void nextFrame() { int newframe = frame == timelined.getTimeline().frames.size() - 1 ? 0 : frame + 1; - if(stillFrame){ + if (stillFrame) { newframe = frame; } if (newframe != frame) { @@ -432,16 +443,15 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis stopAllSounds(); } frame = newframe; - updatePos(lastMouseEvent); - time = 0; - }else{ + time = 0; + } else { time++; } drawFrame(); } - private static SerializableImage getFrame(SWF swf, int frame,int time, Timelined drawable, DepthState stateUnderCursor, int mouseButton) { - String key = "drawable_" + frame + "_" + drawable.hashCode() + "_" + mouseButton + "_" + (stateUnderCursor == null ? "out" : stateUnderCursor.hashCode())+"_"+time; + private static SerializableImage getFrame(SWF swf, int frame, int time, Timelined drawable, DepthState stateUnderCursor, int mouseButton) { + String key = "drawable_" + frame + "_" + drawable.hashCode() + "_" + mouseButton + "_" + (stateUnderCursor == null ? "out" : stateUnderCursor.hashCode()) + "_" + time; SerializableImage img = SWF.getFromCache(key); if (img == null) { if (drawable instanceof BoundedTag) { @@ -488,11 +498,24 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (timelined == null) { return; } + + getOutlines(); Matrix mat = new Matrix(); mat.translateX = swf.displayRect.Xmin; mat.translateY = swf.displayRect.Ymin; - BufferedImage img = getFrame(swf, frame,time, timelined, stateUnderCursor, mouseButton).getBufferedImage(); - List sounds = timelined.getTimeline().getSounds(frame,time, stateUnderCursor, mouseButton); + updatePos(lastMouseEvent, false); + BufferedImage img = getFrame(swf, frame, time, timelined, stateUnderCursor, mouseButton).getBufferedImage(); + List sounds = new ArrayList<>(); + List soundClasses = new ArrayList<>(); + timelined.getTimeline().getSounds(frame, time, stateUnderCursor, mouseButton, sounds, soundClasses); + for (int cid : swf.characters.keySet()) { + CharacterTag c = swf.characters.get(cid); + for (String cls : soundClasses) { + if (cls.equals(c.getClassName())) { + sounds.add(cid); + } + } + } for (int sndId : sounds) { CharacterTag c = swf.characters.get(sndId); if (c instanceof SoundTag) { @@ -520,17 +543,23 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis } } + + iconPanel.setImg(new SerializableImage(img)); + } + + private void getOutlines() { + List objs = new ArrayList<>(); + List outlines = new ArrayList<>(); Matrix m = new Matrix(); RECT rect = timelined.getTimeline().displayRect; m.translate(-rect.Xmin, -rect.Ymin); m.scale(1); - List objs = new ArrayList<>(); - List outlines = new ArrayList<>(); + timelined.getTimeline().getObjectsOutlines(frame, time, frame, stateUnderCursor, mouseButton, m, objs, outlines); for (int i = 0; i < outlines.size(); i++) { outlines.set(i, SHAPERECORD.twipToPixelShape(outlines.get(i))); } - iconPanel.setImg(new SerializableImage(img), objs, outlines); + iconPanel.setOutlines(objs, outlines); } public void stop() { @@ -543,7 +572,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis @Override public void play() { pause(); - if (timelined!=null) { + if (timelined != null) { timer = new Timer(); timer.schedule(new TimerTask() { @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/timeline/Frame.java b/trunk/src/com/jpexs/decompiler/flash/timeline/Frame.java index ae0e7ac55..4c21f7238 100644 --- a/trunk/src/com/jpexs/decompiler/flash/timeline/Frame.java +++ b/trunk/src/com/jpexs/decompiler/flash/timeline/Frame.java @@ -35,6 +35,7 @@ public class Frame { public RGB backgroundColor = new RGBA(0, 0, 0, 0); public Timeline timeline; public List sounds = new ArrayList<>(); + public List soundClasses = new ArrayList<>(); public Frame(Timeline timeline) { this.timeline = timeline; diff --git a/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java index f499c9aa4..469ee4db1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/trunk/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.exporters.Matrix; import com.jpexs.decompiler.flash.tags.DoActionTag; import com.jpexs.decompiler.flash.tags.SetBackgroundColorTag; import com.jpexs.decompiler.flash.tags.ShowFrameTag; +import com.jpexs.decompiler.flash.tags.StartSound2Tag; import com.jpexs.decompiler.flash.tags.StartSoundTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.BoundedTag; @@ -84,6 +85,9 @@ public class Timeline { if (t instanceof StartSoundTag) { frame.sounds.add(((StartSoundTag) t).soundId); } + if (t instanceof StartSound2Tag) { + frame.soundClasses.add(((StartSound2Tag) t).soundClassName); + } if (t instanceof SetBackgroundColorTag) { frame.backgroundColor = ((SetBackgroundColorTag) t).backgroundColor; } @@ -179,16 +183,16 @@ public class Timeline { } - public List getSounds(int frame,int time, DepthState stateUnderCursor, int mouseButton) { - List ret = new ArrayList<>(); + public void getSounds(int frame, int time, DepthState stateUnderCursor, int mouseButton, List sounds, List soundClasses) { Frame fr = this.frames.get(frame); - ret.addAll(fr.sounds); + sounds.addAll(fr.sounds); + soundClasses.addAll(fr.soundClasses); for (int d = this.getMaxDepth(); d >= 0; d--) { DepthState ds = fr.layers.get(d); if (ds != null) { CharacterTag c = swf.characters.get(ds.characterId); if (c instanceof Timelined) { - int dframe = (time+ds.time) % ((Timelined) c).getTimeline().frames.size(); + int dframe = (time + ds.time) % ((Timelined) c).getTimeline().frames.size(); if (c instanceof ButtonTag) { ButtonTag bt = (ButtonTag) c; dframe = ButtonTag.FRAME_UP; @@ -200,11 +204,10 @@ public class Timeline { } } } - ret.addAll(((Timelined) c).getTimeline().getSounds(dframe,time+ds.time, stateUnderCursor, mouseButton)); + ((Timelined) c).getTimeline().getSounds(dframe, time + ds.time, stateUnderCursor, mouseButton, sounds, soundClasses); } } } - return ret; } public void getObjectsOutlines(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, Matrix transformation, List objs, List outlines) { @@ -238,17 +241,18 @@ public class Timeline { dframe = ds.time % ((Timelined) c).getTimeline().frames.size(); if (c instanceof ButtonTag) { ButtonTag bt = (ButtonTag) c; - dframe = ButtonTag.FRAME_UP; - if (stateUnderCursor == ds) { - if (mouseButton > 0) { - dframe = ButtonTag.FRAME_DOWN; - } else { - dframe = ButtonTag.FRAME_OVER; - } - } + dframe = ButtonTag.FRAME_HITTEST; + /*dframe = ButtonTag.FRAME_UP; + if (stateUnderCursor == ds) { + if (mouseButton > 0) { + dframe = ButtonTag.FRAME_DOWN; + } else { + dframe = ButtonTag.FRAME_OVER; + } + }*/ } } - Shape cshape = ((DrawableTag) c).getOutline(dframe, ds.time+time, ds.ratio, stateUnderCursor, mouseButton, m); + Shape cshape = ((DrawableTag) c).getOutline(dframe, ds.time + time, ds.ratio, stateUnderCursor, mouseButton, m); Area addArea = new Area(cshape); if (currentClip != null) { @@ -264,7 +268,7 @@ public class Timeline { outlines.add(addArea); } if (c instanceof Timelined) { - ((Timelined) c).getTimeline().getObjectsOutlines(dframe,time+ds.time,ds.ratio, stateUnderCursor, mouseButton, m, objs, outlines); + ((Timelined) c).getTimeline().getObjectsOutlines(dframe, time + ds.time, ds.ratio, stateUnderCursor, mouseButton, m, objs, outlines); } } } @@ -299,7 +303,7 @@ public class Timeline { int dframe = 0; if (c instanceof Timelined) { - dframe = (time+ds.time) % ((Timelined) c).getTimeline().frames.size(); + dframe = (time + ds.time) % ((Timelined) c).getTimeline().frames.size(); if (c instanceof ButtonTag) { ButtonTag bt = (ButtonTag) c; dframe = ButtonTag.FRAME_UP; @@ -312,7 +316,7 @@ public class Timeline { } } } - Shape cshape = ((DrawableTag) c).getOutline(dframe, time+ds.time,ds.ratio, stateUnderCursor, mouseButton, m); + Shape cshape = ((DrawableTag) c).getOutline(dframe, time + ds.time, ds.ratio, stateUnderCursor, mouseButton, m); Area addArea = new Area(cshape); if (currentClip != null) { diff --git a/trunk/src/com/jpexs/helpers/SerializableImage.java b/trunk/src/com/jpexs/helpers/SerializableImage.java index 452916d0d..56de36420 100644 --- a/trunk/src/com/jpexs/helpers/SerializableImage.java +++ b/trunk/src/com/jpexs/helpers/SerializableImage.java @@ -143,12 +143,14 @@ public class SerializableImage implements Serializable { } private void writeObject(ObjectOutputStream out) throws IOException { - // out.writeObject(bounds); - ImageIO.write(image, "png", out); + try{ + ImageIO.write(image, "png", out); + }catch(Exception ex){ + //ignore + } } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - // bounds = (Rectangle2D) in.readObject(); image = ImageIO.read(in); } }