private void HandleLayerOpacityChange(float val, Layer layer)
        {
            float oldOpacity = layer.Opacity;

            var doc = LayerCommandsViewModel.Owner.BitmapManager.ActiveDocument;

            doc.RaisePropertyChange(nameof(doc.LayerStructure));

            layer.OpacityUndoTriggerable = val;

            doc.LayerStructure.ExpandParentGroups(layer.LayerGuid);

            doc.RaisePropertyChange(nameof(doc.LayerStructure));

            UndoManager undoManager = doc.UndoManager;


            undoManager.AddUndoChange(
                new Change(
                    UpdateNumberInputLayerOpacityProcess,
                    new object[] { oldOpacity },
                    UpdateNumberInputLayerOpacityProcess,
                    new object[] { val }));
            undoManager.SquashUndoChanges(2);
        }
示例#2
0
        public void TestThatUndoInvokesLoadFromDeviceAndExecutesProcess()
        {
            using Document document = GenerateTestDocument();

            using StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
            bool undoInvoked = false;

            Action <Layer[], UndoLayer[]> testUndoProcess = (layers, data) =>
            {
                undoInvoked = true;
                Assert.Equal(document.Layers.Count, layers.Length);
                Assert.Equal(document.Layers.Count, data.Length);
                foreach (var undoLayer in data)
                {
                    Assert.False(File.Exists(undoLayer.StoredPngLayerName));
                }
            };

            Action <object[]> testRedoProcess = parameters => { };

            Change undoChange = change.ToChange(testUndoProcess, testRedoProcess, null);

            using UndoManager manager = new UndoManager(this);

            manager.AddUndoChange(undoChange);
            manager.Undo();

            Assert.True(undoInvoked);
        }
示例#3
0
 public void TestAddToUndoStack()
 {
     PrepareUnoManagerForTest();
     UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
     Assert.True(UndoManager.UndoStack.Count == 1);
     Assert.True((int)UndoManager.UndoStack.Peek().OldValue == ExampleProperty);
 }
示例#4
0
 public void TestThatUndoAddsToRedoStack()
 {
     PrepareUnoManagerForTest();
     UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
     UndoManager.Undo();
     Assert.True(UndoManager.RedoStack.Count == 1);
 }
示例#5
0
        public void TestThatRedoInvokesSaveToDeviceAndExecutesProcess()
        {
            using Document document = GenerateTestDocument();

            using StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
            bool redoInvoked = false;

            Action <Layer[], UndoLayer[]> testUndoProcess = (layers, data) => { };

            Action <object[]> testRedoProcess = parameters =>
            {
                redoInvoked = true;
                foreach (var undoLayer in change.StoredLayers)
                {
                    Assert.True(File.Exists(undoLayer.StoredPngLayerName));
                    Assert.NotNull(parameters);
                    Assert.Single(parameters);
                    Assert.IsType <int>(parameters[0]);
                    Assert.Equal(2, parameters[0]);
                }
            };

            Change undoChange = change.ToChange(testUndoProcess, testRedoProcess, new object[] { 2 });

            using UndoManager manager = new UndoManager(this);

            manager.AddUndoChange(undoChange);
            manager.Undo();
            manager.Redo();

            Assert.True(redoInvoked);
        }
示例#6
0
        public void TestThatMixedProcessOfUndoAndRedoWorks()
        {
            PrepareUnoManagerForTest();


            int newVal = 5;


            UndoManager.AddUndoChange(
                new Change("ExampleProperty",
                           ReverseProcess,
                           new object[] { ExampleProperty },
                           newVal));

            ExampleProperty = newVal;

            Assert.Equal(newVal, ExampleProperty);

            UndoManager.Undo();

            Assert.Equal(1, ExampleProperty);

            UndoManager.Redo();

            Assert.Equal(newVal, ExampleProperty);
        }
示例#7
0
        public void TestThatProcessBasedUndoAndRedoWorks()
        {
            PrepareUndoManagerForTest();
            using UndoManager undoManager = new UndoManager(this);

            int newVal = 5;

            using var change = new Change(
                      ReverseProcess,
                      new object[] { ExampleProperty },
                      ReverseProcess,
                      new object[] { newVal });
            undoManager.AddUndoChange(change);

            ExampleProperty = newVal;

            Assert.Equal(newVal, ExampleProperty);

            undoManager.Undo();

            Assert.Equal(1, ExampleProperty);

            undoManager.Redo();

            Assert.Equal(newVal, ExampleProperty);
        }
