Пример #1
0
 public static bool HasInside(this ScriptPortal.Vegas.Region Region, Timecode Start, Timecode End)
 {
     if (Start < Region.Position && End > Region.End)
     {
         return(true);
     }
     return(false);
 }
Пример #2
0
        ///
        /// Implementation
        ///
        internal void RegionCreateFromEvents_Invoked(object sender, EventArgs e)
        {
            var eventgroups = myVegas.Project.GetEventGroups();
            var regions     = (myVegas.Project.Regions.Count != 0)
                                                                                                ? new List <ScriptPortal.Vegas.Region>(myVegas.Project.Regions)
                                                                                                : new List <ScriptPortal.Vegas.Region>();

            bool selectionSet = false;

            if (myVegas.SelectionLength != Timecode.FromMilliseconds(0))
            {
                if (myVegas.Cursor == myVegas.SelectionStart ||
                    myVegas.Cursor == myVegas.SelectionStart + myVegas.SelectionLength)
                {
                    selectionSet = true;
                }
            }

            using (var undo = new UndoBlock("Create regions"))
            {
                foreach (var egrp in eventgroups)
                {
                    Timecode groupStart = null;
                    Timecode groupEnd   = null;
                    foreach (var ev in egrp)
                    {
                        if (groupStart == null || ev.Start < groupStart)
                        {
                            groupStart = ev.Start;
                        }
                        if (groupEnd == null || ev.End > groupEnd)
                        {
                            groupEnd = ev.End;
                        }
                    }

                    // skip outside seletion
                    if (selectionSet)
                    {
                        if (groupEnd >= (myVegas.SelectionStart + myVegas.SelectionLength) ||
                            groupStart <= myVegas.SelectionStart)
                        {
                            continue;
                        }
                    }

                    // don't write inside existing regions
                    if (regions.Any(reg => reg.ContainsTime(groupStart, (groupEnd - groupStart))))
                    {
                        continue;
                    }

                    // don't surround existing regions
                    if (regions.HasInside(groupStart, groupEnd))
                    {
                        continue;
                    }

                    var NewRegion = new ScriptPortal.Vegas.Region(groupStart, (groupEnd - groupStart));
                    myVegas.Project.Regions.Add(NewRegion);
                }
            }
        }