Beispiel #1
0
        /// <summary>
        /// Creates a new file output.
        /// </summary>
        /// <returns></returns>
        public static ObsOutput CreateOutput()
        {
            string videoDirectory = $"{FolderService.GetPath(KnownFolder.Videos)}\\{Store.Data.Record.VideoOutputFolder}";

            if (Store.Data.Record.RecordedFiles.Count == 0)
            {
                Store.Data.Record.LastVideoName = $"ScreenRecording {DateTime.Now:yyyy-MM-dd HH.mm.ss}";
            }

            string videoFileName = Store.Data.Record.LastVideoName + "_part " + (Store.Data.Record.RecordedFiles.Count + 1) + ".mp4";

            string videoFilePath = $"{videoDirectory}\\{videoFileName}";

            Store.Data.Record.RecordedFiles.Add(new FileInfo(videoFilePath));

            Directory.CreateDirectory(videoDirectory);
            videoFilePath = videoFilePath.Replace("\\", "/"); // OBS uses forward slashes

            ObsOutput obsOutput = new ObsOutput(ObsOutputType.Dummy, "ffmpeg_muxer", "simple_file_output");

            ObsData outputSettings = new ObsData();

            outputSettings.SetString("path", videoFilePath);
            outputSettings.SetString("muxer_settings", "movflags=faststart");
            obsOutput.Update(outputSettings);
            outputSettings.Dispose();

            return(obsOutput);
        }
        private void AddFont(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            Label label = new Label
            {
                Width       = 300,
                Height      = 60,
                AutoSize    = false,
                BorderStyle = BorderStyle.Fixed3D,
                TextAlign   = ContentAlignment.MiddleCenter
            };

            Button button = new Button {
                Text = "Select..."
            };

            using (ObsData fontData = new ObsData(setting.GetObject(name)))
            {
                string family = fontData.GetString("face");
                //string style = fontData.GetString("style");	//not supported in Windows
                ObsFontFlags flags = (ObsFontFlags)fontData.GetInt("flags");

                label.Font = new Font(family, 25F, (FontStyle)flags);;
                label.Text = family;
            }

            button.Click += (sender, args) =>
            {
                var fontDialog = new FontDialog();

                using (ObsData fontData = new ObsData(setting.GetObject(name)))
                {
                    float size = fontData.GetInt("size");
                    fontDialog.Font = new Font(label.Font.FontFamily, size, label.Font.Style);
                }

                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    var font = fontDialog.Font;

                    using (ObsData fontData = new ObsData(setting.GetObject(name)))
                    {
                        fontData.SetString("face", font.Name.ToString());
                        fontData.SetString("style", "");                                //not supported in Windows
                        fontData.SetInt("size", (int)font.SizeInPoints);
                        fontData.SetInt("flags", (int)font.Style);
                    }

                    view.PropertyChanged(property);

                    font       = new Font(font.Name, 25f, font.Style);
                    label.Font = font;
                    label.Text = font.Name;
                }
            };

            controls.Add(label);
            controls.Add(button);
        }
        /// <summary>
        /// Sets the audio output to the device with the given audio output id.
        /// </summary>
        /// <param name="savedAudioOutputId"></param>
        /// <returns></returns>
        public static string SetAudioOutput(string savedAudioOutputId)
        {
            ObsData aoSettings = new ObsData();

            aoSettings.SetBool(Constants.Audio.SettingKeys.UseDeviceTiming, false);
            Store.Data.Audio.OutputSource = Store.Data.Obs.Presentation.CreateSource(Constants.Audio.SettingKeys.WasapiOutputCapture, Constants.Audio.Settings.WasapiOutputCaptureName, aoSettings);
            aoSettings.Dispose();
            Store.Data.Audio.OutputSource.AudioOffset = Constants.Audio.DELAY_OUTPUT; // For some reason, this offset needs to be here before presentation.CreateSource is called again to take affect
            Store.Data.Obs.Presentation.AddSource(Store.Data.Audio.OutputSource);
            Store.Data.Audio.OutputItem      = Store.Data.Obs.Presentation.CreateItem(Store.Data.Audio.OutputSource);
            Store.Data.Audio.OutputItem.Name = Constants.Audio.Settings.WasapiOutputCaptureName;

            Store.Data.Audio.OutputMeter       = new VolMeter();
            Store.Data.Audio.OutputMeter.Level = float.NegativeInfinity;
            Store.Data.Audio.OutputMeter.AttachSource(Store.Data.Audio.OutputSource);
            Store.Data.Audio.OutputMeter.AddCallBack(MagnitudeService.OutputVolumeCallback);

            List <AudioDevice> allAudioOutputs = GetAudioOutputDevices();
            bool savedIsInAvailableOutputs     = allAudioOutputs.Any(x => x.id == savedAudioOutputId);

            var usedAudioOutputId = string.Empty;

            if (savedAudioOutputId != null && savedIsInAvailableOutputs)
            {
                UpdateAudioOutput(savedAudioOutputId);
                usedAudioOutputId = savedAudioOutputId;
            }
            else
            {
                UpdateAudioOutput(Constants.Audio.NO_DEVICE_ID);
                usedAudioOutputId = Constants.Audio.NO_DEVICE_ID;
            }

            return(usedAudioOutputId);
        }
