Beispiel #1
0
        public void TestThatClipCanvasWorksForMultipleLayers(int initialWidth, int initialHeight, int secondLayerPixelX, int secondLayerPixelY)
        {
            Document      document = new Document(initialWidth, initialHeight);
            BitmapManager manager  = new BitmapManager
            {
                ActiveDocument = document
            };

            manager.AddNewLayer("test");
            manager.ActiveLayer.SetPixel(new Coordinates((int)Math.Ceiling(initialWidth / 2f),
                                                         (int)Math.Ceiling(initialHeight / 2f)), Colors.Black); //Set pixel in center

            manager.AddNewLayer("test2");

            manager.ActiveLayer.SetPixel(new Coordinates(secondLayerPixelX, secondLayerPixelY), Colors.Black);

            document.ClipCanvas();

            int totalWidth = Math.Abs(manager.ActiveDocument.Layers[1].OffsetX +
                                      manager.ActiveDocument.Layers[1].Width - (manager.ActiveDocument.Layers[0].OffsetX +
                                                                                manager.ActiveDocument.Layers[0].Width)) + 1;

            int totalHeight = Math.Abs(manager.ActiveDocument.Layers[1].OffsetY +
                                       manager.ActiveDocument.Layers[1].Height - (manager.ActiveDocument.Layers[0].OffsetY +
                                                                                  manager.ActiveDocument.Layers[0].Height)) + 1;

            Assert.Equal(totalWidth, document.Width);
            Assert.Equal(totalHeight, document.Height);
        }
Beispiel #2
0
        public void TestThatCenterContentCentersContentForMultipleLayers(int docWidth, int docHeight)
        {
            Document      doc     = new Document(docWidth, docHeight);
            BitmapManager manager = new BitmapManager
            {
                ActiveDocument = doc
            };

            manager.AddNewLayer("test");
            manager.ActiveLayer.SetPixel(new Coordinates(0, 0), Colors.Green);

            manager.AddNewLayer("test2");
            manager.ActiveLayer.SetPixel(new Coordinates(1, 1), Colors.Green);

            doc.CenterContent();

            int midWidth  = (int)Math.Floor(docWidth / 2f);
            int midHeight = (int)Math.Floor(docHeight / 2f);

            Assert.Equal(midWidth - 1, manager.ActiveDocument.Layers[0].OffsetX);
            Assert.Equal(midHeight - 1, manager.ActiveDocument.Layers[0].OffsetY);

            Assert.Equal(midWidth, manager.ActiveDocument.Layers[1].OffsetX);
            Assert.Equal(midHeight, manager.ActiveDocument.Layers[1].OffsetY);
        }
Beispiel #3
0
        public void TestThatBitmapManagerRemovesLayer()
        {
            BitmapManager bitmapManager = new BitmapManager
            {
                ActiveDocument = new Document(10, 10)
            };

            bitmapManager.AddNewLayer("_");
            bitmapManager.AddNewLayer("_1");
            Assert.Equal(2, bitmapManager.ActiveDocument.Layers.Count);
            bitmapManager.RemoveLayer(0);
            Assert.Single(bitmapManager.ActiveDocument.Layers);
        }
Beispiel #4
0
        public void TestThatBitmapManagerAddsEmptyNewLayer()
        {
            string        layerName     = "TestLayer";
            BitmapManager bitmapManager = new BitmapManager
            {
                ActiveDocument = new Document(10, 10)
            };

            bitmapManager.AddNewLayer(layerName);
            Assert.Single(bitmapManager.ActiveDocument.Layers);
            Assert.Equal(layerName, bitmapManager.ActiveDocument.ActiveLayer.Name);
            Assert.Equal(0, bitmapManager.ActiveDocument.ActiveLayer.Width + bitmapManager.ActiveDocument.ActiveLayer.Height);
        }
Beispiel #5
0
        public void TestThatCenterContentCentersContentForSingleLayer(int docWidth, int docHeight)
        {
            Document      doc     = new Document(docWidth, docHeight);
            BitmapManager manager = new BitmapManager
            {
                ActiveDocument = doc
            };

            manager.AddNewLayer("test");

            manager.ActiveLayer.SetPixel(new Coordinates(0, 0), Colors.Green);

            doc.CenterContent();

            Assert.Equal(Math.Floor(docWidth / 2f), manager.ActiveLayer.OffsetX);
            Assert.Equal(Math.Floor(docHeight / 2f), manager.ActiveLayer.OffsetY);
        }
        public void TestThatBitmapOperationsUtilityExecutesPenToolProperly()
        {
            BitmapManager manager = new BitmapManager
            {
                ActiveDocument = new Document(10, 10),
                PrimaryColor   = Colors.Black,
            };

            manager.AddNewLayer("Test layer", 10, 10);

            BitmapOperationsUtility util = new BitmapOperationsUtility(manager);

            List <Coordinates> mouseMove = new List <Coordinates>(new [] { new Coordinates(0, 0) });

            util.ExecuteTool(new Coordinates(0, 0), mouseMove, new MockedSinglePixelPen());
            Assert.Equal(manager.ActiveLayer.GetPixel(0, 0), Colors.Black);
        }
Beispiel #7
0
        public void TestThatBitmapChangesExecuteToolExecutesPenTool()
        {
            BitmapManager bitmapManager = new BitmapManager
            {
                ActiveDocument = new Document(5, 5)
            };

            bitmapManager.AddNewLayer("Layer");
            bitmapManager.SetActiveTool(new MockedSinglePixelPen());
            bitmapManager.PrimaryColor = Colors.Green;

            bitmapManager.MouseController.StartRecordingMouseMovementChanges(true);
            bitmapManager.MouseController.RecordMouseMovementChange(new Coordinates(1, 1));
            bitmapManager.MouseController.StopRecordingMouseMovementChanges();

            bitmapManager.ExecuteTool(new Coordinates(1, 1), true);

            Assert.Equal(Colors.Green, bitmapManager.ActiveLayer.GetPixelWithOffset(1, 1));
        }
Beispiel #8
0
        public void TestThatClipCanvasWorksForSingleLayer(int initialWidth, int initialHeight, int additionalPixelX, int additionalPixelY)
        {
            Document      document = new Document(initialWidth, initialHeight);
            BitmapManager manager  = new BitmapManager
            {
                ActiveDocument = document
            };

            manager.AddNewLayer("test");
            manager.ActiveLayer.SetPixel(new Coordinates((int)Math.Ceiling(initialWidth / 2f),
                                                         (int)Math.Ceiling(initialHeight / 2f)), Colors.Black);

            manager.ActiveLayer.SetPixel(new Coordinates(additionalPixelX, additionalPixelY), Colors.Black);

            document.ClipCanvas();

            Assert.Equal(manager.ActiveLayer.Width, document.Width);
            Assert.Equal(manager.ActiveLayer.Height, document.Height);
        }