fCraft.FontHandler.CreateGraphicsAndDraw C# (CSharp) Method

CreateGraphicsAndDraw() public method

public CreateGraphicsAndDraw ( string Sentence ) : void
Sentence string
return void
        public void CreateGraphicsAndDraw( string Sentence )
        {
            SizeF size = MeasureTextSize( Sentence, player.font ); //measure the text size to create a bmp)
            Bitmap img = new Bitmap( ( int )size.Width, ( int )size.Height ); //make an image based on string size
            using ( Graphics g = Graphics.FromImage( img ) ) { //IDisposable
                g.FillRectangle( Brushes.White, 0, 0, img.Width, img.Height ); //make background, else crop will not work
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; //fix to bleeding
                g.DrawString( Sentence, player.font, Brushes.Black, 0, 0 ); //draw some sexytext
                img = Crop( img ); //crop the image to fix all problems with location
                img.RotateFlip( RotateFlipType.Rotate180FlipX ); //flip this badboy
                Draw( img ); //make the blockupdates
                img.Dispose(); //gtfo homeslice
            }
        }

Usage Example

Example #1
0
 static void WriteCallback( Player player, Vector3I[] marks, object tag )
 {
     Block block = new Block();
     string sentence = ( string )tag;
     //block bugfix kinda
     if ( player.LastUsedBlockType == Block.Undefined ) {
         block = Block.Stone;
     } else {
         block = player.LastUsedBlockType;
     }
     Direction direction = DirectionFinder.GetDirection( marks );
     try {
         FontHandler render = new FontHandler( block, marks, player, direction ); //create new instance
         render.CreateGraphicsAndDraw( sentence ); //render the sentence
         if ( render.blockCount > 0 ) {
             player.Message( "/Write (Size {0}, {1}: Writing '{2}' using {3} blocks of {4}",
                 player.font.Size,
                 player.font.FontFamily.Name,
                 sentence, render.blockCount,
                 block.ToString() );
         } else {
             player.Message( "&WNo direction was set" );
         }
         render = null; //get lost
     } catch ( Exception e ) {
         player.Message( e.Message );
         Logger.Log( LogType.Error, "WriteCommand: " + e );
     }
 }