Beispiel #4
0
        /// <summary>
        /// Create a property dialog for an existing source
        /// </summary>
        /// <param name="source">Source of type ObsSource</param>
        public TestProperties(ObsSource source)
            : this()
        {
            this.source = source;
            ObsData sourceSettings = source.GetSettings();

            view = new PropertiesView(sourceSettings, source, source.GetProperties, source.GetDefaults, source.Update);
            propertyPanel.Controls.Add(view);

            undoButton.Click += (sender, args) =>
            {
                view.ResetChanges();
            };

            defaultButton.Click += (sender, args) =>
            {
                view.ResetToDefaults();
            };

            okButton.Click += (o, args) =>
            {
                view.UpdateSettings();
                DialogResult = DialogResult.OK;
                Close();
            };

            cancelButton.Click += (o, args) =>
            {
                view.ResetChanges();
                DialogResult = DialogResult.Cancel;
                Close();
            };
        }
Beispiel #5
0
        private void InitializeWebcamObsSource(ObsData webcamSettings)
        {
            if (Store.Data.Webcam.Source == null)
            {
                if (webcamSettings == null)
                {
                    Store.Data.Webcam.Source = Store.Data.Obs.Presentation.CreateSource("dshow_input", "Webcam");
                }
                else
                {
                    Store.Data.Webcam.Source = Store.Data.Obs.Presentation.CreateSource("dshow_input", "Webcam", webcamSettings);
                }

                Store.Data.Webcam.Source.AudioOffset = Constants.Audio.DELAY_INPUT_ATTACHED_TO_WEBCAM;
                Store.Data.Obs.Presentation.AddSource(Store.Data.Webcam.Source);
            }

            if (Store.Data.Webcam.Item == null)
            {
                Store.Data.Webcam.Item      = Store.Data.Obs.Presentation.CreateItem(Store.Data.Webcam.Source);
                Store.Data.Webcam.Item.Name = "Webcam SceneItem";
                Store.Data.Webcam.Item.SetBounds(new Vector2((float)(Width - (BorderSize * 2)), (float)(Height - (BorderSize * 2))), ObsBoundsType.ScaleOuter, ObsAlignment.Center);
                Store.Data.Obs.MainScene.Items.Add(Store.Data.Webcam.Item);
            }
        }
        private void AddText(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            TextBox textbox = new TextBox
            {
                Width = 300,
                Text  = setting.GetString(name)
            };

            if (property.TextType == ObsTextType.Password)
            {
                textbox.PasswordChar = '*';
            }
            else if (property.TextType == ObsTextType.Multiline)
            {
                textbox.Multiline = true;
                textbox.Height   *= 3;
            }

            textbox.TextChanged += (sender, args) =>
            {
                setting.SetString(name, textbox.Text);
                view.PropertyChanged(property);
            };

            controls.Add(textbox);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new Obs audio encoder with default settings.
        /// </summary>
        /// <returns></returns>
        public static ObsEncoder CreateAudioEncoder()
        {
            // mf_aac for W8 and later, ffmpeg_aac for W7
            string encoderId = "mf_aac";

            // Windows 7 is Version 6.1. Check if version 6.1 and below. We don't support anything below Windows 7.
            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT &&
                ((System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor <= 1) ||
                 System.Environment.OSVersion.Version.Major < 6)
                )
            {
                encoderId = "ffmpeg_aac";
            }

            ObsEncoder obsAudioEncoder = new ObsEncoder(ObsEncoderType.Audio, encoderId, "simple_aac");

            obsAudioEncoder.SetAudio(Obs.GetAudio());

            ObsData audioEncoderSettings = new ObsData();

            audioEncoderSettings.SetInt("bitrate", Constants.Audio.ENCODER_BITRATE);
            audioEncoderSettings.SetString("rate_control", Constants.Audio.RATE_CONTROL);
            audioEncoderSettings.SetInt("samplerate", Constants.Audio.SAMPLES_PER_SEC);
            audioEncoderSettings.SetBoolDefault("allow he-aac", true);
            obsAudioEncoder.Update(audioEncoderSettings);
            audioEncoderSettings.Dispose();

            return(obsAudioEncoder);
        }
        private void InitView()
        {
            oldSettings = new ObsData(settings);

            // force double buffering on to eliminate control flickering during refresh
            WinFormsHelper.DoubleBufferControl(panel);

            ReloadProperties();
        }
        private void AddPath(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            TextBox textbox = new TextBox
            {
                Width = 300,
                Text  = setting.GetString(name)
            };
            Button button = new Button {
                Text = "Browse..."
            };

            if (property.PathType == ObsPathType.File)
            {
                OpenFileDialog dialog = new OpenFileDialog
                {
                    AutoUpgradeEnabled = true,
                    Filter             = property.PathFilter.ToString(),
                    InitialDirectory   = property.PathDefault,
                    FilterIndex        = 1
                };

                button.Click += (sender, args) =>
                {
                    if (dialog.ShowDialog(this) == DialogResult.OK)
                    {
                        textbox.Text = dialog.FileName;
                    }
                };
            }
            else if (property.PathType == ObsPathType.Directory)
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog
                {
                    SelectedPath = property.PathDefault
                };

                button.Click += (sender, args) =>
                {
                    if (dialog.ShowDialog(this) == DialogResult.OK)
                    {
                        textbox.Text = dialog.SelectedPath;
                    }
                };
            }

            textbox.TextChanged += (sender, args) =>
            {
                setting.SetString(name, textbox.Text);
                view.PropertyChanged(property);
            };

            controls.Add(textbox);
            controls.Add(button);
        }
        private void AddButton(ObsProperty property, ObsData setting, List <Control> controls)
        {
            Button button = new Button {
                Text = property.Description
            };

            button.Click += (sender, args) => view.PropertyButtonClicked(property);

            controls.Add(button);
        }
        /// <summary>
        /// Initializes a view for ObsProperties. </summary>
        /// <param name="settings"> The source of properties. </param>
        /// <param name="type"> Type of the object. </param>
        /// <param name="reloadDelegate"> Callback used for refreshing properties with given type. </param>
        /// <param name="defaultsDelegate"> Optional: Callback used for reseting the settings to default values with given type. </param>
        public PropertiesView(ObsData settings, string type,
                              Func <string, ObsProperties> reloadDelegate, Func <string, ObsData> defaultsDelegate = null)
        {
            InitializeComponent();

            this.settings         = settings;
            this.reloadDelegate   = () => { return(reloadDelegate(type)); };
            this.defaultsDelegate = () => { return(defaultsDelegate(type)); };

            InitView();
        }
        /// <summary>
        /// Creates the click highlight settings.
        /// </summary>
        /// <returns></returns>
        private ObsData CreateClickHighlightSettings()
        {
            ObsData settings = new ObsData();

            settings.SetBool(MediaSource.IS_LOCAL_FILE, true);
            settings.SetBool(MediaSource.LOOPING, true);
            settings.SetBool(MediaSource.RESTART_ON_ACTIVATE, true);
            settings.SetBool(MediaSource.HW_DECODE, true);
            settings.SetString(MediaSource.LOCAL_FILE_PATH, _highlightImagePath);
            settings.SetBool(Common.ACTIVATE, true);
            return(settings);
        }
        /// <summary>
        /// Updates the current audio output device.
        /// </summary>
        /// <param name="deviceId"></param>
        public static void UpdateAudioOutput(string deviceId)
        {
            Store.Data.Audio.CurrentOutputId = deviceId;

            ObsData aoSettings = new ObsData();

            aoSettings.SetString(Constants.Audio.SettingKeys.DeviceId, deviceId.Equals(Constants.Audio.NO_DEVICE_ID) ? Constants.Audio.DEFAULT_DEVICE_ID : deviceId);
            Store.Data.Audio.OutputSource.Update(aoSettings);
            aoSettings.Dispose();

            Store.Data.Audio.OutputSource.Enabled = !deviceId.Equals(Constants.Audio.NO_DEVICE_ID);
            Store.Data.Audio.OutputSource.Muted   = deviceId.Equals(Constants.Audio.NO_DEVICE_ID); // Muted is used to update audio meter
        }
        /// <summary>
        /// Initializes a view for ObsProperties. </summary>
        /// <param name="settings"> The source of properties. </param>
        /// <param name="context"> Owner of the settings, receives callbacks when a change occurs. </param>
        /// <param name="reloadDelegate"> Callback used for refreshing properties. </param>
        /// <param name="defaultsDelegate"> Optional: Callback used for reseting the settings to default values. </param>
        /// <param name="updateDelegate"> Optional: Callback used for notifying the object when update is needed. </param>
        public PropertiesView(ObsData settings, IObsContextData context,
                              Func <ObsProperties> reloadDelegate, Func <ObsData> defaultsDelegate = null,
                              Action <ObsData> updateDelegate = null)
        {
            InitializeComponent();

            this.settings         = settings;
            this.context          = context;
            this.reloadDelegate   = reloadDelegate;
            this.defaultsDelegate = defaultsDelegate;
            this.updateDelegate   = updateDelegate;

            InitView();
        }
        private void AddColor(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            // note: libobs stores color in ABGR instead of ARGB

            Color   color   = ColorHelper.FromAbgr((int)setting.GetInt(name));
            TextBox textbox = new TextBox
            {
                Width     = 300,
                ForeColor = color.GetBrightness() > 0.93 ? Color.Black : color,
                Text      = color.ToHtml(),
                TextAlign = HorizontalAlignment.Center
            };

            Button button = new Button {
                Text = "Select..."
            };

            textbox.TextChanged += (sender, args) =>
            {
                Color newColor = ColorHelper.FromAbgr((int)setting.GetInt(name));
                newColor = newColor.FromHtml(textbox.Text);

                textbox.ForeColor = newColor.GetBrightness() > 0.93 ? Color.Black : newColor;
                setting.SetInt(name, newColor.ToAbgr());
                view.PropertyChanged(property);
            };

            button.Click += (sender, args) =>
            {
                ColorDialog colorDialog = new ColorDialog
                {
                    AllowFullOpen = true,
                    AnyColor      = true,
                    Color         = ColorHelper.TryColorFromHtml(textbox.Text),
                    FullOpen      = true
                };
                colorDialog.Color = colorDialog.Color.FromHtml(textbox.Text);

                if (colorDialog.ShowDialog(this) == DialogResult.OK)
                {
                    textbox.Text = colorDialog.Color.ToHtml();
                }
            };

            controls.Add(textbox);
            controls.Add(button);
        }
