private void SetLink(int index, IDataflowProvider <CoalescedValue <int> > indexProvider, IDataflowProvider <CoalescedValue <float> > weightProvider)
        {
            var currentIndexValue  = indexProvider.GetValue();
            var currentWeightValue = weightProvider.GetValue();
            var indexEditor        = indexEditors[index];
            var weightEditor       = weightsSliders[index];

            indexEditor.Submitted += text => SetIndexValue(index, indexEditor, currentIndexValue);
            weightEditor.Changed  += () => SetWeightValue(index, weightEditor);
            weightEditor.Value     = currentWeightValue.IsDefined ? currentWeightValue.Value : 0;
            indexEditor.AddChangeLateWatcher(indexProvider,
                                             v => indexEditor.Text = v.IsDefined ? v.Value.ToString() : ManyValuesText);
            weightEditor.AddChangeLateWatcher(weightProvider,
                                              v => {
                weightEditor.Value = v.IsDefined ? v.Value : 0;
                if (!v.IsDefined)
                {
                    weightEditor.LabelText = ManyValuesText;
                }
            });
            weightEditor.DragStarted += () => {
                EditorParams.History?.BeginTransaction();
                previousValue = weightEditor.Value;
            };
            weightEditor.DragEnded += () => {
                if (weightEditor.Value != previousValue || (EditorParams.Objects.Skip(1).Any() && SameValues()))
                {
                    EditorParams.History?.CommitTransaction();
                }
                EditorParams.History?.EndTransaction();
            };
            ManageManyValuesOnFocusChange(indexEditor, indexProvider);
            ManageManyValuesOnFocusChange(weightEditor.Editor, weightProvider);
        }
Beispiel #2
0
 public void SetPosition(string text)
 {
     if (float.TryParse(text, out var newPosition))
     {
         SetControlPointProperty(nameof(GradientControlPoint.Position), Mathf.Clamp(newPosition, 0, 1));
     }
     positionEditor.Text = selectedPointPositionProperty.GetValue().ToString("0.###");
 }
Beispiel #3
0
 public void SetComponent(string text, IDataflowProvider <float> current)
 {
     if (Parser.TryParse(text, out double newValue))
     {
         SetProperty((float)newValue);
     }
     editor.Text = current.GetValue().ToString("0.###");
 }
                private IEnumerator <object> DragTask(Widget canvas)
                {
                    while (true)
                    {
                        yield return(null);

                        if (!canvas.Input.WasMousePressed())
                        {
                            continue;
                        }
                        var d = canvas.LocalMousePosition() - Project(canvas, GetPosition());
                        if (d.Length > 7)
                        {
                            continue;
                        }
                        canvas.Input.ConsumeKey(Key.Mouse0);
                        var history = editor.EditorParams.History;
                        try {
                            history?.BeginTransaction();
                            var v = valueProvider.GetValue().Value;
                            while (canvas.Input.IsMousePressed())
                            {
                                history?.RollbackTransaction();
                                v = valueProvider.GetValue().Value;
                                var p = Unproject(canvas, canvas.LocalMousePosition());
                                p.X = Mathf.Clamp(p.X, 0, 1);
                                p.Y = Mathf.Clamp(p.Y, 0, 1);
                                if (index == 0)
                                {
                                    v.P1 = p;
                                }
                                else
                                {
                                    v.P2 = p;
                                }
                                propertySetter(v);
                                yield return(null);
                            }
                            propertySetter(v);
                            history?.CommitTransaction();
                        } finally {
                            history?.EndTransaction();
                        }
                    }
                }
Beispiel #5
0
        private void SetLink(int idx, IDataflowProvider <SkinningWeights> provider)
        {
            var currentValue = provider.GetValue();

            indexEditors[idx].Submitted   += text => SetIndexValue(EditorParams, idx, indexEditors[idx], currentValue);
            weigthsEditors[idx].Submitted += text => SetWeightValue(EditorParams, idx, weigthsEditors[idx], currentValue);
            indexEditors[idx].AddChangeWatcher(provider, v => indexEditors[idx].Text     = v[idx].Index.ToString());
            weigthsEditors[idx].AddChangeWatcher(provider, v => weigthsEditors[idx].Text = v[idx].Weight.ToString());
        }
Beispiel #6
0
 public void SetColor(string text)
 {
     if (Color4.TryParse(text, out var newColor))
     {
         SetControlPointProperty(nameof(GradientControlPoint.Color), newColor);
     }
     else
     {
         colorEditor.Text = currentColorString.GetValue();
     }
 }
Beispiel #7
0
 public void SetComponent(string text, IDataflowProvider <string> currentColorString)
 {
     if (Color4.TryParse(text, out var newColor))
     {
         SetProperty(newColor);
     }
     else
     {
         editor.Text = SameValues() ? currentColorString.GetValue() : ManyValuesText;
     }
 }
Beispiel #8
0
        public void SetComponent(string text, IDataflowProvider <string> currentColorString)
        {
            Color4 newColor;

            if (Color4.TryParse(text, out newColor))
            {
                SetProperty(newColor);
            }
            else
            {
                editor.Text = currentColorString.GetValue();
            }
        }
        private void SetLink(int idx, IDataflowProvider <CoalescedValue <int> > indexProvider, IDataflowProvider <CoalescedValue <float> > weightProvider)
        {
            var currentIndexValue  = indexProvider.GetValue();
            var currentWeightValue = weightProvider.GetValue();

            indexEditors[idx].Submitted   += text => SetIndexValue(EditorParams, idx, indexEditors[idx], currentIndexValue);
            weigthsEditors[idx].Submitted += text => SetWeightValue(EditorParams, idx, weigthsEditors[idx], currentWeightValue);
            indexEditors[idx].AddChangeLateWatcher(indexProvider,
                                                   v => indexEditors[idx].Text = v.IsDefined ? v.Value.ToString() : ManyValuesText);
            weigthsEditors[idx].AddChangeLateWatcher(weightProvider,
                                                     v => weigthsEditors[idx].Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText);
            ManageManyValuesOnFocusChange(indexEditors[idx], indexProvider);
            ManageManyValuesOnFocusChange(weigthsEditors[idx], weightProvider);
        }
Beispiel #10
0
 private void SelectPoint(GradientControlPoint point)
 {
     colorEditor.Tasks.Clear();
     positionEditor.Tasks.Clear();
     selectedPointColorProperty    = new Property <Color4>(point, nameof(GradientControlPoint.Color));
     selectedPointPositionProperty = new Property <float>(point, nameof(GradientControlPoint.Position));
     currentColorString            = selectedPointColorProperty.DistinctUntilChanged().Select(i => i.ToString(Color4.StringPresentation.Dec));
     colorEditor.Tasks.Add(currentColorString.Consume(v => colorEditor.Text = v));
     colorPanel.Color = selectedPointColorProperty.GetValue();
     colorEditor.Tasks.Add(selectedPointColorProperty.DistinctUntilChanged().Consume(v => {
         if (colorPanel.Color != v)
         {
             colorPanel.Color = v;
         }
     }));
     positionEditor.Tasks.Add(selectedPointPositionProperty.DistinctUntilChanged().Consume(v => positionEditor.Text = v.ToString()));
 }