Ejemplo n.º 1
0
        public override void AfterAddedUndo(UndoManager undoManager)
        {
            if (currentSelection != null && currentSelection.Length > 0)
            {
                Change changes = undoManager.UndoStack.Peek();

                // Inject to default undo system change custom changes made by this tool
                foreach (var item in startPixelColors)
                {
                    BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(startSelection, item.Value);
                    BitmapPixelChanges afterMovePixels  = BitmapPixelChanges.FromArrays(currentSelection, endPixelColors[item.Key]);
                    Guid layerGuid = item.Key;
                    var  oldValue  = (LayerChange[])changes.OldValue;

                    if (oldValue.Any(x => x.LayerGuid == layerGuid))
                    {
                        var layer = oldValue.First(x => x.LayerGuid == layerGuid);
                        layer.PixelChanges.ChangedPixels.AddRangeOverride(afterMovePixels.ChangedPixels);
                        layer.PixelChanges.ChangedPixels
                        .AddRangeOverride(beforeMovePixels.ChangedPixels);

                        ((LayerChange[])changes.NewValue).First(x => x.LayerGuid == layerGuid).PixelChanges.ChangedPixels
                        .AddRangeNewOnly(BitmapPixelChanges
                                         .FromSingleColoredArray(startSelection, System.Windows.Media.Colors.Transparent)
                                         .ChangedPixels);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public BitmapPixelChanges MoveSelection(Layer layer, Coordinates[] mouseMove)
        {
            Coordinates end = mouseMove[0];

            currentSelection = TranslateSelection(end);
            if (updateViewModelSelection)
            {
                ViewModelMain.Current.BitmapManager.ActiveDocument.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
            }

            lastMouseMove = end;
            return(BitmapPixelChanges.FromArrays(currentSelection, startPixelColors[layer.LayerGuid]));
        }
Ejemplo n.º 3
0
        public void TestThatFormArraysWorks()
        {
            Coordinates[] coordinatesArray = { new Coordinates(0, 0), new Coordinates(2, 3), new Coordinates(5, 5) };
            Color[]       colorsArray      = { Colors.Red, Colors.Green, Colors.Blue };
            var           result           = BitmapPixelChanges.FromArrays(coordinatesArray, colorsArray);

            for (int i = 0; i < coordinatesArray.Length; i++)
            {
                var cords = coordinatesArray[i];
                Assert.Equal(colorsArray[i], result.ChangedPixels[cords]);
            }
            Assert.False(result.WasBuiltAsSingleColored);
        }
Ejemplo n.º 4
0
        public void DeletePixels(Layer[] layers, Coordinates[] pixels)
        {
            var changes   = BitmapPixelChanges.FromSingleColoredArray(pixels, Color.FromArgb(0, 0, 0, 0));
            var oldValues = BitmapUtils.GetPixelsForSelection(layers, pixels);

            LayerChange[] old       = new LayerChange[layers.Length];
            LayerChange[] newChange = new LayerChange[layers.Length];
            for (int i = 0; i < layers.Length; i++)
            {
                old[i] = new LayerChange(
                    BitmapPixelChanges.FromArrays(pixels, oldValues[layers[i]]), i);
                newChange[i] = new LayerChange(changes, i);
                layers[i].SetPixels(changes);
            }

            UndoManager.AddUndoChange(new Change("UndoChanges", old, newChange, "Deleted pixels"));
        }
Ejemplo n.º 5
0
        public override void AfterAddedUndo()
        {
            if (_currentSelection != null && _currentSelection.Length != 0)
            {
                //Inject to default undo system change custom changes made by this tool
                foreach (var item in _startPixelColors)
                {
                    BitmapPixelChanges beforeMovePixels = BitmapPixelChanges.FromArrays(_startSelection, item.Value);
                    Change             changes          = UndoManager.UndoStack.Peek();
                    int layerIndex = ViewModelMain.Current.BitmapManager.ActiveDocument.Layers.IndexOf(item.Key);

                    ((LayerChange[])changes.OldValue).First(x => x.LayerIndex == layerIndex).PixelChanges.ChangedPixels
                    .AddRangeOverride(beforeMovePixels.ChangedPixels);

                    ((LayerChange[])changes.NewValue).First(x => x.LayerIndex == layerIndex).PixelChanges.ChangedPixels
                    .AddRangeNewOnly(BitmapPixelChanges
                                     .FromSingleColoredArray(_startSelection, System.Windows.Media.Colors.Transparent)
                                     .ChangedPixels);
                }
            }
        }
Ejemplo n.º 6
0
        public void DeletePixels(Layer[] layers, Coordinates[] pixels)
        {
            if (Manager.ActiveDocument == null)
            {
                return;
            }

            BitmapPixelChanges         changes   = BitmapPixelChanges.FromSingleColoredArray(pixels, Color.FromArgb(0, 0, 0, 0));
            Dictionary <Guid, Color[]> oldValues = BitmapUtils.GetPixelsForSelection(layers, pixels);

            LayerChange[] old       = new LayerChange[layers.Length];
            LayerChange[] newChange = new LayerChange[layers.Length];
            for (int i = 0; i < layers.Length; i++)
            {
                Guid guid = layers[i].LayerGuid;
                old[i] = new LayerChange(
                    BitmapPixelChanges.FromArrays(pixels, oldValues[layers[i].LayerGuid]), guid);
                newChange[i] = new LayerChange(changes, guid);
                layers[i].SetPixels(changes);
            }

            Manager.ActiveDocument.UndoManager.AddUndoChange(new Change("UndoChanges", old, newChange, "Deleted pixels"));
        }
Ejemplo n.º 7
0
 public void TestThatFromArraysThrowsError()
 {
     Assert.Throws <ArrayLengthMismatchException>
         (() => BitmapPixelChanges.FromArrays(new[] { new Coordinates(0, 0) }, new[] { Colors.Red, Colors.Green }));
 }