TimeRulerLibrary.Layout.Place C# (CSharp) Method

Place() public method

Layouting specified region
public Place ( Rectangle region, float horizontalMargin, float verticalMargine, Alignment alignment ) : Rectangle
region Microsoft.Xna.Framework.Rectangle placing rectangle
horizontalMargin float
verticalMargine float
alignment Alignment
return Microsoft.Xna.Framework.Rectangle
        public Rectangle Place( Rectangle region, float horizontalMargin,
                                            float verticalMargine, Alignment alignment )
        {
            // Horizontal layout.
            if ( ( alignment & Alignment.Left ) != 0 )
            {
                region.X = ClientArea.X + (int)( ClientArea.Width * horizontalMargin );
            }
            else if ( ( alignment & Alignment.Right ) != 0 )
            {
                region.X = ClientArea.X +
                            (int)( ClientArea.Width * ( 1.0f - horizontalMargin ) ) -
                            region.Width;
            }
            else if ( ( alignment & Alignment.HorizontalCenter ) != 0 )
            {
                region.X = ClientArea.X + ( ClientArea.Width - region.Width ) / 2 +
                            (int)( horizontalMargin * ClientArea.Width );
            }
            else
            {
                // Don't do layout.
            }

            // Vertical layout.
            if ( ( alignment & Alignment.Top ) != 0 )
            {
                region.Y = ClientArea.Y + (int)( ClientArea.Height * verticalMargine );
            }
            else if ( ( alignment & Alignment.Bottom ) != 0 )
            {
                region.Y = ClientArea.Y +
                            (int)( ClientArea.Height * ( 1.0f - verticalMargine ) ) -
                            region.Height;
            }
            else if ( ( alignment & Alignment.VerticalCenter ) != 0 )
            {
                region.Y = ClientArea.Y + ( ClientArea.Height - region.Height ) / 2 +
                            (int)( verticalMargine * ClientArea.Height );
            }
            else
            {
                // Don't do layout.
            }

            // Make sure layout region is in the safe area.
            if ( region.Left < SafeArea.Left )
                region.X = SafeArea.Left;

            if ( region.Right > SafeArea.Right )
                region.X = SafeArea.Right - region.Width;

            if ( region.Top < SafeArea.Top )
                region.Y = SafeArea.Top;

            if ( region.Bottom > SafeArea.Bottom )
                region.Y = SafeArea.Bottom - region.Height;

            return region;
        }

Same methods

Layout::Place ( Vector2 size, float horizontalMargin, float verticalMargine, Alignment alignment ) : Vector2

Usage Example

Exemplo n.º 1
0
        public override void Draw(GameTime gameTime)
        {
            sampleFrames++;

            SpriteBatch spriteBatch = debugManager.SpriteBatch;
            SpriteFont  font        = debugManager.DebugFont;

            // Compute size of borader area.
            Vector2   size = font.MeasureString("X");
            Rectangle rc   =
                new Rectangle(0, 0, (int)(size.X * 14f), (int)(size.Y + size.Y * 1.3f));

            Layout layout = new Layout(spriteBatch.GraphicsDevice.Viewport);

            rc = layout.Place(rc, 0.01f, 0.01f, Alignment.TopLeft);

            // Place FPS string in borader area.
            size = font.MeasureString(stringBuilder);
            layout.ClientArea = rc;
            Vector2 pos = layout.Place(size, 0, 0.1f, Alignment.Center);

            // Draw
            spriteBatch.Begin();
            spriteBatch.Draw(debugManager.WhiteTexture, rc, new Color(0, 0, 0, 128));
            spriteBatch.DrawString(font, stringBuilder, pos, Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
All Usage Examples Of TimeRulerLibrary.Layout::Place