Exemple #1
0
        public void Render()
        {
            if (this._executedRecordIndex >= this.AllReadObjects.Count - 1)
            {
                return;
                //For looping:
                //foreach (DictionaryEntry de in this._objectByDepth)
                //    ((Sprite)de.Value).Dispose();
                //this._objectByDepth.Clear();
                //this._executedRecordIndex = 0; //loop from start
            }

            //EH.Put("New frame!" + this._executedRecordIndex.ToString() + "/"+this.AllReadObjects.Count.ToString());

            ArrayList newSprites     = new ArrayList();
            ArrayList removedSprites = new ArrayList();

            //loop through the parsed flash file:
            while (this._executedRecordIndex < this.AllReadObjects.Count - 1)
            {
                this._executedRecordIndex++;
                Record record = (Record)this.AllReadObjects[this._executedRecordIndex];
                //EH.Put("Tag: "+record.Tag.ToString());

                if (record is Placement.Placement)
                {
                    // like "put member in sprite on stage"
                    Placement.Placement placement = (Placement.Placement)record;
                    Sprite spExisting             = (Sprite)this._objectByDepth[placement.Depth];
                    Sprite sp = placement.Execute(this, spExisting);
                    if (spExisting == null)
                    {
                        this._objectByDepth.Add(placement.Depth, sp);
                        newSprites.Add(spExisting);
                    }
                }
                else if (record is Placement.Remove)
                {
                    Placement.Remove remove = (Placement.Remove)record;
                    if (!this._objectByDepth.Contains(remove.Depth))
                    {
                        EH.Put("Removing nonexistent sprite?");
                    }
                    else
                    {
                        Sprite sp = (Sprite)this._objectByDepth[remove.Depth];
                        this._objectByDepth.Remove(remove.Depth);
                        removedSprites.Add(sp);
                    }
                }
                else if (record.Tag == Tags.SetBackgroundColor)
                {
                }
                else if (record.Tag == Tags.ShowFrame)
                {
                    break;
                }
            }
//			foreach (Sprite sp in newSprites)
//				sp.Visible = true;
            foreach (Sprite sp in removedSprites)
            {
                sp.Dispose();
            }

            float msecsPerFrame = 1000f / this.FrameRate;

            //float msecsPerFrame = 300; //;
            this._nextUpdateTime = DateTime.Now.Ticks + (int)(msecsPerFrame * 1000 * 10);
        }
