using System.Collections; using Eto.Forms; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; namespace TimelapseApi; internal class ExportForm :Form, IEnumerator> , IEnumerable> { int _i=-1; int i {get {return _i;} set{bar.Value=value+1; bar.Invalidate(); _i=value; }} int count; ProgressBar bar; Button cancel; CancellationTokenSource src; TimelapseProject _proj; public ExportForm(TimelapseProject proj,CancellationTokenSource token) { Width=258; Height=73; Title="Exporting"; _proj=proj; src=token; bar=new ProgressBar {MaxValue=proj.FrameCount,MinValue=0}; cancel=new Button {Text = "Cancel"}; count=proj.FrameCount; DynamicLayout lyt=new DynamicLayout(); lyt.BeginVertical(); lyt.BeginHorizontal(); lyt.Add(bar,true); lyt.EndHorizontal(); lyt.EndBeginVertical(); lyt.AddSpace(true,true); lyt.BeginHorizontal(); lyt.AddSpace(true); lyt.Add(cancel); lyt.EndHorizontal(); lyt.EndVertical(); Content=lyt; } private Image GetImage() { if(_proj.ProjectLocation==null) { return new Image(1280,720); } using(var s=_proj.ProjectLocation.Open($"Sections/{_proj.SectionName}/{i}.png",FileMode.Open,FileAccess.Read,FileShare.Read)) { return Image.Load(s); } } public Image Current { get { return GetImage(); } } object IEnumerator.Current {get{return Current;}} public IEnumerator> GetEnumerator() { return this; } public bool MoveNext() { return ++i < count; } public void Reset() { i=-1; } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } }