コード例 #1
0
        protected void InitRenderingData()
        {
            api = game.Graphics;

            using( Font font = new Font( "Arial", 14 ) ) {
                DrawTextArgs args = new DrawTextArgs( DisplayName, font, true );
                nameTex = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 );
            }
        }
コード例 #2
0
ファイル: TextWidget.cs プロジェクト: Hetal728/ClassicalSharp
 public void SetText( string text )
 {
     graphicsApi.DeleteTexture( ref texture );
     if( String.IsNullOrEmpty( text ) ) {
         texture = new Texture();
         Height = defaultHeight;
     } else {
         DrawTextArgs args = new DrawTextArgs( text, true );
         texture = game.Drawer2D.MakeTextTexture( font, 0, 0, ref args );
         X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalDocking );
         Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalDocking );
         Height = texture.Height;
     }
     Width = texture.Width;
 }
コード例 #3
0
        public override void Init()
        {
            graphicsApi.Fog = false;
            titleWidget = TextWidget.Create( game, 0, 30, serverName, Docking.Centre, Docking.LeftOrTop, font );
            messageWidget = TextWidget.Create( game, 0, 60, serverMotd, Docking.Centre, Docking.LeftOrTop, font );
            progX = game.Width / 2f - progWidth / 2f;

            Size size = new Size( progWidth, progHeight );
            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                using( IDrawer2D drawer = game.Drawer2D ) {
                    drawer.SetBitmap( bmp );
                    drawer.DrawRectBounds( Color.White, 5f, 0, 0, progWidth, progHeight );
                    progressBoxTexture = drawer.Make2DTexture( bmp, size, (int)progX, (int)progY );
                }
            }
            game.Events.MapLoading += MapLoading;
        }
コード例 #4
0
        public override void SetText( string text )
        {
            graphicsApi.DeleteTexture( ref texture );
            if( String.IsNullOrEmpty( text ) ) {
                texture = new Texture();
                Height = defaultHeight;
            } else {
                DrawTextArgs args = new DrawTextArgs( text, font, true );
                texture = game.Drawer2D.UseBitmappedChat ?
                    game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
                    game.Drawer2D.MakeTextTexture( ref args, 0, 0 );

                X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalAnchor );
                Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalAnchor );
                Height = texture.Height;
            }
            Width = texture.Width;
        }
コード例 #5
0
        public void SetText( int index, string text )
        {
            graphicsApi.DeleteTexture( ref Textures[index] );
            DrawTextArgs args = new DrawTextArgs( text, font, true );
            Font underlineFont = new Font( font, FontStyle.Underline );
            urlBounds[index] = null;

            if( !String.IsNullOrEmpty( text ) ) {
                Texture tex = NextToken( text, 0 ) == -1 ? DrawSimple( ref args ) :
                    DrawAdvanced( ref args, index, text );
                tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
                tex.Y1 = CalcY( index, tex.Height );
                Textures[index] = tex;
                lines[index] = text;
            } else {
                Textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 );
                lines[index] = null;
            }
            UpdateDimensions();
        }
コード例 #6
0
        public override void Init()
        {
            int y = game.Height - blockSize;

            Size size = new Size( 32, 32 );
            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                using( IDrawer2D drawer = game.Drawer2D ) {
                    drawer.SetBitmap( bmp );
                    drawer.DrawRectBounds( Color.White, blockSize / 8, 0, 0, blockSize, blockSize );
                    selectedBlock = drawer.Make2DTexture( bmp, size, 0, y );
                }
            }

            int x = game.Width / 2 - ( blockSize * barTextures.Length ) / 2;
            X = x;
            Y = y;
            Width = blockSize * barTextures.Length;
            Height = blockSize;

            for( int i = 0; i < barTextures.Length; i++ ) {
                barTextures[i] = MakeTexture( x, y, game.Inventory.Hotbar[i] );
                x += blockSize;
            }
        }
コード例 #7
0
 public override void Init()
 {
     game.Events.BlockPermissionsChanged += BlockPermissionsChanged;
     Size size = new Size( blockSize, blockSize );
     using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
         using( IDrawer2D drawer = game.Drawer2D ) {
             drawer.SetBitmap( bmp );
             drawer.DrawRectBounds( Color.White, blockSize / 8, 0, 0, blockSize, blockSize );
             selectedBlock = drawer.Make2DTexture( bmp, size, 0, 0 );
         }
     }
     RecreateBlockTextures();
 }
コード例 #8
0
 public BlockDrawInfo( Texture texture, Block block )
 {
     Texture = texture;
     BlockId = block;
 }
