fCraft.ShapesLib.Draw C# (CSharp) Method

Draw() public method

public Draw ( Bitmap img ) : void
img System.Drawing.Bitmap
return void
        public void Draw( Bitmap img )
        {
            //guess how big the draw will be
            int Count = 0;
            for ( int x = 0; x < img.Width; x++ ) {
                for ( int z = 0; z < img.Height; z++ ) {
                    if ( img.GetPixel( x, z ).ToArgb() != System.Drawing.Color.White.ToArgb() ) {
                        Count++;
                    }
                }
            }
            //check if player can make the drawing
            if ( !player.CanDraw( Count ) ) {
                player.Message( String.Format( "You are only allowed to run commands that affect up to {0} blocks. This one would affect {1} blocks.",
                                               player.Info.Rank.DrawLimit, Count ) );
                return;
            }
            //check direction and draw
            switch ( direction ) {
                case Direction.one:
                    for ( int x = 0; x < img.Width; x++ ) {
                        for ( int z = 0; z < img.Height; z++ ) {
                            if ( img.GetPixel( x, z ).ToArgb() != System.Drawing.Color.White.ToArgb() ) {
                                DrawOneBlock( player, player.World.Map, PixelData.BlockColor,
                                      new Vector3I( ( PixelData.X + x ), PixelData.Y, ( PixelData.Z + z ) ), BlockChangeContext.Drawn,
                                      ref blocks, ref blocksDenied, undoState );
                                blockCount++;
                            }
                        }
                    }
                    break;

                case Direction.two:
                    for ( int x = 0; x < img.Width; x++ ) {
                        for ( int z = 0; z < img.Height; z++ ) {
                            if ( img.GetPixel( x, z ).ToArgb() != System.Drawing.Color.White.ToArgb() ) {
                                DrawOneBlock( player, player.World.Map, PixelData.BlockColor,
                                      new Vector3I( ( PixelData.X - x ), PixelData.Y, ( PixelData.Z + z ) ), BlockChangeContext.Drawn,
                                      ref blocks, ref blocksDenied, undoState );
                                blockCount++;
                            }
                        }
                    }
                    break;

                case Direction.three:
                    for ( int y = 0; y < img.Width; y++ ) {
                        for ( int z = 0; z < img.Height; z++ ) {
                            if ( img.GetPixel( y, z ).ToArgb() != System.Drawing.Color.White.ToArgb() ) {
                                DrawOneBlock( player, player.World.Map, PixelData.BlockColor,
                                      new Vector3I( PixelData.X, ( PixelData.Y + y ), ( PixelData.Z + z ) ), BlockChangeContext.Drawn,
                                      ref blocks, ref blocksDenied, undoState );
                                blockCount++;
                            }
                        }
                    }
                    break;

                case Direction.four:
                    for ( int y = 0; y < img.Width; y++ ) {
                        for ( int z = 0; z < img.Height; z++ ) {
                            if ( img.GetPixel( y, z ).ToArgb() != System.Drawing.Color.White.ToArgb() ) {
                                DrawOneBlock( player, player.World.Map, PixelData.BlockColor,
                                      new Vector3I( PixelData.X, ( ( PixelData.Y ) - y ), ( PixelData.Z + z ) ), BlockChangeContext.Drawn,
                                      ref blocks, ref blocksDenied, undoState );
                                blockCount++;
                            }
                        }
                    }
                    break;

                default:
                    break; //if blockcount = 0, message is shown and returned
            }
        }