public void CreateImageTest()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(255, Color.FromArgb(r.Next())));
                }
            }

            DrawingGrid grid = new DrawingGrid(bmp, 10, 1);

            // Generate a 5x scale image of the bitmap
            Bitmap scaledBmp = grid.CreateImage(5);

            // Check that the new image is 5 times larger
            AreEqual(scaledBmp.Width, 5 * bmp.Width);
            AreEqual(scaledBmp.Height, 5 * bmp.Height);

            // Verify that the new bitmap has the same colors as the old bitmap
            for (int x = 0; x < 20; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    AreEqual(bmp.GetPixel(x, y), scaledBmp.GetPixel(x * 5, y * 5));
                }
            }
        }
        public void BasicConstructorTest()
        {
            Random r      = new Random();
            int    width  = r.Next(20);
            int    height = r.Next(20);
            int    scale  = r.Next(20);

            // Create a new random grid
            DrawingGrid grid = new DrawingGrid(width, height, scale);

            // Verify that the grid maintains the correct parameters
            AreEqual(grid.Scale, scale);
            AreEqual(grid.size.Width, width);
            AreEqual(grid.size.Height, height);
            AreEqual(grid.Grid.GetLength(0), width);
            AreEqual(grid.Grid.GetLength(1), height);

            // Verify that the interior grid is entirely the default color
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    AreEqual(grid.GetCell(x, y), Color.White);
                }
            }
        }
Exemple #3
0
 public void ImportPNG(Stream pngStream, int scale, int nativeScale)
 {
     Grid       = new DrawingGrid(pngStream, scale, nativeScale);
     this.size  = Grid.size;
     this.Size  = new Size(size.Width * scale, size.Height * scale);
     this.scale = scale;
     DisplayImage();
 }
Exemple #4
0
 public void ImportGifFrame(Bitmap frame, int scale, int nativeScale)
 {
     Grid       = new DrawingGrid(frame, scale, nativeScale);
     this.size  = Grid.size;
     this.Size  = new Size(size.Width * scale, size.Height * scale);
     this.scale = scale;
     DisplayImage();
 }
Exemple #5
0
 /// <summary>
 /// implementação do pattern "singleton"
 /// com o objetivo de garantir a presenca de apenas um opbjeto do tipo "Grid"
 /// durante a execução do programa, e fornecer um acesso global a esse objeto;
 /// Overload do método, com a acriação de um grid padrão de tamanho 9;
 /// </summary>
 /// <returns>retorna a unica instancia de "grid"</returns>
 public static DrawingGrid GetGrid()
 {
     if (uniqueGrid == null)
     {
         uniqueGrid = new DrawingGrid(9);
     }
     return(uniqueGrid);
 }
Exemple #6
0
 public void Redo()
 {
     currentHistory++;
     if (currentHistory > history.Count - 1)
     {
         currentHistory = history.Count - 1;
     }
     Grid = new DrawingGrid(history[currentHistory], scale, scale);
     DisplayImage();
 }
Exemple #7
0
 public frmModifyText(DrawingGrid p_objGrid, string p_strTextValue, int p_intRegID, string p_strCol, int p_intPageNo)
     : this()
 {
     objGrid            = p_objGrid;
     strPreText         = p_strTextValue;
     this.txtValue.Text = p_strTextValue;
     intRegID           = p_intRegID;
     strCol             = p_strCol;
     intPageNo          = p_intPageNo;
 }
        public void NativeScalingTest()
        {
            // Generate a randomly scaled 20 x 20 bitmap

            Random r           = new Random();
            int    nativeScale = r.Next(2, 11);
            Bitmap bmp         = new Bitmap(20 * nativeScale, 20 * nativeScale);
            string pngPath     = "NativeScalingTest.png";

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
            }

            // Save as a .png temporarily
            FileStream bmpFile = new FileStream(pngPath, FileMode.Create);

            BitmapConverters.SaveBitmapAsPNG(bmp, bmpFile);
            bmpFile.Close();

            // Convert the saved png back into a bitmap
            FileStream pngFile = new FileStream(pngPath, FileMode.Open);

            // Create a grid from the png saved
            DrawingGrid grid = new DrawingGrid(pngFile, 2, nativeScale);

            pngFile.Close();

            // Clean up png
            if (File.Exists(pngPath))
            {
                File.Delete(pngPath);
            }

            // Verify that the grid maintains the same parameters
            AreEqual(grid.Scale, 2);
            AreEqual(grid.size.Width, 20);
            AreEqual(grid.size.Height, 20);
            AreEqual(grid.Grid.GetLength(0), 20);
            AreEqual(grid.Grid.GetLength(1), 20);

            // Verify that the interior grid has the same colors as the bitmap saved
            for (int x = 0; x < 20; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    AreEqual(grid.GetCell(x, y), bmp.GetPixel(x * nativeScale, y * nativeScale));
                }
            }
        }