コード例 #9
0
        void RecreateBlockTextures()
        {
            int blocksCount = 0;
            for( int i = 0; i < BlockInfo.BlocksCount; i++ ) {
                if( game.Inventory.CanPlace[i] || game.Inventory.CanDelete[i] ) {
                    blocksCount++;
                }
            }

            rows = blocksCount / blocksPerRow + ( blocksCount % blocksPerRow != 0 ? 1 : 0 );
            startX = game.Width / 2 - ( blockSize * blocksPerRow ) / 2;
            startY = game.Height / 2 - ( rows * blockSize ) / 2;
            int x = startX, y = startY;
            blocksTable = new BlockDrawInfo[blocksCount];

            int tableIndex = 0;
            for( int tile = 1; tile < BlockInfo.BlocksCount; tile++ ) {
                if( game.Inventory.CanPlace[tile] || game.Inventory.CanDelete[tile] ) {
                    Block block = (Block)tile;
                    int texId = game.BlockInfo.GetTextureLoc( (byte)block, TileSide.Left );
                    TextureRectangle rec = game.TerrainAtlas.GetTexRec( texId );
                    int verSize = blockSize;
                    float height = game.BlockInfo.Height[(byte)block];
                    int blockY = y;

                    if( height != 1 ) {
                        rec.V1 = rec.V1 + TerrainAtlas2D.invElementSize * height;
                        verSize = (int)( blockSize * height );
                        blockY = y + blockSize - verSize;
                    }
                    Texture texture = new Texture( -1, x, blockY, blockSize, verSize, rec );

                    blocksTable[tableIndex++] = new BlockDrawInfo( texture, block );
                    x += blockSize;
                    if( tableIndex % blocksPerRow == 0 ) { // end of row, start next one.
                        x = startX;
                        y += blockSize;
                    }
                }
            }
        }
コード例 #10
0
        void DrawString()
        {
            int totalHeight = 0;
            for( int i = 0; i < lines; i++ ) {
                totalHeight += sizes[i].Height;
            }
            Size size = new Size( maxWidth, totalHeight );
            int y = game.Height - size.Height - YOffset;

            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                using( IDrawer2D drawer = game.Drawer2D ) {
                    drawer.SetBitmap( bmp );
                    DrawTextArgs args = new DrawTextArgs( null, font, false );

                    int yyy = 0;
                    for( int i = 0; i < parts.Length; i++ ) {
                        if( parts[i] == null ) break;
                        args.Text = parts[i];

                        drawer.Clear( backColour, 0, yyy, sizes[i].Width, sizes[i].Height );
                        drawer.DrawText( ref args, 0, yyy );
                        yyy += sizes[i].Height;
                    }
                    chatInputTexture = drawer.Make2DTexture( bmp, size, 10, y );
                }
            }

            caretTexture.Y1 = y + caretTexture.Y1;
            Y = y;
            Width = size.Width;
            Height = size.Height;
        }
コード例 #11
0
 public void ReducePadding( ref Texture tex, int point )
 {
     ReducePadding( ref tex, point, 4 );
 }
コード例 #12
0
ファイル: ChatScreen.cs プロジェクト: Cheesse/ClassicalSharp
 void UpdateAnnouncement( string text )
 {
     DrawTextArgs args = new DrawTextArgs( text, announcementFont, true );
     announcementTex = game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
     announcementTex.X1 = game.Width / 2 - announcementTex.Width / 2;
     announcementTex.Y1 = game.Height / 4 - announcementTex.Height / 2;
 }
コード例 #13
0
        void RecreateBlockInfoTexture()
        {
            if( selectedIndex == lastCreatedIndex ) return;
            lastCreatedIndex = selectedIndex;

            graphicsApi.DeleteTexture( ref blockInfoTexture );
            if( selectedIndex == -1 ) return;

            Block block = blocksTable[selectedIndex];
            UpdateBlockInfoString( block );
            string value = buffer.GetString();

            DrawTextArgs args = new DrawTextArgs( value, font, true );
            Size size = game.Drawer2D.MeasureSize( ref args );
            int x = startX + (blockSize * blocksPerRow) / 2 - size.Width / 2;
            int y = startY - size.Height - 5;

            args.SkipPartsCheck = true;
            blockInfoTexture = game.Drawer2D.MakeTextTexture( ref args, x, y );
        }
コード例 #14
0
        public void SetText( int index, string text )
        {
            graphicsApi.DeleteTexture( ref Textures[index] );

            if( !String.IsNullOrEmpty( text ) ) {
                DrawTextArgs args = new DrawTextArgs( text, true );
                Texture tex = game.Drawer2D.MakeTextTexture( font, 0, 0, ref args );
                tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
                tex.Y1 = CalcY( index, tex.Height );
                Textures[index] = tex;
            } else {
                Textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 );
            }
            UpdateDimensions();
        }