Beispiel #16
0
        /// <summary>
        /// Creates a new Obs video encoder with default settings.
        /// </summary>
        /// <returns></returns>
        public static ObsEncoder CreateVideoEncoder()
        {
            ObsEncoder obsVideoEncoder = new ObsEncoder(ObsEncoderType.Video, "obs_x264", "simple_h264_stream");
            IntPtr     obsVideoPointer = Obs.GetVideo();

            obsVideoEncoder.SetVideo(obsVideoPointer);

            ObsData videoEncoderSettings = new ObsData();

            videoEncoderSettings.SetInt("bitrate", Constants.Video.ENCODER_BITRATE);
            videoEncoderSettings.SetString("rate_control", Constants.Video.RATE_CONTROL);
            obsVideoEncoder.Update(videoEncoderSettings);
            videoEncoderSettings.Dispose();

            return(obsVideoEncoder);
        }
Beispiel #17
0
 private void toolOpenData_Click(object sender, EventArgs e)
 {
     Init();
     openFileDialog1.Filter = "(txt文件)|*txt";
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         try
         {
             Obs = FileHelper.ReadFile(openFileDialog1.FileName);
             UpdateViews();
         }
         catch (Exception)
         {
             throw new Exception("数据导入失败!");
         }
     }
 }
Beispiel #18
0
        private ObsData CreateWebcamSettings()
        {
            ObsData webcamSettings = new ObsData();

            webcamSettings.SetString(VideoCapture.VIDEO_DEVICE_ID, selectedWebcam.value);

            int buffering = 2;

            webcamSettings.SetInt(VideoCapture.BUFFERING, buffering); // 0 = Auto, 1 = Enable, 2 = Disable

            // need to check webcam whitelist
            if (Store.Data.Webcam.WebcamSettings.ShouldUseCustomSettings)
            {
                webcamSettings.SetString(VideoCapture.RESOLUTION, Store.Data.Webcam.WebcamSettings.Resolution);
                webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                webcamSettings.SetInt(VideoCapture.VIDEO_FORMAT, (int)Store.Data.Webcam.WebcamSettings.VideoFormat);
                webcamSettings.SetInt(VideoCapture.FRAME_INTERVAL, Store.Data.Webcam.WebcamSettings.Fps);
            }
            else
            {
                if (selectedWebcamResolution != null)
                {
                    webcamSettings.SetString(VideoCapture.RESOLUTION, selectedWebcamResolution.value);
                    webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                }
                else
                {
                    var preferredResolution = WebcamService.GetOptimalWebcamResolution(selectedWebcam.dsDeviceValue);

                    if (!string.IsNullOrEmpty(preferredResolution))
                    {
                        webcamSettings.SetString(VideoCapture.RESOLUTION, preferredResolution);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 1);
                    }
                    else
                    {
                        webcamSettings.Erase(VideoCapture.RESOLUTION);
                        webcamSettings.SetInt(VideoCapture.RESOLUTION_TYPE, 0);
                    }
                }
            }

            webcamSettings.SetBool(VideoCapture.ACTIVATE, true);

            return(webcamSettings);
        }
        private void EditableListChanged(ListBox listBox, ObsProperty property, ObsData setting)
        {
            string       propertyName = property.Name;
            ObsDataArray array        = new ObsDataArray();

            foreach (string item in listBox.Items)
            {
                ObsData itemArray = new ObsData();
                itemArray.SetString("value", item);

                array.Add(itemArray);
                itemArray.Dispose();
            }

            setting.SetArray(propertyName, array);
            array.Dispose();
        }
        /// <summary>
        /// Sets the audio input to the device with the given audio input id.
        /// </summary>
        /// <param name="savedAudioInputId"></param>
        /// <returns></returns>
        public static string SetAudioInput(string savedAudioInputId)
        {
            ObsData aiSettings = new ObsData();

            aiSettings.SetBool(Constants.Audio.SettingKeys.UseDeviceTiming, false);
            Store.Data.Audio.InputSource = Store.Data.Obs.Presentation.CreateSource(Constants.Audio.SettingKeys.WasapiInputCapture, Constants.Audio.Settings.WasapiInputCaptureName, aiSettings);
            aiSettings.Dispose();

            Store.Data.Audio.InputSource.AudioOffset = Constants.Audio.DELAY_INPUT;
            Store.Data.Obs.Presentation.AddSource(Store.Data.Audio.InputSource);
            Store.Data.Audio.InputItem      = Store.Data.Obs.Presentation.CreateItem(Store.Data.Audio.InputSource);
            Store.Data.Audio.InputItem.Name = Constants.Audio.Settings.WasapiInputCaptureName;

            Store.Data.Audio.InputMeter       = new VolMeter();
            Store.Data.Audio.InputMeter.Level = float.NegativeInfinity;
            Store.Data.Audio.InputMeter.AttachSource(Store.Data.Audio.InputSource);
            Store.Data.Audio.InputMeter.AddCallBack(MagnitudeService.InputVolumeCallback);

            List <AudioDevice> allAudioInputs = GetAudioInputDevices();
            bool savedIsInAvailableInputs     = allAudioInputs.Any(x => x.id == savedAudioInputId);

            var usedAudioInputId = string.Empty;

            if (savedAudioInputId != null && savedIsInAvailableInputs)
            {
                UpdateAudioInput(savedAudioInputId);
                usedAudioInputId = savedAudioInputId;
            }
            else
            {
                string defaultDeviceId = Constants.Audio.NO_DEVICE_ID;

                IEnumerable <AudioDevice> availableInputs = allAudioInputs.Where(x => x.id != Constants.Audio.NO_DEVICE_ID);
                if (availableInputs.Any())
                {
                    defaultDeviceId = availableInputs.First().id;
                }

                UpdateAudioInput(defaultDeviceId);
                usedAudioInputId = defaultDeviceId;
            }

            return(usedAudioInputId);
        }
        private void AddBool(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            CheckBox checkbox = new CheckBox
            {
                Width     = 300,
                Height    = 18,
                Checked   = setting.GetBool(name),
                Text      = property.Description,
                TextAlign = ContentAlignment.MiddleLeft
            };

            checkbox.CheckedChanged += (sender, args) =>
            {
                setting.SetBool(name, checkbox.Checked);
                view.PropertyChanged(property);
            };

            controls.Add(checkbox);
        }