Exemple #2
0
        public void Read(string a_sFilename)
        {
            FileStream stream = new FileStream(a_sFilename,
                                               FileMode.Open, FileAccess.Read);

            this.reader = new BinaryFlashReader(stream);

            //Header
            //Compressed or uncompressed?
            bool bCompressed = (this.reader.ReadChar().ToString() == "C")?true:false;

            //char 2-3 is always WS:
            string sWS = new string(this.reader.ReadChars(2));

            if (sWS != "WS")
            {
                throw(new Exception("Not a Flash file"));
            }

            //Testing: I'm writing some data to an XML doc in order to see what the parser's results are
            //TODO: instead, the whole Flash data structure (after parsing) should be serializable to XML
            //I.e. a Flash->XML->Flash converter is a must later on. Or preferably XAML.
//			XmlDocument xdoc = new XmlDocument();
//			XmlNode xnode = xdoc.CreateElement("root");
//			xdoc.AppendChild(xnode);

            int Version = this.reader.ReadByte();

//			this.AddNodeAndValue(xnode, "Version", Version.ToString());

            long nFileLength = this.reader.ReadUInt32();

            //rect for the bounding rect of the whole Flash file:
            ERectangle boundingRect = this.reader.ReadRect();

//			this.AddNodeAndValue(xnode, "BoundingRect", boundingRect.ToString());

            this.FrameRate = this.reader.ReadFixed16();
            int FrameCount = this.reader.ReadUInt16();

//			this.AddNodeAndValue(xnode, "FrameRate", FrameRate.ToString());
//			this.AddNodeAndValue(xnode, "FrameCount", FrameCount.ToString());


            this.AllReadObjects = new ArrayList();
            this.Characters     = new Hashtable();
            this.Members        = new Hashtable();

            //read tag by tag until end of file:
            while (true)
            {
                Record record    = new Record(reader, this);
                Record newRecord = null;
                switch (record.Tag)
                {
                case Tags.SetBackgroundColor:
                    EH.Instance.Stage.Color = record.GetDataReader().ReadRGB();
                    break;

                case Tags.ShowFrame:
                    newRecord = record;
                    break;

                case Tags.DefineBits:
                case Tags.DefineBitsJPEG2:
                case Tags.DefineBitsJPEG3:
                case Tags.DefineBitsLossless:
                case Tags.DefineBitsLossless2:
                    if (record.Tag == Tags.DefineBits)
                    {
                        newRecord = new Shape.Image(this._jpegTables);
                    }
                    else
                    {
                        newRecord = new Shape.Image();
                    }
                    break;

                case Tags.JPEGTables:
                    if (this._jpegTables == null)
                    {
                        BinaryFlashReader subReader = record.GetDataReader();
                        this._jpegTables = subReader.ReadBytes((int)record.TagLength - 2);
                        if (subReader.ReadUInt16() != 0xd9ff)
                        {
                            throw new Exception("JPEG error");
                        }
                    }
                    break;


                case Tags.DefineFont:
                    newRecord = new Text.Font();                            //record
                    break;

                case Tags.DefineFontInfo:
                    break;

                case Tags.DefineText2:
                    newRecord = new Text.Text();                            //record
                    break;

                case Tags.DefineShape:
                case Tags.DefineShape2:
                case Tags.DefineShape3:
                case Tags.DefineShape4:
                case Tags.DefineShape5:
                    newRecord = new Shape.Shape();
                    break;

                case Tags.DefineMorphShape:
                    newRecord = new Shape.MorphShape();
                    break;

                case Tags.PlaceObject:
                case Tags.PlaceObject2:
                    newRecord = new Placement.Placement();
                    break;

                case Tags.RemoveObject:
                case Tags.RemoveObject2:
                    newRecord = new Placement.Remove();
                    break;

                case Tags.DoAction:
                case Tags.DoInitAction:
                    //newRecord = new Action.DoAnAction();
                    break;
                }

                if (newRecord != null)
                {
                    if (!newRecord.Inited)
                    {
                        newRecord.Init(record);
                    }
                    this.AllReadObjects.Add(newRecord);
                }

                if (record.Tag == Tags.End)
                {
                    break;
                }
                if (this.reader.BaseStream.Position >= nFileLength - 1)
                {
                    break;
                }
            }

            //xdoc.Save(a_sFilename+".xml");
            //zoom in:
            //this.TwipSize = 1; //20
            this._executedRecordIndex    = -1;
            this._objectByDepth          = new SortedList();
            this.CharacterIdsByDepth     = new Hashtable();
            EH.Instance.EnterFrameEvent += new EnterFrame(Instance_EnterFrameEvent);
        }