Exemple #9
0
    void Awake()
    {
        PatternSingletonAwake();

        mouseTrail.FollowingMouse = false;
        delegateHaSubs            = false;
        spellsGrid   = DrawingGrid.GetGrid(3);
        newSpellCast = new QuadsDrawing();
        mousePath    = new List <Vector3>();
        states.PlayerStatesInitializer();
        charController = GetComponent <CharacterController>();
    }
Exemple #10
0
        public void Undo()
        {
            currentHistory--;
            if (currentHistory < 0)
            {
                currentHistory = 0;
            }

            //Grid = new DrawingGrid(history[currentHistory].Width, history[currentHistory].Height, scale);
            //Grid.DisplayMap = history[currentHistory];
            Grid = new DrawingGrid(history[currentHistory], scale, scale);
            DisplayImage();
        }
        public void ClearRegionTest()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(255, Color.FromArgb(r.Next())));
                }
            }

            // Initialize a grid of the random bitmap
            DrawingGrid grid = new DrawingGrid(bmp, 10, 1);

            // Generate a random inbounds rectangle
            Rectangle inBounds = new Rectangle(0, 0, r.Next(20), r.Next(20));

            // Clear the region
            grid.ClearRegion(inBounds);

            // Verify that the region was actually cleared
            for (int x = 0; x < inBounds.Width; x++)
            {
                for (int y = 0; y < inBounds.Height; y++)
                {
                    AreEqual(grid.GetCell(x, y), Color.White);
                }
            }

            // Now Generate a random out of bounds rectangle
            Rectangle outBounds = new Rectangle(r.Next(5, 10), r.Next(5, 10), 20, 20);

            // Clear that region
            grid = new DrawingGrid(bmp, 10, 1);
            grid.ClearRegion(outBounds);

            // Verify that the region was cleared
            for (int x = 0; x < inBounds.Width; x++)
            {
                for (int y = 0; y < inBounds.Height; y++)
                {
                    if (x + outBounds.X < grid.size.Width && y + outBounds.Y < grid.size.Height)
                    {
                        AreEqual(grid.GetCell(x + outBounds.X, y + outBounds.Y), Color.White);
                    }
                }
            }
        }
