public void CreateUI()
        {
            AnnotationValue.PropertyChanged += new PropertyChangedEventHandler(OnResourcePropertyChanged);

            if (IsTexture)
            {
                UIElement = new ImagePicker(this);
            }
            else if (DataType.IsBool() && IsScalar)
            {
                UIElement = PropertyHelpers.CreateCheckBox(this, "Value", Value);
            }
            else if (!DataType.IsBool() && IsScalar && (IsSNorm || IsUNorm ||
                                                        (Annotations?.Contains(new KeyValuePair <string, string>("UIWidget", "Slider")) ?? false)))
            {
                object val = Value;
                if (val == null)
                {
                    if (DataType.IsIntegral())
                    {
                        Value = 0;
                    }
                    else
                    {
                        Value = 0.0;
                    }
                }
                UIElement = PropertyHelpers.CreateSlider(this, "Value", this, val);
            }
            else if (!IsMatrix && (Columns == 3 || Columns == 4) &&
                     (Annotations?.Contains(new KeyValuePair <string, string>("UIWidget", "Color")) ?? false))
            {
                UIElement = PropertyHelpers.CreateColorPicker(this, "Value", (Columns == 4) ? true : false, Value);
            }
            else if (IsScalar)
            {
                UIElement = PropertyHelpers.CreateSpinner(this, "Value", this, Value);
            }
            else
            {
                UIElement = new DropdownVecMatProperty(this);
            }
        }
예제 #2
0
        private void InitializeItemsSource()
        {
            DataType type = AnnotationVariable.DataType;

            if (type.IsBool())
            {
                if (Values == null || Values.Count != AnnotationVariable.Rows * AnnotationVariable.Columns)
                {
                    Values = new ObservableCollection <object>(new object[AnnotationVariable.Rows * AnnotationVariable.Columns]);
                }

                for (int row = 0; row < AnnotationVariable.Rows; ++row)
                {
                    StackPanel panel = new StackPanel();
                    panel.Orientation = Orientation.Horizontal;
                    for (int column = 0; column < AnnotationVariable.Columns; ++column)
                    {
                        UIElement element = PropertyHelpers.CreateCheckBox(this, $"Values[{row * (int)AnnotationVariable.Columns + column}]", Values[row * (int)AnnotationVariable.Columns + column]);
                        panel.Children.Add(element);
                    }
                    Items.Add(panel);
                }
            }
            else if ((AnnotationVariable.Columns == 3 || AnnotationVariable.Columns == 4) &&
                     (AnnotationVariable.Annotations?.Contains(new KeyValuePair <string, string>("UIWidget", "Color")) ?? false))
            {
                if (Values == null || Values.Count != AnnotationVariable.Rows)
                {
                    Values = new ObservableCollection <object>(new object[AnnotationVariable.Rows]);
                }

                for (int row = 0; row < AnnotationVariable.Rows; ++row)
                {
                    UIElement element = PropertyHelpers.CreateColorPicker(this, $"Values[{row}]", (AnnotationVariable.Columns == 4) ? true : false, Values[row]);
                    Items.Add(element);
                }
            }
            else if (AnnotationVariable.Columns == 1 &&
                     (AnnotationVariable.Annotations?.Contains(new KeyValuePair <string, string>("UIWidget", "Slider")) ?? false))
            {
                if (Values == null || Values.Count != AnnotationVariable.Rows)
                {
                    Values = new ObservableCollection <object>(new object[AnnotationVariable.Rows]);
                }

                for (int row = 0; row < AnnotationVariable.Rows; ++row)
                {
                    object val = Values[row];
                    if (val == null)
                    {
                        if (AnnotationVariable.DataType.IsIntegral())
                        {
                            Values[row] = 0;
                        }
                        else
                        {
                            Values[row] = 0.0;
                        }
                    }
                    UIElement element = PropertyHelpers.CreateSlider(this, $"Values[{row}]", AnnotationVariable, val);
                    Items.Add(element);
                }
            }
            else
            {
                if (Values == null || Values.Count != AnnotationVariable.Rows * AnnotationVariable.Columns)
                {
                    Values = new ObservableCollection <object>(new object[AnnotationVariable.Rows * AnnotationVariable.Columns]);
                }
                for (int row = 0; row < AnnotationVariable.Rows; ++row)
                {
                    StackPanel panel = new StackPanel();
                    panel.Orientation = Orientation.Horizontal;
                    for (int column = 0; column < AnnotationVariable.Columns; ++column)
                    {
                        UIElement element = PropertyHelpers.CreateSpinner(this, $"Values[{row * (int)AnnotationVariable.Columns + column}]", AnnotationVariable, Values[row * (int)AnnotationVariable.Columns + column]);
                        panel.Children.Add(element);
                    }
                    Items.Add(panel);
                }
            }
        }