示例#8
0
 public void TestUndo()
 {
     PrepareUnoManagerForTest();
     UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
     ExampleProperty = 55;
     UndoManager.Undo();
     Assert.True((int)UndoManager.RedoStack.Peek().OldValue == ExampleProperty);
 }
示例#9
0
 public override void OnMouseUp() //This adds undo if there is no selection, reason why this isn't in AfterUndoAdded,
 {                                //is because it doesn't fire if no pixel changes were made.
     if (_currentSelection != null && _currentSelection.Length == 0)
     {
         UndoManager.AddUndoChange(new Change(ApplyOffsets, new object[] { _startingOffsets },
                                              ApplyOffsets, new object[] { GetOffsets(_affectedLayers) }, "Move layers"));
     }
 }
示例#10
0
        public void TestThatUndoAddsToRedoStack()
        {
            PrepareUndoManagerForTest();
            using UndoManager undoManager = new UndoManager(this);

            using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
            undoManager.AddUndoChange(change);
            undoManager.Undo();
            Assert.True(undoManager.RedoStack.Count == 1);
        }
示例#11
0
        public void TestAddToUndoStack()
        {
            PrepareUndoManagerForTest();
            using UndoManager undoManager = new UndoManager(this);

            using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
            undoManager.AddUndoChange(change);
            Assert.True(undoManager.UndoStack.Count == 1);
            Assert.True((int)undoManager.UndoStack.Peek().OldValue == ExampleProperty);
        }
示例#12
0
        public override void OnMouseUp(MouseEventArgs e)
        {
            if (ViewModelMain.Current.ActiveSelection.SelectedPoints.Count() <= 1)
            {
                // If we have not selected multiple points, clear the selection
                ViewModelMain.Current.ActiveSelection.Clear();
            }

            UndoManager.AddUndoChange(new Change("ActiveSelection", _oldSelection,
                                                 ViewModelMain.Current.ActiveSelection, "Select pixels"));
        }
示例#13
0
        public void TestRedo()
        {
            PrepareUndoManagerForTest();
            UndoManager undoManager = new UndoManager(this);

            ExampleProperty = 55;
            undoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
            undoManager.Undo();
            undoManager.Redo();
            Assert.True((int)undoManager.UndoStack.Peek().NewValue == ExampleProperty);
        }
示例#14
0
        public void TestThatFindRootProcessWorks()
        {
            PrepareUndoManagerForTest();
            UndoManager undoManager = new UndoManager(this);

            undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));

            Change change = undoManager.UndoStack.Peek();

            Assert.Equal(TestPropClass, change.FindRootProcess(change.FindRootProcessArgs));
        }
        public void FlipActiveDocument(FlipType flip)
        {
            object[] processArgs = { flip };

            FlipDocumentProcess(processArgs);

            UndoManager.AddUndoChange(new Change(
                                          FlipDocumentProcess,
                                          processArgs,
                                          FlipDocumentProcess,
                                          processArgs,
                                          $"Flip layer: {flip}"));
        }
示例#16
0
        public void TestThatUndoForFindRootProcessWorks()
        {
            PrepareUndoManagerForTest();
            UndoManager undoManager = new UndoManager(this);

            undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));

            TestPropClass.IntProperty = 5;

            undoManager.Undo();

            Assert.Equal(0, TestPropClass.IntProperty);
        }
        public void RotateActiveDocument(float degrees)
        {
            object[] processArgs        = { degrees };
            object[] reverseProcessArgs = { -degrees };

            RotateDocumentProcess(processArgs);

            UndoManager.AddUndoChange(new Change(
                                          RotateDocumentProcess,
                                          reverseProcessArgs,
                                          RotateDocumentProcess,
                                          processArgs,
                                          "Rotate layer"));
        }
        /// <summary>
        ///     Resizes all document layers using NearestNeighbor interpolation.
        /// </summary>
        /// <param name="newWidth">New document width.</param>
        /// <param name="newHeight">New document height.</param>
        public void Resize(int newWidth, int newHeight)
        {
            object[]           reverseArgs = { Width, Height };
            object[]           args        = { newWidth, newHeight };
            StorageBasedChange change      = new StorageBasedChange(this, Layers);

            ResizeDocument(newWidth, newHeight);

            UndoManager.AddUndoChange(
                change.ToChange(
                    RestoreDocumentLayersProcess,
                    reverseArgs,
                    ResizeDocumentProcess,
                    args,
                    "Resize document"));
        }