コード例 #15
0
ファイル: FpsScreen.cs プロジェクト: Daribon/ClassicalSharp
        void MakePosTextWidget()
        {
            DrawTextArgs args = new DrawTextArgs( "", posFont, true );
            for( int i = 0; i < possibleChars.Length; i++ ) {
                args.Text = new String( possibleChars[i], 1 );
                widths[i] = game.Drawer2D.MeasureChatSize( ref args ).Width;
            }

            using( IDrawer2D drawer = game.Drawer2D ) {
                args.Text = "Feet pos: ";
                Size size = game.Drawer2D.MeasureChatSize( ref args );
                baseWidth = size.Width;
                size.Width += 16 * possibleChars.Length;
                posHeight = size.Height;

                using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                    drawer.SetBitmap( bmp );
                    drawer.DrawChatText( ref args, 0, 0 );

                    for( int i = 0; i < possibleChars.Length; i++ ) {
                        args.Text = new String( possibleChars[i], 1 );
                        drawer.DrawChatText( ref args, baseWidth + 16 * i, 0 );
                    }

                    int y = fpsTextWidget.Height + 2;
                    posTexture = drawer.Make2DTexture( bmp, size, 0, y );
                    posTexture.U2 = (float)baseWidth / bmp.Width;
                    posTexture.Width = baseWidth;
                    texWidth = bmp.Width;
                }
            }
        }
コード例 #16
0
        void DrawString( Size size, string value, bool skipCheck )
        {
            size.Height = Math.Max( size.Height, chatCaretTexture.Height );
            int y = game.Height - ChatInputYOffset - size.Height / 2;

            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                using( IDrawer2D drawer = game.Drawer2D ) {
                    drawer.SetBitmap( bmp );
                    drawer.DrawRect( backColour, 0, 0, bmp.Width, bmp.Height );
                    DrawTextArgs args = new DrawTextArgs( value, Color.White, false );
                    args.SkipPartsCheck = skipCheck;
                    drawer.DrawText(  font, ref args, 0, 0 );
                    chatInputTexture = drawer.Make2DTexture( bmp, size, 10, y );
                }
            }

            chatCaretTexture.Y1 = chatInputTexture.Y1;
            Y = y;
            Width = size.Width;
            Height = size.Height;
        }
コード例 #17
0
 void MakeSelectionTexture()
 {
     Size size = new Size( blockSize, blockSize );
     using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
         using( IDrawer2D drawer = game.Drawer2D ) {
             drawer.SetBitmap( bmp );
             drawer.DrawRectBounds( selCol, 3, 0, 0, blockSize, blockSize );
             selectedBlock = drawer.Make2DTexture( bmp, size, 0, Y );
         }
     }
 }
コード例 #18
0
        unsafe void Make( Element e, Font font )
        {
            Size* sizes = stackalloc Size[e.Contents.Length / e.CharsPerItem];
            MeasureContentSizes( e, font, sizes );
            Size bodySize = CalculateContentSize( e, sizes, out elementSize );
            int titleWidth = MeasureTitles( font ), titleHeight = elements[0].TitleSize.Height;
            Size size = new Size( Math.Max( bodySize.Width, titleWidth ), bodySize.Height + titleHeight );

            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) )
                using( IDrawer2D drawer = game.Drawer2D )
            {
                drawer.SetBitmap( bmp );
                DrawTitles( drawer, font );
                drawer.Clear( new FastColour( 30, 30, 30, 200 ), 0, titleHeight,
                             size.Width, bodySize.Height );

                DrawContent( drawer, font, e, titleHeight );
                texture = drawer.Make2DTexture( bmp, size, X, Y );
            }
        }
コード例 #19
0
ファイル: ChatScreen.cs プロジェクト: Hetal728/ClassicalSharp
 void UpdateAnnouncement( string text )
 {
     announcementDisplayTime = DateTime.UtcNow;
     DrawTextArgs args = new DrawTextArgs( text, true );
     announcementTex = game.Drawer2D.MakeTextTexture( announcementFont, 0, 0, ref args );
     announcementTex.X1 = game.Width / 2 - announcementTex.Width / 2;
     announcementTex.Y1 = game.Height / 4 - announcementTex.Height / 2;
 }
