Beispiel #1
0
        public bool HasSymbols(Vex.Timeline tl)
        {
            bool result = false;

            for (int i = 0; i < tl.InstanceCount; i++)
            {
                Vex.IDefinition idef = stage.Library[tl.InstanceAt(i).DefinitionId].Definition;
                if (idef is Vex.Symbol)
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Beispiel #2
0
 private void DrawTimeline(Vex.Timeline tl)
 {
     for (int i = 0; i < tl.InstanceCount; i++)
     {
         Vex.IDefinition idef = stage.Library[tl.InstanceAt(i).DefinitionId].Definition;
         if (idef is Vex.Symbol)
         {
             DrawSymbol((Vex.Symbol)idef);
         }
         else if (idef is Vex.Timeline)
         {
             DrawTimeline((Vex.Timeline)idef);
         }
     }
 }
Beispiel #3
0
 // filtered meaning remove annotations like box2d bounding boxes
 private void DrawFilteredTimeline(Vex.Timeline tl, uint frame)
 {
     for (int i = 0; i < tl.InstanceCount; i++)
     {
         Vex.Instance inst = (Vex.Instance)tl.InstanceAt(i);
         if (inst.GetTransformAtTime(frame) != null)
         {
             Vex.IDefinition idef = stage.Library[inst.DefinitionId].Definition;
             if (idef is Vex.Symbol || idef is Vex.Timeline)
             {
                 GraphicsState gs = g.Save();
                 using (Matrix nm = inst.GetTransformAtTime(0).Matrix.GetDrawing2DMatrix())
                 {
                     nm.Multiply(g.Transform, MatrixOrder.Append);
                     g.Transform = nm;
                     if (idef is Vex.Symbol)
                     {
                         DrawFilteredSymbol((Vex.Symbol)idef);
                     }
                     else
                     {
                         DrawFilteredTimeline((Vex.Timeline)idef, frame);
                     }
                 }
                 g.Restore(gs);
             }
             else if (idef is Vex.Text)
             {
                 DrawText((Vex.Text)idef, inst.Transformations[0].Matrix);
             }
             else if (idef is Vex.Image)
             {
                 Matrix pm = g.Transform.Clone();
                 Matrix nm = inst.GetTransformAtTime(0).Matrix.GetDrawing2DMatrix();
                 nm.Multiply(pm, MatrixOrder.Append);
                 g.Transform = nm;
                 DrawImage(stage.BitmapCache.GetBitmap(idef));
                 g.Transform = pm;
             }
         }
     }
 }
Beispiel #4
0
        private Vex.Timeline GetNamedSymbol(Vex.Timeline tl)
        {
            Vex.Timeline result = null;

            if (tl.Name != "")
            {
                result = tl;
            }
            else
            {
                for (int i = 0; i < tl.InstanceCount; i++)
                {
                    Vex.IDefinition idef = stage.Library[tl.InstanceAt(i).DefinitionId].Definition;
                    if (idef is Vex.Timeline && ((Vex.Timeline)idef).Name != "")
                    {
                        result = (Vex.Timeline)idef;
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
        public LibraryItem[] AddSwf(string path)
        {
            List <LibraryItem> result = new List <LibraryItem>();

            if (File.Exists(path))
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    BinaryReader br = new BinaryReader(fs);

                    string    name = Path.GetFileNameWithoutExtension(path);
                    SwfReader r    = new SwfReader(br.ReadBytes((int)fs.Length));

                    SwfCompilationUnit scu = new SwfCompilationUnit(r);

                    if (scu.IsValid)
                    {
                        SwfToVex      s2v          = new SwfToVex();
                        Vex.VexObject v            = s2v.Convert(scu);
                        DateTime      creationTime = File.GetLastWriteTimeUtc(path);

                        string swfName = Path.GetFileName(path);

                        string wf = MainForm.CurrentStage.WorkingFolderFull;
                        bool   inWorkingFolder = path.IndexOf(wf) == 0;
                        string wp          = inWorkingFolder ? path.Substring(wf.Length) : swfName;
                        string workingPath = wp.Substring(0, wp.Length - swfName.Length);

                        TreeNode existingNode  = symbolTree.GetNode(workingPath, swfName);
                        bool     isUpdatingSwf = (existingNode != null);

                        LibraryItem             li;
                        Dictionary <uint, uint> translator      = new Dictionary <uint, uint>();
                        List <uint>             recycledInstIds = new List <uint>();
                        foreach (uint key in v.Definitions.Keys)
                        {
                            Vex.IDefinition loadedDef = v.Definitions[key];
                            if (scu.SymbolClasses.ContainsKey(key))
                            {
                                loadedDef.Name = scu.SymbolClasses[key];
                            }
                            uint loadedId   = loadedDef.Id;
                            bool isTimeline = loadedDef is Vex.Timeline;

                            LibraryItem existingLi = null;
                            if (isUpdatingSwf)
                            {
                                loadedDef.HasSaveableChanges = true;
                                existingLi = isTimeline ? MainForm.CurrentLibrary.GetLibraryItem(workingPath + swfName, loadedDef.Name) : MainForm.CurrentLibrary.GetByOriginalSourceId(loadedDef.Id);
                            }

                            if (existingLi != null)
                            {
                                loadedDef.Id         = existingLi.DefinitionId;
                                translator[loadedId] = loadedDef.Id;
                                existingLi.Date      = creationTime;
                                if (isTimeline)
                                {
                                    Vex.Timeline    orgTl     = (Vex.Timeline)existingLi.Definition;
                                    Vex.IInstance[] instances = orgTl.Instances.ToArray();
                                    for (int i = 0; i < instances.Length; i++)
                                    {
                                        recycledInstIds.Add(instances[i].InstanceHash);
                                        orgTl.RemoveInstance(instances[i]);
                                        MainForm.CurrentStage.InstanceManager.RemoveInstance(instances[i].InstanceHash);
                                    }
                                }
                                MainForm.CurrentStage.vexObject.Definitions[loadedDef.Id] = loadedDef;
                                existingLi.Definition = loadedDef;
                            }
                            else
                            {
                                li                   = MainForm.CurrentStage.CreateLibraryItem(loadedDef, false);
                                li.Date              = creationTime;
                                li.LibraryPath       = workingPath + swfName;
                                li.OriginalSourceId  = loadedId;
                                translator[loadedId] = li.Definition.Id;

                                if (isTimeline)
                                {
                                    result.Add(li);
                                    AddItemToLibrary(li);
                                }
                            }

                            if (isTimeline)
                            {
                                Vex.Timeline tl = (Vex.Timeline)loadedDef;
                                for (int i = 0; i < tl.InstanceCount; i++)
                                {
                                    Vex.IInstance inst = tl.InstanceAt(i);
                                    if (recycledInstIds.Count > 0)
                                    {
                                        inst.InstanceHash = recycledInstIds[0];
                                        recycledInstIds.RemoveAt(0);
                                    }

                                    inst.DefinitionId       = translator[inst.DefinitionId];
                                    inst.ParentDefinitionId = translator[inst.ParentDefinitionId];
                                    MainForm.CurrentStage.CreateInstance((Vex.Instance)inst);
                                }
                            }
                        }
                    }
                }
            }
            return(result.ToArray());
        }