Beispiel #22
0
        private void SetWebcamSourceSettings()
        {
            // Start a timer to see when the webcam resolution has changed
            webcamWidthBeforeChange  = (int)Store.Data.Webcam.Source.Width;
            webcamHeightBeforeChange = (int)Store.Data.Webcam.Source.Height;

            ObsData webcamSettings = CreateWebcamSettings();

            Store.Data.Webcam.Source.Update(webcamSettings);
            webcamSettings.Dispose();

            InitializeWebcamPreview();

            changeResolutionTimer?.Stop();
            changeResolutionTimer          = new SystemTimer();
            changeResolutionTimer.Interval = 100;
            changeResolutionTimer.Elapsed += new ElapsedEventHandler(CheckIfWebcamResolutionChanged);
            changeResolutionTimer.Enabled  = true;
            changeResolutionTimer.Start();
            changeResolutionTimer.Disposed += delegate(object sender, EventArgs e)
            {
                elapsedTimerTime = 0;
            };
        }
 public Filter(string id, string name, ObsData settings)
     : base(ObsSourceType.Filter, id, name, settings)
 {
 }
        private void AddEditableList(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;
            ObsEditableListType type = property.EditableListType;

            FlowLayoutPanel layoutPanel = new FlowLayoutPanel()
            {
                FlowDirection = FlowDirection.TopDown,
                AutoSize      = true,
                AutoSizeMode  = AutoSizeMode.GrowAndShrink
            };

            ListBox listBox = new ListBox()
            {
                Width          = 300,
                Height         = 180,
                IntegralHeight = false,
                SelectionMode  = SelectionMode.MultiExtended,
            };

            //TODO: use icons for list buttons
            Button buttonAdd = new Button {
                Text = "+", Width = 25, Tag = listBox
            };
            Button buttonAddMulti = new Button {
                Text = "B", Width = 25, Tag = listBox
            };
            Button buttonRemove = new Button {
                Text = "-", Width = 25, Tag = listBox
            };
            Button buttonConfig = new Button {
                Text = "C", Width = 25, Tag = listBox
            };
            Button buttonUp = new Button {
                Text = "^", Width = 25, Tag = listBox
            };
            Button buttonDown = new Button {
                Text = "v", Width = 25, Tag = listBox
            };

            using (ObsDataArray array = setting.GetArray(name))
            {
                listBox.BeginUpdate();

                if (array != null)
                {
                    foreach (ObsData item in array)
                    {
                        listBox.Items.Add(item.GetString("value"));
                    }
                }

                listBox.EndUpdate();
            }

            buttonAdd.Click += (sender, args) =>
            {
                //TODO: open dialog with ok/cancel options, text field and browse button (with allowFiles)
            };

            buttonAddMulti.Click += (sender, args) =>
            {
                OpenFileDialog dialog = new OpenFileDialog
                {
                    AutoUpgradeEnabled = true,
                    Filter             = property.EditableListFilter.ToString(),
                    FilterIndex        = 1,
                    InitialDirectory   = property.EditableListPathDefault,
                    Multiselect        = true
                };

                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    listBox.BeginUpdate();
                    listBox.Items.AddRange(dialog.FileNames);
                    listBox.EndUpdate();

                    EditableListChanged(listBox, property, setting);
                }
            };

            buttonRemove.Click += (sender, args) =>
            {
                if (listBox.SelectedItems.Count == 0)
                {
                    return;
                }

                listBox.BeginUpdate();

                for (int i = listBox.SelectedItems.Count - 1; i >= 0; i--)
                {
                    listBox.Items.RemoveAt(listBox.SelectedIndices[i]);
                }

                listBox.EndUpdate();

                EditableListChanged(listBox, property, setting);
            };

            buttonConfig.Click += (sender, args) =>
            {
                // To avoid confusion, only allow to edit one item at the time
                if (listBox.SelectedItems.Count != 1)
                {
                    return;
                }


                //TODO: open dialog with ok/cancel options, text field and browse button (with allowFiles), same as in add

                /*OpenFileDialog dialog = new OpenFileDialog
                 * {
                 *      FileName = listBox.SelectedItem.ToString(),
                 *      AutoUpgradeEnabled = true,
                 *      Filter = property.EditableListFilter.ToString(),
                 *      FilterIndex = 1,
                 *      InitialDirectory = property.EditableListPathDefault,
                 *      Multiselect = true
                 * };
                 *
                 * if (dialog.ShowDialog(this) == DialogResult.OK)
                 * {
                 *      listBox.Items[listBox.SelectedIndex] = dialog.FileName;
                 *      EditableListChanged(listBox, property, setting);
                 * }*/
            };

            buttonUp.Click += (sender, args) =>
            {
                if (listBox.SelectedItems.Count == 0)
                {
                    return;
                }

                listBox.BeginUpdate();

                int lastIndex = -1;
                for (int i = 0; i < listBox.SelectedItems.Count; i++)
                {
                    int    index    = listBox.SelectedIndices[i];
                    int    newIndex = Math.Max(index - 1, 0);
                    object item     = listBox.Items[index];

                    if (index != newIndex && newIndex != lastIndex)
                    {
                        listBox.Items.RemoveAt(index);
                        listBox.Items.Insert(newIndex, item);
                        listBox.SetSelected(newIndex, true);
                    }
                    lastIndex = newIndex;
                }

                listBox.EndUpdate();

                EditableListChanged(listBox, property, setting);
            };

            buttonDown.Click += (sender, args) =>
            {
                if (listBox.SelectedItems.Count == 0)
                {
                    return;
                }

                listBox.BeginUpdate();

                int lastIndex = -1;
                for (int i = listBox.SelectedItems.Count - 1; i >= 0; i--)
                {
                    int    index    = listBox.SelectedIndices[i];
                    int    newIndex = Math.Min(index + 1, listBox.Items.Count - 1);
                    object item     = listBox.Items[index];

                    if (index != newIndex && newIndex != lastIndex)
                    {
                        listBox.Items.RemoveAt(index);
                        listBox.Items.Insert(newIndex, item);
                        listBox.SetSelected(newIndex, true);
                    }
                    lastIndex = newIndex;
                }

                listBox.EndUpdate();

                EditableListChanged(listBox, property, setting);
            };

            layoutPanel.Controls.Add(buttonAdd);

            if (type == ObsEditableListType.Strings)
            {
                layoutPanel.Controls.Add(buttonAddMulti);
            }
            else
            {
                throw new NotImplementedException(type.ToString());
            }

            layoutPanel.Controls.Add(buttonRemove);
            layoutPanel.Controls.Add(buttonConfig);
            layoutPanel.Controls.Add(buttonUp);
            layoutPanel.Controls.Add(buttonDown);

            controls.Add(listBox);
            controls.Add(layoutPanel);
        }