示例#19
0
        public void TestThatUndoManagerUndoAndRedoWithCustomRootCorrectly()
        {
            PrepareUnoManagerForTest();
            TestPropertyClass testProp = new TestPropertyClass();
            int newVal = 5;

            testProp.IntProperty = newVal;
            UndoManager.AddUndoChange(new Change("IntProperty", 0, newVal, root: testProp));
            Assert.Equal(newVal, testProp.IntProperty);

            UndoManager.Undo();

            Assert.Equal(0, testProp.IntProperty);

            UndoManager.Redo();

            Assert.Equal(newVal, testProp.IntProperty);
        }
示例#20
0
        public void TestThatNestedPropertyUndoWorks()
        {
            PrepareUnoManagerForTest();
            int newVal = 5;

            UndoManager.AddUndoChange(new Change("TestPropClass.IntProperty", TestPropClass.IntProperty,
                                                 newVal));

            TestPropClass.IntProperty = newVal;

            Assert.Equal(newVal, TestPropClass.IntProperty);

            UndoManager.Undo();

            Assert.Equal(0, TestPropClass.IntProperty);

            UndoManager.Redo();

            Assert.Equal(newVal, TestPropClass.IntProperty);
        }
示例#21
0
        public void TestThatNestedPropertyUndoWorks()
        {
            PrepareUndoManagerForTest();
            using UndoManager undoManager = new UndoManager(this);

            int newVal = 5;

            using var change = new Change("TestPropClass.IntProperty", TestPropClass.IntProperty, newVal);
            undoManager.AddUndoChange(change);

            TestPropClass.IntProperty = newVal;

            Assert.Equal(newVal, TestPropClass.IntProperty);

            undoManager.Undo();

            Assert.Equal(0, TestPropClass.IntProperty);

            undoManager.Redo();

            Assert.Equal(newVal, TestPropClass.IntProperty);
        }
        /// <summary>
        ///     Resizes canvas to specified width and height to selected anchor.
        /// </summary>
        /// <param name="width">New width of canvas.</param>
        /// <param name="height">New height of canvas.</param>
        /// <param name="anchor">
        ///     Point that will act as "starting position" of resizing. Use pipe to connect horizontal and
        ///     vertical.
        /// </param>
        public void ResizeCanvas(int width, int height, AnchorPoint anchor, bool addToUndo = true)
        {
            int oldWidth  = Width;
            int oldHeight = Height;

            int offsetX = GetOffsetXForAnchor(Width, width, anchor);
            int offsetY = GetOffsetYForAnchor(Height, height, anchor);

            Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0))
                                     .ToArray();

            object[] processArgs        = { newOffsets, width, height };
            object[] reverseProcessArgs = { Width, Height };

            if (addToUndo)
            {
                StorageBasedChange change = new(this, Layers);
                ResizeCanvas(newOffsets, width, height);

                UndoManager.AddUndoChange(change.ToChange(
                                              RestoreDocumentLayersProcess,
                                              reverseProcessArgs,
                                              ResizeCanvasProcess,
                                              processArgs,
                                              "Resize canvas"));
            }
            else
            {
                ResizeCanvas(newOffsets, width, height);
            }

            if (oldWidth == Width && Height == oldHeight)
            {
                return;
            }

            DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height));
        }
示例#23
0
        /// <summary>
        ///     Resizes canvas to specified width and height to selected anchor.
        /// </summary>
        /// <param name="width">New width of canvas.</param>
        /// <param name="height">New height of canvas.</param>
        /// <param name="anchor">
        ///     Point that will act as "starting position" of resizing. Use pipe to connect horizontal and
        ///     vertical.
        /// </param>
        public void ResizeCanvas(int width, int height, AnchorPoint anchor)
        {
            int oldWidth  = Width;
            int oldHeight = Height;

            int offsetX = GetOffsetXForAnchor(Width, width, anchor);
            int offsetY = GetOffsetYForAnchor(Height, height, anchor);

            Thickness[] oldOffsets = Layers.Select(x => x.Offset).ToArray();
            Thickness[] newOffsets = Layers.Select(x => new Thickness(offsetX + x.OffsetX, offsetY + x.OffsetY, 0, 0))
                                     .ToArray();

            object[] processArgs        = { newOffsets, width, height };
            object[] reverseProcessArgs = { oldOffsets, Width, Height };

            ResizeCanvas(newOffsets, width, height);
            UndoManager.AddUndoChange(new Change(
                                          ResizeCanvasProcess,
                                          reverseProcessArgs,
                                          ResizeCanvasProcess,
                                          processArgs,
                                          "Resize canvas"));
            DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(oldWidth, oldHeight, width, height));
        }
示例#24
0
 public override void OnMouseUp(MouseEventArgs e)
 {
     UndoManager.AddUndoChange(new Change("ActiveSelection", _oldSelection,
                                          ViewModelMain.Current.ActiveSelection, "Select pixels"));
 }