Ejemplo n.º 1
0
        public WorkFlowCommand CreateCommand()
        {
            var command = GetCommand();

            command.Properties.Add(new CustomProperty()
            {
                Name         = "OverlayFile",
                PropertyType = CustomPropertyType.File,
                Value        = ""
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "StrechOverlay",
                PropertyType = CustomPropertyType.Bool,
                Value        = "true"
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "Position",
                PropertyType = CustomPropertyType.ValueList,
                Value        = Enum.GetNames(typeof(Gravity)).ToList()[0],
                ValueList    = Enum.GetNames(typeof(Gravity)).ToList()
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "Transparency",
                PropertyType = CustomPropertyType.Number,
                Value        = "100",
                RangeMin     = 0,
                RangeMax     = 100
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "Text",
                PropertyType = CustomPropertyType.String,
                Description  = "Multiline can be used use \\n for a new line",
                Value        = ""
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "TextPointSize",
                PropertyType = CustomPropertyType.Number,
                Value        = "50",
                RangeMin     = 8,
                RangeMax     = 500
            });
            command.Properties.Items.Add(new CustomProperty()
            {
                Name         = "TextFillColor",
                PropertyType = CustomPropertyType.Color,
                Value        = "Red"
            });
            command.Properties.Items.Add(new CustomProperty()
            {
                Name         = "TextStrokeColor",
                PropertyType = CustomPropertyType.Color,
                Value        = "Blue"
            });
            command.Properties.Items.Add(new CustomProperty()
            {
                Name         = "TextFont",
                PropertyType = CustomPropertyType.String,
                Value        = "Arial",
                ValueList    = Fonts()
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "TextPosition",
                PropertyType = CustomPropertyType.ValueList,
                Value        = Enum.GetNames(typeof(Gravity)).ToList()[0],
                ValueList    = Enum.GetNames(typeof(Gravity)).ToList()
            });
            command.Properties.Add(new CustomProperty()
            {
                Name         = "TextTransparency",
                PropertyType = CustomPropertyType.Number,
                Value        = "100",
                RangeMin     = 0,
                RangeMax     = 100
            });
            return(command);
        }
Ejemplo n.º 2
0
        public static void ComboBox(SerializedProperty property)
        {
            var action       = (Action)property.Object;
            var propertyInfo = property.Property;
            var enumData     = (Enum)property.Property.GetValue(action);

            var panel = new DockPanel {
                VerticalAlignment = VerticalAlignment.Center,
                // Margin = new Thickness(5, 0, 5, 0)
                Margin = actionPropertyIndex == 0 ? new Thickness(5, 0, 5, 0) : new Thickness(5, 5, 5, 0)
            };

            actionPropertyIndex++;

            var options = (string[])Enum.GetNames(enumData.GetType());

            var label = propertyInfo.GetCustomAttribute <LabelAttribute>()?.text ?? propertyInfo.Name.ToDisplayName();

            // var actions = ActionsControl.control;
            var textBlock = new TextBlock {
                Text              = label,
                Width             = 100,
                VerticalAlignment = VerticalAlignment.Center
            };

            var tooltip = property.Property.GetCustomAttribute <TooltipAttribute>();

            if (tooltip is TooltipAttribute attr)
            {
                textBlock.ToolTip = attr.toolTip;
                ToolTipService.SetShowDuration(textBlock, int.MaxValue);
            }

            var comboBox = new ComboBox {
                Margin     = new Thickness(5, 0, 2, 0),
                Foreground = Brushes.Black
            };

            comboBox.DropDownClosed += (sender, evt) => {
                // ActionsControl.OnActionsUpdated(sender);
            };

            foreach (var option in options)
            {
                var v           = Enum.Parse(enumData.GetType(), option);
                var bindingData = new BindingData {
                    Action   = action,
                    Property = propertyInfo,
                    Label    = textBlock,
                    Input    = comboBox,
                    Value    = v
                };
                var comboBoxItem = new ComboBoxItem {
                    DataContext = bindingData,
                    Content     = new TextBlock {
                        Text = option.ToDisplayName(), Foreground = Brushes.Black
                    },
                };
                if (propertyInfo.GetValue(action).Equals(v))
                {
                    comboBox.SelectedItem = comboBoxItem;
                }
                comboBox.Items.Add(comboBoxItem);
            }

            // Note: Add the event after the initial selection so it doesn't get triggered.
            comboBox.SelectionChanged += (sender, evt) => {
                var comboBox = (ComboBox)sender;
                var item     = (ComboBoxItem)comboBox.SelectedItem;
                var context  = (BindingData)item.DataContext;
                propertyInfo.SetValue(action, context.Value);
                EventBus.OnLayerActionChanged(sender);
            };

            DockPanel.SetDock(textBlock, Dock.Left);
            DockPanel.SetDock(comboBox, Dock.Right);

            panel.Children.Add(textBlock);
            panel.Children.Add(comboBox);

            AddAction(panel, property);
        }