コード例 #20
0
        void MakeTexture( string text )
        {
            DrawTextArgs args = new DrawTextArgs( text, font, true );
            Size size = game.Drawer2D.MeasureSize( ref args );

            int xOffset = Math.Max( size.Width, DesiredMaxWidth ) - size.Width;
            size.Width = Math.Max( size.Width, DesiredMaxWidth );
            int yOffset = Math.Max( size.Height, DesiredMaxHeight ) - size.Height;
            size.Height = Math.Max( size.Height, DesiredMaxHeight );
            Size baseSize = size;
            const int borderSize = 3; // 1 px for base border, 2 px for shadow, 1 px for offset text
            size.Width += borderSize; size.Height += borderSize;

            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                using( IDrawer2D drawer = game.Drawer2D ) {
                    drawer.SetBitmap( bmp );
                    drawer.DrawRoundedRect( shadowCol, 3, IDrawer2D.Offset, IDrawer2D.Offset,
                                           baseSize.Width, baseSize.Height );
                    drawer.DrawRoundedRect( boxCol, 3, 0, 0, baseSize.Width, baseSize.Height );

                    args.SkipPartsCheck = true;
                    drawer.DrawText( ref args, 1 + xOffset / 2, 1 + yOffset / 2 );
                    texture = drawer.Make2DTexture( bmp, size, 0, 0 );
                }
            }
        }
コード例 #21
0
        public void SetText( string value )
        {
            chatInputText.Append( 0, value );
            DrawTextArgs args = new DrawTextArgs( value, font, false );
            Size textSize = game.Drawer2D.MeasureSize( ref args );
            Size size = new Size( Math.Max( textSize.Width, DesiredMaxWidth ),
                                 Math.Max( textSize.Height, DesiredMaxHeight ) );

            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
                using( IDrawer2D drawer = game.Drawer2D ) {
                    drawer.SetBitmap( bmp );
                    drawer.DrawRect( backColour, 0, 0, size.Width, size.Height );
                    args.SkipPartsCheck = true;
                    drawer.DrawText( ref args, 0, 0 );

                    args.Text = Validator.Range;
                    args.SkipPartsCheck = false;
                    Size hintSize = drawer.MeasureSize( ref args );

                    args.SkipPartsCheck = true;
                    int hintX = size.Width - hintSize.Width;
                    if( textSize.Width < hintX )
                        drawer.DrawText( ref args, hintX, 0 );
                    chatInputTexture = drawer.Make2DTexture( bmp, size, 0, 0 );
                }
            }

            X = CalcOffset( game.Width, size.Width, XOffset, HorizontalAnchor );
            Y = CalcOffset( game.Height, size.Height, YOffset, VerticalAnchor );
            chatCaretTexture.X1 = chatInputTexture.X1 = X;
            chatCaretTexture.X1 += textSize.Width;
            chatCaretTexture.Y1 = chatInputTexture.Y1 = Y;
            chatCaretTexture.Y1 = (Y + size.Height) - chatCaretTexture.Height;
            Width = size.Width;
            Height = size.Height;
        }
コード例 #22
0
 public void SetText( string text )
 {
     graphicsApi.DeleteTexture( ref texture );
     Text = text;
     if( String.IsNullOrEmpty( text ) ) {
         texture = new Texture();
         Height = defaultHeight;
     } else {
         MakeTexture( text );
         X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalAnchor );
         Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalAnchor );
         Height = texture.Height;
     }
     Width = texture.Width;
 }
コード例 #23
0
        public void ReducePadding( ref Texture tex, int point, int scale )
        {
            if( !UseBitmappedChat ) return;
            point = AdjTextSize( point );

            int padding = (tex.Height - point) / scale;
            float vAdj = (float)padding / Utils.NextPowerOf2( tex.Height );
            tex.V1 += vAdj; tex.V2 -= vAdj;
            tex.Height -= padding * 2;
        }
コード例 #24
0
        void DrawString()
        {
            int totalHeight = 0;
            for( int i = 0; i < lines; i++ )
                totalHeight += sizes[i].Height;
            Size size = new Size( maxWidth, totalHeight );

            int realHeight = 0;
            using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) )
                using( IDrawer2D drawer = game.Drawer2D )
            {
                drawer.SetBitmap( bmp );
                DrawTextArgs args = new DrawTextArgs( null, font, true );

                for( int i = 0; i < parts.Length; i++ ) {
                    if( parts[i] == null ) break;
                    args.Text = parts[i];

                    drawer.DrawChatText( ref args, 0, realHeight );
                    realHeight += sizes[i].Height;
                }
                inputTex = drawer.Make2DTexture( bmp, size, 10, 0 );
            }

            Height = realHeight == 0 ? defaultHeight : realHeight;
            Y = game.Height - Height - YOffset;
            inputTex.Y1 = Y;
            caretTex.Y1 += Y;
            Width = size.Width;
        }