예제 #1
0
        public void TestUndoOperationSized()
        {
            // Create the objects
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);
            byte[] originalHash = GetHashForBitmap(target);

            // Create the test subjects
            PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil");
            PencilPaintOperation       operation = new PencilPaintOperation(target)
            {
                Color = Color.Black, Notifier = generator, Size = 5
            };

            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);
            operation.DrawTo(5, 5);

            operation.FinishOperation();

            // Undo the task
            generator.UndoTask.Undo();

            byte[] afterUndoHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_AfterUndoSized");

            Assert.IsTrue(originalHash.SequenceEqual(afterUndoHash), "After undoing a paint operation's task, its pixels must return to their original state before the operation was applied");
        }
예제 #2
0
        /// <summary>
        /// Starts this pencil operation on a specified point
        /// </summary>
        /// <param name="point">The point to start this operation on</param>
        private void StartOperation(Point point)
        {
            mouseDown = true;

            lastMousePosition = point;

            Color penColor = (penId == 0 ? firstColor : secondColor);

            pencilOperation.Color           = penColor;
            pencilOperation.CompositingMode = CompositingMode;

            undoGenerator            = new PlottingPaintUndoGenerator(pictureBox.Bitmap, undoDecription);
            pencilOperation.Notifier = undoGenerator;

            pencilOperation.StartOpertaion(accumulateAlpha);

            pencilOperation.MoveTo(point.X, point.Y);
            DrawPencil(point, null);
        }
예제 #3
0
        public void TestRedoOperation_SizedSourceOverAlpha()
        {
            // Create the objects
            Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10);

            // Create the test subjects
            PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil");
            PencilPaintOperation       operation = new PencilPaintOperation(target)
            {
                Color           = Color.FromArgb(127, 0, 0, 0),
                CompositingMode = CompositingMode.SourceOver,
                Size            = 5,
                Notifier        = generator
            };

            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);
            operation.DrawTo(5, 5);

            operation.FinishOperation();

            byte[] originalHash = GetHashForBitmap(target);

            // Undo and redo the task back
            generator.UndoTask.Undo();
            generator.UndoTask.Redo();

            byte[] afterRedoHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_AfterRedo_SizedSourceOverAlpha");

            Assert.IsTrue(originalHash.SequenceEqual(afterRedoHash), "After redoing a paint operation's task, its pixels must return to their original state after the operation was applied");
        }
예제 #4
0
        /// <summary>
        /// Performs the Line paint operation with the given parameters
        /// </summary>
        /// <param name="color">The color to use when drawing the line</param>
        /// <param name="firstPoint">The first point of the line to draw</param>
        /// <param name="secondPoint">The second point of the line to draw</param>
        /// <param name="bitmap">The Bitmap to draw the line on</param>
        /// <param name="compositingMode">The CompositingMode to use when drawing the line</param>
        /// <param name="size">The size of the line to draw</param>
        /// <param name="recordUndo">Whether to generate an undo operation for this line operation</param>
        /// <returns>An undo task for the line operation, or null, if recordUndo is false</returns>
        public static PerPixelUndoTask PerformLineOperation(Color color, Point firstPoint, Point secondPoint, Bitmap bitmap, CompositingMode compositingMode, int size, bool recordUndo)
        {
            PlottingPaintUndoGenerator generator = null;

            if (recordUndo)
            {
                generator = new PlottingPaintUndoGenerator(bitmap, "Line");
            }

            PencilPaintOperation operation = new PencilPaintOperation(bitmap, true, firstPoint)
            {
                Color           = color,
                CompositingMode = compositingMode,
                Notifier        = generator,
                Size            = size
            };

            operation.StartOpertaion(false);
            operation.DrawTo(secondPoint.X, secondPoint.Y);
            operation.FinishOperation();

            return(recordUndo ? generator.UndoTask : null);
        }
예제 #5
0
        public void TestUndoOperation_SourceOverAlphaFailing()
        {
            // Create the objects
            Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10);

            byte[] originalHash = GetHashForBitmap(target);

            // Create the test subjects
            PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil", keepReplacedUndos: false);
            PencilPaintOperation       operation = new PencilPaintOperation(target)
            {
                Color           = Color.FromArgb(127, 0, 0, 0),
                CompositingMode = CompositingMode.SourceOver,
                Notifier        = generator
            };

            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);
            operation.DrawTo(5, 5);

            operation.FinishOperation();

            // Undo the task
            generator.UndoTask.Undo();

            byte[] afterUndoHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_AfterUndo_SourceOverAlpha_Failed");

            Assert.IsFalse(originalHash.SequenceEqual(afterUndoHash),
                           "Plotting the same pixel repeatedly with an undo generator that has keepReplacedOriginals should fail, since the redrawn pixels have their undo color replaced");
        }