Beispiel #1
0
        private void RebuildModel(int selectionIndex)
        {
            GradientStopCollection gradientStopCollection = (GradientStopCollection)this.BasisProperty.SceneNodeObjectSet.DesignerContext.PlatformConverter.ConvertToWpf(this.BasisProperty.SceneNodeObjectSet.DocumentContext, this.gradientStopsProperty.GetValue());
            int count1          = this.gradientStops.Count;
            int currentPosition = this.gradientStopsView.CurrentPosition;

            if (gradientStopCollection != null && this.gradientStops.Count == gradientStopCollection.Count)
            {
                return;
            }
            foreach (GradientStopEditor gradientStopEditor in (Collection <GradientStopEditor>) this.gradientStops)
            {
                gradientStopEditor.PropertyChanged -= new PropertyChangedEventHandler(this.OnStopEditorPropertyChanged);
                gradientStopEditor.Disassociate();
            }
            this.gradientStops.Clear();
            if (gradientStopCollection != null)
            {
                for (int propertyIndex = 0; propertyIndex < gradientStopCollection.Count; ++propertyIndex)
                {
                    GradientStopEditor gradientStopEditor = new GradientStopEditor(this.BrushEditor, this.gradientStopsProperty, propertyIndex);
                    gradientStopEditor.PropertyChanged += new PropertyChangedEventHandler(this.OnStopEditorPropertyChanged);
                    this.gradientStops.Add(gradientStopEditor);
                }
            }
            int count2 = this.gradientStopsView.Count;

            if (count2 > count1)
            {
                if (this.IsSynchronizedWithArtboard() && currentPosition == -1)
                {
                    this.SetSelectionFromService();
                }
                else if (selectionIndex >= 0)
                {
                    this.gradientStopsView.MoveCurrentToPosition(selectionIndex);
                }
                else
                {
                    this.gradientStopsView.MoveCurrentToPosition(count2 - 1);
                }
            }
            else
            {
                int val1 = currentPosition;
                if (this.IsSynchronizedWithArtboard())
                {
                    val1 = this.BasisProperty.SceneNodeObjectSet.DesignerContext.GradientToolSelectionService.Index;
                }
                int num = Math.Max(0, Math.Min(val1, this.gradientStopsView.Count - 1));
                if (val1 != num)
                {
                    this.SetSelectedStopIndex(num);
                }
                this.gradientStopsView.MoveCurrentToPosition(num);
            }
            this.OnPropertyChanged("GradientStops");
            this.OnPropertyChanged("Brush");
        }
Beispiel #2
0
        private void ReverseGradientStopsHandler()
        {
            PropertyValueEditorCommands.get_BeginTransaction().Execute((object)null, (IInputElement)this.BrushEditor);
            if (!this.BasisProperty.IsValueLocal)
            {
                this.BasisProperty.DoSetLocalValue();
            }
            Dictionary <double, List <GradientStopEditor> > dictionary = new Dictionary <double, List <GradientStopEditor> >();

            foreach (GradientStopEditor gradientStopEditor in (IEnumerable)this.GradientStops)
            {
                if (!dictionary.ContainsKey(gradientStopEditor.Offset))
                {
                    dictionary.Add(gradientStopEditor.Offset, new List <GradientStopEditor>());
                }
                dictionary[gradientStopEditor.Offset].Add(gradientStopEditor);
            }
            SceneNodeObjectSet sceneNodeObjectSet = this.BasisProperty.SceneNodeObjectSet;

            foreach (KeyValuePair <double, List <GradientStopEditor> > keyValuePair in dictionary)
            {
                double key = keyValuePair.Key;
                List <GradientStopEditor> list = keyValuePair.Value;
                bool flag    = list.Count > 1;
                bool isMixed = false;
                for (int index = 0; index < list.Count; ++index)
                {
                    list[index].Offset = RoundingHelper.RoundScale(1.0 - key);
                    if (flag && index < list.Count / 2)
                    {
                        GradientStopEditor gradientStopEditor1  = list[index];
                        GradientStopEditor gradientStopEditor2  = list[list.Count - 1 - index];
                        DocumentNode       valueAsDocumentNode1 = gradientStopEditor1.ColorProperty.GetLocalValueAsDocumentNode(false, out isMixed);
                        DocumentNode       valueAsDocumentNode2 = gradientStopEditor2.ColorProperty.GetLocalValueAsDocumentNode(false, out isMixed);
                        gradientStopEditor1.ColorProperty.SetValue((object)valueAsDocumentNode2);
                        gradientStopEditor2.ColorProperty.SetValue((object)valueAsDocumentNode1);
                    }
                }
            }
            PropertyValueEditorCommands.get_CommitTransaction().Execute((object)null, (IInputElement)this.BrushEditor);
            this.RebuildModel(-1);
        }