Beispiel #25
0
 public Transition(string id, string name, ObsData settings) : base(ObsSourceType.Transition, id, name, settings)
 {
 }
        public PropertyControl(PropertiesView view, ObsProperty property, ObsData setting)
        {
            SuspendLayout();
            AutoSize = true;
            Margin   = new Padding(0, 1, 0, 1);
            Size     = new Size(600, 25);
            ResumeLayout(false);

            this.view = view;

            DoubleBuffered = true;
            Padding        = new Padding(2);

            ObsPropertyType type     = property.Type;
            bool            addLabel = true;
            List <Control>  controls = new List <Control>();

            switch (type)
            {
            case ObsPropertyType.Bool:
            {
                addLabel = false;
                AddBool(property, setting, controls);
                break;
            }

            case ObsPropertyType.Int:
            case ObsPropertyType.Float:
            {
                AddNumeric(property, setting, controls);
                break;
            }

            case ObsPropertyType.Text:
            {
                AddText(property, setting, controls);
                break;
            }

            case ObsPropertyType.Path:
            {
                AddPath(property, setting, controls);
                break;
            }

            case ObsPropertyType.List:
            {
                AddList(property, setting, controls);
                break;
            }

            case ObsPropertyType.Color:
            {
                AddColor(property, setting, controls);
                break;
            }

            case ObsPropertyType.Button:
            {
                addLabel = false;
                AddButton(property, setting, controls);
                break;
            }

            case ObsPropertyType.Font:
            {
                AddFont(property, setting, controls);
                break;
            }

            case ObsPropertyType.EditableList:
            {
                addLabel = false;
                AddEditableList(property, setting, controls);
                break;
            }

            default:
            {
                throw new Exception(String.Format("Error, unimplemented property type {0} for property {1}", type, property.Description));
            }
            }

            Label nameLabel = new Label
            {
                Text        = addLabel ? property.Description : "",
                TextAlign   = ContentAlignment.MiddleRight,
                MinimumSize = new Size(170, 0),
                AutoSize    = true,
                Dock        = DockStyle.Left
            };

            controls.Insert(0, nameLabel);

            foreach (Control control in controls)
            {
                WinFormsHelper.DoubleBufferControl(control);

                int     margin    = 0;
                Padding oldmargin = control.Margin;
                oldmargin.Top    = margin;
                oldmargin.Bottom = margin;
                control.Margin   = oldmargin;
            }

            SuspendLayout();
            Controls.AddRange(controls.ToArray());
            ResumeLayout();
        }
        private void AddList(ObsProperty property, ObsData setting, List <Control> controls)
        {
            string name = property.Name;

            int index = 0;

            string[]     names  = property.GetListItemNames();
            object[]     values = property.GetListItemValues();
            EventHandler selectedIndexChanged = null;
            ComboBox     combobox             = new ComboBox {
                Width = 300
            };

            combobox.Items.AddRange(names.ToArray());

            //if (namelist.Length > 0)
            //	combobox.SelectedIndex = 0;

            if (property.ListType == ObsComboType.List)
            {
                combobox.DropDownStyle = ComboBoxStyle.DropDownList;
            }

            switch (property.ListFormat)
            {
            case ObsComboFormat.Float:
            {
                index = Array.IndexOf(values, setting.GetDouble(name));

                selectedIndexChanged = (sender, args) =>
                {
                    double value = (double)values.GetValue(combobox.SelectedIndex);
                    setting.SetDouble(name, value);
                    view.PropertyChanged(property);
                };
                break;
            }

            case ObsComboFormat.Int:
            {
                var val = setting.GetInt(name);
                index = Array.IndexOf(values, setting.GetInt(name));

                selectedIndexChanged = (sender, args) =>
                {
                    long value = (long)values[combobox.SelectedIndex];
                    setting.SetInt(name, (int)value);
                    view.PropertyChanged(property);
                };
                break;
            }

            case ObsComboFormat.String:
            {
                index = Array.IndexOf(values, setting.GetString(name));

                selectedIndexChanged = (sender, args) =>
                {
                    string value = (string)values[combobox.SelectedIndex];
                    setting.SetString(name, value);
                    view.PropertyChanged(property);
                };
                break;
            }
            }

            if (index != -1)
            {
                combobox.SelectedIndex = index;
            }

            combobox.SelectedIndexChanged += selectedIndexChanged;

            if (index == -1 && names.Length > 0)
            {
                combobox.SelectedIndex = 0;
            }

            controls.Add(combobox);
        }
