MonoGameUi.Textbox.OnDrawContent C# (CSharp) Method

OnDrawContent() protected method

Malt den Content des Controls
protected OnDrawContent ( SpriteBatch batch, Rectangle area, GameTime gameTime, float alpha ) : void
batch Microsoft.Xna.Framework.Graphics.SpriteBatch Spritebatch
area Microsoft.Xna.Framework.Rectangle Bereich für den Content in absoluten Koordinaten
gameTime Microsoft.Xna.Framework.GameTime GameTime
alpha float Die Transparenz des Controls.
return void
        protected override void OnDrawContent(SpriteBatch batch, Rectangle area, GameTime gameTime, float alpha)
        {
            if (CursorPosition > Text.Length)
                CursorPosition = Text.Length;
            if (SelectionStart > Text.Length)
                SelectionStart = CursorPosition;
            // Selektion
            if (SelectionStart != CursorPosition)
            {
                int from = Math.Min(SelectionStart, CursorPosition);
                int to = Math.Max(SelectionStart, CursorPosition);
                var selectFrom = Font.MeasureString(Text.Substring(0, from));
                var selectTo = Font.MeasureString(Text.Substring(from, to - from));
                batch.Draw(Skin.Pix, new Rectangle(area.X + (int)selectFrom.X, area.Y, (int)selectTo.X, (int)selectTo.Y), Color.LightBlue);
            }

            base.OnDrawContent(batch, area, gameTime, alpha);

            // Cursor (wenn Fokus)
            if (Focused == TreeState.Active)
            {
                if ((int)gameTime.TotalGameTime.TotalSeconds % 2 == 0)
                {
                    var selectionSize = Font.MeasureString(Text.Substring(0, CursorPosition));
                    batch.Draw(Skin.Pix, new Rectangle(area.X + (int)selectionSize.X, area.Y, 1, Font.LineSpacing), TextColor);
                }
            }
        }