Exemple #1
0
        /***********************************************************************/
        /*                                DRAG                                 */
        /***********************************************************************/

        private void DragDown(MouseEventArgs e)
        {
            drawX         = e.X;
            drawY         = e.Y;
            tempClipboard = Grid.CopyRegion(selectedRegion);
            Grid.ClearRegion(selectedRegion);
            dragable = true;
        }
        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);
                    }
                }
            }
        }