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);
}
}
}