Beispiel #28
0
 public Source(string id, string name, ObsData settings)
     : base(ObsSourceType.Input, id, name, settings)
 {
     Filters = new BindingList <Filter>();
 }
Beispiel #29
0
        /// <summary>
        /// Create a property dialog for an existing source
        /// </summary>
        /// <param name="source">Source of type ObsSource</param>
        public TestFilter(Source source)
            : this()
        {
            FilterSource   = source;
            sourceSettings = FilterSource.GetSettings();

            FilterListBox.DisplayMember = "Name";
            FilterListBox.DataSource    = FilterSource.Filters;

            oldfilters = FilterSource.Filters;

            undoButton.Enabled    = false;
            defaultButton.Enabled = false;

            if (FilterSource.Filters.Any())
            {
                Select(FilterSource.Filters.First());
                undoButton.Enabled    = true;
                defaultButton.Enabled = true;
            }

            defaultButton.Click += (sender, args) =>
            {
                view.ResetToDefaults();
            };

            okButton.Click += (o, args) =>
            {
                if (view != null)
                {
                    view.UpdateSettings();
                }
                DialogResult = DialogResult.OK;
                Close();
            };

            cancelButton.Click += (o, args) =>
            {
                FilterSource.ClearFilters();

                foreach (Filter oldfilter in oldfilters)
                {
                    FilterSource.AddFilter(oldfilter);
                }

                DialogResult = DialogResult.Cancel;
                Close();
            };

            undoButton.Click += (sender, args) =>
            {
                view.ResetChanges();
            };

            AddFilterButton.Click += (sender, args) =>
            {
                FilterMenu().Show(this, PointToClient(Cursor.Position));
            };

            RemoveFilterButton.Click += (sender, args) =>
            {
                if (SelectedFilter != null)
                {
                    FilterSource.RemoveFilter(SelectedFilter);
                    propertyPanel.Controls.Clear();
                    view = null;
                }
            };
        }
        private void AddNumeric(ObsProperty property, ObsData setting, List <Control> controls)
        {
            ObsPropertyType type = property.Type;
            string          name = property.Name;

            NumericUpDown numeric = new NumericUpDown
            {
                Width         = 300,
                DecimalPlaces = 0
            };

            if (type == ObsPropertyType.Int)
            {
                int  intMin   = property.IntMin;
                int  intMax   = property.IntMax;
                long intValue = setting.GetInt(name);
                intValue = Math.Max(Math.Min(intValue, intMax), intMin);

                numeric.Minimum   = intMin;
                numeric.Maximum   = intMax;
                numeric.Increment = property.IntStep;
                numeric.Value     = intValue;

                numeric.ValueChanged += (sender, args) =>
                {
                    setting.SetInt(name, (int)numeric.Value);
                    view.PropertyChanged(property);
                };
            }
            else if (type == ObsPropertyType.Float)
            {
                double floatMin   = property.FloatMin;
                double floatMax   = property.FloatMax;
                double floatValue = setting.GetDouble(name);
                floatValue = Math.Max(Math.Min(floatValue, floatMax), floatMin);

                numeric.DecimalPlaces = 2;
                numeric.Minimum       = (decimal)floatMin;
                numeric.Maximum       = (decimal)floatMax;
                numeric.Increment     = (decimal)property.FloatStep;
                numeric.Value         = (decimal)floatValue;

                numeric.ValueChanged += (sender, args) =>
                {
                    setting.SetDouble(name, (double)numeric.Value);
                    view.PropertyChanged(property);
                };
            }

            if (property.IntType == ObsNumberType.Slider || property.FloatType == ObsNumberType.Slider)
            {
                numeric.Width  = 75;
                numeric.Height = 23;

                const int multiplier = 1000;
                var       trackbar   = new TrackBar
                {
                    AutoSize    = false,
                    Width       = 300,
                    Height      = 23,
                    TickStyle   = TickStyle.None,
                    Minimum     = (int)(numeric.Minimum * multiplier),
                    Maximum     = (int)(numeric.Maximum * multiplier),
                    SmallChange = (int)(numeric.Increment * multiplier),
                    LargeChange = (int)(numeric.Increment * multiplier),
                    Value       = (int)(numeric.Value * multiplier)
                };
                trackbar.ValueChanged += (sender, args) => numeric.Value = (decimal)trackbar.Value / multiplier;
                numeric.ValueChanged  += (sender, args) => trackbar.Value = (int)(numeric.Value * multiplier);
                controls.Add(trackbar);
            }
            controls.Add(numeric);
        }