Exemple #12
0
        public DrawPane(DrawingGrid grid)
        {
            InitializeComponent();

            Grid      = grid;
            this.size = Grid.size;
            this.Size = new Size(size.Width * Grid.Scale, size.Height * Grid.Scale);
            scale     = Grid.Scale;

            frame = 1;

            history = new List <Bitmap>();
            history.Add((Bitmap)Grid.DisplayMap.Clone());
        }
        public void CopyRegionTest()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(255, Color.FromArgb(r.Next())));
                }
            }

            // Initialize a grid of the random bitmap
            DrawingGrid grid = new DrawingGrid(bmp, 10, 1);

            // Generate a random inbounds rectangle
            Rectangle inBounds = new Rectangle(0, 0, r.Next(20), r.Next(20));

            // Copy the inbounds region
            DrawingGrid.GridCell[,] copy = grid.CopyRegion(inBounds);
            // Verify that the region was correctly copied
            copyVerifier(copy, grid);

            // Generate a random out of bounds (on the right) rectangle
            Rectangle outR = new Rectangle(0, 0, r.Next(21, 40), r.Next(20));

            // Copy the region
            copy = grid.CopyRegion(outR);
            // Verify
            copyVerifier(copy, grid);

            // Generate a random out of bounds (on the bottom) rectangle
            Rectangle outB = new Rectangle(0, 0, r.Next(20), r.Next(21, 40));

            // Copy the region
            copy = grid.CopyRegion(outB);
            // Verify
            copyVerifier(copy, grid);

            // Generate a random out of bounds rectangle
            Rectangle outBR = new Rectangle(0, 0, r.Next(21, 40), r.Next(21, 40));

            // Copy the region
            copy = grid.CopyRegion(outB);
            // Verify
            copyVerifier(copy, grid);
        }
 private void copyVerifier(DrawingGrid.GridCell[,] copy, DrawingGrid source)
 {
     for (int x = 0; x < copy.GetLength(0); x++)
     {
         for (int y = 0; y < copy.GetLength(1); y++)
         {
             if (x < source.size.Width && y < source.size.Height)
             {
                 AreEqual(copy[x, y].color, source.GetCell(x, y));
             }
             else
             {
                 AreEqual(copy[x, y].color, Color.White);
             }
         }
     }
 }
        public void DrawToGridTest()
        {
            DrawingGrid grid = new DrawingGrid(20, 20, 1);

            // Select a random location and color
            Random r = new Random();
            int    x = r.Next(20);
            int    y = r.Next(20);
            Color  c = Color.FromArgb(255, Color.FromArgb(r.Next()));

            // Color that pixel
            grid.DrawToGrid(x, y, c);

            // Get the new bitmap of the grid
            Bitmap newBmp = grid.DisplayMap;

            // Verify that the pixel specified got colored correctly
            AreEqual(newBmp.GetPixel(x, y), c);
        }
Exemple #16
0
        public void PixelTests()
        {
            Bitmap      b = new Bitmap(10, 10);
            DrawingGrid g = new DrawingGrid(b, 1, 1);
            DrawPane    d = new DrawPane(g);

            // color a pixel within the range of the bitmap
            d.ColorPixel(new Point(0, 0), Color.Blue);
            Assert.AreEqual(d.GetPixel(0, 0), Color.Blue);

            // color a pixel outside the range of the bitmap
            d.ColorPixel(new Point(11, 11), Color.Blue); // show this won't crash

            // retreive the valid pixel
            Assert.AreEqual(d.GetPixel(new Point(0, 0)), Color.Blue);

            // retrieve the
            Assert.AreEqual(d.GetImage(), g.DisplayMap);
        }
        public void PasteRegionTest()
        {
            // Generate a white 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.White);
                }
            }

            // Generate a grid from the bitmap
            DrawingGrid grid = new DrawingGrid(bmp, 10, 1);

            // Generate a randomly colored 5 x 5 region
            DrawingGrid.GridCell[,] region = new DrawingGrid.GridCell[5, 5];
            for (int x = 0; x < region.GetLength(0); x++)
            {
                for (int y = 0; y < region.GetLength(1); y++)
                {
                    region[x, y] = new DrawingGrid.GridCell(Color.FromArgb(255, Color.FromArgb(r.Next())));
                }
            }

            // Paste the region in at (0,0)
            grid.PasteRegion(0, 0, region);

            // Verify that the region was correctly copied
            for (int x = 0; x < region.GetLength(0); x++)
            {
                for (int y = 0; y < region.GetLength(1); y++)
                {
                    AreEqual(region[x, y].color, grid.GetCell(x, y));
                }
            }
        }
Exemple #18
0
        public void OptionTests()
        {
            Bitmap      b = new Bitmap(10, 10);
            DrawingGrid g = new DrawingGrid(b, 1, 1);
            DrawPane    d = new DrawPane(g);

            Color c = Color.Blue;

            d.SetPrimaryColor(c);

            c = Color.Red;
            d.SetSecondaryColor(c);

            d.SetLineThickness(2);

            d.SetPrimaryAlpha(50);

            d.SetSecondaryAlpha(100);

            MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0);


            //d.DrawPane_MouseDown(new object(), e);
        }