예제 #1
0
        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);
        }
예제 #2
0
        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);
        }