using FlashCap.Devices; using FlashCap.Utilities; using FlashCap; using Eto.Forms; using TimelapseApi; using System.Collections.ObjectModel; namespace Timelapse.Desktop { public class SelectCamera : Dialog { public class CameraObject { public CameraObject(CaptureDeviceDescriptor desc) { Descriptor=desc; } public CaptureDeviceDescriptor Descriptor {get;set;} public override string ToString() { return Descriptor.Name; } } public class CharacteristicsObject { public CharacteristicsObject(VideoCharacteristics chr) { Characteristics=chr; } public VideoCharacteristics Characteristics {get;set;} public override string ToString() { return Characteristics.ToString(); } } public SelectCamera() { this.Title="Select Camera"; Button accept=new Button(){Text="Select",Enabled=false}; DropDown cameraSelector = new DropDown(); DropDown characteristicsSelector=new DropDown(); var devices = new CaptureDevices(); List cobj=new List(); ObservableCollection chrobj=new ObservableCollection(); foreach (var descriptor in devices.EnumerateDescriptors()) { if(descriptor.Characteristics.Length >0) { cobj.Add(new CameraObject(descriptor)); } } cameraSelector.DataStore=cobj; characteristicsSelector.DataStore=chrobj; characteristicsSelector.Enabled=false; characteristicsSelector.SelectedIndexChanged+=(sender,e)=> { accept.Enabled=characteristicsSelector.SelectedIndex > -1; }; cameraSelector.SelectedIndexChanged += (sender,e)=>{ if(cameraSelector.SelectedIndex > -1) { characteristicsSelector.Enabled=true; chrobj.Clear(); foreach(var item in cobj[cameraSelector.SelectedIndex].Descriptor.Characteristics) { chrobj.Add(new CharacteristicsObject(item)); } } }; bool close=false; accept.Click +=(sender,e)=>{ int cSI=cameraSelector.SelectedIndex; int charSI = characteristicsSelector.SelectedIndex; if(cSI > -1 && cobj.Count > 0 && charSI > -1 && chrobj.Count > 0) { Result=new TimelapseCamera(cobj[cSI].Descriptor,chrobj[charSI].Characteristics); close=true; Close(); } }; Closing += (sender,e)=>{ if(!close) { Result=null; } }; DynamicLayout lyt=new DynamicLayout(); lyt.BeginVertical(); lyt.BeginHorizontal(); lyt.Add(cameraSelector,true); lyt.EndBeginHorizontal(); lyt.Add(characteristicsSelector); lyt.EndBeginHorizontal(); lyt.Add(accept); lyt.EndHorizontal(); lyt.EndVertical(); this.Content=lyt; } } }