Exemplo n.º 1
0
        public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ColorBoxButton colorBox;
            var            panel        = new ColorPickerPanel();
            var            currentColor = CoalescedPropertyValue(Color4.White).DistinctUntilChanged();

            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout {
                    DefaultCell = new DefaultLayoutCell(Alignment.Center)
                },
                Nodes =
                {
                    (editor   = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (colorBox = new ColorBoxButton(currentColor)),
                    CreatePipetteButton(),
                    Spacer.HStretch(),
                },
            });
            ExpandableContent.AddNode(panel.Widget);
            panel.Widget.Padding = panel.Widget.Padding + new Thickness(right: 12.0f);
            panel.Widget.Tasks.Add(currentColor.Consume(v => {
                if (panel.Color != v)
                {
                    panel.Color = v;
                }
                Changed?.Invoke();
            }));
            panel.Changed += () => {
                EditorParams.History?.RollbackTransaction();
                SetProperty(panel.Color);
            };
            panel.DragStarted += () => {
                EditorParams.History?.BeginTransaction();
                lastColor = panel.Color;
            };
            panel.DragEnded += () => {
                if (panel.Color != lastColor)
                {
                    EditorParams.History?.CommitTransaction();
                }
                EditorParams.History?.EndTransaction();
            };
            colorBox.Clicked += () => Expanded = !Expanded;
            var currentColorString = currentColor.Select(i => i.ToString(Color4.StringPresentation.Dec));

            editor.Submitted += text => SetComponent(text, currentColorString);
            editor.Tasks.Add(currentColorString.Consume(v => editor.Text = v));
            editor.AddChangeWatcher(() => editor.Text, value => CheckEditorText(value, editor));
        }
Exemplo n.º 2
0
        public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ColorBoxButton colorBox;
            var            panel        = new ColorPickerPanel();
            var            currentColor = CoalescedPropertyValue(Color4.White).DistinctUntilChanged();

            ContainerWidget.AddNode(new Widget {
                Layout = new HBoxLayout {
                    CellDefaults = new LayoutCell(Alignment.Center)
                },
                Nodes =
                {
                    (editor   = editorParams.EditBoxFactory()),
                    new HSpacer(4),
                    (colorBox = new ColorBoxButton(currentColor)),
                    CreatePipetteButton(),
                }
            });
            ExpandableContent.AddNode(panel.Widget);
            panel.Widget.Padding.Right = 12;
            panel.Widget.Tasks.Add(currentColor.Consume(v => panel.Color = v));
            panel.Changed     += () => SetProperty(panel.Color);
            panel.DragStarted += Document.Current.History.BeginTransaction;
            panel.DragEnded   += Document.Current.History.EndTransaction;
            colorBox.Clicked  += () => Expanded = !Expanded;
            var currentColorString = currentColor.Select(i => i.ToString(Color4.StringPresentation.Dec));

            editor.Submitted += text => {
                Color4 newColor;
                if (Color4.TryParse(text, out newColor))
                {
                    SetProperty(newColor);
                }
                else
                {
                    editor.Text = currentColorString.GetValue();
                }
            };
            editor.Tasks.Add(currentColorString.Consume(v => editor.Text = v));
        }