Exemple #3
0
        public void Read(string a_sFilename)
        {
            FileStream stream = new FileStream(a_sFilename,
                FileMode.Open, FileAccess.Read);
            this.reader = new BinaryFlashReader(stream);

            //Header
            //Compressed or uncompressed?
            bool bCompressed = (this.reader.ReadChar().ToString() == "C")?true:false;

            //char 2-3 is always WS:
            string sWS = new string(this.reader.ReadChars(2));
            if (sWS != "WS")
                throw(new Exception("Not a Flash file"));

            //Testing: I'm writing some data to an XML doc in order to see what the parser's results are
            //TODO: instead, the whole Flash data structure (after parsing) should be serializable to XML
            //I.e. a Flash->XML->Flash converter is a must later on. Or preferably XAML.
            //			XmlDocument xdoc = new XmlDocument();
            //			XmlNode xnode = xdoc.CreateElement("root");
            //			xdoc.AppendChild(xnode);

            int Version = this.reader.ReadByte();

            //			this.AddNodeAndValue(xnode, "Version", Version.ToString());

            long nFileLength = this.reader.ReadUInt32();

            //rect for the bounding rect of the whole Flash file:
            ERectangle boundingRect = this.reader.ReadRect();

            //			this.AddNodeAndValue(xnode, "BoundingRect", boundingRect.ToString());

            this.FrameRate = this.reader.ReadFixed16();
            int FrameCount = this.reader.ReadUInt16();

            //			this.AddNodeAndValue(xnode, "FrameRate", FrameRate.ToString());
            //			this.AddNodeAndValue(xnode, "FrameCount", FrameCount.ToString());

            this.AllReadObjects = new ArrayList();
            this.Characters = new Hashtable();
            this.Members = new Hashtable();

            //read tag by tag until end of file:
            while (true)
            {
                Record record = new Record(reader, this);
                Record newRecord = null;
                switch (record.Tag)
                {
                    case Tags.SetBackgroundColor:
                        EH.Instance.Stage.Color = record.GetDataReader().ReadRGB();
                        break;

                    case Tags.ShowFrame:
                        newRecord = record;
                        break;

                    case Tags.DefineBits:
                    case Tags.DefineBitsJPEG2:
                    case Tags.DefineBitsJPEG3:
                    case Tags.DefineBitsLossless:
                    case Tags.DefineBitsLossless2:
                        if (record.Tag == Tags.DefineBits)
                            newRecord = new Shape.Image(this._jpegTables);
                        else
                            newRecord = new Shape.Image();
                        break;
                    case Tags.JPEGTables:
                        if (this._jpegTables == null)
                        {
                            BinaryFlashReader subReader = record.GetDataReader();
                            this._jpegTables = subReader.ReadBytes((int)record.TagLength - 2);
                            if (subReader.ReadUInt16() != 0xd9ff)
                                throw new Exception("JPEG error");
                        }
                        break;

                    case Tags.DefineFont:
                        newRecord = new Text.Font();//record
                        break;
                    case Tags.DefineFontInfo:
                        break;
                    case Tags.DefineText2:
                        newRecord = new Text.Text();//record
                        break;

                    case Tags.DefineShape:
                    case Tags.DefineShape2:
                    case Tags.DefineShape3:
                    case Tags.DefineShape4:
                    case Tags.DefineShape5:
                        newRecord = new Shape.Shape();
                        break;

                    case Tags.DefineMorphShape:
                        newRecord = new Shape.MorphShape();
                        break;

                    case Tags.PlaceObject:
                    case Tags.PlaceObject2:
                        newRecord = new Placement.Placement();
                        break;

                    case Tags.RemoveObject:
                    case Tags.RemoveObject2:
                        newRecord = new Placement.Remove();
                        break;

                    case Tags.DoAction:
                    case Tags.DoInitAction:
                        //newRecord = new Action.DoAnAction();
                        break;
                }

                if (newRecord!=null)
                {
                    if (!newRecord.Inited)
                        newRecord.Init(record);
                    this.AllReadObjects.Add(newRecord);
                }

                if (record.Tag == Tags.End)
                    break;
                if (this.reader.BaseStream.Position >= nFileLength-1)
                    break;
            }

            //xdoc.Save(a_sFilename+".xml");
            //zoom in:
            //this.TwipSize = 1; //20
            this._executedRecordIndex = -1;
            this._objectByDepth = new SortedList();
            this.CharacterIdsByDepth = new Hashtable();
            EH.Instance.EnterFrameEvent+=new EnterFrame(Instance_EnterFrameEvent);
        }