Exemplo n.º 3
0
        public ColorGradientPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            if (editorParams.Objects.Count() > 1)
            {
                ExpandButton.Visible = false;
                EditorContainer.AddNode(new ThemedSimpleText {
                    Text       = "Unable to edit multiple gradients",
                    VAlignment = VAlignment.Center,
                    LayoutCell = new LayoutCell(Alignment.Center, stretchX: 0),
                });
                return;
            }
            gradientControlWidget = new TransactionalGradientControlWidget(EditorParams.History)
            {
                MinMaxHeight = 35f,
                Height       = 35f,
                LayoutCell   = new LayoutCell(Alignment.LeftCenter),
                Padding      = new Thickness {
                    Right = 5f, Bottom = 5f
                }
            };
            var gradientProperty = CoalescedPropertyValue(new ColorGradient(Color4.White, Color4.Black)).DistinctUntilChanged();

            gradientControlWidget.Gradient = gradientProperty.GetValue();
            ContainerWidget.AddChangeWatcher(gradientProperty, g => gradientControlWidget.Gradient = g);
            gradientControlWidget.SelectionChanged += SelectPoint;
            EditorContainer.AddNode(gradientControlWidget);
            EditorContainer.AddNode(CreatePipetteButton());
            ExpandableContent.Padding = new Thickness {
                Left = 25f, Right = 25f, Top = 5f
            };
            ExpandableContent.AddNode(new Widget {
                Layout = new HBoxLayout {
                    Spacing = 10f
                },
                Nodes =
                {
                    new ThemedSimpleText {
                        Text = nameof(GradientControlPoint.Position), MinWidth = 150
                    },
                    (positionEditor = EditorParams.NumericEditBoxFactory())
                },
                Padding = new Thickness(0, 3f)
            });
            ExpandableContent.AddNode(new Widget {
                Layout = new HBoxLayout {
                    Spacing = 10f
                },
                Nodes =
                {
                    new ThemedSimpleText {
                        Text = nameof(GradientControlPoint.Color), MinWidth = 150
                    },
                    (colorEditor = EditorParams.EditBoxFactory())
                },
                Padding = new Thickness(0, 3f)
            });
            positionEditor.Step       = 0.005f;
            colorEditor.Submitted    += SetColor;
            positionEditor.Submitted += SetPosition;
            colorPanel = new ColorPickerPanel();
            ExpandableContent.AddNode(colorPanel.Widget);
            var padding = colorPanel.Widget.Padding;

            padding.Right                      = 12;
            colorPanel.Widget.Padding          = padding;
            colorPanel.DragStarted            += () => EditorParams.History?.BeginTransaction();
            gradientControlWidget.DragStarted += () => EditorParams.History?.BeginTransaction();
            gradientControlWidget.DragEnded   += () => {
                EditorParams.History?.CommitTransaction();
                EditorParams.History?.EndTransaction();
            };
            colorPanel.DragEnded += () => {
                EditorParams.History?.CommitTransaction();
                EditorParams.History?.EndTransaction();
            };
            colorPanel.Changed += () => {
                EditorParams.History?.RollbackTransaction();
                Core.Operations.SetProperty.Perform(selectedControlPoint, nameof(GradientControlPoint.Color), colorPanel.Color);
            };
            SelectPoint(selectedControlPoint);
        }
Exemplo n.º 4
0
        public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            ColorBoxButton colorBox;

            panel = new ColorPickerPanel();
            var objects  = EditorParams.Objects.ToList();
            var first    = PropertyValue(objects.First()).GetValue();
            var @default = objects.All(o =>
                                       PropertyValue(o).GetValue().A == first.A) ? new Color4(255, 255, 255, first.A) : Color4.White;
            var currentColor = CoalescedPropertyValue(@default).DistinctUntilChanged();

            panel.Color = currentColor.GetValue().Value;
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout {
                    DefaultCell = new DefaultLayoutCell(Alignment.Center)
                },
                Nodes =
                {
                    (editor   = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (colorBox = new ColorBoxButton(currentColor)),
                    CreatePipetteButton(),
                    Spacer.HStretch(),
                },
            });
            ExpandableContent.AddNode(panel.Widget);
            panel.Widget.Padding += new Thickness(right: 12.0f);
            panel.Widget.Components.GetOrAdd <LateConsumeBehaviour>().Add(currentColor.Consume(v => {
                if (panel.Color != v.Value)
                {
                    panel.Color = v.Value;
                }
                Changed?.Invoke();
            }));
            panel.Changed += () => {
                EditorParams.History?.RollbackTransaction();
                if ((panel.Color.ABGR & 0xFFFFFF) == (previousColor.ABGR & 0xFFFFFF) && panel.Color.A != previousColor.A)
                {
                    SetProperty <Color4>(c => {
                        c.A = panel.Color.A;
                        return(c);
                    });
                }
                else
                {
                    SetProperty(panel.Color);
                }
            };
            panel.DragStarted += () => {
                EditorParams.History?.BeginTransaction();
                previousColor = panel.Color;
            };
            panel.DragEnded += () => {
                if (panel.Color != previousColor || (editorParams.Objects.Skip(1).Any() && SameValues()))
                {
                    EditorParams.History?.CommitTransaction();
                }
                EditorParams.History?.EndTransaction();
            };
            colorBox.Clicked += () => Expanded = !Expanded;
            var currentColorString = currentColor.Select(i => i.Value.ToString(Color4.StringPresentation.Dec));

            editor.Submitted += text => {
                SetComponent(text, currentColorString);
            };
            editor.AddChangeLateWatcher(currentColorString, v => editor.Text = SameValues() ? v : ManyValuesText);
            editor.AddChangeLateWatcher(() => editor.Text, value => CheckEditorText(value, editor));
            ManageManyValuesOnFocusChange(editor, currentColor);
        }